Skip to content

Commit

Permalink
Disable xids and empty transactions in TAP test
Browse files Browse the repository at this point in the history
Instead of filtering the output of `pg_logical_slot_get_changes` we set
the option `skip-empty-xacts` and clear `include-xids` to get stable
tests.

Since the option 'skip-empty-xacts' is set, this changes the order of
messages since the BEGIN of a transaction is not generated until the
decoder plugin can see that the transaction started and messages do not
count as part of a transaction.
  • Loading branch information
mkindahl committed Sep 11, 2024
1 parent 17ab214 commit 20f30de
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions tsl/test/t/002_logrepl_decomp_marker.pl
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ sub query_generates_wal

$db->safe_psql('postgres', $query);
my $result = $db->safe_psql('postgres',
qq/SELECT data FROM pg_logical_slot_get_changes('slot', NULL, NULL);/
qq/SELECT data FROM pg_logical_slot_get_changes('slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');/
);
$result =~ s/\s+creation_time.*//g
; # creation_time is non-deterministic, so strip it from wal (it's always the final column)
$result =~ s/(BEGIN|COMMIT) \d+/$1/g
; # BEGIN/COMMIT statements contain the statement number, which we don't care about

# creation_time is non-deterministic, so strip it from wal (it's
# always the final column)
$result =~ s/\s+creation_time.*//g;

is($result, $expected_wal, $description);
}

sub discard_wal
{
$db->safe_psql('postgres',
qq/SELECT data FROM pg_logical_slot_get_changes('slot', NULL, NULL);/
qq/SELECT data FROM pg_logical_slot_get_changes('slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');/
);
}

Expand Down Expand Up @@ -79,8 +79,8 @@ sub discard_wal
query_generates_wal(
"compress chunk",
qq(SELECT compress_chunk('_timescaledb_internal._hyper_1_1_chunk'::regclass, TRUE);),
qq(BEGIN
message: transactional: 1 prefix: ::timescaledb-compression-start, sz: 0 content:
qq(message: transactional: 1 prefix: ::timescaledb-compression-start, sz: 0 content:
BEGIN
table _timescaledb_catalog.chunk: INSERT: id[integer]:2 hypertable_id[integer]:2 schema_name[name]:'_timescaledb_internal' table_name[name]:'compress_hyper_2_2_chunk' compressed_chunk_id[integer]:null dropped[boolean]:false status[integer]:0 osm_chunk[boolean]:false
table _timescaledb_catalog.compression_settings: INSERT: relid[regclass]:'_timescaledb_internal.compress_hyper_2_2_chunk' segmentby[text[]]:'{device_id}' orderby[text[]]:'{time}' orderby_desc[boolean[]]:'{f}' orderby_nullsfirst[boolean[]]:'{f}'
table _timescaledb_internal.compress_hyper_2_2_chunk: INSERT: _ts_meta_count[integer]:1 _ts_meta_sequence_num[integer]:10 device_id[bigint]:1 _ts_meta_min_1[timestamp with time zone]:'2023-06-30 17:00:00-07' _ts_meta_max_1[timestamp with time zone]:'2023-06-30 17:00:00-07' "time"[_timescaledb_internal.compressed_data]:'BAAAAqJgYhxAAAAComBiHEAAAAAAAQAAAAEAAAAAAAAADgAFRMDEOIAA' value[_timescaledb_internal.compressed_data]:'AwA/8AAAAAAAAAAAAAEAAAABAAAAAAAAAAEAAAAAAAAAAQAAAAEAAAABAAAAAAAAAAEAAAAAAAAAAQAAAAEGAAAAAAAAAAIAAAABAAAAAQAAAAAAAAAEAAAAAAAAAAoAAAABCgAAAAAAAAP/'
Expand All @@ -93,8 +93,8 @@ sub discard_wal
query_generates_wal(
"decompress chunk",
qq(SELECT decompress_chunk('_timescaledb_internal._hyper_1_1_chunk'::regclass, TRUE);),
qq(BEGIN
message: transactional: 1 prefix: ::timescaledb-decompression-start, sz: 0 content:
qq(message: transactional: 1 prefix: ::timescaledb-decompression-start, sz: 0 content:
BEGIN
table _timescaledb_internal._hyper_1_1_chunk: INSERT: "time"[timestamp with time zone]:'2023-06-30 17:00:00-07' device_id[bigint]:1 value[double precision]:1
table _timescaledb_catalog.compression_chunk_size: DELETE: chunk_id[integer]:1
table _timescaledb_catalog.chunk: UPDATE: id[integer]:1 hypertable_id[integer]:1 schema_name[name]:'_timescaledb_internal' table_name[name]:'_hyper_1_1_chunk' compressed_chunk_id[integer]:null dropped[boolean]:false status[integer]:0 osm_chunk[boolean]:false
Expand All @@ -112,10 +112,9 @@ sub discard_wal
query_generates_wal(
"recompress chunk (NOOP)",
qq(SELECT compress_chunk('_timescaledb_internal._hyper_1_1_chunk'::regclass, TRUE);),
qq(BEGIN
message: transactional: 1 prefix: ::timescaledb-compression-start, sz: 0 content:
message: transactional: 1 prefix: ::timescaledb-compression-end, sz: 0 content:
COMMIT),);
qq(message: transactional: 1 prefix: ::timescaledb-compression-start, sz: 0 content:
message: transactional: 1 prefix: ::timescaledb-compression-end, sz: 0 content:),
);

query_generates_wal(
"insert into uncompressed chunk",
Expand All @@ -128,8 +127,8 @@ sub discard_wal
query_generates_wal(
"recompress chunk",
qq(SELECT compress_chunk('_timescaledb_internal._hyper_1_1_chunk'::regclass, TRUE);),
qq(BEGIN
message: transactional: 1 prefix: ::timescaledb-compression-start, sz: 0 content:
qq(message: transactional: 1 prefix: ::timescaledb-compression-start, sz: 0 content:
BEGIN
table _timescaledb_catalog.chunk: UPDATE: id[integer]:1 hypertable_id[integer]:1 schema_name[name]:'_timescaledb_internal' table_name[name]:'_hyper_1_1_chunk' compressed_chunk_id[integer]:3 dropped[boolean]:false status[integer]:1 osm_chunk[boolean]:false
table _timescaledb_internal._hyper_1_1_chunk: DELETE: "time"[timestamp with time zone]:'2023-06-30 18:00:00-07' device_id[bigint]:1 value[double precision]:1
table _timescaledb_internal.compress_hyper_2_3_chunk: DELETE: (no-tuple-data)
Expand All @@ -149,8 +148,8 @@ sub discard_wal
query_generates_wal(
"update rows in uncompressed and compressed chunk",
qq(UPDATE metrics SET value = 22 WHERE time IN ('2023-07-01T00:00:00Z', '2023-07-01T02:00:00Z');),
qq(BEGIN
message: transactional: 1 prefix: ::timescaledb-decompression-start, sz: 0 content:
qq(message: transactional: 1 prefix: ::timescaledb-decompression-start, sz: 0 content:
BEGIN
table _timescaledb_internal.compress_hyper_2_3_chunk: DELETE: (no-tuple-data)
table _timescaledb_internal._hyper_1_1_chunk: INSERT: "time"[timestamp with time zone]:'2023-06-30 17:00:00-07' device_id[bigint]:1 value[double precision]:1
table _timescaledb_internal._hyper_1_1_chunk: INSERT: "time"[timestamp with time zone]:'2023-06-30 18:00:00-07' device_id[bigint]:1 value[double precision]:1
Expand All @@ -162,8 +161,8 @@ sub discard_wal
query_generates_wal(
"compress chunk after update",
qq(SELECT compress_chunk('_timescaledb_internal._hyper_1_1_chunk'::regclass, TRUE);),
qq(BEGIN
message: transactional: 1 prefix: ::timescaledb-compression-start, sz: 0 content:
qq(message: transactional: 1 prefix: ::timescaledb-compression-start, sz: 0 content:
BEGIN
table _timescaledb_catalog.chunk: UPDATE: id[integer]:1 hypertable_id[integer]:1 schema_name[name]:'_timescaledb_internal' table_name[name]:'_hyper_1_1_chunk' compressed_chunk_id[integer]:3 dropped[boolean]:false status[integer]:1 osm_chunk[boolean]:false
table _timescaledb_internal._hyper_1_1_chunk: DELETE: "time"[timestamp with time zone]:'2023-06-30 18:00:00-07' device_id[bigint]:1 value[double precision]:1
table _timescaledb_internal._hyper_1_1_chunk: DELETE: "time"[timestamp with time zone]:'2023-06-30 19:00:00-07' device_id[bigint]:1 value[double precision]:22
Expand All @@ -184,8 +183,8 @@ sub discard_wal
query_generates_wal(
"delete row in compressed chunk",
qq(DELETE FROM metrics WHERE time IN ('2023-07-01T00:00:00Z', '2023-07-01T03:00:00Z');),
qq(BEGIN
message: transactional: 1 prefix: ::timescaledb-decompression-start, sz: 0 content:
qq(message: transactional: 1 prefix: ::timescaledb-decompression-start, sz: 0 content:
BEGIN
table _timescaledb_internal.compress_hyper_2_3_chunk: DELETE: (no-tuple-data)
table _timescaledb_internal._hyper_1_1_chunk: INSERT: "time"[timestamp with time zone]:'2023-06-30 17:00:00-07' device_id[bigint]:1 value[double precision]:22
table _timescaledb_internal._hyper_1_1_chunk: INSERT: "time"[timestamp with time zone]:'2023-06-30 18:00:00-07' device_id[bigint]:1 value[double precision]:1
Expand Down

0 comments on commit 20f30de

Please sign in to comment.