Enabled interleaving in LevelDB backend.

This commit is contained in:
Sascha L. Teichmann 2014-08-23 19:00:43 +02:00
parent a0bdf95f95
commit 35130a5202
2 changed files with 31 additions and 22 deletions

View File

@ -16,6 +16,7 @@ import (
type LevelDBBackend struct {
cache *leveldb.Cache
db *leveldb.DB
interleaved bool
encoder common.KeyTranscoder
decoder common.KeyTranscoder
mutex sync.RWMutex
@ -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,9 +49,23 @@ 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,
interleaved: interleaved,
encoder: encoder,
decoder: decoder}
return

16
main.go
View File

@ -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)
}
}