Skip to content

Commit

Permalink
Merge pull request #10268 from gyuho/dump-db
Browse files Browse the repository at this point in the history
tools/etcd-dump-db: add "--timeout" flag
  • Loading branch information
gyuho authored Nov 16, 2018
2 parents af893d3 + f8a513c commit bb25891
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tools/etcd-dump-db/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ func snapDir(dataDir string) string {
}

func getBuckets(dbPath string) (buckets []string, err error) {
db, derr := bolt.Open(dbPath, 0600, &bolt.Options{})
db, derr := bolt.Open(dbPath, 0600, &bolt.Options{Timeout: flockTimeout})
if derr != nil {
return nil, derr
return nil, fmt.Errorf("failed to open bolt DB %v", derr)
}
defer db.Close()

Expand Down Expand Up @@ -94,9 +94,9 @@ func leaseDecoder(k, v []byte) {
}

func iterateBucket(dbPath, bucket string, limit uint64, decode bool) (err error) {
db, derr := bolt.Open(dbPath, 0600, &bolt.Options{})
if derr != nil {
return derr
db, err := bolt.Open(dbPath, 0600, &bolt.Options{Timeout: flockTimeout})
if err != nil {
return fmt.Errorf("failed to open bolt DB %v", err)
}
defer db.Close()

Expand Down
3 changes: 3 additions & 0 deletions tools/etcd-dump-db/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/spf13/cobra"
)
Expand All @@ -46,10 +47,12 @@ var (
}
)

var flockTimeout time.Duration
var iterateBucketLimit uint64
var iterateBucketDecode bool

func init() {
rootCommand.PersistentFlags().DurationVar(&flockTimeout, "timeout", 10*time.Second, "time to wait to obtain a file lock on db file, 0 to block indefinitely")
iterateBucketCommand.PersistentFlags().Uint64Var(&iterateBucketLimit, "limit", 0, "max number of key-value pairs to iterate (0< to iterate all)")
iterateBucketCommand.PersistentFlags().BoolVar(&iterateBucketDecode, "decode", false, "true to decode Protocol Buffer encoded data")

Expand Down

0 comments on commit bb25891

Please sign in to comment.