Skip to content

Commit be8f00e

Browse files
committed
docs: explain timestamp collision prevention in tablespace rename
Add comment documenting why timestamp collision cannot occur during temp tablespace rename operations on tmpfs storage. The comment clarifies that consuming charms ensure leader-only execution and PostgreSQL serializes operations through exclusive locks, making second-precision timestamps sufficient for uniqueness. Addresses feedback from PR review comment: #54 (comment) Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
1 parent 32416d3 commit be8f00e

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

single_kernel_postgresql/utils/postgresql.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,8 @@ def _handle_temp_tablespace_on_reboot(
11241124
if is_tmpfs(temp_location):
11251125
# tmpfs: Directory is empty after reboot, safe to rename and recreate
11261126
# Rename existing temp tablespace instead of dropping it.
1127+
# Timestamp collision is not possible: the charm ensures this code runs leader-only,
1128+
# and it executes within a single database transaction holding exclusive locks.
11271129
new_name = f"temp_{datetime.now(timezone.utc).strftime('%Y%m%d%H%M%S')}"
11281130
cursor.execute(f"ALTER TABLESPACE temp RENAME TO {new_name};")
11291131

0 commit comments

Comments
 (0)