mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
swarm/storage: Factor in accesscount in ordered gc test
Amended access count increment in tryAccessIdx to only affect requested chunk and not the offset of the next added chunk
This commit is contained in:
parent
5c8bd94513
commit
50df43c670
2 changed files with 36 additions and 18 deletions
|
|
@ -719,14 +719,16 @@ func (s *LDBStore) tryAccessIdx(ikey []byte, index *dpaDBIndex) bool {
|
|||
}
|
||||
decodeIndex(idata, index)
|
||||
s.batch.Put(keyAccessCnt, U64ToBytes(s.accessCnt))
|
||||
s.accessCnt++
|
||||
index.Access = s.accessCnt
|
||||
// presumably, we only want to increase the access count of the chunk in question, and not the offset of any future ones?
|
||||
//s.accessCnt++
|
||||
index.Access = s.accessCnt + 1
|
||||
idata = encodeIndex(index)
|
||||
s.batch.Put(ikey, idata)
|
||||
select {
|
||||
case s.batchesC <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
log.Trace("tryaccessidx", "addr", fmt.Sprintf("%x", ikey[1:]), "indexdata", index, "data", idata)
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -345,7 +345,9 @@ func TestLDBStoreCollectGarbage(t *testing.T) {
|
|||
func TestLDBStoreCollectGarbageOrdered(t *testing.T) {
|
||||
capacity := 10000
|
||||
chunkCount := 20000
|
||||
gcThreshold := int(maxGCitems * gcArrayFreeRatio)
|
||||
hasher := MakeHashFunc(DefaultHash)()
|
||||
writeBatchTolerance := 128 // according to log ldb seems to write in batches of 6
|
||||
|
||||
// four byte value incremented sequentially as chunk data (one chunk has 1024 values)
|
||||
var byteValue uint32 = 0
|
||||
|
|
@ -355,9 +357,10 @@ func TestLDBStoreCollectGarbageOrdered(t *testing.T) {
|
|||
buf := make([][ch.DefaultSize]byte, capacity)
|
||||
|
||||
// record keeping
|
||||
madeChunks := make([]Chunk, capacity)
|
||||
madeAddrs := make([]Address, capacity)
|
||||
matchAddrs := make([]Address, capacity)
|
||||
chunkSaveCount := gcThreshold - writeBatchTolerance
|
||||
madeChunks := make([]Chunk, chunkSaveCount)
|
||||
madeAddrs := make([]Address, chunkSaveCount)
|
||||
matchAddrs := make([]Address, chunkSaveCount)
|
||||
|
||||
// needed for hashing (all chunks are full chunks here)
|
||||
meta := make([]byte, 8)
|
||||
|
|
@ -368,6 +371,7 @@ func TestLDBStoreCollectGarbageOrdered(t *testing.T) {
|
|||
store.setCapacity(uint64(capacity))
|
||||
defer cleanup()
|
||||
|
||||
log.Info("gc ordered test", "gcthreshold", gcThreshold, "savecount", chunkSaveCount, "cap", capacity, "count", chunkCount)
|
||||
for i := 0; i < chunkCount; i++ {
|
||||
hasher.ResetWithLength(meta)
|
||||
|
||||
|
|
@ -380,25 +384,37 @@ func TestLDBStoreCollectGarbageOrdered(t *testing.T) {
|
|||
byteValue++
|
||||
}
|
||||
|
||||
// create chunk, add to record keeping and put chunk in store
|
||||
madeChunks[cursor] = NewChunk(hasher.Sum(nil), buf[cursor][:])
|
||||
madeAddrs[cursor] = madeChunks[cursor].Address()
|
||||
matchAddrs[cursor] = madeChunks[cursor].Address()
|
||||
savedChunk, err := mput(store, 1, func(n int64) Chunk { return madeChunks[cursor] })
|
||||
// create and put chunk
|
||||
newChunk := NewChunk(hasher.Sum(nil), buf[cursor][:])
|
||||
_, err := mput(store, 1, func(n int64) Chunk { return newChunk })
|
||||
if err != nil {
|
||||
t.Fatalf("store put fail: %v", err)
|
||||
} else if !bytes.Equal(savedChunk[0].Address(), madeAddrs[cursor]) { // probably redundant but let's be careful for now
|
||||
t.Fatalf("saved addr mismatch %x/%x: %v", savedChunk[0].Address(), madeAddrs[cursor], err)
|
||||
}
|
||||
|
||||
log.Debug("putting", "address", matchAddrs[cursor])
|
||||
log.Trace("putting", "address", newChunk.Address(), "i", i)
|
||||
|
||||
// add to record keeping if it's among the last chunkSaveCount chunks
|
||||
if i > chunkCount-chunkSaveCount {
|
||||
madeChunks[cursor] = newChunk
|
||||
madeAddrs[cursor] = madeChunks[cursor].Address()
|
||||
matchAddrs[cursor] = madeChunks[cursor].Address()
|
||||
|
||||
// get the chunk at least gcThreshold times. That should put the chunk access count comfortable above the limit of any previously added chunks (and give time to flush the db batch writes, too)
|
||||
for i := 0; i < gcThreshold; i++ {
|
||||
log.Trace("accessing", "address", madeChunks[cursor].Address())
|
||||
store.Get(context.TODO(), madeChunks[cursor].Address())
|
||||
}
|
||||
|
||||
cursor++
|
||||
|
||||
// wrap cursor on capacity.
|
||||
//cursor %= capacity
|
||||
|
||||
}
|
||||
|
||||
// wrap cursor on capacity.
|
||||
cursor++
|
||||
cursor %= capacity
|
||||
}
|
||||
|
||||
log.Info("chunks put, sir", "cursor", cursor, "lastvalue", byteValue, "count", len(madeAddrs))
|
||||
log.Info("chunks put, sir", "cursor", cursor, "capacity", capacity, "lastvalue", byteValue, "count", len(madeAddrs))
|
||||
|
||||
// madeAddrs should now contain only the last added chunks.
|
||||
var matches uint64
|
||||
|
|
@ -437,7 +453,7 @@ func TestLDBStoreCollectGarbageOrdered(t *testing.T) {
|
|||
|
||||
// check the retrieve errors
|
||||
if err != nil {
|
||||
t.Fatalf("matches %d/%d, retrieve fail: %v", matches, capacity, err)
|
||||
t.Fatalf("matches %d/%d, retrieve fail: %v", matches, chunkSaveCount, err)
|
||||
}
|
||||
|
||||
// if all elements are found the array should be empty
|
||||
|
|
|
|||
Loading…
Reference in a new issue