Removed pos recalc from leveldb backend.

This commit is contained in:
Sascha L. Teichmann 2014-08-07 20:20:04 +02:00
parent c09d74ae0f
commit f474ef6920
2 changed files with 8 additions and 15 deletions

View File

@ -69,16 +69,14 @@ func (ldb *LevelDBBackend) Shutdown() error {
func (ldbs *LevelDBSession) Fetch(hash, key []byte) (value []byte, err error) {
var pos int64
if pos, err = bytes2pos(key); err != nil {
return
}
// Re-code it to make LevelDB happy.
key = pos2bytes(pos)
ldbs.backend.doRead(func(db *leveldb.DB) {
ro := leveldb.NewReadOptions()
value, err = ldbs.backend.db.Get(ro, key)
if err != nil {
log.Printf("Fetch key = '%s' len(value) = %d\n", key, len(value))
} else {
log.Printf("Fetch key '%s' failed.\n", key)
}
ro.Close()
})
return
@ -101,23 +99,18 @@ func keyExists(db *leveldb.DB, key []byte) (exists bool, err error) {
func (ldbs *LevelDBSession) Store(hash, key, value []byte) (exists bool, err error) {
var pos int64
if pos, err = bytes2pos(key); err != nil {
return
}
// Re-code it to make LevelDB happy.
key = pos2bytes(pos)
ldbs.backend.doWrite(func(db *leveldb.DB) {
if exists, err = keyExists(db, key); err != nil {
return
}
if ldbs.tx != nil {
log.Printf("Stored in tx: key = '%s' len(value) = %d\n", key, len(value))
ldbs.tx.Put(key, value)
return
}
log.Printf("Stored: key = '%s' len(value) = %d\n", key, len(value))
wo := leveldb.NewWriteOptions()
err = ldbs.backend.db.Put(wo, key, value)
wo.Close()

View File

@ -198,7 +198,7 @@ func (rce *RedisCommandExecutor) execute() bool {
case "EXEC":
return rce.commands.Exec()
}
log.Printf("WARN unkown command: %s", cmd)
log.Printf("WARN unkown command: '%s'", cmd)
return false
}