Skip to content

Commit 3c170cc

Browse files
Validate max_batches in compact_chunk
Replace Assert with ereport for negative max_batches so callers get a proper error instead of a crash in debug builds.
1 parent ca6925d commit 3c170cc

4 files changed

Lines changed: 17 additions & 1 deletion

File tree

.unreleased/pr_10340

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes: #10340 Validate max_batches in compact_chunk

tsl/src/compression/recompress.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,12 @@ tsl_compact_chunk(PG_FUNCTION_ARGS)
289289
}
290290

291291
int max_batches = PG_GETARG_INT32(1);
292-
Assert(max_batches >= 0);
292+
if (max_batches < 0)
293+
{
294+
ereport(ERROR,
295+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
296+
errmsg("max_batches must be greater than or equal to 0")));
297+
}
293298

294299
uncompressed_relid = compact_chunk_impl(chunk, max_batches);
295300

tsl/test/expected/compact_chunk.out

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ SELECT DISTINCT _timescaledb_functions.chunk_status_text(chunk) FROM show_chunks
115115
-------------------
116116
{COMPRESSED}
117117

118+
-- compact_chunk with negative max_batches must fail
119+
\set ON_ERROR_STOP 0
120+
SELECT _timescaledb_functions.compact_chunk(chunk, -1) FROM show_chunks('metrics') chunk;
121+
ERROR: max_batches must be greater than or equal to 0
122+
\set ON_ERROR_STOP 1
118123
-- compact an uncompressed chunk
119124
-- Create a new uncompressed chunk for a different time range by
120125
-- inserting with direct compress insert disabled.

tsl/test/sql/compact_chunk.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ ORDER BY _ts_meta_min_1;
7676
-- Status should not contain UNORDERED flag
7777
SELECT DISTINCT _timescaledb_functions.chunk_status_text(chunk) FROM show_chunks('metrics') chunk;
7878

79+
-- compact_chunk with negative max_batches must fail
80+
\set ON_ERROR_STOP 0
81+
SELECT _timescaledb_functions.compact_chunk(chunk, -1) FROM show_chunks('metrics') chunk;
82+
\set ON_ERROR_STOP 1
83+
7984
-- compact an uncompressed chunk
8085
-- Create a new uncompressed chunk for a different time range by
8186
-- inserting with direct compress insert disabled.

0 commit comments

Comments
 (0)