mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-06-06 05:59:33 +00:00
postgres_driver: add more error handling when creating partitions
Given that multiple nodes can be connected to the same database, it can happen that other node did something that my node was willing to do. In this commit, we overcome the possible "interleaved" partition creation.
This commit is contained in:
parent
3262e0c0ac
commit
14ff3c1e42
@ -954,6 +954,24 @@ proc performWriteQueryWithLock*(
|
||||
debug "skip performWriteQuery because the advisory lock is acquired by other"
|
||||
return ok()
|
||||
|
||||
if error.contains("already exists"):
|
||||
## expected to happen when trying to add a partition table constraint that already exists
|
||||
## e.g., constraint "constraint_name" for relation "messages_1720364735_1720364740" already exists
|
||||
debug "skip already exists error", error = error
|
||||
return ok()
|
||||
|
||||
if error.contains("is already a partition"):
|
||||
## expected to happen when a node tries to add a partition that is already attached,
|
||||
## e.g., "messages_1720364735_1720364740" is already a partition
|
||||
debug "skip is already a partition error", error = error
|
||||
return ok()
|
||||
|
||||
if error.contains("does not exist"):
|
||||
## expected to happen when trying to drop a constraint that has already been dropped by other
|
||||
## constraint "constraint_name" of relation "messages_1720364735_1720364740" does not exist
|
||||
debug "skip does not exist error", error = error
|
||||
return ok()
|
||||
|
||||
debug "protected query ended with error", error = $error
|
||||
return err("protected query ended with error:" & $error)
|
||||
|
||||
@ -984,10 +1002,6 @@ proc addPartition(
|
||||
" (LIKE messages INCLUDING DEFAULTS INCLUDING CONSTRAINTS);"
|
||||
|
||||
(await self.performWriteQueryWithLock(createPartitionQuery)).isOkOr:
|
||||
if error.contains("already exists"):
|
||||
debug "skip create new partition as it already exists: ", skipped_error = $error
|
||||
return ok()
|
||||
|
||||
return err(fmt"error adding partition [{partitionName}]: " & $error)
|
||||
|
||||
## Add constraint to the partition table so that EXCLUSIVE ACCESS is not performed when
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user