enhance etcd-dump-db to display keys in meta more friendly
@@ -53,12 +53,14 @@ func getBuckets(dbPath string) (buckets []string, err error) {
type decoder func(k, v []byte)
+// key is the bucket name, and value is the function to decode K/V in the bucket.
var decoders = map[string]decoder{
"key": keyDecoder,
"lease": leaseDecoder,
"auth": authDecoder,
"authRoles": authRolesDecoder,
"authUsers": authUsersDecoder,
+ "meta": metaDecoder,
}
type revision struct {
@@ -73,6 +75,10 @@ func bytesToRev(bytes []byte) revision {
}
}
+func defaultDecoder(k, v []byte) {
+ fmt.Printf("key=%q, value=%q\n", k, v)
+}
+
func keyDecoder(k, v []byte) {
rev := bytesToRev(k)
var kv mvccpb.KeyValue
@@ -125,6 +131,14 @@ func authUsersDecoder(k, v []byte) {
fmt.Printf("user=%q, roles=%q, option=%v\n", user.Name, user.Roles, user.Options)
}
+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 {
+ defaultDecoder(k, v)
+ }
+}
+
func iterateBucket(dbPath, bucket string, limit uint64, decode bool) (err error) {
db, err := bolt.Open(dbPath, 0600, &bolt.Options{Timeout: flockTimeout})
if err != nil {
@@ -147,7 +161,7 @@ func iterateBucket(dbPath, bucket string, limit uint64, decode bool) (err error)
if dec, ok := decoders[bucket]; decode && ok {
dec(k, v)
} else {
- fmt.Printf("key=%q, value=%q\n", k, v)
+ defaultDecoder(k, v)
}
limit--
