Add reclaim to the fcli_db prune cmd (#2122)
This commit is contained in:
parent
2cbc16be8b
commit
6c2c99a9ae
|
@ -359,6 +359,13 @@ proc deleteContentOutOfRadius*(db: ContentDB, localId: UInt256, radius: UInt256)
|
|||
"SQL query OK"
|
||||
)
|
||||
|
||||
proc reclaimAndTruncate*(db: ContentDB) =
|
||||
notice "Reclaiming unused pages"
|
||||
db.reclaimSpace()
|
||||
if db.manualCheckpoint:
|
||||
notice "Truncating WAL file"
|
||||
db.backend.checkpoint(SqStoreCheckpointKind.truncate)
|
||||
|
||||
proc forcePrune*(db: ContentDB, localId: UInt256, radius: UInt256) =
|
||||
## Force prune the database to a statically set radius. This will also run
|
||||
## the reclaimSpace (vacuum) to free unused pages. As side effect this will
|
||||
|
@ -369,11 +376,7 @@ proc forcePrune*(db: ContentDB, localId: UInt256, radius: UInt256) =
|
|||
## skipped.
|
||||
notice "Starting the pruning of content"
|
||||
db.deleteContentOutOfRadius(localId, radius)
|
||||
notice "Reclaiming unused pages"
|
||||
db.reclaimSpace()
|
||||
if db.manualCheckpoint:
|
||||
notice "Truncating WAL file"
|
||||
db.backend.checkpoint(SqStoreCheckpointKind.truncate)
|
||||
db.reclaimAndTruncate()
|
||||
notice "Finished database pruning"
|
||||
|
||||
proc put*(
|
||||
|
|
|
@ -167,7 +167,9 @@ proc run(config: PortalConf) {.raises: [CatchableError].} =
|
|||
# TODO I: Perhaps we want to add an offset to counter the latter.
|
||||
# TODO II: Perhaps for dynamical radius, we want to also apply the vacuum
|
||||
# without the forcePrune flag and purely by checking the amount of free
|
||||
# space versus the pruning fraction.
|
||||
# space versus the pruning fraction. The problem with this is that the
|
||||
# vacuum will temporarily double the space usage (WAL + DB) and thus to do
|
||||
# this automatically without user requesting it could be dangerous.
|
||||
# TODO III: Adding Radius metadata to the db could be yet another way to
|
||||
# decide whether or not to force prune, instead of this flag.
|
||||
db.forcePrune(d.localNode.id, radius)
|
||||
|
|
|
@ -52,7 +52,11 @@ type
|
|||
name: "content-amount"
|
||||
.}: uint64
|
||||
of DbCmd.prune:
|
||||
discard
|
||||
reclaimOnly* {.
|
||||
desc: "Only reclaim space from the database, don't actually prune it",
|
||||
defaultValue: true,
|
||||
name: "reclaim-only"
|
||||
.}: bool
|
||||
of DbCmd.validate:
|
||||
discard
|
||||
|
||||
|
@ -117,6 +121,19 @@ proc cmdBench(conf: DbConf) =
|
|||
|
||||
printTimers(timers)
|
||||
|
||||
proc cmdPrune(conf: DbConf) =
|
||||
if conf.reclaimOnly:
|
||||
let db = ContentDB.new(
|
||||
conf.databaseDir.string,
|
||||
storageCapacity = 1_000_000, # Doesn't matter if only space reclaiming is done
|
||||
manualCheckpoint = true,
|
||||
)
|
||||
|
||||
db.reclaimAndTruncate()
|
||||
else:
|
||||
notice "Functionality not yet implemented"
|
||||
quit QuitSuccess
|
||||
|
||||
proc controlCHook() {.noconv.} =
|
||||
notice "Shutting down after having received SIGINT."
|
||||
quit QuitSuccess
|
||||
|
@ -138,6 +155,6 @@ when isMainModule:
|
|||
of DbCmd.generate:
|
||||
cmdGenerate(conf)
|
||||
of DbCmd.prune:
|
||||
notice "Functionality not yet implemented"
|
||||
cmdPrune(conf)
|
||||
of DbCmd.validate:
|
||||
notice "Functionality not yet implemented"
|
||||
|
|
Loading…
Reference in New Issue