Commit 9df7f53d authored by acud's avatar acud Committed by GitHub

storage, localstore: remove unused mode set access (#1149)

parent 5ada4b4d
...@@ -702,10 +702,6 @@ func addRandomChunks(t *testing.T, count int, db *DB, pin bool) []swarm.Chunk { ...@@ -702,10 +702,6 @@ func addRandomChunks(t *testing.T, count int, db *DB, pin bool) []swarm.Chunk {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = db.Set(context.Background(), storage.ModeSetAccess, ch.Address())
if err != nil {
t.Fatal(err)
}
_, err = db.Get(context.Background(), storage.ModeGetRequest, ch.Address()) _, err = db.Get(context.Background(), storage.ModeGetRequest, ch.Address())
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
...@@ -714,7 +710,6 @@ func addRandomChunks(t *testing.T, count int, db *DB, pin bool) []swarm.Chunk { ...@@ -714,7 +710,6 @@ func addRandomChunks(t *testing.T, count int, db *DB, pin bool) []swarm.Chunk {
// Non pinned chunks could be GC'd by the time they reach here. // Non pinned chunks could be GC'd by the time they reach here.
// so it is okay to ignore the error // so it is okay to ignore the error
_ = db.Set(context.Background(), storage.ModeSetSync, ch.Address()) _ = db.Set(context.Background(), storage.ModeSetSync, ch.Address())
_ = db.Set(context.Background(), storage.ModeSetAccess, ch.Address())
_, _ = db.Get(context.Background(), storage.ModeGetRequest, ch.Address()) _, _ = db.Get(context.Background(), storage.ModeGetRequest, ch.Address())
} }
chunks = append(chunks, ch) chunks = append(chunks, ch)
......
...@@ -549,6 +549,7 @@ func testIndexCounts(t *testing.T, pushIndex, pullIndex, gcIndex, gcExcludeIndex ...@@ -549,6 +549,7 @@ func testIndexCounts(t *testing.T, pushIndex, pullIndex, gcIndex, gcExcludeIndex
// index debug function // index debug function
func TestDBDebugIndexes(t *testing.T) { func TestDBDebugIndexes(t *testing.T) {
db := newTestDB(t, nil) db := newTestDB(t, nil)
ctx := context.Background()
uploadTimestamp := time.Now().UTC().UnixNano() uploadTimestamp := time.Now().UTC().UnixNano()
defer setNow(func() (t int64) { defer setNow(func() (t int64) {
...@@ -557,7 +558,7 @@ func TestDBDebugIndexes(t *testing.T) { ...@@ -557,7 +558,7 @@ func TestDBDebugIndexes(t *testing.T) {
ch := generateTestRandomChunk() ch := generateTestRandomChunk()
_, err := db.Put(context.Background(), storage.ModePutUpload, ch) _, err := db.Put(ctx, storage.ModePutUpload, ch)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -567,11 +568,10 @@ func TestDBDebugIndexes(t *testing.T) { ...@@ -567,11 +568,10 @@ func TestDBDebugIndexes(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
// for reference: testIndexCounts(t *testing.T, pushIndex, pullIndex, gcIndex, gcExcludeIndex, pinIndex, retrievalDataIndex, retrievalAccessIndex int, indexInfo map[string]int)
testIndexCounts(t, 1, 1, 0, 0, 0, 1, 0, indexCounts) testIndexCounts(t, 1, 1, 0, 0, 0, 1, 0, indexCounts)
// set the chunk for pinning and expect the index count to grow // set the chunk for pinning and expect the index count to grow
err = db.Set(context.Background(), storage.ModeSetPin, ch.Address()) err = db.Set(ctx, storage.ModeSetPin, ch.Address())
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -583,18 +583,4 @@ func TestDBDebugIndexes(t *testing.T) { ...@@ -583,18 +583,4 @@ func TestDBDebugIndexes(t *testing.T) {
// assert that there's a pin and gc exclude entry now // assert that there's a pin and gc exclude entry now
testIndexCounts(t, 1, 1, 0, 1, 1, 1, 0, indexCounts) testIndexCounts(t, 1, 1, 0, 1, 1, 1, 0, indexCounts)
// set the chunk as accessed and expect the access index to grow
err = db.Set(context.Background(), storage.ModeSetAccess, ch.Address())
if err != nil {
t.Fatal(err)
}
indexCounts, err = db.DebugIndices()
if err != nil {
t.Fatal(err)
}
// assert that there's a pin and gc exclude entry now
testIndexCounts(t, 1, 1, 0, 1, 1, 1, 1, indexCounts)
} }
...@@ -59,24 +59,6 @@ func (db *DB) set(mode storage.ModeSet, addrs ...swarm.Address) (err error) { ...@@ -59,24 +59,6 @@ func (db *DB) set(mode storage.ModeSet, addrs ...swarm.Address) (err error) {
triggerPullFeed := make(map[uint8]struct{}) // signal pull feed subscriptions to iterate triggerPullFeed := make(map[uint8]struct{}) // signal pull feed subscriptions to iterate
switch mode { switch mode {
case storage.ModeSetAccess:
// A lazy populated map of bin ids to properly set
// BinID values for new chunks based on initial value from database
// and incrementing them.
binIDs := make(map[uint8]uint64)
for _, addr := range addrs {
po := db.po(addr)
c, err := db.setAccess(batch, binIDs, addr, po)
if err != nil {
return err
}
gcSizeChange += c
triggerPullFeed[po] = struct{}{}
}
for po, id := range binIDs {
db.binIDs.PutInBatch(batch, uint64(po), id)
}
case storage.ModeSetSync: case storage.ModeSetSync:
for _, addr := range addrs { for _, addr := range addrs {
c, err := db.setSync(batch, addr, mode) c, err := db.setSync(batch, addr, mode)
...@@ -137,74 +119,6 @@ func (db *DB) set(mode storage.ModeSet, addrs ...swarm.Address) (err error) { ...@@ -137,74 +119,6 @@ func (db *DB) set(mode storage.ModeSet, addrs ...swarm.Address) (err error) {
return nil return nil
} }
// setAccess sets the chunk access time by updating required indexes:
// - add to pull, insert to gc
// Provided batch and binID map are updated.
func (db *DB) setAccess(batch *leveldb.Batch, binIDs map[uint8]uint64, addr swarm.Address, po uint8) (gcSizeChange int64, err error) {
item := addressToItem(addr)
// need to get access timestamp here as it is not
// provided by the access function, and it is not
// a property of a chunk provided to Accessor.Put.
i, err := db.retrievalDataIndex.Get(item)
switch {
case err == nil:
item.StoreTimestamp = i.StoreTimestamp
item.BinID = i.BinID
case errors.Is(err, leveldb.ErrNotFound):
err = db.pushIndex.DeleteInBatch(batch, item)
if err != nil {
return 0, err
}
item.StoreTimestamp = now()
item.BinID, err = db.incBinID(binIDs, po)
if err != nil {
return 0, err
}
default:
return 0, err
}
i, err = db.retrievalAccessIndex.Get(item)
switch {
case err == nil:
item.AccessTimestamp = i.AccessTimestamp
err = db.gcIndex.DeleteInBatch(batch, item)
if err != nil {
return 0, err
}
gcSizeChange--
case errors.Is(err, leveldb.ErrNotFound):
// the chunk is not accessed before
default:
return 0, err
}
item.AccessTimestamp = now()
err = db.retrievalAccessIndex.PutInBatch(batch, item)
if err != nil {
return 0, err
}
err = db.pullIndex.PutInBatch(batch, item)
if err != nil {
return 0, err
}
ok, err := db.pinIndex.Has(item)
if err != nil {
return 0, err
}
if !ok {
err = db.gcIndex.PutInBatch(batch, item)
if err != nil {
return 0, err
}
gcSizeChange++
}
return gcSizeChange, nil
}
// setSync adds the chunk to the garbage collection after syncing by updating indexes // setSync adds the chunk to the garbage collection after syncing by updating indexes
// - ModeSetSync - the corresponding tag is incremented, then item is removed // - ModeSetSync - the corresponding tag is incremented, then item is removed
// from push sync index // from push sync index
......
...@@ -21,7 +21,6 @@ import ( ...@@ -21,7 +21,6 @@ import (
"errors" "errors"
"io/ioutil" "io/ioutil"
"testing" "testing"
"time"
"github.com/ethersphere/bee/pkg/logging" "github.com/ethersphere/bee/pkg/logging"
statestore "github.com/ethersphere/bee/pkg/statestore/mock" statestore "github.com/ethersphere/bee/pkg/statestore/mock"
...@@ -33,43 +32,6 @@ import ( ...@@ -33,43 +32,6 @@ import (
"github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb"
) )
// TestModeSetAccess validates ModeSetAccess index values on the provided DB.
func TestModeSetAccess(t *testing.T) {
for _, tc := range multiChunkTestCases {
t.Run(tc.name, func(t *testing.T) {
db := newTestDB(t, nil)
chunks := generateTestRandomChunks(tc.count)
wantTimestamp := time.Now().UTC().UnixNano()
defer setNow(func() (t int64) {
return wantTimestamp
})()
err := db.Set(context.Background(), storage.ModeSetAccess, chunkAddresses(chunks)...)
if err != nil {
t.Fatal(err)
}
binIDs := make(map[uint8]uint64)
for _, ch := range chunks {
po := db.po(ch.Address())
binIDs[po]++
newPullIndexTest(db, ch, binIDs[po], nil)(t)
newGCIndexTest(db, ch, wantTimestamp, wantTimestamp, binIDs[po], nil)(t)
}
t.Run("gc index count", newItemsCountTest(db.gcIndex, tc.count))
t.Run("pull index count", newItemsCountTest(db.pullIndex, tc.count))
t.Run("gc size", newIndexGCSizeTest(db))
})
}
}
// here we try to set a normal tag (that should be handled by pushsync) // here we try to set a normal tag (that should be handled by pushsync)
// as a result we should expect the tag value to remain in the pull index // as a result we should expect the tag value to remain in the pull index
// and we expect that the tag should not be incremented by pull sync set // and we expect that the tag should not be incremented by pull sync set
......
...@@ -86,8 +86,6 @@ type ModeSet int ...@@ -86,8 +86,6 @@ type ModeSet int
func (m ModeSet) String() string { func (m ModeSet) String() string {
switch m { switch m {
case ModeSetAccess:
return "Access"
case ModeSetSync: case ModeSetSync:
return "Sync" return "Sync"
case ModeSetRemove: case ModeSetRemove:
...@@ -103,10 +101,8 @@ func (m ModeSet) String() string { ...@@ -103,10 +101,8 @@ func (m ModeSet) String() string {
// Setter modes. // Setter modes.
const ( const (
// ModeSetAccess: when an update request is received for a chunk or chunk is retrieved for delivery
ModeSetAccess ModeSet = iota
// ModeSetSync: when a push sync receipt is received for a chunk // ModeSetSync: when a push sync receipt is received for a chunk
ModeSetSync ModeSetSync ModeSet = iota
// ModeSetRemove: when a chunk is removed // ModeSetRemove: when a chunk is removed
ModeSetRemove ModeSetRemove
// ModeSetPin: when a chunk is pinned during upload or separately // ModeSetPin: when a chunk is pinned during upload or separately
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment