mirror of https://github.com/tikv/client-go.git
unionstore: make lock earlier (#484)
Signed-off-by: xiongjiwei <xiongjiwei1996@outlook.com>
This commit is contained in:
parent
577843f1b9
commit
3984ffee09
|
|
@ -111,14 +111,15 @@ func (db *MemDB) Staging() int {
|
||||||
|
|
||||||
// Release publish all modifications in the latest staging buffer to upper level.
|
// Release publish all modifications in the latest staging buffer to upper level.
|
||||||
func (db *MemDB) Release(h int) {
|
func (db *MemDB) Release(h int) {
|
||||||
|
db.Lock()
|
||||||
|
defer db.Unlock()
|
||||||
|
|
||||||
if h != len(db.stages) {
|
if h != len(db.stages) {
|
||||||
// This should never happens in production environment.
|
// This should never happens in production environment.
|
||||||
// Use panic to make debug easier.
|
// Use panic to make debug easier.
|
||||||
panic("cannot release staging buffer")
|
panic("cannot release staging buffer")
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Lock()
|
|
||||||
defer db.Unlock()
|
|
||||||
if h == 1 {
|
if h == 1 {
|
||||||
tail := db.vlog.checkpoint()
|
tail := db.vlog.checkpoint()
|
||||||
if !db.stages[0].isSamePosition(&tail) {
|
if !db.stages[0].isSamePosition(&tail) {
|
||||||
|
|
@ -131,6 +132,9 @@ func (db *MemDB) Release(h int) {
|
||||||
// Cleanup cleanup the resources referenced by the StagingHandle.
|
// Cleanup cleanup the resources referenced by the StagingHandle.
|
||||||
// If the changes are not published by `Release`, they will be discarded.
|
// If the changes are not published by `Release`, they will be discarded.
|
||||||
func (db *MemDB) Cleanup(h int) {
|
func (db *MemDB) Cleanup(h int) {
|
||||||
|
db.Lock()
|
||||||
|
defer db.Unlock()
|
||||||
|
|
||||||
if h > len(db.stages) {
|
if h > len(db.stages) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -140,8 +144,6 @@ func (db *MemDB) Cleanup(h int) {
|
||||||
panic("cannot cleanup staging buffer")
|
panic("cannot cleanup staging buffer")
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Lock()
|
|
||||||
defer db.Unlock()
|
|
||||||
cp := &db.stages[h-1]
|
cp := &db.stages[h-1]
|
||||||
if !db.vlogInvalid {
|
if !db.vlogInvalid {
|
||||||
curr := db.vlog.checkpoint()
|
curr := db.vlog.checkpoint()
|
||||||
|
|
@ -294,6 +296,9 @@ func (db *MemDB) Dirty() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *MemDB) set(key []byte, value []byte, ops ...kv.FlagsOp) error {
|
func (db *MemDB) set(key []byte, value []byte, ops ...kv.FlagsOp) error {
|
||||||
|
db.Lock()
|
||||||
|
defer db.Unlock()
|
||||||
|
|
||||||
if db.vlogInvalid {
|
if db.vlogInvalid {
|
||||||
// panic for easier debugging.
|
// panic for easier debugging.
|
||||||
panic("vlog is resetted")
|
panic("vlog is resetted")
|
||||||
|
|
@ -308,9 +313,6 @@ func (db *MemDB) set(key []byte, value []byte, ops ...kv.FlagsOp) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Lock()
|
|
||||||
defer db.Unlock()
|
|
||||||
|
|
||||||
if len(db.stages) == 0 {
|
if len(db.stages) == 0 {
|
||||||
db.dirty = true
|
db.dirty = true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue