rename, fix wrong logic.

This commit is contained in:
Chris Lu 2021-08-14 21:46:34 -07:00
parent cb53802752
commit c34747c79d
8 changed files with 560 additions and 549 deletions

View file

@ -96,7 +96,7 @@ message ListEntriesResponse {
message RemoteEntry {
string storage_name = 1;
int64 local_mtime = 2;
int64 last_local_sync_ts_ms = 2;
string remote_e_tag = 3;
int64 remote_mtime = 4;
int64 remote_size = 5;

View file

@ -239,7 +239,7 @@ func shouldSendToRemote(entry *filer_pb.Entry) bool {
if entry.RemoteEntry == nil {
return true
}
if entry.RemoteEntry.LocalMtime < entry.Attributes.Mtime {
if entry.RemoteEntry.LastLocalSyncTsNs/1e9 < entry.Attributes.Mtime {
return true
}
return false

View file

@ -96,7 +96,7 @@ message ListEntriesResponse {
message RemoteEntry {
string storage_name = 1;
int64 local_mtime = 2;
int64 last_local_sync_ts_ns = 2;
string remote_e_tag = 3;
int64 remote_mtime = 4;
int64 remote_size = 5;

File diff suppressed because it is too large Load diff

View file

@ -153,7 +153,7 @@ func (fs *FilerServer) DownloadToLocal(ctx context.Context, req *filer_pb.Downlo
newEntry := entry.ShallowClone()
newEntry.Chunks = chunks
newEntry.Remote = proto.Clone(entry.Remote).(*filer_pb.RemoteEntry)
newEntry.Remote.LocalMtime = entry.Mtime.Unix()
newEntry.Remote.LastLocalSyncTsNs = time.Now().UnixNano()
// this skips meta data log events

View file

@ -118,7 +118,7 @@ func shouldCacheToLocal(entry *filer_pb.Entry) bool {
if entry.RemoteEntry == nil {
return false
}
if entry.RemoteEntry.LocalMtime < entry.Attributes.Mtime && entry.RemoteEntry.RemoteSize > 0 {
if entry.RemoteEntry.LastLocalSyncTsNs == 0 && entry.RemoteEntry.RemoteSize > 0 {
return true
}
return false
@ -131,7 +131,7 @@ func mayHaveCachedToLocal(entry *filer_pb.Entry) bool {
if entry.RemoteEntry == nil {
return false // should not uncache an entry that is not in remote
}
if entry.RemoteEntry.LocalMtime > 0 && len(entry.Chunks) > 0 {
if entry.RemoteEntry.LastLocalSyncTsNs > 0 && len(entry.Chunks) > 0 {
return true
}
return false

View file

@ -234,6 +234,16 @@ func (c *commandRemoteMount) saveMountMapping(commandEnv *CommandEnv, writer io.
return nil
}
// if an entry has synchronized metadata but has not synchronized content
// entry.Attributes.FileSize == entry.RemoteEntry.RemoteSize
// entry.Attributes.Mtime == entry.RemoteEntry.RemoteMtime
// entry.RemoteEntry.LastLocalSyncTsNs == 0
// if an entry has synchronized metadata but has synchronized content before
// entry.Attributes.FileSize == entry.RemoteEntry.RemoteSize
// entry.Attributes.Mtime == entry.RemoteEntry.RemoteMtime
// entry.RemoteEntry.LastLocalSyncTsNs > 0
// if an entry has synchronized metadata but has new updates
// entry.Attributes.Mtime * 1,000,000,000 > entry.RemoteEntry.LastLocalSyncTsNs
func doSaveRemoteEntry(client filer_pb.SeaweedFilerClient, localDir string, existingEntry *filer_pb.Entry, remoteEntry *filer_pb.RemoteEntry) error {
existingEntry.RemoteEntry = remoteEntry
existingEntry.Attributes.FileSize = uint64(remoteEntry.RemoteSize)

View file

@ -89,11 +89,11 @@ func (c *commandRemoteUncache) uncacheContentData(commandEnv *CommandEnv, writer
return true
}
if entry.RemoteEntry.LocalMtime < entry.Attributes.Mtime {
if entry.RemoteEntry.LastLocalSyncTsNs/1e9 < entry.Attributes.Mtime {
return true // should not uncache an entry that is not synchronized with remote
}
entry.RemoteEntry.LocalMtime = 0
entry.RemoteEntry.LastLocalSyncTsNs = 0
entry.Chunks = nil
println(dir, entry.Name)