From 35130a52026ba7c1201bf4e6429982b53d91014c Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Sat, 23 Aug 2014 19:00:43 +0200 Subject: [PATCH] Enabled interleaving in LevelDB backend. --- leveldb.go | 37 ++++++++++++++++++++++++++----------- main.go | 16 +++++----------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/leveldb.go b/leveldb.go index b0715a1..27ebd24 100644 --- a/leveldb.go +++ b/leveldb.go @@ -14,11 +14,12 @@ import ( ) type LevelDBBackend struct { - cache *leveldb.Cache - db *leveldb.DB - encoder common.KeyTranscoder - decoder common.KeyTranscoder - mutex sync.RWMutex + cache *leveldb.Cache + db *leveldb.DB + interleaved bool + encoder common.KeyTranscoder + decoder common.KeyTranscoder + mutex sync.RWMutex } type LevelDBSession struct { @@ -28,9 +29,9 @@ type LevelDBSession struct { func NewLeveDBBackend( path string, - encoder common.KeyTranscoder, - decoder common.KeyTranscoder, + interleaved bool, cacheSize int) (ldb *LevelDBBackend, err error) { + opts := leveldb.NewOptions() var cache *leveldb.Cache @@ -48,11 +49,25 @@ func NewLeveDBBackend( } return } + var ( + encoder common.KeyTranscoder + decoder common.KeyTranscoder + ) + + if interleaved { + encoder = common.TranscodeInterleavedToPlain + decoder = common.TranscodePlainToInterleaved + } else { + encoder = common.IdentityTranscoder + decoder = common.IdentityTranscoder + } + ldb = &LevelDBBackend{ - cache: cache, - db: db, - encoder: encoder, - decoder: decoder} + cache: cache, + db: db, + interleaved: interleaved, + encoder: encoder, + decoder: decoder} return } diff --git a/main.go b/main.go index 6787803..2476cdf 100644 --- a/main.go +++ b/main.go @@ -13,8 +13,6 @@ import ( "os/signal" "runtime" "time" - - "bitbucket.org/s_l_teichmann/mtredisalize/common" ) const ( @@ -48,9 +46,7 @@ func main() { os.Exit(0) } - args := flag.Args() - - if len(args) < 1 { + if flag.NArg() < 1 { log.Fatal("Missing path to world") } @@ -64,16 +60,14 @@ func main() { log.Fatal(err) } + path := flag.Arg(0) + if driver == "sqlite" { - if backend, err = NewSqliteBackend(args[0], interleaved); err != nil { + if backend, err = NewSqliteBackend(path, interleaved); err != nil { log.Fatal(err) } } else { - if backend, err = NewLeveDBBackend( - args[0], - common.IdentityTranscoder, - common.IdentityTranscoder, - cacheSize); err != nil { + if backend, err = NewLeveDBBackend(path, interleaved, cacheSize); err != nil { log.Fatal(err) } }