@@ -93,7 +93,7 @@ func (lk *lockedKeys) all() []uint64 {
93
93
// DB provides the various functions required to interact with Badger.
94
94
// DB is thread-safe.
95
95
type DB struct {
96
- sync.RWMutex // Guards list of inmemory tables, not individual reads and writes.
96
+ lock sync.RWMutex // Guards list of inmemory tables, not individual reads and writes.
97
97
98
98
dirLockGuard * directoryLockGuard
99
99
// nil if Dir and ValueDir are the same
@@ -432,15 +432,15 @@ func (db *DB) MaxVersion() uint64 {
432
432
maxVersion = a
433
433
}
434
434
}
435
- db .Lock ()
435
+ db .lock . Lock ()
436
436
// In read only mode, we do not create new mem table.
437
437
if ! db .opt .ReadOnly {
438
438
update (db .mt .maxVersion )
439
439
}
440
440
for _ , mt := range db .imm {
441
441
update (mt .maxVersion )
442
442
}
443
- db .Unlock ()
443
+ db .lock . Unlock ()
444
444
for _ , ti := range db .Tables () {
445
445
update (ti .MaxVersion )
446
446
}
@@ -582,8 +582,8 @@ func (db *DB) close() (err error) {
582
582
db .opt .Debugf ("Flushing memtable" )
583
583
for {
584
584
pushedFlushTask := func () bool {
585
- db .Lock ()
586
- defer db .Unlock ()
585
+ db .lock . Lock ()
586
+ defer db .lock . Unlock ()
587
587
y .AssertTrue (db .mt != nil )
588
588
select {
589
589
case db .flushChan <- flushTask {mt : db .mt }:
@@ -689,8 +689,8 @@ func (db *DB) Sync() error {
689
689
690
690
// getMemtables returns the current memtables and get references.
691
691
func (db * DB ) getMemTables () ([]* memTable , func ()) {
692
- db .RLock ()
693
- defer db .RUnlock ()
692
+ db .lock . RLock ()
693
+ defer db .lock . RUnlock ()
694
694
695
695
var tables []* memTable
696
696
@@ -984,8 +984,8 @@ var errNoRoom = errors.New("No room for write")
984
984
// ensureRoomForWrite is always called serially.
985
985
func (db * DB ) ensureRoomForWrite () error {
986
986
var err error
987
- db .Lock ()
988
- defer db .Unlock ()
987
+ db .lock . Lock ()
988
+ defer db .lock . Unlock ()
989
989
990
990
y .AssertTrue (db .mt != nil ) // A nil mt indicates that DB is being closed.
991
991
if ! db .mt .isFull () {
@@ -1089,7 +1089,7 @@ func (db *DB) flushMemtable(lc *z.Closer) error {
1089
1089
err := db .handleFlushTask (ft )
1090
1090
if err == nil {
1091
1091
// Update s.imm. Need a lock.
1092
- db .Lock ()
1092
+ db .lock . Lock ()
1093
1093
// This is a single-threaded operation. ft.mt corresponds to the head of
1094
1094
// db.imm list. Once we flush it, we advance db.imm. The next ft.mt
1095
1095
// which would arrive here would match db.imm[0], because we acquire a
@@ -1098,7 +1098,7 @@ func (db *DB) flushMemtable(lc *z.Closer) error {
1098
1098
y .AssertTrue (ft .mt == db .imm [0 ])
1099
1099
db .imm = db .imm [1 :]
1100
1100
ft .mt .DecrRef () // Return memory.
1101
- db .Unlock ()
1101
+ db .lock . Unlock ()
1102
1102
1103
1103
break
1104
1104
}
@@ -1235,7 +1235,7 @@ func (db *DB) Size() (lsm, vlog int64) {
1235
1235
1236
1236
// Sequence represents a Badger sequence.
1237
1237
type Sequence struct {
1238
- sync.Mutex
1238
+ lock sync.Mutex
1239
1239
db * DB
1240
1240
key []byte
1241
1241
next uint64
@@ -1246,8 +1246,8 @@ type Sequence struct {
1246
1246
// Next would return the next integer in the sequence, updating the lease by running a transaction
1247
1247
// if needed.
1248
1248
func (seq * Sequence ) Next () (uint64 , error ) {
1249
- seq .Lock ()
1250
- defer seq .Unlock ()
1249
+ seq .lock . Lock ()
1250
+ defer seq .lock . Unlock ()
1251
1251
if seq .next >= seq .leased {
1252
1252
if err := seq .updateLease (); err != nil {
1253
1253
return 0 , err
@@ -1262,8 +1262,8 @@ func (seq *Sequence) Next() (uint64, error) {
1262
1262
// before closing the associated DB. However it is valid to use the sequence after
1263
1263
// it was released, causing a new lease with full bandwidth.
1264
1264
func (seq * Sequence ) Release () error {
1265
- seq .Lock ()
1266
- defer seq .Unlock ()
1265
+ seq .lock . Lock ()
1266
+ defer seq .lock . Unlock ()
1267
1267
err := seq .db .Update (func (txn * Txn ) error {
1268
1268
item , err := txn .Get (seq .key )
1269
1269
if err != nil {
@@ -1425,8 +1425,8 @@ func (db *DB) KeySplits(prefix []byte) []string {
1425
1425
_ = iter .Close ()
1426
1426
}
1427
1427
1428
- db .Lock ()
1429
- defer db .Unlock ()
1428
+ db .lock . Lock ()
1429
+ defer db .lock . Unlock ()
1430
1430
var memTables []* memTable
1431
1431
memTables = append (memTables , db .imm ... )
1432
1432
for _ , mt := range memTables {
@@ -1660,8 +1660,8 @@ func (db *DB) dropAll() (func(), error) {
1660
1660
f ()
1661
1661
}
1662
1662
// Block all foreign interactions with memory tables.
1663
- db .Lock ()
1664
- defer db .Unlock ()
1663
+ db .lock . Lock ()
1664
+ defer db .lock . Unlock ()
1665
1665
1666
1666
// Remove inmemory tables. Calling DecrRef for safety. Not sure if they're absolutely needed.
1667
1667
db .mt .DecrRef ()
@@ -1724,8 +1724,8 @@ func (db *DB) DropPrefix(prefixes ...[]byte) error {
1724
1724
return nil
1725
1725
}
1726
1726
// Block all foreign interactions with memory tables.
1727
- db .Lock ()
1728
- defer db .Unlock ()
1727
+ db .lock . Lock ()
1728
+ defer db .lock . Unlock ()
1729
1729
1730
1730
db .imm = append (db .imm , db .mt )
1731
1731
for _ , memtable := range db .imm {
0 commit comments