mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-24 17:20:18 +01:00
Removed pos recalc from leveldb backend.
This commit is contained in:
parent
c09d74ae0f
commit
f474ef6920
21
leveldb.go
21
leveldb.go
@ -69,16 +69,14 @@ func (ldb *LevelDBBackend) Shutdown() error {
|
|||||||
|
|
||||||
func (ldbs *LevelDBSession) Fetch(hash, key []byte) (value []byte, err 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) {
|
ldbs.backend.doRead(func(db *leveldb.DB) {
|
||||||
ro := leveldb.NewReadOptions()
|
ro := leveldb.NewReadOptions()
|
||||||
value, err = ldbs.backend.db.Get(ro, key)
|
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()
|
ro.Close()
|
||||||
})
|
})
|
||||||
return
|
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) {
|
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) {
|
ldbs.backend.doWrite(func(db *leveldb.DB) {
|
||||||
if exists, err = keyExists(db, key); err != nil {
|
if exists, err = keyExists(db, key); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if ldbs.tx != nil {
|
if ldbs.tx != nil {
|
||||||
|
log.Printf("Stored in tx: key = '%s' len(value) = %d\n", key, len(value))
|
||||||
ldbs.tx.Put(key, value)
|
ldbs.tx.Put(key, value)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("Stored: key = '%s' len(value) = %d\n", key, len(value))
|
||||||
wo := leveldb.NewWriteOptions()
|
wo := leveldb.NewWriteOptions()
|
||||||
err = ldbs.backend.db.Put(wo, key, value)
|
err = ldbs.backend.db.Put(wo, key, value)
|
||||||
wo.Close()
|
wo.Close()
|
||||||
|
Loading…
Reference in New Issue
Block a user