From b8a5e1a244affe39b831146a58c474a1fc4bfff8 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Mon, 3 Feb 2020 09:18:21 +0100 Subject: [PATCH] cmd/stindex: Print missing sequence ranges concisely --- cmd/stindex/idxck.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/cmd/stindex/idxck.go b/cmd/stindex/idxck.go index 1d24bbc9e..7defbe2ae 100644 --- a/cmd/stindex/idxck.go +++ b/cmd/stindex/idxck.go @@ -11,6 +11,7 @@ import ( "encoding/binary" "fmt" "log" + "sort" "github.com/syncthing/syncthing/lib/db" "github.com/syncthing/syncthing/lib/db/backend" @@ -114,6 +115,7 @@ func idxck(ldb backend.Backend) (success bool) { return } + var missingSeq []sequenceKey for fk, fi := range fileInfos { if fk.name != fi.Name { fmt.Printf("Mismatching FileInfo name, %q (key) != %q (actual)\n", fk.name, fi.Name) @@ -132,9 +134,11 @@ func idxck(ldb backend.Backend) (success bool) { } if fk.device == localDeviceKey { - name, ok := sequences[sequenceKey{fk.folder, uint64(fi.Sequence)}] + sk := sequenceKey{fk.folder, uint64(fi.Sequence)} + name, ok := sequences[sk] if !ok { fmt.Printf("Sequence entry missing for FileInfo %q, folder %q, seq %d\n", fi.Name, folder, fi.Sequence) + missingSeq = append(missingSeq, sk) success = false continue } @@ -155,6 +159,31 @@ func idxck(ldb backend.Backend) (success bool) { } } + // Aggregate the ranges of missing sequence entries, print them + + sort.Slice(missingSeq, func(a, b int) bool { + if missingSeq[a].folder != missingSeq[b].folder { + return missingSeq[a].folder < missingSeq[b].folder + } + return missingSeq[a].sequence < missingSeq[b].sequence + }) + + var folder uint32 + var startSeq, prevSeq uint64 + for _, sk := range missingSeq { + if folder != sk.folder || sk.sequence != prevSeq+1 { + if folder != 0 { + fmt.Printf("Folder %d missing %d sequence entries: #%d - #%d\n", folder, prevSeq-startSeq+1, startSeq, prevSeq) + } + startSeq = sk.sequence + folder = sk.folder + } + prevSeq = sk.sequence + } + if folder != 0 { + fmt.Printf("Folder %d missing %d sequence entries: #%d - #%d\n", folder, prevSeq-startSeq+1, startSeq, prevSeq) + } + for gk, vl := range globals { folder := folders[gk.folder] if folder == "" {