Skip to content

Commit

Permalink
Improve snapshot status
Browse files Browse the repository at this point in the history
Signed-off-by: Cenk Alti <cenkalti@gmail.com>
  • Loading branch information
cenkalti committed May 30, 2023
1 parent bd5d0a5 commit d634c55
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 7 additions & 3 deletions etcdutl/snapshot/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@ package snapshot

import (
"encoding/binary"
"fmt"
)

type revision struct {
main int64
sub int64
}

func bytesToRev(bytes []byte) revision {
func bytesToRev(bytes []byte) (revision, error) {
if len(bytes) != 17 {
return revision{}, fmt.Errorf("invalid revision size: %d, expected size is 17 (2 * size(int64) + delimiter)", len(bytes))
}
return revision{
main: int64(binary.BigEndian.Uint64(bytes[0:8])),
sub: int64(binary.BigEndian.Uint64(bytes[9:])),
}
sub: int64(binary.BigEndian.Uint64(bytes[9:17])),
}, nil
}
12 changes: 11 additions & 1 deletion etcdutl/snapshot/v3_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

bolt "go.etcd.io/bbolt"
"go.etcd.io/etcd/api/v3/etcdserverpb"
"go.etcd.io/etcd/api/v3/mvccpb"
"go.etcd.io/etcd/client/pkg/v3/fileutil"
"go.etcd.io/etcd/client/pkg/v3/types"
clientv3 "go.etcd.io/etcd/client/v3"
Expand Down Expand Up @@ -138,6 +139,7 @@ func (s *v3Manager) Status(dbPath string) (ds Status, err error) {
if v != nil {
ds.Version = v.String()
}
var kv mvccpb.KeyValue
c := tx.Cursor()
for next, _ := c.First(); next != nil; next, _ = c.Next() {
b := tx.Bucket(next)
Expand All @@ -156,8 +158,16 @@ func (s *v3Manager) Status(dbPath string) (ds Status, err error) {
return fmt.Errorf("cannot write to bucket %s", err.Error())
}
if iskeyb {
rev := bytesToRev(k)
rev, err := bytesToRev(k)
if err != nil {
return fmt.Errorf("cannot parse revision key : %s", err.Error())
}
ds.Revision = rev.main

err = kv.Unmarshal(v)
if err != nil {
return fmt.Errorf("cannot unmarshal value : %s", err.Error())
}
}
ds.TotalKey++
return nil
Expand Down

0 comments on commit d634c55

Please sign in to comment.