swarm/storage: fix access count on dbstore after cache hit (#17978)
Access count was not incremented when chunk was retrieved from cache. So the garbage collector might have deleted the most frequently accessed chunk from disk. Co-authored-by: Ferenc Szabo <ferenc.szabo@ethereum.org>
This commit is contained in:
committed by
Viktor Trón
parent
1212c7b844
commit
8080265f3f
@ -31,7 +31,6 @@ import (
|
||||
ch "github.com/ethereum/go-ethereum/swarm/chunk"
|
||||
"github.com/ethereum/go-ethereum/swarm/log"
|
||||
"github.com/ethereum/go-ethereum/swarm/storage/mock/mem"
|
||||
|
||||
ldberrors "github.com/syndtr/goleveldb/leveldb/errors"
|
||||
)
|
||||
|
||||
@ -105,6 +104,46 @@ func testDbStoreCorrect(n int, chunksize int64, mock bool, t *testing.T) {
|
||||
testStoreCorrect(db, n, chunksize, t)
|
||||
}
|
||||
|
||||
func TestMarkAccessed(t *testing.T) {
|
||||
db, cleanup, err := newTestDbStore(false, true)
|
||||
defer cleanup()
|
||||
if err != nil {
|
||||
t.Fatalf("init dbStore failed: %v", err)
|
||||
}
|
||||
|
||||
h := GenerateRandomChunk(ch.DefaultSize)
|
||||
|
||||
db.Put(context.Background(), h)
|
||||
|
||||
var index dpaDBIndex
|
||||
addr := h.Address()
|
||||
idxk := getIndexKey(addr)
|
||||
|
||||
idata, err := db.db.Get(idxk)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
decodeIndex(idata, &index)
|
||||
|
||||
if index.Access != 0 {
|
||||
t.Fatalf("Expected the access index to be %d, but it is %d", 0, index.Access)
|
||||
}
|
||||
|
||||
db.MarkAccessed(addr)
|
||||
db.writeCurrentBatch()
|
||||
|
||||
idata, err = db.db.Get(idxk)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
decodeIndex(idata, &index)
|
||||
|
||||
if index.Access != 1 {
|
||||
t.Fatalf("Expected the access index to be %d, but it is %d", 1, index.Access)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestDbStoreRandom_1(t *testing.T) {
|
||||
testDbStoreRandom(1, 0, false, t)
|
||||
}
|
||||
|
Reference in New Issue
Block a user