swarm/storage/localstore: unexport modeAccess and modeRemoval

This commit is contained in:
Janos Guljas 2018-12-03 10:54:16 +01:00
parent b1ded5a80b
commit 572f3cb960
2 changed files with 12 additions and 11 deletions

View file

@ -37,7 +37,7 @@ func TestAccessors(t *testing.T) {
ModeUpload, ModeUpload,
ModeRequest, ModeRequest,
ModeSynced, ModeSynced,
ModeAccess, modeAccess,
} { } {
t.Run(ModeName(m), func(t *testing.T) { t.Run(ModeName(m), func(t *testing.T) {
a := db.Accessor(m) a := db.Accessor(m)
@ -61,7 +61,7 @@ func TestAccessors(t *testing.T) {
// Removal mode is a special case as it removes the chunk // Removal mode is a special case as it removes the chunk
// from the database. // from the database.
t.Run(ModeName(ModeRemoval), func(t *testing.T) { t.Run(ModeName(modeRemoval), func(t *testing.T) {
a := db.Accessor(ModeUpload) a := db.Accessor(ModeUpload)
want := generateRandomChunk() want := generateRandomChunk()
@ -80,7 +80,7 @@ func TestAccessors(t *testing.T) {
t.Errorf("got chunk data %x, want %x", got.Data(), want.Data()) t.Errorf("got chunk data %x, want %x", got.Data(), want.Data())
} }
a = db.Accessor(ModeRemoval) a = db.Accessor(modeRemoval)
// removal accessor actually removes the chunk on Put // removal accessor actually removes the chunk on Put
err = a.Put(context.Background(), want) err = a.Put(context.Background(), want)

View file

@ -33,10 +33,11 @@ const (
ModeUpload ModeUpload
ModeRequest ModeRequest
ModeSynced ModeSynced
ModeAccess // this modes are internal only
// Q: this mode is not needed, // they can be removed completely
// as it will be used only internally for GC. // if accessors are not used internally
ModeRemoval modeAccess
modeRemoval
) )
// ModeName returns a descriptive name of a Mode. // ModeName returns a descriptive name of a Mode.
@ -51,9 +52,9 @@ func ModeName(m Mode) (name string) {
return "request" return "request"
case ModeSynced: case ModeSynced:
return "synced" return "synced"
case ModeAccess: case modeAccess:
return "access" return "access"
case ModeRemoval: case modeRemoval:
return "removal" return "removal"
} }
return "" return ""
@ -162,14 +163,14 @@ func (db *DB) updateBatch(b *batch, mode Mode, item shed.IndexItem) (err error)
db.pushIndex.DeleteInBatch(b.Batch, item) db.pushIndex.DeleteInBatch(b.Batch, item)
db.gcIndex.PutInBatch(b.Batch, item) db.gcIndex.PutInBatch(b.Batch, item)
case ModeAccess: case modeAccess:
// update accessTimeStamp in retrieve, gc // update accessTimeStamp in retrieve, gc
db.gcIndex.DeleteInBatch(b.Batch, item) db.gcIndex.DeleteInBatch(b.Batch, item)
item.AccessTimestamp = now() item.AccessTimestamp = now()
db.retrievalIndex.PutInBatch(b.Batch, item) db.retrievalIndex.PutInBatch(b.Batch, item)
db.gcIndex.PutInBatch(b.Batch, item) db.gcIndex.PutInBatch(b.Batch, item)
case ModeRemoval: case modeRemoval:
// delete from retrieve, pull, gc // delete from retrieve, pull, gc
db.retrievalIndex.DeleteInBatch(b.Batch, item) db.retrievalIndex.DeleteInBatch(b.Batch, item)
db.pullIndex.DeleteInBatch(b.Batch, item) db.pullIndex.DeleteInBatch(b.Batch, item)