mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
storage: add newBackend and newBatchTx
This is for ease of testing.
This commit is contained in:
parent
d2cb732c7b
commit
4b9b0cbcc1
@ -27,6 +27,10 @@ type backend struct {
|
||||
}
|
||||
|
||||
func New(path string, d time.Duration, limit int) Backend {
|
||||
return newBackend(path, d, limit)
|
||||
}
|
||||
|
||||
func newBackend(path string, d time.Duration, limit int) *backend {
|
||||
db, err := bolt.Open(path, 0600, nil)
|
||||
if err != nil {
|
||||
log.Panicf("backend: cannot open database at %s (%v)", path, err)
|
||||
@ -37,13 +41,11 @@ func New(path string, d time.Duration, limit int) Backend {
|
||||
|
||||
batchInterval: d,
|
||||
batchLimit: limit,
|
||||
batchTx: &batchTx{},
|
||||
|
||||
stopc: make(chan struct{}),
|
||||
donec: make(chan struct{}),
|
||||
}
|
||||
b.batchTx.backend = b
|
||||
b.batchTx.Commit()
|
||||
b.batchTx = newBatchTx(b)
|
||||
go b.run()
|
||||
return b
|
||||
}
|
||||
|
@ -26,6 +26,12 @@ type batchTx struct {
|
||||
pending int
|
||||
}
|
||||
|
||||
func newBatchTx(backend *backend) *batchTx {
|
||||
tx := &batchTx{backend: backend}
|
||||
tx.Commit()
|
||||
return tx
|
||||
}
|
||||
|
||||
func (t *batchTx) UnsafeCreateBucket(name []byte) {
|
||||
_, err := t.tx.CreateBucket(name)
|
||||
if err != nil && err != bolt.ErrBucketExists {
|
||||
|
Loading…
x
Reference in New Issue
Block a user