# Tests for locking conflicts with CLUSTER command on a CFS table. # # Mirrors cluster-conflict.spec: CLUSTER (a full rewrite into a new # relfilenode, the same atomic swap CFS compaction uses) must block on a # conflicting lock and succeed after it is released. The CFS additions: # the table actually holds compressed data, and after the swap both the # clustering session (s2_verify) and the session that had held a lock on # the old relfilenode (s1_verify) must see intact data and structurally # valid sidecar files. setup { CREATE ROLE regress_cluster_conflict; CREATE TABLE cluster_tab (a int, payload text) WITH (algorithm = 'lz4'); INSERT INTO cluster_tab SELECT g, md5(g::text) FROM generate_series(1, 200) g; CREATE INDEX cluster_ind ON cluster_tab(a); ALTER TABLE cluster_tab OWNER TO regress_cluster_conflict; } teardown { DROP TABLE cluster_tab; DROP ROLE regress_cluster_conflict; } session s1 step s1_begin { BEGIN; } step s1_lock { LOCK cluster_tab IN SHARE UPDATE EXCLUSIVE MODE; } step s1_commit { COMMIT; } step s1_verify { SELECT count(*) FROM cluster_tab; } step s1_check { SELECT ok FROM pg_cfs_check('cluster_tab'::regclass, true); } session s2 step s2_auth { SET ROLE regress_cluster_conflict; } step s2_cluster { CLUSTER cluster_tab USING cluster_ind; } step s2_reset { RESET ROLE; } step s2_verify { SELECT count(*) FROM cluster_tab; } step s2_check { SELECT ok FROM pg_cfs_check('cluster_tab'::regclass, true); } # The role has privileges to cluster the table, CLUSTER will block if # another session holds a lock on the table and succeed in all cases. permutation s1_begin s1_lock s2_auth s2_cluster s1_commit s2_reset s2_verify s2_check s1_verify s1_check permutation s1_begin s2_auth s1_lock s2_cluster s1_commit s2_reset s2_verify s2_check s1_verify s1_check