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:
Bulat-Ziganshin 2022-06-28 19:10:05 +03:00 committed by GitHub
parent c0b385176d
commit 15ae157e61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 39 deletions

View File

@ -41,8 +41,8 @@ method putBlock*(
method delBlock*( method delBlock*(
s: BlockStore, s: BlockStore,
cid: Cid): Future[bool] {.base.} = cid: Cid): Future[?!void] {.base.} =
## Delete a block/s from the block store ## Delete a block from the blockstore
## ##
raiseAssert("Not implemented!") raiseAssert("Not implemented!")

View File

@ -109,23 +109,20 @@ method putBlock*(
method delBlock*( method delBlock*(
self: CacheStore, self: CacheStore,
cid: Cid): Future[bool] {.async.} = cid: Cid): Future[?!void] {.async.} =
## delete a block/s from the block store ## Delete a block from the blockstore
## ##
trace "Deleting block from cache", cid trace "Deleting block from cache", cid
if cid.isEmpty: if cid.isEmpty:
trace "Empty block, ignoring" trace "Empty block, ignoring"
return true return success()
try: let removed = self.cache.del(cid)
let removed = self.cache.del(cid) if removed.isSome:
if removed.isSome: self.currentSize -= removed.get.data.len
self.currentSize -= removed.get.data.len
return true return success()
return false
except EmptyLruCacheError:
return false
func new*( func new*(
_: type CacheStore, _: type CacheStore,

View File

@ -97,26 +97,25 @@ method putBlock*(
method delBlock*( method delBlock*(
self: FSStore, self: FSStore,
cid: Cid): Future[bool] {.async.} = cid: Cid): Future[?!void] {.async.} =
## Delete a block/s from the block store ## Delete a block from the blockstore
## ##
trace "Deleting block from filestore", cid
if cid.isEmpty: if cid.isEmpty:
trace "Empty block, ignoring" trace "Empty block, ignoring"
return true return success()
let path = self.blockPath(cid) let
if ( path = self.blockPath(cid)
let res = io2.removeFile(path); res = io2.removeFile(path)
res.isErr):
let error = io2.ioErrorMsg(res.error)
trace "Unable to delete block", path, cid, error
return false
if not (await self.cache.delBlock(cid)): if res.isErr:
trace "Unable to delete block from cache", cid 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 = method hasBlock*(self: FSStore, cid: Cid): bool =
## Check if the block exists in the blockstore ## Check if the block exists in the blockstore

View File

@ -66,11 +66,12 @@ method putBlock*(
method delBlock*( method delBlock*(
self: NetworkStore, self: NetworkStore,
cid: Cid): Future[bool] = cid: Cid): Future[?!void] =
## Delete a block/s from the block store ## Delete a block from the blockstore
## ##
self.localStore.delBlock(cid) trace "Deleting block from networkstore", cid
return self.localStore.delBlock(cid)
{.pop.} {.pop.}

View File

@ -93,17 +93,18 @@ suite "Cache Store tests":
test "delBlock": test "delBlock":
# empty cache # empty cache
check not await store.delBlock(newBlock1.cid) (await store.delBlock(newBlock1.cid)).tryGet()
# successfully deleted # successfully deleted
discard await store.putBlock(newBlock1) discard await store.putBlock(newBlock1)
check await store.delBlock(newBlock1.cid) (await store.delBlock(newBlock1.cid)).tryGet()
# deletes item should decrement size # deletes item should decrement size
store = CacheStore.new(@[newBlock1, newBlock2, newBlock3]) store = CacheStore.new(@[newBlock1, newBlock2, newBlock3])
check: check:
store.currentSize == 300 store.currentSize == 300
await store.delBlock(newBlock2.cid) (await store.delBlock(newBlock2.cid)).tryGet()
check:
store.currentSize == 200 store.currentSize == 200
newBlock2.cid notin store newBlock2.cid notin store

View File

@ -68,5 +68,5 @@ suite "FS Store":
createDir(store.blockPath(newBlock.cid).parentDir) createDir(store.blockPath(newBlock.cid).parentDir)
writeFile(store.blockPath(newBlock.cid), newBlock.data) 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)) check not fileExists(store.blockPath(newBlock.cid))

View File

@ -66,7 +66,7 @@ suite "Erasure encode/decode":
for _ in 0..<encoded.M: for _ in 0..<encoded.M:
dropped.add(encoded[column]) dropped.add(encoded[column])
check (await store.delBlock(encoded[column])) (await store.delBlock(encoded[column])).tryGet()
column.inc(encoded.steps) column.inc(encoded.steps)
var var
@ -93,7 +93,7 @@ suite "Erasure encode/decode":
for _ in 0..<encoded.M + 1: for _ in 0..<encoded.M + 1:
dropped.add(encoded[column]) dropped.add(encoded[column])
check (await store.delBlock(encoded[column])) (await store.delBlock(encoded[column])).tryGet()
column.inc(encoded.steps) column.inc(encoded.steps)
var var
@ -125,7 +125,7 @@ suite "Erasure encode/decode":
offset.inc offset.inc
for idx in blocks: for idx in blocks:
check (await store.delBlock(encoded[idx])) (await store.delBlock(encoded[idx])).tryGet()
discard (await erasure.decode(encoded)).tryGet() discard (await erasure.decode(encoded)).tryGet()
@ -158,7 +158,7 @@ suite "Erasure encode/decode":
offset.inc offset.inc
for idx in blocks: for idx in blocks:
check (await store.delBlock(encoded[idx])) (await store.delBlock(encoded[idx])).tryGet()
var var
decoded: Manifest decoded: Manifest
@ -174,7 +174,7 @@ suite "Erasure encode/decode":
let encoded = await encode(buffers, parity) let encoded = await encode(buffers, parity)
for b in encoded.blocks[0..<encoded.steps * encoded.M]: 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() discard (await erasure.decode(encoded)).tryGet()
@ -189,7 +189,7 @@ suite "Erasure encode/decode":
let encoded = await encode(buffers, parity) let encoded = await encode(buffers, parity)
for b in encoded.blocks[^(encoded.steps * encoded.M)..^1]: 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() discard (await erasure.decode(encoded)).tryGet()