From 6443b059a425ce654453a29cf3ce62930ef69e90 Mon Sep 17 00:00:00 2001 From: Ivan FB <128452529+Ivansete-status@users.noreply.github.com> Date: Mon, 12 Aug 2024 10:47:01 +0200 Subject: [PATCH] faster retention policy when error and use of detach finalize when needed (#2966) --- waku/waku_archive/archive.nim | 4 ++++ .../driver/postgres_driver/postgres_driver.nim | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/waku/waku_archive/archive.nim b/waku/waku_archive/archive.nim index caf746170a..aabfe8a0a7 100644 --- a/waku/waku_archive/archive.nim +++ b/waku/waku_archive/archive.nim @@ -24,6 +24,7 @@ const # Retention policy WakuArchiveDefaultRetentionPolicyInterval* = chronos.minutes(30) + WakuArchiveDefaultRetentionPolicyIntervalWhenError* = chronos.minutes(1) # Metrics reporting WakuArchiveDefaultMetricsReportInterval* = chronos.minutes(30) @@ -192,6 +193,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) diff --git a/waku/waku_archive/driver/postgres_driver/postgres_driver.nim b/waku/waku_archive/driver/postgres_driver/postgres_driver.nim index 42c56b5a6e..559fd0be35 100644 --- a/waku/waku_archive/driver/postgres_driver/postgres_driver.nim +++ b/waku/waku_archive/driver/postgres_driver/postgres_driver.nim @@ -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