faster retention policy when error and use of detach finalize when needed (#2966)

This commit is contained in:
Ivan FB 2024-08-12 10:47:01 +02:00 committed by GitHub
parent 5f0fbd78c4
commit 71d4a11647
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -24,6 +24,7 @@ const
# Retention policy
WakuArchiveDefaultRetentionPolicyInterval* = chronos.minutes(30)
WakuArchiveDefaultRetentionPolicyIntervalWhenError* = chronos.minutes(1)
# Metrics reporting
WakuArchiveDefaultMetricsReportInterval* = chronos.minutes(30)
@ -193,6 +194,9 @@ proc periodicRetentionPolicy(self: WakuArchive) {.async.} =
(await policy.execute(self.driver)).isOkOr:
waku_archive_errors.inc(labelValues = [retPolicyFailure])
error "failed execution of retention policy", error = error
await sleepAsync(WakuArchiveDefaultRetentionPolicyIntervalWhenError)
## in case of error, let's try again faster
continue
await sleepAsync(WakuArchiveDefaultRetentionPolicyInterval)

View File

@ -1326,7 +1326,16 @@ proc removePartition(
"ALTER TABLE messages DETACH PARTITION " & partitionName & " CONCURRENTLY;"
debug "removeOldestPartition", query = detachPartitionQuery
(await self.performWriteQuery(detachPartitionQuery)).isOkOr:
return err(fmt"error in {detachPartitionQuery}: " & $error)
if ($error).contains("FINALIZE"):
## We assume the database is suggesting to use FINALIZE when detaching a partition
let detachPartitionFinalizeQuery =
"ALTER TABLE messages DETACH PARTITION " & partitionName & " FINALIZE;"
debug "removeOldestPartition detaching with FINALIZE",
query = detachPartitionFinalizeQuery
(await self.performWriteQuery(detachPartitionFinalizeQuery)).isOkOr:
return err(fmt"error in FINALIZE {detachPartitionFinalizeQuery}: " & $error)
else:
return err(fmt"error in {detachPartitionQuery}: " & $error)
## Drop the partition
let dropPartitionQuery = "DROP TABLE " & partitionName