Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit c8b4335

Browse files
committed
Fix skipping compression of first to last chunk
Due to a bug in logic, we were skipping compression of the first to last chunk which ended over an hour ago from current time. This was causing to have one more chunk per metric uncompressed, causing us to use more storage than necessary.
1 parent e05376c commit c8b4335

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ We use the following categories for changes:
1919

2020
### Fixed
2121
- Fix broken `promscale_packager` telemetry field for docker envs [#1077]
22+
- Fix compression of old chunks thus reducing storage requirements [#1081]
2223

2324
## [0.8.0] - 2022-01-18
2425

pkg/migrations/migration_files_generated.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/migrations/sql/idempotent/base.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2911,21 +2911,22 @@ BEGIN
29112911
DECLARE
29122912
chunk_schema_name name;
29132913
chunk_table_name name;
2914+
chunk_range_end timestamptz;
29142915
chunk_num INT;
29152916
BEGIN
2916-
FOR chunk_schema_name, chunk_table_name, chunk_num IN
2917+
FOR chunk_schema_name, chunk_table_name, chunk_range_end, chunk_num IN
29172918
SELECT
29182919
chunk_schema,
29192920
chunk_name,
2921+
range_end,
29202922
row_number() OVER (ORDER BY range_end DESC)
29212923
FROM timescaledb_information.chunks
29222924
WHERE hypertable_schema = 'SCHEMA_DATA'
29232925
AND hypertable_name = metric_table
29242926
AND NOT is_compressed
2925-
AND range_end <= compress_before
29262927
ORDER BY range_end ASC
29272928
LOOP
2928-
CONTINUE WHEN chunk_num <= 1;
2929+
CONTINUE WHEN chunk_num <= 1 OR chunk_range_end > compress_before;
29292930
PERFORM SCHEMA_CATALOG.compress_chunk_for_metric(metric_table, chunk_schema_name, chunk_table_name);
29302931
COMMIT;
29312932
END LOOP;

pkg/tests/end_to_end_tests/create_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,19 @@ func TestCustomCompressionJob(t *testing.T) {
12331233
if chunkIsCompressed("1970-03-01 00:00:00.001+00") {
12341234
t.Error("third chunk compressed too soon")
12351235
}
1236+
1237+
// Add an chunk at current time
1238+
insert = fmt.Sprintf(`INSERT INTO prom_data."%s" VALUES (NOW(), 0.1, 1);`, tableName)
1239+
_, err = db.Exec(context.Background(), insert)
1240+
if err != nil {
1241+
t.Fatal(err)
1242+
}
1243+
1244+
runCompressionJob()
1245+
// third chunk should be compressed since its not the last chunk anymore
1246+
if !chunkIsCompressed("1970-03-01 00:00:00.001+00") {
1247+
t.Error("third chunk not compressed when it should have been")
1248+
}
12361249
})
12371250
}
12381251

0 commit comments

Comments
 (0)