From 2e900c3047552859e1917bed75b955ac97f31808 Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Sat, 13 Apr 2024 13:56:56 +0100 Subject: [PATCH] Enhance the etcd-dump-db: reuse revision in package mvcc Signed-off-by: Benjamin Wang --- tools/etcd-dump-db/backend.go | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/tools/etcd-dump-db/backend.go b/tools/etcd-dump-db/backend.go index 5c9df5e42e0..6d64c005b75 100644 --- a/tools/etcd-dump-db/backend.go +++ b/tools/etcd-dump-db/backend.go @@ -26,6 +26,7 @@ import ( "go.etcd.io/etcd/api/v3/mvccpb" "go.etcd.io/etcd/server/v3/lease/leasepb" "go.etcd.io/etcd/server/v3/storage/backend" + "go.etcd.io/etcd/server/v3/storage/mvcc" "go.etcd.io/etcd/server/v3/storage/schema" ) @@ -63,24 +64,12 @@ var decoders = map[string]decoder{ "meta": metaDecoder, } -type revision struct { - main int64 - sub int64 -} - -func bytesToRev(bytes []byte) revision { - return revision{ - main: int64(binary.BigEndian.Uint64(bytes[0:8])), - sub: int64(binary.BigEndian.Uint64(bytes[9:])), - } -} - func defaultDecoder(k, v []byte) { fmt.Printf("key=%q, value=%q\n", k, v) } func keyDecoder(k, v []byte) { - rev := bytesToRev(k) + rev := mvcc.BytesToBucketKey(k) var kv mvccpb.KeyValue if err := kv.Unmarshal(v); err != nil { panic(err) @@ -135,7 +124,7 @@ func metaDecoder(k, v []byte) { if string(k) == string(schema.MetaConsistentIndexKeyName) || string(k) == string(schema.MetaTermKeyName) { fmt.Printf("key=%q, value=%v\n", k, binary.BigEndian.Uint64(v)) } else if string(k) == string(schema.ScheduledCompactKeyName) || string(k) == string(schema.FinishedCompactKeyName) { - rev := bytesToRev(v) + rev := mvcc.BytesToRev(v) fmt.Printf("key=%q, value=%v\n", k, rev) } else { defaultDecoder(k, v)