mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
backedn: protect backend access with lock
This commit is contained in:
parent
4991cda202
commit
c0cf44f134
@ -201,6 +201,18 @@ func (b *backend) Commits() int64 {
|
||||
}
|
||||
|
||||
func (b *backend) Defrag() error {
|
||||
err := b.defrag()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// commit to update metadata like db.size
|
||||
b.batchTx.Commit()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *backend) defrag() error {
|
||||
// TODO: make this non-blocking?
|
||||
// lock batchTx to ensure nobody is using previous tx, and then
|
||||
// close previous ongoing tx.
|
||||
@ -251,8 +263,6 @@ func (b *backend) Defrag() error {
|
||||
if err != nil {
|
||||
log.Fatalf("backend: cannot begin tx (%s)", err)
|
||||
}
|
||||
// commit to update metadata like db.size
|
||||
b.batchTx.commit(false)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -160,6 +160,8 @@ func (t *batchTx) commit(stop bool) {
|
||||
// commit the last tx
|
||||
if t.tx != nil {
|
||||
if t.pending == 0 && !stop {
|
||||
t.backend.mu.RLock()
|
||||
defer t.backend.mu.RUnlock()
|
||||
atomic.StoreInt64(&t.backend.size, t.tx.Size())
|
||||
return
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user