@@ -26,11 +26,12 @@ import (
26
26
"strings"
27
27
"text/template"
28
28
29
- bolt "github.com/coreos/bbolt"
30
- "github.com/coreos/etcd/mvcc/mvccpb"
31
29
"github.com/etcd-io/auger/pkg/encoding"
32
30
"k8s.io/apimachinery/pkg/runtime"
33
31
"k8s.io/apimachinery/pkg/runtime/serializer"
32
+
33
+ bolt "go.etcd.io/bbolt"
34
+ "go.etcd.io/etcd/api/v3/mvccpb"
34
35
)
35
36
36
37
// See etcd/mvcc/kvstore.go:keyBucketName
@@ -150,13 +151,19 @@ type Checksum struct {
150
151
CompactRevision int64
151
152
}
152
153
154
+ func boltOpen (path string ) (* bolt.DB , error ) {
155
+ return bolt .Open (path , 0400 , & bolt.Options {
156
+ ReadOnly : true ,
157
+ })
158
+ }
159
+
153
160
// HashByRevision returns the checksum and revision. The checksum is of the live keyspace at a
154
161
// particular revision. It is equivalent to performing a range request of all key-value pairs can
155
162
// computing a hash of the data. If revision is 0, the latest revision is checksumed, else revision
156
163
// is checksumed. The resulting hash is consistent particular revision in the presence of
157
164
// compactions; so long as the revions itself has not been compacted, the hash never changes.
158
165
func HashByRevision (filename string , revision int64 ) (Checksum , error ) {
159
- db , err := bolt . Open (filename , 0400 , & bolt. Options {} )
166
+ db , err := boltOpen (filename )
160
167
if err != nil {
161
168
return Checksum {}, err
162
169
}
@@ -203,7 +210,7 @@ func getCompactRevision(db *bolt.DB) (int64, error) {
203
210
// ListKeySummaries returns a result set with all the provided filters and projections applied.
204
211
func ListKeySummaries (codecs serializer.CodecFactory , filename string , filters []Filter , proj * KeySummaryProjection , revision int64 ) ([]* KeySummary , error ) {
205
212
var err error
206
- db , err := bolt . Open (filename , 0400 , & bolt. Options {} )
213
+ db , err := boltOpen (filename )
207
214
if err != nil {
208
215
return nil , err
209
216
}
@@ -304,7 +311,7 @@ func sortKeySummaries(m map[string]*KeySummary) []*KeySummary {
304
311
305
312
// ListVersions lists all versions of a object with the given key.
306
313
func ListVersions (filename string , key string ) ([]int64 , error ) {
307
- db , err := bolt . Open (filename , 0400 , & bolt. Options {} )
314
+ db , err := boltOpen (filename )
308
315
if err != nil {
309
316
return nil , err
310
317
}
@@ -327,7 +334,7 @@ func ListVersions(filename string, key string) ([]int64, error) {
327
334
// GetValue scans the bucket of the bolt db file for a etcd v3 record with the given key and returns the value.
328
335
// Because bolt db files are indexed by revision
329
336
func GetValue (filename string , key string , version int64 ) ([]byte , error ) {
330
- db , err := bolt . Open (filename , 0400 , & bolt. Options {} )
337
+ db , err := boltOpen (filename )
331
338
if err != nil {
332
339
return nil , err
333
340
}
0 commit comments