mirror of https://github.com/ledisdb/ledisdb.git
optimize memory cost while iterating data segments in bitmap
This commit is contained in:
parent
5d5e0f4d58
commit
dd1db989f4
|
@ -255,7 +255,7 @@ func (db *DB) bDelete(t *tx, key []byte) (drop int64) {
|
||||||
maxKey := db.bEncodeBinKey(key, maxSeq)
|
maxKey := db.bEncodeBinKey(key, maxSeq)
|
||||||
it := db.db.RangeIterator(minKey, maxKey, leveldb.RangeClose)
|
it := db.db.RangeIterator(minKey, maxKey, leveldb.RangeClose)
|
||||||
for ; it.Valid(); it.Next() {
|
for ; it.Valid(); it.Next() {
|
||||||
t.Delete(it.Key())
|
t.Delete(it.RawKey())
|
||||||
drop++
|
drop++
|
||||||
}
|
}
|
||||||
it.Close()
|
it.Close()
|
||||||
|
@ -450,14 +450,14 @@ func (db *DB) BGet(key []byte) (data []byte, err error) {
|
||||||
|
|
||||||
var seq, s, e uint32
|
var seq, s, e uint32
|
||||||
for ; it.Valid(); it.Next() {
|
for ; it.Valid(); it.Next() {
|
||||||
if _, seq, err = db.bDecodeBinKey(it.Key()); err != nil {
|
if _, seq, err = db.bDecodeBinKey(it.RawKey()); err != nil {
|
||||||
data = nil
|
data = nil
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
s = seq << segByteWidth
|
s = seq << segByteWidth
|
||||||
e = MinUInt32(s+segByteSize, capByteSize)
|
e = MinUInt32(s+segByteSize, capByteSize)
|
||||||
copy(data[s:e], it.Value())
|
copy(data[s:e], it.RawValue())
|
||||||
}
|
}
|
||||||
it.Close()
|
it.Close()
|
||||||
|
|
||||||
|
@ -664,7 +664,7 @@ func (db *DB) BCount(key []byte, start int32, end int32) (cnt int32, err error)
|
||||||
|
|
||||||
it := db.db.RangeIterator(skey, ekey, leveldb.RangeOpen)
|
it := db.db.RangeIterator(skey, ekey, leveldb.RangeOpen)
|
||||||
for ; it.Valid(); it.Next() {
|
for ; it.Valid(); it.Next() {
|
||||||
segment = it.Value()
|
segment = it.RawValue()
|
||||||
for _, bt := range segment {
|
for _, bt := range segment {
|
||||||
cnt += bitsInByte[bt]
|
cnt += bitsInByte[bt]
|
||||||
}
|
}
|
||||||
|
@ -777,12 +777,12 @@ func (db *DB) BOperation(op uint8, dstkey []byte, srckeys ...[]byte) (blen int32
|
||||||
// ps : init segments by data corresponding to the 1st valid source key
|
// ps : init segments by data corresponding to the 1st valid source key
|
||||||
it := db.bIterator(srckeys[srcIdx])
|
it := db.bIterator(srckeys[srcIdx])
|
||||||
for ; it.Valid(); it.Next() {
|
for ; it.Valid(); it.Next() {
|
||||||
if _, seq, err = db.bDecodeBinKey(it.Key()); err != nil {
|
if _, seq, err = db.bDecodeBinKey(it.RawKey()); err != nil {
|
||||||
// to do ...
|
// to do ...
|
||||||
it.Close()
|
it.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
segments[seq] = it.Value()
|
segments[seq] = it.RawValue()
|
||||||
}
|
}
|
||||||
it.Close()
|
it.Close()
|
||||||
srcIdx++
|
srcIdx++
|
||||||
|
@ -799,7 +799,7 @@ func (db *DB) BOperation(op uint8, dstkey []byte, srckeys ...[]byte) (blen int32
|
||||||
for idx, end := uint32(0), false; !end; it.Next() {
|
for idx, end := uint32(0), false; !end; it.Next() {
|
||||||
end = !it.Valid()
|
end = !it.Valid()
|
||||||
if !end {
|
if !end {
|
||||||
if _, seq, err = db.bDecodeBinKey(it.Key()); err != nil {
|
if _, seq, err = db.bDecodeBinKey(it.RawKey()); err != nil {
|
||||||
// to do ...
|
// to do ...
|
||||||
it.Close()
|
it.Close()
|
||||||
return
|
return
|
||||||
|
@ -820,7 +820,7 @@ func (db *DB) BOperation(op uint8, dstkey []byte, srckeys ...[]byte) (blen int32
|
||||||
}
|
}
|
||||||
|
|
||||||
if !end {
|
if !end {
|
||||||
res = it.Value()
|
res = it.RawValue()
|
||||||
exeOp(segments[seq], res, &res)
|
exeOp(segments[seq], res, &res)
|
||||||
segments[seq] = res
|
segments[seq] = res
|
||||||
idx++
|
idx++
|
||||||
|
|
Loading…
Reference in New Issue