MCPcopy
hub / github.com/etcd-io/etcd / iterateBucket

Function iterateBucket

tools/etcd-dump-db/backend.go:134–168  ·  view source on GitHub ↗
(dbPath, bucket string, limit uint64, decode bool)

Source from the content-addressed store, hash-verified

132}
133
134func iterateBucket(dbPath, bucket string, limit uint64, decode bool) (err error) {
135 db, err := bolt.Open(dbPath, 0o600, &bolt.Options{Timeout: flockTimeout})
136 if err != nil {
137 return fmt.Errorf("failed to open bolt DB %w", err)
138 }
139 defer db.Close()
140
141 err = db.View(func(tx *bolt.Tx) error {
142 b := tx.Bucket([]byte(bucket))
143 if b == nil {
144 return fmt.Errorf("got nil bucket for %s", bucket)
145 }
146
147 c := b.Cursor()
148
149 // iterate in reverse order (use First() and Next() for ascending order)
150 for k, v := c.Last(); k != nil; k, v = c.Prev() {
151 // TODO: remove sensitive information
152 // (https://github.com/etcd-io/etcd/issues/7620)
153 if dec, ok := decoders[bucket]; decode && ok {
154 dec(k, v)
155 } else {
156 defaultDecoder(k, v)
157 }
158
159 limit--
160 if limit == 0 {
161 break
162 }
163 }
164
165 return nil
166 })
167 return err
168}
169
170func getHash(dbPath string) (hash uint32, err error) {
171 b := backend.NewDefaultBackend(zap.NewNop(), dbPath)

Callers 1

iterateBucketCommandFuncFunction · 0.85

Calls 4

defaultDecoderFunction · 0.85
OpenMethod · 0.80
ErrorfMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…