lib/db: Refactor away the large genericReplace thing
This removes a significant, complex chunk of database code. The "replace" operation walked both the old and new in lockstep and made the relevant changes to make the new situation correct. But since delta indexes we pretty much never need this - we just used replace to drop the existing data and start over. This makes that explicit and removes the complexity. (This is one of those things that would be annoying to make case insensitive, while the actual "drop and then insert" that we do is easier.) This is fairly well unit tested... The one change to the tests is to cover the fact that previously replace with something identical didn't bump the sequence number, while obviously removing everything and re-inserting does. This is not behavior we depend on anywhere. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4500 LGTM: imsodin, AudriusButkevicius
This commit is contained in:
committed by
Audrius Butkevicius
parent
57d5dfa80c
commit
d7d45d8092
@@ -206,7 +206,7 @@ func (m *Model) startFolderLocked(folder string) config.FolderType {
|
||||
for _, available := range fs.ListDevices() {
|
||||
if _, ok := expected[available]; !ok {
|
||||
l.Debugln("dropping", folder, "state for", available)
|
||||
fs.Replace(available, nil)
|
||||
fs.Drop(available)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -814,7 +814,8 @@ func (m *Model) Index(deviceID protocol.DeviceID, folder string, fs []protocol.F
|
||||
m.deviceDownloads[deviceID].Update(folder, makeForgetUpdate(fs))
|
||||
m.pmut.RUnlock()
|
||||
|
||||
files.Replace(deviceID, fs)
|
||||
files.Drop(deviceID)
|
||||
files.Update(deviceID, fs)
|
||||
|
||||
events.Default.Log(events.RemoteIndexUpdated, map[string]interface{}{
|
||||
"device": deviceID.String(),
|
||||
@@ -980,7 +981,7 @@ func (m *Model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterCon
|
||||
// do not support delta indexes and we should clear any
|
||||
// information we have from them before accepting their
|
||||
// index, which will presumably be a full index.
|
||||
fs.Replace(deviceID, nil)
|
||||
fs.Drop(deviceID)
|
||||
} else if dev.IndexID != theirIndexID {
|
||||
// The index ID we have on file is not what they're
|
||||
// announcing. They must have reset their database and
|
||||
@@ -988,7 +989,7 @@ func (m *Model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterCon
|
||||
// information we have and remember this new index ID
|
||||
// instead.
|
||||
l.Infof("Device %v folder %s has a new index ID (%v)", deviceID, folder.Description(), dev.IndexID)
|
||||
fs.Replace(deviceID, nil)
|
||||
fs.Drop(deviceID)
|
||||
fs.SetIndexID(deviceID, dev.IndexID)
|
||||
} else {
|
||||
// They're sending a recognized index ID and will most
|
||||
|
||||
@@ -2084,8 +2084,10 @@ func TestIndexesForUnknownDevicesDropped(t *testing.T) {
|
||||
dbi := db.OpenMemory()
|
||||
|
||||
files := db.NewFileSet("default", defaultFs, dbi)
|
||||
files.Replace(device1, genFiles(1))
|
||||
files.Replace(device2, genFiles(1))
|
||||
files.Drop(device1)
|
||||
files.Update(device1, genFiles(1))
|
||||
files.Drop(device2)
|
||||
files.Update(device2, genFiles(1))
|
||||
|
||||
if len(files.ListDevices()) != 2 {
|
||||
t.Error("expected two devices")
|
||||
|
||||
Reference in New Issue
Block a user