From 4f5e47e907967f2e707dd5e0a8aefec14701612f Mon Sep 17 00:00:00 2001 From: siddontang Date: Fri, 25 Jul 2014 19:41:04 +0800 Subject: [PATCH] update lmdv --- bootstrap.sh | 2 +- store/config.go | 5 ++++- store/mdb/batch.go | 12 ++++++------ store/mdb/mdb.go | 4 ++-- store/store_test.go | 26 ++++++++++++++++++++++++++ 5 files changed, 39 insertions(+), 10 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index 40b737b..1cf49b6 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -7,4 +7,4 @@ go get github.com/siddontang/go-snappy/snappy go get github.com/siddontang/copier go get github.com/syndtr/goleveldb/leveldb -go get github.com/szferi/gomdb \ No newline at end of file +go get github.com/influxdb/gomdb \ No newline at end of file diff --git a/store/config.go b/store/config.go index f2c8eee..b2939dc 100644 --- a/store/config.go +++ b/store/config.go @@ -5,10 +5,13 @@ type Config struct { Path string - //for leveldb, goleveldb, rocksdb + //for leveldb, goleveldb Compression bool BlockSize int WriteBufferSize int CacheSize int MaxOpenFiles int + + //for lmdb + MapSize int } diff --git a/store/mdb/batch.go b/store/mdb/batch.go index 2bf2c04..60b6812 100644 --- a/store/mdb/batch.go +++ b/store/mdb/batch.go @@ -6,27 +6,27 @@ type Write struct { } type WriteBatch struct { - db MDB + db *MDB wb []Write } -func (w WriteBatch) Close() error { +func (w *WriteBatch) Close() error { return nil } -func (w WriteBatch) Put(key, value []byte) { +func (w *WriteBatch) Put(key, value []byte) { w.wb = append(w.wb, Write{key, value}) } -func (w WriteBatch) Delete(key []byte) { +func (w *WriteBatch) Delete(key []byte) { w.wb = append(w.wb, Write{key, nil}) } -func (w WriteBatch) Commit() error { +func (w *WriteBatch) Commit() error { return w.db.BatchPut(w.wb) } -func (w WriteBatch) Rollback() error { +func (w *WriteBatch) Rollback() error { w.wb = []Write{} return nil } diff --git a/store/mdb/mdb.go b/store/mdb/mdb.go index ef9d2bf..038121a 100644 --- a/store/mdb/mdb.go +++ b/store/mdb/mdb.go @@ -20,7 +20,7 @@ type MDB struct { func Open(c *Config) (MDB, error) { path := c.Path if c.MapSize == 0 { - c.MapSize = 1 * 1024 * 1024 * 1024 + c.MapSize = 10 * 1024 * 1024 } env, err := mdb.NewEnv() @@ -245,5 +245,5 @@ func (db MDB) NewIterator() driver.IIterator { } func (db MDB) NewWriteBatch() driver.IWriteBatch { - return WriteBatch{db, []Write{}} + return &WriteBatch{&db, []Write{}} } diff --git a/store/store_test.go b/store/store_test.go index b6fc70c..b911cb5 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -137,6 +137,16 @@ func TestIterator(t *testing.T) { db.Put(key, value) } + i = db.NewIterator() + i.SeekToFirst() + + if !i.Valid() { + t.Fatal("must valid") + } else if string(i.Key()) != "key_0" { + t.Fatal(string(i.Key())) + } + i.Close() + var it *RangeLimitIterator k := func(i int) []byte { @@ -147,51 +157,67 @@ func TestIterator(t *testing.T) { if err := checkIterator(it, 1, 2, 3, 4, 5); err != nil { t.Fatal(err) } + it.Close() + + it = db.RangeLimitIterator(k(1), k(5), RangeClose, 0, -1) + if err := checkIterator(it, 1, 2, 3, 4, 5); err != nil { + t.Fatal(err) + } + it.Close() it = db.RangeLimitIterator(k(1), k(5), RangeClose, 1, 3) if err := checkIterator(it, 2, 3, 4); err != nil { t.Fatal(err) } + it.Close() it = db.RangeLimitIterator(k(1), k(5), RangeLOpen, 0, -1) if err := checkIterator(it, 2, 3, 4, 5); err != nil { t.Fatal(err) } + it.Close() it = db.RangeLimitIterator(k(1), k(5), RangeROpen, 0, -1) if err := checkIterator(it, 1, 2, 3, 4); err != nil { t.Fatal(err) } + it.Close() it = db.RangeLimitIterator(k(1), k(5), RangeOpen, 0, -1) if err := checkIterator(it, 2, 3, 4); err != nil { t.Fatal(err) } + it.Close() it = db.RevRangeLimitIterator(k(1), k(5), RangeClose, 0, -1) if err := checkIterator(it, 5, 4, 3, 2, 1); err != nil { t.Fatal(err) } + it.Close() it = db.RevRangeLimitIterator(k(1), k(5), RangeClose, 1, 3) if err := checkIterator(it, 4, 3, 2); err != nil { t.Fatal(err) } + it.Close() it = db.RevRangeLimitIterator(k(1), k(5), RangeLOpen, 0, -1) if err := checkIterator(it, 5, 4, 3, 2); err != nil { t.Fatal(err) } + it.Close() it = db.RevRangeLimitIterator(k(1), k(5), RangeROpen, 0, -1) if err := checkIterator(it, 4, 3, 2, 1); err != nil { t.Fatal(err) } + it.Close() it = db.RevRangeLimitIterator(k(1), k(5), RangeOpen, 0, -1) if err := checkIterator(it, 4, 3, 2); err != nil { t.Fatal(err) } + it.Close() } func TestCloseMore(t *testing.T) {