Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

Commit ab8e73d

Browse files
authored
storage/localstore: do not later batch in setSync if moveToGc is false (#1909)
1 parent fa6a3f7 commit ab8e73d

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

storage/localstore/mode_set.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -201,20 +201,6 @@ func (db *DB) setSync(batch *leveldb.Batch, addr chunk.Address, mode chunk.ModeS
201201
item.StoreTimestamp = i.StoreTimestamp
202202
item.BinID = i.BinID
203203

204-
i, err = db.retrievalAccessIndex.Get(item)
205-
switch err {
206-
case nil:
207-
item.AccessTimestamp = i.AccessTimestamp
208-
db.gcIndex.DeleteInBatch(batch, item)
209-
gcSizeChange--
210-
case leveldb.ErrNotFound:
211-
// the chunk is not accessed before
212-
default:
213-
return 0, err
214-
}
215-
item.AccessTimestamp = now()
216-
db.retrievalAccessIndex.PutInBatch(batch, item)
217-
218204
// moveToGc toggles the deletion of the item from pushsync index
219205
// it will be false in the case pull sync was called but push sync was meant on that chunk (!tag.Anonymous)
220206
moveToGc := true
@@ -258,6 +244,20 @@ func (db *DB) setSync(batch *leveldb.Batch, addr chunk.Address, mode chunk.ModeS
258244
if !moveToGc {
259245
return 0, nil
260246
}
247+
248+
i, err = db.retrievalAccessIndex.Get(item)
249+
switch err {
250+
case nil:
251+
item.AccessTimestamp = i.AccessTimestamp
252+
db.gcIndex.DeleteInBatch(batch, item)
253+
gcSizeChange--
254+
case leveldb.ErrNotFound:
255+
// the chunk is not accessed before
256+
default:
257+
return 0, err
258+
}
259+
item.AccessTimestamp = now()
260+
db.retrievalAccessIndex.PutInBatch(batch, item)
261261
db.pushIndex.DeleteInBatch(batch, item)
262262

263263
// Add in gcIndex only if this chunk is not pinned

storage/localstore/mode_set_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ func TestModeSetSyncPull(t *testing.T) {
220220
po := db.po(ch.Address())
221221
binIDs[po]++
222222

223-
newRetrieveIndexesTestWithAccess(db, ch, wantTimestamp, wantTimestamp)(t)
224223
newPullIndexTest(db, ch, binIDs[po], nil)(t)
225224
newPushIndexTest(db, ch, wantTimestamp, mtc.expErrPushIndex)(t)
226225
newGCIndexTest(db, ch, wantTimestamp, wantTimestamp, binIDs[po], mtc.expErrGCIndex)(t)
@@ -230,6 +229,7 @@ func TestModeSetSyncPull(t *testing.T) {
230229
if mtc.anonymous && mtc.mode != chunk.ModeSetSyncPush {
231230
// run gc index count test
232231
newItemsCountTest(db.gcIndex, tc.count)
232+
newRetrieveIndexesTestWithAccess(db, ch, wantTimestamp, wantTimestamp)(t)
233233
}
234234
}
235235

0 commit comments

Comments
 (0)