store add compact and string interface

This commit is contained in:
siddontang 2014-09-12 15:06:36 +08:00
parent 5f404a5240
commit 8284c94453
10 changed files with 44 additions and 5 deletions

View File

@ -152,6 +152,10 @@ func (db *DB) BatchPut(writes []driver.Write) error {
return err
}
func (db *DB) Compact() error {
return nil
}
func init() {
driver.Register(Store{})
}

View File

@ -6,6 +6,11 @@ import (
type DB struct {
driver.IDB
name string
}
func (db *DB) String() string {
return db.name
}
func (db *DB) NewIterator() *Iterator {
@ -29,6 +34,10 @@ func (db *DB) NewSnapshot() (*Snapshot, error) {
return s, nil
}
func (db *DB) Compact() error {
return db.IDB.Compact()
}
func (db *DB) RangeIterator(min []byte, max []byte, rangeType uint8) *RangeLimitIterator {
return NewRangeLimitIterator(db.NewIterator(), &Range{min, max, rangeType}, &Limit{0, -1})
}

View File

@ -23,6 +23,8 @@ type IDB interface {
NewSnapshot() (ISnapshot, error)
Begin() (Tx, error)
Compact() error
}
type ISnapshot interface {

View File

@ -6,6 +6,7 @@ import (
"github.com/siddontang/goleveldb/leveldb/filter"
"github.com/siddontang/goleveldb/leveldb/opt"
"github.com/siddontang/goleveldb/leveldb/storage"
"github.com/siddontang/goleveldb/leveldb/util"
"github.com/siddontang/ledisdb/config"
"github.com/siddontang/ledisdb/store/driver"
@ -180,6 +181,10 @@ func (db *DB) NewSnapshot() (driver.ISnapshot, error) {
return s, nil
}
func (db *DB) Compact() error {
return db.db.CompactRange(util.Range{nil, nil})
}
func init() {
driver.Register(Store{})
driver.Register(MemStore{})

View File

@ -270,6 +270,11 @@ func (db *DB) Begin() (driver.Tx, error) {
return nil, driver.ErrTxSupport
}
func (db *DB) Compact() error {
C.leveldb_compact_range(db.db, nil, 0, nil, 0)
return nil
}
func init() {
driver.Register(Store{})
}

View File

@ -270,6 +270,11 @@ func (db *DB) Begin() (driver.Tx, error) {
return nil, driver.ErrTxSupport
}
func (db *DB) Compact() error {
C.leveldb_compact_range(db.db, nil, 0, nil, 0)
return nil
}
func init() {
driver.Register(Store{})
}

View File

@ -240,9 +240,6 @@ func (db MDB) Path() string {
return db.path
}
func (db MDB) Compact() {
}
func (db MDB) iterator(rdonly bool) *MDBIterator {
flags := uint(0)
if rdonly {
@ -286,6 +283,10 @@ func (db MDB) NewSnapshot() (driver.ISnapshot, error) {
return newSnapshot(db)
}
func (db MDB) Compact() error {
return nil
}
func init() {
driver.Register(Store{})
}

View File

@ -296,6 +296,11 @@ func (db *DB) Begin() (driver.Tx, error) {
return nil, driver.ErrTxSupport
}
func (db *DB) Compact() error {
C.rocksdb_compact_range(db.db, nil, 0, nil, 0)
return nil
}
func init() {
driver.Register(Store{})
}

View File

@ -36,7 +36,7 @@ func Open(cfg *config.Config) (*DB, error) {
return nil, err
}
db := &DB{idb}
db := &DB{idb, s.String()}
return db, nil
}

View File

@ -148,6 +148,9 @@ func checkIterator(it *RangeLimitIterator, cv ...int) error {
v := make([]string, 0, len(cv))
for ; it.Valid(); it.Next() {
k := it.Key()
if string(it.Value()) != "value" {
return fmt.Errorf("invalid value")
}
v = append(v, string(k))
}
@ -175,7 +178,7 @@ func testIterator(db *DB, t *testing.T) {
for i := 0; i < 10; i++ {
key := []byte(fmt.Sprintf("key_%d", i))
value := []byte("")
value := []byte("value")
db.Put(key, value)
}