Skip to content

Commit 4d7c11c

Browse files
committed
libnet: boltdb: remove PersistConnection
This parameter was used to tell the boltdb kvstore not to open/close the underlying boltdb db file before/after each get/put operation. Since d21d088, we've a single datastore instance shared by all components that need it. That commit set `PersistConnection=true`. We can now safely remove this param altogether, and remove all the code that was opening and closing the db file before and after each operation -- it's dead code! Signed-off-by: Albin Kerouanton <[email protected]>
1 parent 8070a9a commit 4d7c11c

3 files changed

Lines changed: 10 additions & 50 deletions

File tree

libnetwork/datastore/datastore.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ func DefaultScope(dataDir string) ScopeCfg {
9292
Config: &store.Config{
9393
Bucket: "libnetwork",
9494
ConnectionTimeout: time.Minute,
95-
PersistConnection: true,
9695
},
9796
},
9897
}

libnetwork/internal/kvstore/boltdb/boltdb.go

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ type BoltDB struct {
2929
dbIndex uint64
3030
path string
3131
timeout time.Duration
32-
// By default libkv opens and closes the bolt DB connection for every
33-
// get/put operation. This allows multiple apps to use a Bolt DB at the
34-
// same time.
35-
// PersistConnection flag provides an option to override ths behavior.
36-
// ie: open the connection in New and use it till Close is called.
37-
PersistConnection bool
3832
}
3933

4034
const (
@@ -53,15 +47,11 @@ func New(endpoint string, options *store.Config) (store.Store, error) {
5347
return nil, err
5448
}
5549

56-
var db *bolt.DB
57-
if options.PersistConnection {
58-
var err error
59-
db, err = bolt.Open(endpoint, filePerm, &bolt.Options{
60-
Timeout: options.ConnectionTimeout,
61-
})
62-
if err != nil {
63-
return nil, err
64-
}
50+
db, err := bolt.Open(endpoint, filePerm, &bolt.Options{
51+
Timeout: options.ConnectionTimeout,
52+
})
53+
if err != nil {
54+
return nil, err
6555
}
6656

6757
timeout := transientTimeout
@@ -70,38 +60,19 @@ func New(endpoint string, options *store.Config) (store.Store, error) {
7060
}
7161

7262
b := &BoltDB{
73-
client: db,
74-
path: endpoint,
75-
boltBucket: []byte(options.Bucket),
76-
timeout: timeout,
77-
PersistConnection: options.PersistConnection,
63+
client: db,
64+
path: endpoint,
65+
boltBucket: []byte(options.Bucket),
66+
timeout: timeout,
7867
}
7968

8069
return b, nil
8170
}
8271

83-
func (b *BoltDB) reset() {
84-
b.path = ""
85-
b.boltBucket = []byte{}
86-
}
87-
8872
func (b *BoltDB) getDBhandle() (*bolt.DB, error) {
89-
if !b.PersistConnection {
90-
db, err := bolt.Open(b.path, filePerm, &bolt.Options{Timeout: b.timeout})
91-
if err != nil {
92-
return nil, err
93-
}
94-
b.client = db
95-
}
9673
return b.client, nil
9774
}
9875

99-
func (b *BoltDB) releaseDBhandle() {
100-
if !b.PersistConnection {
101-
b.client.Close()
102-
}
103-
}
104-
10576
// Put the key, value pair. index number metadata is prepended to the value
10677
func (b *BoltDB) Put(key string, value []byte) error {
10778
b.mu.Lock()
@@ -111,7 +82,6 @@ func (b *BoltDB) Put(key string, value []byte) error {
11182
if err != nil {
11283
return err
11384
}
114-
defer b.releaseDBhandle()
11585

11686
return db.Update(func(tx *bolt.Tx) error {
11787
bucket, err := tx.CreateBucketIfNotExists(b.boltBucket)
@@ -137,7 +107,6 @@ func (b *BoltDB) Exists(key string) (bool, error) {
137107
if err != nil {
138108
return false, err
139109
}
140-
defer b.releaseDBhandle()
141110

142111
var exists bool
143112
err = db.View(func(tx *bolt.Tx) error {
@@ -167,7 +136,6 @@ func (b *BoltDB) List(keyPrefix string) ([]*store.KVPair, error) {
167136
if err != nil {
168137
return nil, err
169138
}
170-
defer b.releaseDBhandle()
171139

172140
var kv []*store.KVPair
173141
err = db.View(func(tx *bolt.Tx) error {
@@ -216,7 +184,6 @@ func (b *BoltDB) AtomicDelete(key string, previous *store.KVPair) error {
216184
if err != nil {
217185
return err
218186
}
219-
defer b.releaseDBhandle()
220187

221188
return db.Update(func(tx *bolt.Tx) error {
222189
bucket := tx.Bucket(b.boltBucket)
@@ -246,7 +213,6 @@ func (b *BoltDB) AtomicPut(key string, value []byte, previous *store.KVPair) (*s
246213
if err != nil {
247214
return nil, err
248215
}
249-
defer b.releaseDBhandle()
250216

251217
var dbIndex uint64
252218
dbval := make([]byte, libkvmetadatalen)
@@ -293,9 +259,5 @@ func (b *BoltDB) Close() {
293259
b.mu.Lock()
294260
defer b.mu.Unlock()
295261

296-
if !b.PersistConnection {
297-
b.reset()
298-
} else {
299-
b.client.Close()
300-
}
262+
b.client.Close()
301263
}

libnetwork/internal/kvstore/kvstore.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ var (
2828
type Config struct {
2929
ConnectionTimeout time.Duration
3030
Bucket string
31-
PersistConnection bool
3231
}
3332

3433
// Store represents the backend K/V storage

0 commit comments

Comments
 (0)