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 {
|
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)
|
db, err := bolt.Open(path, 0600, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicf("backend: cannot open database at %s (%v)", path, err)
|
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,
|
batchInterval: d,
|
||||||
batchLimit: limit,
|
batchLimit: limit,
|
||||||
batchTx: &batchTx{},
|
|
||||||
|
|
||||||
stopc: make(chan struct{}),
|
stopc: make(chan struct{}),
|
||||||
donec: make(chan struct{}),
|
donec: make(chan struct{}),
|
||||||
}
|
}
|
||||||
b.batchTx.backend = b
|
b.batchTx = newBatchTx(b)
|
||||||
b.batchTx.Commit()
|
|
||||||
go b.run()
|
go b.run()
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,12 @@ type batchTx struct {
|
|||||||
pending int
|
pending int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newBatchTx(backend *backend) *batchTx {
|
||||||
|
tx := &batchTx{backend: backend}
|
||||||
|
tx.Commit()
|
||||||
|
return tx
|
||||||
|
}
|
||||||
|
|
||||||
func (t *batchTx) UnsafeCreateBucket(name []byte) {
|
func (t *batchTx) UnsafeCreateBucket(name []byte) {
|
||||||
_, err := t.tx.CreateBucket(name)
|
_, err := t.tx.CreateBucket(name)
|
||||||
if err != nil && err != bolt.ErrBucketExists {
|
if err != nil && err != bolt.ErrBucketExists {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user