diff --git a/benchmarks/repostore_rw_bench.nim b/benchmarks/repostore_rw_bench.nim index 69b08932..eead440e 100644 --- a/benchmarks/repostore_rw_bench.nim +++ b/benchmarks/repostore_rw_bench.nim @@ -78,6 +78,13 @@ proc readData( let blk = (await store.getBlock(blocks[i].cid)).tryGet() assert blk.cid == blocks[i].cid +proc deleteData( + dataset: Dataset, store: RepoStore +): Future[void] {.async: (raises: [CatchableError]).} = + let (blocks, tree, manifest) = dataset + for i in 0 ..< NBlocks: + (await store.delBlock(blocks[i].cid)).tryGet() + proc writeData( dataset: Dataset, store: FileStore ): Future[void] {.async: (raises: [CatchableError]).} = @@ -99,14 +106,21 @@ proc readData( let blk = (await file.getBlock(i)).tryGet() assert blk.cid == blocks[i].cid +proc deleteData( + dataset: Dataset, store: FileStore +): Future[void] {.async: (raises: [CatchableError]).} = + let (blocks, tree, manifest) = dataset + let file = store.create(manifest).tryGet() + file.delete().tryGet() + proc runRepostoreBench( dataset: Dataset ): Future[void] {.async: (raises: [CatchableError]).} = - let perf = Perf.attach("./perf-ctl", "./perf-ack").expect( - "failed to locate perf ctl/ack files" - ) + # let perf = Perf.attach("./perf-ctl", "./perf-ack").expect( + # "failed to locate perf ctl/ack files" + # ) - perf.perfOff().expect("failed to disable perf") + # perf.perfOff().expect("failed to disable perf") let dir = createTempDir("repostore-bench", "") @@ -119,19 +133,22 @@ proc runRepostoreBench( benchmark "repostore write data": await writeData(dataset, store) - perf.perfOn().expect("failed to enable perf") + # perf.perfOn().expect("failed to enable perf") benchmark "repostore read data": - await writeData(dataset, store) + await readData(dataset, store) + + benchmark "repostore delete data": + await deleteData(dataset, store) proc runFilestoreBench( dataset: Dataset ): Future[void] {.async: (raises: [CatchableError]).} = - let perf = Perf.attach("./perf-ctl", "./perf-ack").expect( - "failed to locate perf ctl/ack files" - ) + # let perf = Perf.attach("./perf-ctl", "./perf-ack").expect( + # "failed to locate perf ctl/ack files" + # ) - perf.perfOff().expect("failed to disable perf") + # perf.perfOff().expect("failed to disable perf") let dir = createTempDir("filestore-bench", "") @@ -144,11 +161,14 @@ proc runFilestoreBench( benchmark "filestore write data": await writeData(dataset, store) - perf.perfOn().expect("failed to enable perf") + # perf.perfOn().expect("failed to enable perf") benchmark "filestore read data": await readData(dataset, store) + benchmark "filestore delete data": + await deleteData(dataset, store) + let dataset = makeDataset(NBlocks, BlockSize).tryGet() waitFor runRepostoreBench(dataset) -#waitFor runFilestoreBench(dataset) +waitFor runFilestoreBench(dataset) diff --git a/codex/stores/filestore.nim b/codex/stores/filestore.nim index bac7e2fc..959676a8 100644 --- a/codex/stores/filestore.nim +++ b/codex/stores/filestore.nim @@ -95,6 +95,11 @@ proc putBlock*( success() +proc delete*(self: File): ?!void = + discard close(self.fd) + osfiles.removeFile(self.filepath) + success() + proc create*(self: FileStore, manifest: Manifest): ?!File = let path = self.root & "/" & $manifest.treeCid initDataset(path, manifest)