From 36c49f8902c461f91545173f80e1840a34db774c Mon Sep 17 00:00:00 2001 From: siddontang Date: Tue, 29 Jul 2014 08:22:47 +0800 Subject: [PATCH 1/2] use forked goleveldb because of google blocked go get code.google snappy is very hard now --- bootstrap.sh | 2 +- store/goleveldb/batch.go | 2 +- store/goleveldb/db.go | 8 ++++---- store/goleveldb/iterator.go | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index 1cf49b6..a62b20e 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -6,5 +6,5 @@ go get github.com/siddontang/go-log/log 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/siddontang/goleveldb/leveldb go get github.com/influxdb/gomdb \ No newline at end of file diff --git a/store/goleveldb/batch.go b/store/goleveldb/batch.go index f3ff67c..bdfb457 100644 --- a/store/goleveldb/batch.go +++ b/store/goleveldb/batch.go @@ -1,7 +1,7 @@ package goleveldb import ( - "github.com/syndtr/goleveldb/leveldb" + "github.com/siddontang/goleveldb/leveldb" ) type WriteBatch struct { diff --git a/store/goleveldb/db.go b/store/goleveldb/db.go index 8ae1f73..c9e393f 100644 --- a/store/goleveldb/db.go +++ b/store/goleveldb/db.go @@ -1,11 +1,11 @@ package goleveldb import ( + "github.com/siddontang/goleveldb/leveldb" + "github.com/siddontang/goleveldb/leveldb/cache" + "github.com/siddontang/goleveldb/leveldb/filter" + "github.com/siddontang/goleveldb/leveldb/opt" "github.com/siddontang/ledisdb/store/driver" - "github.com/syndtr/goleveldb/leveldb" - "github.com/syndtr/goleveldb/leveldb/cache" - "github.com/syndtr/goleveldb/leveldb/filter" - "github.com/syndtr/goleveldb/leveldb/opt" "os" ) diff --git a/store/goleveldb/iterator.go b/store/goleveldb/iterator.go index c1fd8b5..bd06376 100644 --- a/store/goleveldb/iterator.go +++ b/store/goleveldb/iterator.go @@ -1,7 +1,7 @@ package goleveldb import ( - "github.com/syndtr/goleveldb/leveldb/iterator" + "github.com/siddontang/goleveldb/leveldb/iterator" ) type Iterator struct { From f46d63cf6209b63678a6e27b113ddf6d60d3391e Mon Sep 17 00:00:00 2001 From: siddontang Date: Tue, 29 Jul 2014 08:58:13 +0800 Subject: [PATCH 2/2] update store test --- store/mdb/batch.go | 3 +++ store/store_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/store/mdb/batch.go b/store/mdb/batch.go index d8debf6..d68ee43 100644 --- a/store/mdb/batch.go +++ b/store/mdb/batch.go @@ -15,6 +15,9 @@ func (w *WriteBatch) Close() error { } func (w *WriteBatch) Put(key, value []byte) { + if value == nil { + value = []byte{} + } w.wb = append(w.wb, Write{key, value}) } diff --git a/store/store_test.go b/store/store_test.go index f37c496..c79bddd 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -37,6 +37,16 @@ func testSimple(db *DB, t *testing.T) { } else if v != nil { t.Fatal("must nil") } + + if err := db.Put(key, nil); err != nil { + t.Fatal(err) + } + + if v, err := db.Get(key); err != nil { + t.Fatal(err) + } else if !bytes.Equal(v, []byte{}) { + t.Fatal("must empty") + } } func testBatch(db *DB, t *testing.T) { @@ -80,7 +90,27 @@ func testBatch(db *DB, t *testing.T) { t.Fatal(string(v)) } + wb.Put(key1, nil) + wb.Put(key2, []byte{}) + + if err := wb.Commit(); err != nil { + t.Fatal(err) + } + + if v, err := db.Get(key1); err != nil { + t.Fatal(err) + } else if !bytes.Equal(v, []byte{}) { + t.Fatal("must empty") + } + + if v, err := db.Get(key2); err != nil { + t.Fatal(err) + } else if !bytes.Equal(v, []byte{}) { + t.Fatal("must empty") + } + db.Delete(key1) + db.Delete(key2) } func checkIterator(it *RangeLimitIterator, cv ...int) error {