Skip to content

Commit 27adbc2

Browse files
committed
Fix crash when enabling compression on a dropped table
Enabling compression looks up the hypertable and only takes the lock on it a bit later. If another transaction drops the table in that window, the lock is granted on a table that no longer exists and the reloaded hypertable is empty. We now check for this and raise an error instead of crashing.
1 parent 5dbca63 commit 27adbc2

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

.unreleased/pr_10212

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes: #10212 Fix race condition when enabling compression on a hypertable

tsl/src/compression/create.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,17 @@ tsl_process_compress_table(Hypertable *ht, WithClauseResult *with_clause_options
13791379
/* reload info after lock */
13801380
ht = ts_hypertable_get_by_id(ht->fd.id);
13811381

1382+
/*
1383+
* If the reload returns nothing the hypertable was dropped while we were
1384+
* waiting for the lock above.
1385+
*/
1386+
if (!ht)
1387+
{
1388+
ereport(ERROR,
1389+
(errcode(ERRCODE_UNDEFINED_TABLE),
1390+
errmsg("hypertable was dropped by a concurrent transaction")));
1391+
}
1392+
13821393
if (compress_disable)
13831394
{
13841395
return disable_compression(ht, with_clause_options);

0 commit comments

Comments
 (0)