Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
KANIOYH committed Sep 20, 2024
1 parent 1e66b30 commit c1ce11a
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func (db *DB) flushMemtable(table *memtable) {
sklIter := table.skl.NewIterator()
var deletedKeys [][]byte
var logRecords []*ValueLogRecord

// iterate all records in memtable, divide them into deleted keys and log records
// for every log record, we generate uuid.
for sklIter.SeekToFirst(); sklIter.Valid(); sklIter.Next() {
Expand All @@ -488,20 +488,20 @@ func (db *DB) flushMemtable(table *memtable) {
}
}
_ = sklIter.Close()

// write to value log, get the positions of keys
keyPos, err := db.vlog.writeBatch(logRecords)
if err != nil {
log.Println("vlog writeBatch failed:", err)
return
}

// sync the value log
if err = db.vlog.sync(); err != nil {
log.Println("vlog sync failed:", err)
return
}

// Add old key uuid into deprecatedtable, write all keys and positions to index.
var putMatchKeys []diskhash.MatchKeyFunc
if db.options.IndexType == Hash && len(keyPos) > 0 {
Expand All @@ -510,19 +510,19 @@ func (db *DB) flushMemtable(table *memtable) {
putMatchKeys[i] = MatchKeyFunc(db, keyPos[i].key, nil, nil)
}
}

// Write all keys and positions to index.
oldKeyPostions, err := db.index.PutBatch(keyPos, putMatchKeys...)
if err != nil {
log.Println("index PutBatch failed:", err)
return
}

// Add old key uuid into deprecatedtable
for _, oldKeyPostion := range oldKeyPostions {
db.vlog.setDeprecated(oldKeyPostion.partition, oldKeyPostion.uid)
}

// Add deleted key uuid into deprecatedtable, and delete the deleted keys from index.
var deleteMatchKeys []diskhash.MatchKeyFunc
if db.options.IndexType == Hash && len(deletedKeys) > 0 {
Expand All @@ -531,13 +531,13 @@ func (db *DB) flushMemtable(table *memtable) {
deleteMatchKeys[i] = MatchKeyFunc(db, deletedKeys[i], nil, nil)
}
}

// delete the deleted keys from index
if oldKeyPostions, err = db.index.DeleteBatch(deletedKeys, deleteMatchKeys...); err != nil {
log.Println("index DeleteBatch failed:", err)
return
}

// uuid into deprecatedtable
for _, oldKeyPostion := range oldKeyPostions {
db.vlog.setDeprecated(oldKeyPostion.partition, oldKeyPostion.uid)
Expand All @@ -547,13 +547,13 @@ func (db *DB) flushMemtable(table *memtable) {
log.Println("index sync failed:", err)
return
}

// delete the wal
if err = table.deleteWAl(); err != nil {
log.Println("delete wal failed:", err)
return
}

// delete old memtable kept in memory
db.mu.Lock()
if table == db.activeMem {
Expand Down

0 comments on commit c1ce11a

Please sign in to comment.