Skip to content

Commit

Permalink
changed get to use getbatch for better testing
Browse files Browse the repository at this point in the history
  • Loading branch information
harshil-goel committed Aug 27, 2024
1 parent ae71e90 commit 462c8d0
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,32 +798,39 @@ func (db *DB) getBatch(keys [][]byte, done []bool) ([]y.ValueStruct, error) {
}

func (db *DB) get(key []byte) (y.ValueStruct, error) {
if db.IsClosed() {
return y.ValueStruct{}, ErrDBClosed
}
tables, decr := db.getMemTables() // Lock should be released.
defer decr()

var maxVs y.ValueStruct
version := y.ParseTs(key)

y.NumGetsAdd(db.opt.MetricsEnabled, 1)
for i := 0; i < len(tables); i++ {
vs := tables[i].sl.Get(key)
y.NumMemtableGetsAdd(db.opt.MetricsEnabled, 1)
if vs.Meta == 0 && vs.Value == nil {
continue
}
// Found the required version of the key, return immediately.
if vs.Version == version {
y.NumGetsWithResultsAdd(db.opt.MetricsEnabled, 1)
return vs, nil
}
if maxVs.Version < vs.Version {
maxVs = vs
}
}
return db.lc.get(key, maxVs, 0)
done := make([]bool, 1)
vals, err := db.getBatch([][]byte{key}, done)
if len(vals) != 0 {
return vals[0], err
}
return y.ValueStruct{}, err

//if db.IsClosed() {
// return y.ValueStruct{}, ErrDBClosed
//}
//tables, decr := db.getMemTables() // Lock should be released.
//defer decr()

//var maxVs y.ValueStruct
//version := y.ParseTs(key)

//y.NumGetsAdd(db.opt.MetricsEnabled, 1)
//for i := 0; i < len(tables); i++ {
// vs := tables[i].sl.Get(key)
// y.NumMemtableGetsAdd(db.opt.MetricsEnabled, 1)
// if vs.Meta == 0 && vs.Value == nil {
// continue
// }
// // Found the required version of the key, return immediately.
// if vs.Version == version {
// y.NumGetsWithResultsAdd(db.opt.MetricsEnabled, 1)
// return vs, nil
// }
// if maxVs.Version < vs.Version {
// maxVs = vs
// }
//}
//return db.lc.get(key, maxVs, 0)
}

var requestPool = sync.Pool{
Expand Down

0 comments on commit 462c8d0

Please sign in to comment.