index controlled block deleting
This commit is contained in:
parent
c7fdf4ca9e
commit
72ae2ceabc
|
@ -514,7 +514,7 @@ proc requestStorage*(
|
|||
let purchase = await contracts.purchasing.purchase(request)
|
||||
success purchase.id
|
||||
|
||||
proc debugDelete*(self: CodexNodeRef, cid: Cid, nBlocks: int): Future[?!int] {.async.} =
|
||||
proc debugDelete*(self: CodexNodeRef, cid: Cid, blockIndices: seq[int]): Future[?!int] {.async.} =
|
||||
without manifest =? (await self.fetchManifest(cid)), err:
|
||||
trace "Unable to fetch manifest for cid", cid, err = err.msg
|
||||
return failure(err)
|
||||
|
@ -524,15 +524,15 @@ proc debugDelete*(self: CodexNodeRef, cid: Cid, nBlocks: int): Future[?!int] {.a
|
|||
treeCid = manifest.treeCid
|
||||
|
||||
var
|
||||
index = -1
|
||||
deleted = 0
|
||||
|
||||
while deleted < nBlocks and index < totalBlocks:
|
||||
inc index
|
||||
for index in blockIndices:
|
||||
if index >= totalBlocks:
|
||||
return failure("Index out of range. Index: " & $index & " totalBlocks: " & $totalBlocks)
|
||||
without hasBlock =? (await self.networkStore.hasBlock(treeCid, index)), err:
|
||||
return failure(err)
|
||||
if not hasBlock:
|
||||
continue
|
||||
return failure("Tree does not have this index: " & $index & " totalBlocks: " & $totalBlocks)
|
||||
else:
|
||||
if err =? (await self.networkStore.delBlock(treeCid, index)).errorOption:
|
||||
return failure(err)
|
||||
|
|
|
@ -640,7 +640,7 @@ proc initDebugApi(node: CodexNodeRef, conf: CodexConf, router: var RestRouter) =
|
|||
when codex_enable_api_debug_delete:
|
||||
type
|
||||
DebugDeleteParams = object
|
||||
nBlocks* {.serialize.}: int
|
||||
blockIndices* {.serialize.}: seq[int]
|
||||
|
||||
router.rawApi(
|
||||
MethodPost,
|
||||
|
@ -653,12 +653,12 @@ proc initDebugApi(node: CodexNodeRef, conf: CodexConf, router: var RestRouter) =
|
|||
without params =? DebugDeleteParams.fromJson(body), error:
|
||||
return RestApiResponse.error(Http400, error.msg)
|
||||
|
||||
warn "debug/delete is deleting blocks", cid = $cid, nBlocks = params.nBlocks
|
||||
warn "debug/delete is deleting blocks", cid = $cid, nBlocks = params.blockIndices.len
|
||||
|
||||
without deleted =? (await node.debugDelete(cid, params.nBlocks)), err:
|
||||
without deleted =? (await node.debugDelete(cid, params.blockIndices)), err:
|
||||
return RestApiResponse.error(Http500, err.msg)
|
||||
|
||||
warn "debug/delete has deleted blocks", cid = $cid, nBlocks = params.nBlocks, deleted
|
||||
warn "debug/delete has deleted blocks", cid = $cid, deleted
|
||||
|
||||
return RestApiResponse.response($deleted)
|
||||
except CatchableError as exc:
|
||||
|
|
Loading…
Reference in New Issue