2014-05-22 16:02:22 +04:00
|
|
|
package ledis
|
|
|
|
|
2014-07-03 07:38:52 +04:00
|
|
|
import (
|
|
|
|
"github.com/siddontang/ledisdb/leveldb"
|
|
|
|
)
|
|
|
|
|
2014-06-03 11:40:10 +04:00
|
|
|
func (db *DB) FlushAll() (drop int64, err error) {
|
2014-05-22 16:02:22 +04:00
|
|
|
all := [...](func() (int64, error)){
|
2014-06-12 06:51:36 +04:00
|
|
|
db.flush,
|
|
|
|
db.lFlush,
|
|
|
|
db.hFlush,
|
2014-07-03 07:38:52 +04:00
|
|
|
db.zFlush,
|
|
|
|
db.bFlush}
|
2014-05-22 16:02:22 +04:00
|
|
|
|
|
|
|
for _, flush := range all {
|
|
|
|
if n, e := flush(); e != nil {
|
|
|
|
err = e
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
drop += n
|
|
|
|
}
|
|
|
|
}
|
2014-06-03 11:40:10 +04:00
|
|
|
|
2014-05-22 16:02:22 +04:00
|
|
|
return
|
|
|
|
}
|
2014-06-03 11:40:10 +04:00
|
|
|
|
2014-06-12 06:51:36 +04:00
|
|
|
func (db *DB) newEliminator() *elimination {
|
2014-06-03 11:40:10 +04:00
|
|
|
eliminator := newEliminator(db)
|
2014-07-09 13:01:29 +04:00
|
|
|
eliminator.regRetireContext(kvType, db.kvTx, db.delete)
|
|
|
|
eliminator.regRetireContext(listType, db.listTx, db.lDelete)
|
|
|
|
eliminator.regRetireContext(hashType, db.hashTx, db.hDelete)
|
|
|
|
eliminator.regRetireContext(zsetType, db.zsetTx, db.zDelete)
|
|
|
|
eliminator.regRetireContext(binType, db.binTx, db.bDelete)
|
2014-06-03 11:40:10 +04:00
|
|
|
|
2014-06-12 06:51:36 +04:00
|
|
|
return eliminator
|
2014-06-03 11:40:10 +04:00
|
|
|
}
|
2014-07-03 07:38:52 +04:00
|
|
|
|
|
|
|
func (db *DB) flushRegion(t *tx, minKey []byte, maxKey []byte) (drop int64, err error) {
|
|
|
|
it := db.db.RangeIterator(minKey, maxKey, leveldb.RangeROpen)
|
|
|
|
for ; it.Valid(); it.Next() {
|
2014-07-09 13:01:29 +04:00
|
|
|
t.Delete(it.RawKey())
|
2014-07-03 07:38:52 +04:00
|
|
|
drop++
|
|
|
|
if drop&1023 == 0 {
|
|
|
|
if err = t.Commit(); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
it.Close()
|
|
|
|
return
|
|
|
|
}
|