Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: faster retention policy when error and use of detach finalize when needed #2966

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions waku/waku_archive/archive.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const

# Retention policy
WakuArchiveDefaultRetentionPolicyInterval* = chronos.minutes(30)
WakuArchiveDefaultRetentionPolicyIntervalWhenError* = chronos.minutes(1)

# Metrics reporting
WakuArchiveDefaultMetricsReportInterval* = chronos.minutes(30)
Expand Down Expand Up @@ -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)

Expand Down
11 changes: 10 additions & 1 deletion waku/waku_archive/driver/postgres_driver/postgres_driver.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading