# D1 shared .cfp tail: two backends alternately appending pages of one # CFS relation through the real locked write path. # # Every cfs_test_tail_write() call runs in its OWN backend (a fresh psql # invocation): the handle, its cached append cursor and the compression # scratch are private to that process, so the only state carried between # the alternating writers is the shared metadata slot. With the # authoritative tail in the slot, each writer must resume exactly where # its peer stopped; the returned .cfp offsets are therefore strictly # increasing. A backend that appended at a stale per-handle cursor would # reuse (and overwrite) a peer's record; cfs_test_tail_verify() detects # that as duplicate offsets (-2) or corrupted read-back data (-1) and # returns the verified block count otherwise. use strict; use warnings FATAL => 'all'; use PostgreSQL::Test::Cluster; use Test::More; my $node = PostgreSQL::Test::Cluster->new('cfs_tail_two_backends'); $node->init; $node->start; $node->safe_psql('postgres', 'CREATE EXTENSION test_cfs'); my $rel = 910501; # (session, block): perfect alternation, three pages per backend. my @steps = ( [1, 1], [2, 2], [1, 3], [2, 4], [1, 5], [2, 6]); my $prev_off = 0; for my $step (@steps) { my ($session, $block) = @$step; my $off = $node->safe_psql('postgres', "SELECT cfs_test_tail_write($rel, $block)"); like($off, qr/^\d+$/, "session $session wrote block $block at a numeric offset"); cmp_ok($off, '>', $prev_off, "session $session block $block offset $off is past peer's $prev_off"); $prev_off = $off; } my $verified = $node->safe_psql('postgres', "SELECT cfs_test_tail_verify($rel, 6)"); is($verified, '6', 'all six pages read back intact with strictly increasing offsets'); $node->safe_psql('postgres', "SELECT cfs_test_tail_cleanup($rel)"); $node->stop('immediate'); done_testing();