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,
ModeRequest,
ModeSynced,
ModeAccess,
modeAccess,
} {
t.Run(ModeName(m), func(t *testing.T) {
a := db.Accessor(m)
@ -61,7 +61,7 @@ func TestAccessors(t *testing.T) {
// Removal mode is a special case as it removes the chunk
// from the database.
t.Run(ModeName(ModeRemoval), func(t *testing.T) {
t.Run(ModeName(modeRemoval), func(t *testing.T) {
a := db.Accessor(ModeUpload)
want := generateRandomChunk()
@ -80,7 +80,7 @@ func TestAccessors(t *testing.T) {
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
err = a.Put(context.Background(), want)

View file

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