From 9cef2831513a7137975e4874d4447f1f11543e65 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Fri, 31 Jan 2020 08:27:20 +0100 Subject: [PATCH] cmd/stindex: Teach it about new key types --- cmd/stindex/dump.go | 25 +++++++++++++++++++++++++ cmd/stindex/idxck.go | 20 ++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/cmd/stindex/dump.go b/cmd/stindex/dump.go index e997678f9..fee98b3f7 100644 --- a/cmd/stindex/dump.go +++ b/cmd/stindex/dump.go @@ -80,6 +80,31 @@ func dump(ldb backend.Backend) { fmt.Printf("[deviceidx] K:%d V:%s\n", key, dev) } + case db.KeyTypeIndexID: + device := binary.BigEndian.Uint32(it.Key()[1:]) + folder := binary.BigEndian.Uint32(it.Key()[5:]) + fmt.Printf("[indexid] D:%d F:%d I:%x\n", device, folder, it.Value()) + + case db.KeyTypeFolderMeta: + folder := binary.BigEndian.Uint32(it.Key()[1:]) + fmt.Printf("[foldermeta] F:%d V:%x\n", folder, it.Value()) + + case db.KeyTypeMiscData: + fmt.Printf("[miscdata] K:%q V:%q\n", it.Key()[1:], it.Value()) + + case db.KeyTypeSequence: + folder := binary.BigEndian.Uint32(it.Key()[1:]) + seq := binary.BigEndian.Uint64(it.Key()[5:]) + fmt.Printf("[sequence] F:%d S:%d V:%q\n", folder, seq, it.Value()) + + case db.KeyTypeNeed: + folder := binary.BigEndian.Uint32(it.Key()[1:]) + file := string(it.Key()[5:]) + fmt.Printf("[need] F:%d V:%q\n", folder, file) + + case db.KeyTypeBlockList: + fmt.Printf("[blocklist] H:%x\n", it.Key()[1:]) + default: fmt.Printf("[???]\n %x\n %x\n", it.Key(), it.Value()) } diff --git a/cmd/stindex/idxck.go b/cmd/stindex/idxck.go index 04ece2caa..1d24bbc9e 100644 --- a/cmd/stindex/idxck.go +++ b/cmd/stindex/idxck.go @@ -41,6 +41,8 @@ func idxck(ldb backend.Backend) (success bool) { globals := make(map[globalKey]db.VersionList) sequences := make(map[sequenceKey]string) needs := make(map[globalKey]struct{}) + blocklists := make(map[string]struct{}) + usedBlocklists := make(map[string]struct{}) var localDeviceKey uint32 success = true @@ -99,6 +101,10 @@ func idxck(ldb backend.Backend) (success bool) { folder := binary.BigEndian.Uint32(key[1:]) name := nulString(key[1+4:]) needs[globalKey{folder, name}] = struct{}{} + + case db.KeyTypeBlockList: + hash := string(key[1:]) + blocklists[hash] = struct{}{} } } @@ -137,6 +143,16 @@ func idxck(ldb backend.Backend) (success bool) { success = false } } + + if fi.BlocksHash != nil { + key := string(fi.BlocksHash) + if _, ok := blocklists[key]; !ok { + fmt.Printf("Missing block list for file %q, block list hash %x\n", fi.Name, fi.BlocksHash) + success = false + } else { + usedBlocklists[key] = struct{}{} + } + } } for gk, vl := range globals { @@ -229,6 +245,10 @@ func idxck(ldb backend.Backend) (success bool) { } } + if d := len(blocklists) - len(usedBlocklists); d > 0 { + fmt.Printf("%d block list entries out of %d needs GC\n", d, len(blocklists)) + } + return }