[#660] writecache: Fix remaining addr2key uses

Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
This commit is contained in:
Alejandro Lopez 2023-08-29 15:26:22 +03:00 committed by Evgenii Stratonikov
parent fe5aa06a75
commit 1daef2ceeb
2 changed files with 6 additions and 5 deletions

View file

@ -39,10 +39,10 @@ func (c *cache) Delete(ctx context.Context, addr oid.Address) error {
return writecache.ErrReadOnly return writecache.ErrReadOnly
} }
saddr := addr.EncodeToString() key := addr2key(addr)
err := c.db.Update(func(tx *badger.Txn) error { err := c.db.Update(func(tx *badger.Txn) error {
it, err := tx.Get([]byte(saddr)) it, err := tx.Get(key[:])
if err != nil { if err != nil {
if err == badger.ErrKeyNotFound { if err == badger.ErrKeyNotFound {
return logicerr.Wrap(new(apistatus.ObjectNotFound)) return logicerr.Wrap(new(apistatus.ObjectNotFound))
@ -51,10 +51,10 @@ func (c *cache) Delete(ctx context.Context, addr oid.Address) error {
} }
if it.ValueSize() > 0 { if it.ValueSize() > 0 {
storageType = writecache.StorageTypeDB storageType = writecache.StorageTypeDB
err := tx.Delete([]byte(saddr)) err := tx.Delete(key[:])
if err == nil { if err == nil {
storagelog.Write(c.log, storagelog.Write(c.log,
storagelog.AddressField(saddr), storagelog.AddressField(addr.EncodeToString()),
storagelog.StorageTypeField(wcStorageType), storagelog.StorageTypeField(wcStorageType),
storagelog.OpField("db DELETE"), storagelog.OpField("db DELETE"),
) )

View file

@ -52,8 +52,9 @@ func TestFlush(t *testing.T) {
Desc: "db, invalid object", Desc: "db, invalid object",
InjectFn: func(t *testing.T, wc writecache.Cache) { InjectFn: func(t *testing.T, wc writecache.Cache) {
c := wc.(*cache) c := wc.(*cache)
key := addr2key(oidtest.Address())
require.NoError(t, c.db.Update(func(tx *badger.Txn) error { require.NoError(t, c.db.Update(func(tx *badger.Txn) error {
return tx.Set([]byte(oidtest.Address().EncodeToString()), []byte{1, 2, 3}) return tx.Set(key[:], []byte{1, 2, 3})
})) }))
}, },
}, },