Skip to content

Commit

Permalink
Do DELETE instead of TRUNCATE when locks aren't acquired
Browse files Browse the repository at this point in the history
After compression, the uncompressed part of the chunk is truncated.
This requires upgrading the `ExclusiveLock` to an
`AccessExclusiveLock` and hence is sometimes blocked by other other
operations, including reads, on the chunk. This leads to longer
compress times or potential deadlocks.

Instead of this, we fall back to deleting the tuples in the chunk
row-by-row when the upgraded lock isn't immediately acquired.
  • Loading branch information
kpan2034 committed Mar 4, 2025
1 parent 9115e12 commit d4f6397
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 68 deletions.
1 change: 1 addition & 0 deletions .unreleased/pr_7785
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implements: #7785 Do DELETE instead of TRUNCATE when locks aren't acquired
10 changes: 9 additions & 1 deletion tsl/src/compression/compression.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,15 @@ compress_chunk(Oid in_table, Oid out_table, int insert_options)
if (!ts_guc_enable_delete_after_compression)
{
DEBUG_WAITPOINT("compression_done_before_truncate_uncompressed");
truncate_relation(in_table);
if (ConditionalLockRelation(in_rel, AccessExclusiveLock))
{
truncate_relation(in_table);
}
else
{
/* Instead of waiting, delete rows one-by-one */
delete_relation_rows(in_table);
}
DEBUG_WAITPOINT("compression_done_after_truncate_uncompressed");
}
else
Expand Down
Loading

0 comments on commit d4f6397

Please sign in to comment.