Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .unreleased/pr_10340
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes: #10340 Validate max_batches in compact_chunk
7 changes: 6 additions & 1 deletion tsl/src/compression/recompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,12 @@ tsl_compact_chunk(PG_FUNCTION_ARGS)
}

int max_batches = PG_GETARG_INT32(1);
Assert(max_batches >= 0);
if (max_batches < 0)
{
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("max_batches must be greater than or equal to 0")));
}

uncompressed_relid = compact_chunk_impl(chunk, max_batches);

Expand Down
5 changes: 5 additions & 0 deletions tsl/test/expected/compact_chunk.out
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ SELECT DISTINCT _timescaledb_functions.chunk_status_text(chunk) FROM show_chunks
-------------------
{COMPRESSED}

-- compact_chunk with negative max_batches must fail
\set ON_ERROR_STOP 0
SELECT _timescaledb_functions.compact_chunk(chunk, -1) FROM show_chunks('metrics') chunk;
ERROR: max_batches must be greater than or equal to 0
\set ON_ERROR_STOP 1
-- compact an uncompressed chunk
-- Create a new uncompressed chunk for a different time range by
-- inserting with direct compress insert disabled.
Expand Down
5 changes: 5 additions & 0 deletions tsl/test/sql/compact_chunk.sql
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ ORDER BY _ts_meta_min_1;
-- Status should not contain UNORDERED flag
SELECT DISTINCT _timescaledb_functions.chunk_status_text(chunk) FROM show_chunks('metrics') chunk;

-- compact_chunk with negative max_batches must fail
\set ON_ERROR_STOP 0
SELECT _timescaledb_functions.compact_chunk(chunk, -1) FROM show_chunks('metrics') chunk;
\set ON_ERROR_STOP 1

-- compact an uncompressed chunk
-- Create a new uncompressed chunk for a different time range by
-- inserting with direct compress insert disabled.
Expand Down
Loading