lib/db: Refactor to use global list by version (fixes #6372) (#6638)

Group the global list of files by version, instead of having one flat list for all devices. This removes lots of duplicate protocol.Vectors.

Co-authored-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
Simon Frei
2020-05-30 09:50:23 +02:00
committed by GitHub
co-authored by Jakob Borg
parent 1eea076f5c
commit 1f8e6c55f6
21 changed files with 1540 additions and 504 deletions
+27 -2
View File
@@ -23,6 +23,31 @@ const (
Version13HelloMagic uint32 = 0x9F79BC40 // old
)
// FileIntf is the set of methods implemented by both FileInfo and
// db.FileInfoTruncated.
type FileIntf interface {
FileSize() int64
FileName() string
FileLocalFlags() uint32
IsDeleted() bool
IsInvalid() bool
IsIgnored() bool
IsUnsupported() bool
MustRescan() bool
IsReceiveOnlyChanged() bool
IsDirectory() bool
IsSymlink() bool
ShouldConflict() bool
HasPermissionBits() bool
SequenceNo() int64
BlockSize() int
FileVersion() Vector
FileType() FileInfoType
FilePermissions() uint32
FileModifiedBy() ShortID
ModTime() time.Time
}
func (m Hello) Magic() uint32 {
return HelloMessageMagic
}
@@ -139,7 +164,7 @@ func (f FileInfo) FileModifiedBy() ShortID {
// WinsConflict returns true if "f" is the one to choose when it is in
// conflict with "other".
func (f FileInfo) WinsConflict(other FileInfo) bool {
func WinsConflict(f, other FileIntf) bool {
// If only one of the files is invalid, that one loses.
if f.IsInvalid() != other.IsInvalid() {
return !f.IsInvalid()
@@ -164,7 +189,7 @@ func (f FileInfo) WinsConflict(other FileInfo) bool {
// The modification times were equal. Use the device ID in the version
// vector as tie breaker.
return f.Version.Compare(other.Version) == ConcurrentGreater
return f.FileVersion().Compare(other.FileVersion()) == ConcurrentGreater
}
func (f FileInfo) IsEmpty() bool {
+2 -2
View File
@@ -14,10 +14,10 @@ func TestWinsConflict(t *testing.T) {
}
for _, tc := range testcases {
if !tc[0].WinsConflict(tc[1]) {
if !WinsConflict(tc[0], tc[1]) {
t.Errorf("%v should win over %v", tc[0], tc[1])
}
if tc[1].WinsConflict(tc[0]) {
if WinsConflict(tc[1], tc[0]) {
t.Errorf("%v should not win over %v", tc[1], tc[0])
}
}