From 481f0ab1c44d4b9af308bbd42f58d8bb5020bd66 Mon Sep 17 00:00:00 2001 From: lash Date: Wed, 3 Oct 2018 08:36:18 +0200 Subject: [PATCH] swarm/storage: Add accesscount-indexcount index on put --- swarm/storage/ldbstore.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/swarm/storage/ldbstore.go b/swarm/storage/ldbstore.go index 2a7f51cb38..80aedfa47d 100644 --- a/swarm/storage/ldbstore.go +++ b/swarm/storage/ldbstore.go @@ -61,6 +61,7 @@ var ( keyData = byte(6) keyDistanceCnt = byte(7) keySchema = []byte{8} + keyAccessIdx = []byte{9} // access to chunk data index, used by garbage collection in ascending order from first entry ) var ( @@ -225,6 +226,14 @@ func getDataKey(idx uint64, po uint8) []byte { return key } +func getAccessIdxKey(idx *dpaDBIndex) []byte { + key := make([]byte, 17) + key[0] = keyAccessIdx[0] + binary.BigEndian.PutUint64(key[1:], index.Access) + binary.BigEndian.PutUint64(key[9:], index.Idx) + return key +} + func encodeIndex(index *dpaDBIndex) []byte { data, _ := rlp.EncodeToBytes(index) return data @@ -602,6 +611,9 @@ func (s *LDBStore) Put(ctx context.Context, chunk Chunk) error { idata = encodeIndex(&index) s.batch.Put(ikey, idata) + // add the access-chunkindex index for garbage collection + accessIdx := getAccessIdxKey(&index) + s.batch.Put(accessIdx, nil) s.lock.Unlock() select { @@ -813,16 +825,6 @@ func newMockGetDataFunc(mockStore *mock.NodeStore) func(addr Address) (data []by } } -func (s *LDBStore) updateAccessCnt(addr Address) { - - s.lock.Lock() - defer s.lock.Unlock() - - var index dpaDBIndex - s.tryAccessIdx(getIndexKey(addr), &index) // result_chn == nil, only update access cnt - -} - func (s *LDBStore) setCapacity(c uint64) { s.lock.Lock() defer s.lock.Unlock()