BlockStore: delBlock got new type (#123)
Now every store traces only its own operations and failures (currently implemented only for delBlock)
This commit is contained in:
parent
c0b385176d
commit
15ae157e61
|
@ -41,8 +41,8 @@ method putBlock*(
|
|||
|
||||
method delBlock*(
|
||||
s: BlockStore,
|
||||
cid: Cid): Future[bool] {.base.} =
|
||||
## Delete a block/s from the block store
|
||||
cid: Cid): Future[?!void] {.base.} =
|
||||
## Delete a block from the blockstore
|
||||
##
|
||||
|
||||
raiseAssert("Not implemented!")
|
||||
|
|
|
@ -109,23 +109,20 @@ method putBlock*(
|
|||
|
||||
method delBlock*(
|
||||
self: CacheStore,
|
||||
cid: Cid): Future[bool] {.async.} =
|
||||
## delete a block/s from the block store
|
||||
cid: Cid): Future[?!void] {.async.} =
|
||||
## Delete a block from the blockstore
|
||||
##
|
||||
|
||||
trace "Deleting block from cache", cid
|
||||
if cid.isEmpty:
|
||||
trace "Empty block, ignoring"
|
||||
return true
|
||||
return success()
|
||||
|
||||
try:
|
||||
let removed = self.cache.del(cid)
|
||||
if removed.isSome:
|
||||
self.currentSize -= removed.get.data.len
|
||||
return true
|
||||
return false
|
||||
except EmptyLruCacheError:
|
||||
return false
|
||||
|
||||
return success()
|
||||
|
||||
func new*(
|
||||
_: type CacheStore,
|
||||
|
|
|
@ -97,26 +97,25 @@ method putBlock*(
|
|||
|
||||
method delBlock*(
|
||||
self: FSStore,
|
||||
cid: Cid): Future[bool] {.async.} =
|
||||
## Delete a block/s from the block store
|
||||
cid: Cid): Future[?!void] {.async.} =
|
||||
## Delete a block from the blockstore
|
||||
##
|
||||
|
||||
trace "Deleting block from filestore", cid
|
||||
if cid.isEmpty:
|
||||
trace "Empty block, ignoring"
|
||||
return true
|
||||
return success()
|
||||
|
||||
let path = self.blockPath(cid)
|
||||
if (
|
||||
let res = io2.removeFile(path);
|
||||
res.isErr):
|
||||
let error = io2.ioErrorMsg(res.error)
|
||||
trace "Unable to delete block", path, cid, error
|
||||
return false
|
||||
let
|
||||
path = self.blockPath(cid)
|
||||
res = io2.removeFile(path)
|
||||
|
||||
if not (await self.cache.delBlock(cid)):
|
||||
trace "Unable to delete block from cache", cid
|
||||
if res.isErr:
|
||||
let errmsg = io2.ioErrorMsg(res.error)
|
||||
trace "Unable to delete block", path, cid, errmsg
|
||||
return errmsg.failure
|
||||
|
||||
return true
|
||||
return await self.cache.delBlock(cid)
|
||||
|
||||
method hasBlock*(self: FSStore, cid: Cid): bool =
|
||||
## Check if the block exists in the blockstore
|
||||
|
|
|
@ -66,11 +66,12 @@ method putBlock*(
|
|||
|
||||
method delBlock*(
|
||||
self: NetworkStore,
|
||||
cid: Cid): Future[bool] =
|
||||
## Delete a block/s from the block store
|
||||
cid: Cid): Future[?!void] =
|
||||
## Delete a block from the blockstore
|
||||
##
|
||||
|
||||
self.localStore.delBlock(cid)
|
||||
trace "Deleting block from networkstore", cid
|
||||
return self.localStore.delBlock(cid)
|
||||
|
||||
{.pop.}
|
||||
|
||||
|
|
|
@ -93,17 +93,18 @@ suite "Cache Store tests":
|
|||
|
||||
test "delBlock":
|
||||
# empty cache
|
||||
check not await store.delBlock(newBlock1.cid)
|
||||
(await store.delBlock(newBlock1.cid)).tryGet()
|
||||
|
||||
# successfully deleted
|
||||
discard await store.putBlock(newBlock1)
|
||||
check await store.delBlock(newBlock1.cid)
|
||||
(await store.delBlock(newBlock1.cid)).tryGet()
|
||||
|
||||
# deletes item should decrement size
|
||||
store = CacheStore.new(@[newBlock1, newBlock2, newBlock3])
|
||||
check:
|
||||
store.currentSize == 300
|
||||
await store.delBlock(newBlock2.cid)
|
||||
(await store.delBlock(newBlock2.cid)).tryGet()
|
||||
check:
|
||||
store.currentSize == 200
|
||||
newBlock2.cid notin store
|
||||
|
||||
|
|
|
@ -68,5 +68,5 @@ suite "FS Store":
|
|||
createDir(store.blockPath(newBlock.cid).parentDir)
|
||||
writeFile(store.blockPath(newBlock.cid), newBlock.data)
|
||||
|
||||
check await store.delBlock(newBlock.cid)
|
||||
(await store.delBlock(newBlock.cid)).tryGet()
|
||||
check not fileExists(store.blockPath(newBlock.cid))
|
||||
|
|
|
@ -66,7 +66,7 @@ suite "Erasure encode/decode":
|
|||
|
||||
for _ in 0..<encoded.M:
|
||||
dropped.add(encoded[column])
|
||||
check (await store.delBlock(encoded[column]))
|
||||
(await store.delBlock(encoded[column])).tryGet()
|
||||
column.inc(encoded.steps)
|
||||
|
||||
var
|
||||
|
@ -93,7 +93,7 @@ suite "Erasure encode/decode":
|
|||
|
||||
for _ in 0..<encoded.M + 1:
|
||||
dropped.add(encoded[column])
|
||||
check (await store.delBlock(encoded[column]))
|
||||
(await store.delBlock(encoded[column])).tryGet()
|
||||
column.inc(encoded.steps)
|
||||
|
||||
var
|
||||
|
@ -125,7 +125,7 @@ suite "Erasure encode/decode":
|
|||
offset.inc
|
||||
|
||||
for idx in blocks:
|
||||
check (await store.delBlock(encoded[idx]))
|
||||
(await store.delBlock(encoded[idx])).tryGet()
|
||||
|
||||
discard (await erasure.decode(encoded)).tryGet()
|
||||
|
||||
|
@ -158,7 +158,7 @@ suite "Erasure encode/decode":
|
|||
offset.inc
|
||||
|
||||
for idx in blocks:
|
||||
check (await store.delBlock(encoded[idx]))
|
||||
(await store.delBlock(encoded[idx])).tryGet()
|
||||
|
||||
var
|
||||
decoded: Manifest
|
||||
|
@ -174,7 +174,7 @@ suite "Erasure encode/decode":
|
|||
let encoded = await encode(buffers, parity)
|
||||
|
||||
for b in encoded.blocks[0..<encoded.steps * encoded.M]:
|
||||
check (await store.delBlock(b))
|
||||
(await store.delBlock(b)).tryGet()
|
||||
|
||||
discard (await erasure.decode(encoded)).tryGet()
|
||||
|
||||
|
@ -189,7 +189,7 @@ suite "Erasure encode/decode":
|
|||
let encoded = await encode(buffers, parity)
|
||||
|
||||
for b in encoded.blocks[^(encoded.steps * encoded.M)..^1]:
|
||||
check (await store.delBlock(b))
|
||||
(await store.delBlock(b)).tryGet()
|
||||
|
||||
discard (await erasure.decode(encoded)).tryGet()
|
||||
|
||||
|
|
Loading…
Reference in New Issue