From 00be2bf18d94172729760db8519d8e6299036a53 Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Sun, 22 May 2016 10:16:09 +0000 Subject: [PATCH] lib/model: Track puller creation times (fixes #3145) GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3150 --- lib/model/progressemitter_test.go | 12 ++++++++++++ lib/model/rwfolder.go | 1 + lib/model/sentdownloadstate.go | 10 +++++++--- lib/model/sharedpullerstate.go | 1 + 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/model/progressemitter_test.go b/lib/model/progressemitter_test.go index bb20c2248..2cabc42ac 100644 --- a/lib/model/progressemitter_test.go +++ b/lib/model/progressemitter_test.go @@ -245,6 +245,18 @@ func TestSendDownloadProgressMessages(t *testing.T) { expect(1, state1, protocol.UpdateTypeAppend, v2, []int32{1, 2}, true) expectEmpty() + // Returns forget and append if sharedPullerState creation timer changes. + + state1.available = []int32{1} + state1.availableUpdated = tick() + state1.created = tick() + + p.sendDownloadProgressMessages() + + expect(0, state1, protocol.UpdateTypeForget, v2, nil, false) + expect(1, state1, protocol.UpdateTypeAppend, v2, []int32{1}, true) + expectEmpty() + // Sends an empty update if new file exists, but does not have any blocks yet. (To indicate that the old blocks are no longer available) state1.file.Version = v1 state1.available = nil diff --git a/lib/model/rwfolder.go b/lib/model/rwfolder.go index 01d4d38c7..5c991e521 100644 --- a/lib/model/rwfolder.go +++ b/lib/model/rwfolder.go @@ -1011,6 +1011,7 @@ func (f *rwFolder) handleFile(file protocol.FileInfo, copyChan chan<- copyBlocks version: curFile.Version, mut: sync.NewRWMutex(), sparse: f.allowSparse, + created: time.Now(), } l.Debugf("%v need file %s; copy %d, reused %v", f, file.Name, len(blocks), reused) diff --git a/lib/model/sentdownloadstate.go b/lib/model/sentdownloadstate.go index 9fd50b0bb..8d5a9b543 100644 --- a/lib/model/sentdownloadstate.go +++ b/lib/model/sentdownloadstate.go @@ -18,6 +18,7 @@ type sentFolderFileDownloadState struct { blockIndexes []int32 version protocol.Vector updated time.Time + created time.Time } // sentFolderDownloadState represents a state of what we've announced as available @@ -41,6 +42,7 @@ func (s *sentFolderDownloadState) update(pullers []*sharedPullerState) []protoco pullerBlockIndexes := puller.Available() pullerVersion := puller.file.Version pullerBlockIndexesUpdated := puller.AvailableUpdated() + pullerCreated := puller.created localFile, ok := s.files[name] @@ -52,6 +54,7 @@ func (s *sentFolderDownloadState) update(pullers []*sharedPullerState) []protoco blockIndexes: pullerBlockIndexes, updated: pullerBlockIndexesUpdated, version: pullerVersion, + created: pullerCreated, } updates = append(updates, protocol.FileDownloadProgressUpdate{ @@ -70,9 +73,9 @@ func (s *sentFolderDownloadState) update(pullers []*sharedPullerState) []protoco continue } - if !pullerVersion.Equal(localFile.version) { - // The version has changed, clean up whatever we had for the old - // file, and advertise the new file. + if !pullerVersion.Equal(localFile.version) || !pullerCreated.Equal(localFile.created) { + // The version has changed or the puller was reconstrcuted due to failure. + // Clean up whatever we had for the old file, and advertise the new file. updates = append(updates, protocol.FileDownloadProgressUpdate{ Name: name, Version: localFile.version, @@ -87,6 +90,7 @@ func (s *sentFolderDownloadState) update(pullers []*sharedPullerState) []protoco localFile.blockIndexes = pullerBlockIndexes localFile.updated = pullerBlockIndexesUpdated localFile.version = pullerVersion + localFile.created = pullerCreated continue } diff --git a/lib/model/sharedpullerstate.go b/lib/model/sharedpullerstate.go index eabcbd3e1..a36b6d42e 100644 --- a/lib/model/sharedpullerstate.go +++ b/lib/model/sharedpullerstate.go @@ -29,6 +29,7 @@ type sharedPullerState struct { ignorePerms bool version protocol.Vector // The current (old) version sparse bool + created time.Time // Mutable, must be locked for access err error // The first error we hit