diff --git a/src/backend/distributed/commands/create_distributed_table.c b/src/backend/distributed/commands/create_distributed_table.c index 9849da9f4..85331aea7 100644 --- a/src/backend/distributed/commands/create_distributed_table.c +++ b/src/backend/distributed/commands/create_distributed_table.c @@ -1086,6 +1086,14 @@ CreateCitusTable(Oid relationId, CitusTableType tableType, relation_close(relation, NoLock); + if (tableType == SINGLE_SHARD_DISTRIBUTED && ShardReplicationFactor > 1) + { + ereport(ERROR, (errmsg("could not create single shard table: " + "citus.shard_replication_factor is greater than 1"), + errhint("Consider setting citus.shard_replication_factor to 1 " + "and try again"))); + } + /* * EnsureTableNotDistributed errors out when relation is a citus table but * we don't want to ask user to first undistribute their citus local tables diff --git a/src/test/regress/expected/citus_stat_tenants.out b/src/test/regress/expected/citus_stat_tenants.out index 090f0e10e..e7ddadb71 100644 --- a/src/test/regress/expected/citus_stat_tenants.out +++ b/src/test/regress/expected/citus_stat_tenants.out @@ -888,6 +888,7 @@ SELECT citus_stat_tenants_reset(); (1 row) +SET citus.shard_replication_factor TO 1; CREATE TABLE dist_tbl_text_single_shard(a text, b int); select create_distributed_table('dist_tbl_text_single_shard', NULL); create_distributed_table diff --git a/src/test/regress/expected/insert_select_single_shard_table.out b/src/test/regress/expected/insert_select_single_shard_table.out index f61d6b549..8dbb1cf9a 100644 --- a/src/test/regress/expected/insert_select_single_shard_table.out +++ b/src/test/regress/expected/insert_select_single_shard_table.out @@ -2,6 +2,7 @@ CREATE SCHEMA insert_select_single_shard_table; SET search_path TO insert_select_single_shard_table; SET citus.next_shard_id TO 1820000; SET citus.shard_count TO 32; +SET citus.shard_replication_factor TO 1; SET client_min_messages TO NOTICE; CREATE TABLE nullkey_c1_t1(a int, b int); CREATE TABLE nullkey_c1_t2(a int, b int); diff --git a/src/test/regress/expected/isolation_citus_schema_distribute_undistribute.out b/src/test/regress/expected/isolation_citus_schema_distribute_undistribute.out index a392a0129..88737f262 100644 --- a/src/test/regress/expected/isolation_citus_schema_distribute_undistribute.out +++ b/src/test/regress/expected/isolation_citus_schema_distribute_undistribute.out @@ -8,6 +8,7 @@ citus_add_local_table_to_metadata step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-distribute: SELECT citus_schema_distribute('tenant1'); @@ -53,6 +54,7 @@ citus_schema_distribute step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-undistribute: SELECT citus_schema_undistribute('tenant1'); @@ -90,6 +92,7 @@ citus_add_local_table_to_metadata step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-distribute: SELECT citus_schema_distribute('tenant1'); @@ -137,6 +140,7 @@ citus_schema_distribute step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-undistribute: SELECT citus_schema_undistribute('tenant1'); @@ -174,6 +178,7 @@ citus_add_local_table_to_metadata step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-distribute: SELECT citus_schema_distribute('tenant1'); @@ -184,6 +189,7 @@ citus_schema_distribute (1 row) step s2-add-table: + SET citus.shard_replication_factor TO 1; CREATE TABLE tenant1.table4(id int PRIMARY KEY, name text, col bigint); step s1-commit: @@ -223,6 +229,7 @@ citus_schema_distribute step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-undistribute: SELECT citus_schema_undistribute('tenant1'); @@ -233,6 +240,7 @@ citus_schema_undistribute (1 row) step s2-add-table: + SET citus.shard_replication_factor TO 1; CREATE TABLE tenant1.table4(id int PRIMARY KEY, name text, col bigint); step s1-commit: @@ -261,6 +269,7 @@ citus_add_local_table_to_metadata step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-distribute: SELECT citus_schema_distribute('tenant1'); @@ -308,6 +317,7 @@ citus_schema_distribute step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-undistribute: SELECT citus_schema_undistribute('tenant1'); @@ -345,6 +355,7 @@ citus_add_local_table_to_metadata step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-distribute: SELECT citus_schema_distribute('tenant1'); @@ -393,6 +404,7 @@ citus_schema_distribute step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-undistribute: SELECT citus_schema_undistribute('tenant1'); @@ -431,6 +443,7 @@ citus_add_local_table_to_metadata step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-distribute: SELECT citus_schema_distribute('tenant1'); @@ -479,6 +492,7 @@ citus_schema_distribute step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-undistribute: SELECT citus_schema_undistribute('tenant1'); @@ -518,6 +532,7 @@ citus_add_local_table_to_metadata step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-distribute: SELECT citus_schema_distribute('tenant1'); @@ -566,6 +581,7 @@ citus_schema_distribute step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-undistribute: SELECT citus_schema_undistribute('tenant1'); @@ -603,6 +619,7 @@ citus_add_local_table_to_metadata step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-distribute: SELECT citus_schema_distribute('tenant1'); @@ -651,6 +668,7 @@ citus_schema_distribute step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-undistribute: SELECT citus_schema_undistribute('tenant1'); @@ -689,6 +707,7 @@ citus_add_local_table_to_metadata step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-distribute: SELECT citus_schema_distribute('tenant1'); @@ -737,6 +756,7 @@ citus_schema_distribute step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-undistribute: SELECT citus_schema_undistribute('tenant1'); @@ -778,6 +798,7 @@ step s2-create-unique-index: step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-distribute: SELECT citus_schema_distribute('tenant1'); @@ -829,6 +850,7 @@ citus_schema_distribute step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-undistribute: SELECT citus_schema_undistribute('tenant1'); @@ -867,6 +889,7 @@ citus_add_local_table_to_metadata step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-distribute: SELECT citus_schema_distribute('tenant1'); @@ -916,6 +939,7 @@ citus_schema_distribute step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-undistribute: SELECT citus_schema_undistribute('tenant1'); @@ -959,6 +983,7 @@ step s2-insert: step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-distribute: SELECT citus_schema_distribute('tenant1'); @@ -1011,6 +1036,7 @@ citus_schema_distribute step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-undistribute: SELECT citus_schema_undistribute('tenant1'); @@ -1053,6 +1079,7 @@ step s2-insert: step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-distribute: SELECT citus_schema_distribute('tenant1'); @@ -1105,6 +1132,7 @@ citus_schema_distribute step s1-begin: BEGIN; + SET citus.shard_replication_factor TO 1; step s1-schema-undistribute: SELECT citus_schema_undistribute('tenant1'); diff --git a/src/test/regress/expected/isolation_schema_based_sharding.out b/src/test/regress/expected/isolation_schema_based_sharding.out index 48d00bfa0..f089babf5 100644 --- a/src/test/regress/expected/isolation_schema_based_sharding.out +++ b/src/test/regress/expected/isolation_schema_based_sharding.out @@ -1,8 +1,8 @@ Parsed test spec with 2 sessions starting permutation: s1-begin s2-begin s1-tenant-1-create-table-1 s2-tenant-1-create-table-2 s1-commit s2-tenant-1-verify-colocation s2-commit -step s1-begin: BEGIN; -step s2-begin: BEGIN; +step s1-begin: BEGIN; SET citus.shard_replication_factor TO 1; +step s2-begin: BEGIN; SET citus.shard_replication_factor TO 1; step s1-tenant-1-create-table-1: CREATE TABLE tenant_1.tbl_1 (a int); step s2-tenant-1-create-table-2: CREATE TABLE tenant_1.tbl_2 (a int); step s1-commit: COMMIT; @@ -15,8 +15,8 @@ t step s2-commit: COMMIT; starting permutation: s1-begin s2-begin s1-tenant-4-create-table-1 s2-tenant-4-create-table-2 s1-commit s2-tenant-4-verify-colocation s2-commit -step s1-begin: BEGIN; -step s2-begin: BEGIN; +step s1-begin: BEGIN; SET citus.shard_replication_factor TO 1; +step s2-begin: BEGIN; SET citus.shard_replication_factor TO 1; step s1-tenant-4-create-table-1: CREATE TABLE tenant_4.tbl_1 (a int); step s2-tenant-4-create-table-2: CREATE TABLE tenant_4.tbl_2 (a int); step s1-commit: COMMIT; @@ -29,8 +29,8 @@ t step s2-commit: COMMIT; starting permutation: s1-begin s2-begin s1-tenant-2-create-table-1 s2-tenant-3-create-table-1 s1-commit s2-commit -step s1-begin: BEGIN; -step s2-begin: BEGIN; +step s1-begin: BEGIN; SET citus.shard_replication_factor TO 1; +step s2-begin: BEGIN; SET citus.shard_replication_factor TO 1; step s1-tenant-2-create-table-1: CREATE TABLE tenant_2.tbl_1 (a int); step s2-tenant-3-create-table-1: CREATE TABLE tenant_3.tbl_1 (a int); step s1-commit: COMMIT; diff --git a/src/test/regress/expected/multi_extension.out b/src/test/regress/expected/multi_extension.out index fd297ef85..54862798c 100644 --- a/src/test/regress/expected/multi_extension.out +++ b/src/test/regress/expected/multi_extension.out @@ -1333,6 +1333,7 @@ SELECT * FROM multi_extension.print_extension_changes(); -- Test downgrade to 11.3-1 from 12.0-1 ALTER EXTENSION citus UPDATE TO '12.0-1'; CREATE TABLE null_shard_key (x int, y int); +SET citus.shard_replication_factor TO 1; SELECT create_distributed_table('null_shard_key', null); create_distributed_table --------------------------------------------------------------------- diff --git a/src/test/regress/expected/multi_metadata_sync.out b/src/test/regress/expected/multi_metadata_sync.out index 168d28e8a..b74cdc179 100644 --- a/src/test/regress/expected/multi_metadata_sync.out +++ b/src/test/regress/expected/multi_metadata_sync.out @@ -118,7 +118,6 @@ SELECT create_distributed_table('mx_test_table', 'col_1'); (1 row) reset citus.shard_count; -reset citus.shard_replication_factor; -- Set the replication model of the test table to streaming replication so that it is -- considered as an MX table UPDATE pg_dist_partition SET repmodel='s' WHERE logicalrelid='mx_test_table'::regclass; @@ -131,6 +130,7 @@ SELECT create_distributed_table('single_shard_tbl', null); (1 row) INSERT INTO single_shard_tbl VALUES (1); +reset citus.shard_replication_factor; -- Show that the created MX table is and its sequences are included in the activate node snapshot SELECT unnest(activate_node_snapshot()) order by 1; unnest @@ -184,7 +184,7 @@ SELECT unnest(activate_node_snapshot()) order by 1; UPDATE pg_dist_node SET isactive = TRUE WHERE nodeid = 2 UPDATE pg_dist_node SET metadatasynced = TRUE WHERE nodeid = 2 WITH colocation_group_data (colocationid, shardcount, replicationfactor, distributioncolumntype, distributioncolumncollationname, distributioncolumncollationschema) AS (VALUES (2, 8, 1, 'integer'::regtype, NULL, NULL)) SELECT pg_catalog.citus_internal_add_colocation_metadata(colocationid, shardcount, replicationfactor, distributioncolumntype, coalesce(c.oid, 0)) FROM colocation_group_data d LEFT JOIN pg_collation c ON (d.distributioncolumncollationname = c.collname AND d.distributioncolumncollationschema::regnamespace = c.collnamespace) - WITH colocation_group_data (colocationid, shardcount, replicationfactor, distributioncolumntype, distributioncolumncollationname, distributioncolumncollationschema) AS (VALUES (3, 1, 2, 0, NULL, NULL)) SELECT pg_catalog.citus_internal_add_colocation_metadata(colocationid, shardcount, replicationfactor, distributioncolumntype, coalesce(c.oid, 0)) FROM colocation_group_data d LEFT JOIN pg_collation c ON (d.distributioncolumncollationname = c.collname AND d.distributioncolumncollationschema::regnamespace = c.collnamespace) + WITH colocation_group_data (colocationid, shardcount, replicationfactor, distributioncolumntype, distributioncolumncollationname, distributioncolumncollationschema) AS (VALUES (3, 1, 1, 0, NULL, NULL)) SELECT pg_catalog.citus_internal_add_colocation_metadata(colocationid, shardcount, replicationfactor, distributioncolumntype, coalesce(c.oid, 0)) FROM colocation_group_data d LEFT JOIN pg_collation c ON (d.distributioncolumncollationname = c.collname AND d.distributioncolumncollationschema::regnamespace = c.collnamespace) WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('database', ARRAY['regression']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data; WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('role', ARRAY['postgres']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data; WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('schema', ARRAY['public']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data; diff --git a/src/test/regress/expected/multi_metadata_sync_0.out b/src/test/regress/expected/multi_metadata_sync_0.out index 87800915d..16c319d4e 100644 --- a/src/test/regress/expected/multi_metadata_sync_0.out +++ b/src/test/regress/expected/multi_metadata_sync_0.out @@ -118,7 +118,6 @@ SELECT create_distributed_table('mx_test_table', 'col_1'); (1 row) reset citus.shard_count; -reset citus.shard_replication_factor; -- Set the replication model of the test table to streaming replication so that it is -- considered as an MX table UPDATE pg_dist_partition SET repmodel='s' WHERE logicalrelid='mx_test_table'::regclass; @@ -131,6 +130,7 @@ SELECT create_distributed_table('single_shard_tbl', null); (1 row) INSERT INTO single_shard_tbl VALUES (1); +reset citus.shard_replication_factor; -- Show that the created MX table is and its sequences are included in the activate node snapshot SELECT unnest(activate_node_snapshot()) order by 1; unnest @@ -184,7 +184,7 @@ SELECT unnest(activate_node_snapshot()) order by 1; UPDATE pg_dist_node SET isactive = TRUE WHERE nodeid = 2 UPDATE pg_dist_node SET metadatasynced = TRUE WHERE nodeid = 2 WITH colocation_group_data (colocationid, shardcount, replicationfactor, distributioncolumntype, distributioncolumncollationname, distributioncolumncollationschema) AS (VALUES (2, 8, 1, 'integer'::regtype, NULL, NULL)) SELECT pg_catalog.citus_internal_add_colocation_metadata(colocationid, shardcount, replicationfactor, distributioncolumntype, coalesce(c.oid, 0)) FROM colocation_group_data d LEFT JOIN pg_collation c ON (d.distributioncolumncollationname = c.collname AND d.distributioncolumncollationschema::regnamespace = c.collnamespace) - WITH colocation_group_data (colocationid, shardcount, replicationfactor, distributioncolumntype, distributioncolumncollationname, distributioncolumncollationschema) AS (VALUES (3, 1, 2, 0, NULL, NULL)) SELECT pg_catalog.citus_internal_add_colocation_metadata(colocationid, shardcount, replicationfactor, distributioncolumntype, coalesce(c.oid, 0)) FROM colocation_group_data d LEFT JOIN pg_collation c ON (d.distributioncolumncollationname = c.collname AND d.distributioncolumncollationschema::regnamespace = c.collnamespace) + WITH colocation_group_data (colocationid, shardcount, replicationfactor, distributioncolumntype, distributioncolumncollationname, distributioncolumncollationschema) AS (VALUES (3, 1, 1, 0, NULL, NULL)) SELECT pg_catalog.citus_internal_add_colocation_metadata(colocationid, shardcount, replicationfactor, distributioncolumntype, coalesce(c.oid, 0)) FROM colocation_group_data d LEFT JOIN pg_collation c ON (d.distributioncolumncollationname = c.collname AND d.distributioncolumncollationschema::regnamespace = c.collnamespace) WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('database', ARRAY['regression']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data; WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('role', ARRAY['postgres']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data; WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('schema', ARRAY['public']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data; diff --git a/src/test/regress/expected/query_single_shard_table.out b/src/test/regress/expected/query_single_shard_table.out index 68c178553..5716c570d 100644 --- a/src/test/regress/expected/query_single_shard_table.out +++ b/src/test/regress/expected/query_single_shard_table.out @@ -2,6 +2,7 @@ CREATE SCHEMA query_single_shard_table; SET search_path TO query_single_shard_table; SET citus.next_shard_id TO 1620000; SET citus.shard_count TO 32; +SET citus.shard_replication_factor TO 1; SET client_min_messages TO NOTICE; CREATE TABLE nullkey_c1_t1(a int, b int); CREATE TABLE nullkey_c1_t2(a int, b int); @@ -43,6 +44,7 @@ SELECT create_distributed_table('nullkey_c3_t1', null, colocate_with=>'none'); (1 row) INSERT INTO nullkey_c3_t1 SELECT i, i FROM generate_series(1, 8) i; +RESET citus.shard_replication_factor; CREATE TABLE reference_table(a int, b int); SELECT create_reference_table('reference_table'); create_reference_table @@ -81,6 +83,7 @@ INSERT INTO articles_hash VALUES ( 4, 4, 'altdorfer', 14551),( 5, 5, 'aruru', (28, 8, 'aerophyte', 5454),(29, 9, 'amateur', 9524), (42, 2, 'ausable', 15885),(43, 3, 'affixal', 12723), (49, 9, 'anyone', 2681),(50, 10, 'anjanette', 19519); +SET citus.shard_replication_factor TO 1; SELECT create_distributed_table('articles_hash', null, colocate_with=>'none'); NOTICE: Copying data from local table... NOTICE: copying the data has completed @@ -143,6 +146,7 @@ SELECT create_distributed_table('bigserial_test', null); (1 row) +RESET citus.shard_replication_factor; CREATE TABLE append_table (text_col text, a int); SELECT create_distributed_table('append_table', 'a', 'append'); create_distributed_table @@ -166,6 +170,7 @@ CALL public.create_range_partitioned_shards('range_table', '{"0","25"}','{"24"," INSERT INTO range_table VALUES (0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 50); \set users_table_data_file :abs_srcdir '/data/users_table.data' \set events_table_data_file :abs_srcdir '/data/events_table.data' +SET citus.shard_replication_factor TO 1; CREATE TABLE users_table (user_id int, time timestamp, value_1 int, value_2 int, value_3 float, value_4 bigint); SELECT create_distributed_table('users_table', null, colocate_with=>'none'); create_distributed_table diff --git a/src/test/regress/expected/schema_based_sharding.out b/src/test/regress/expected/schema_based_sharding.out index 6dba7227d..7af81966c 100644 --- a/src/test/regress/expected/schema_based_sharding.out +++ b/src/test/regress/expected/schema_based_sharding.out @@ -384,6 +384,12 @@ SELECT EXISTS( t (1 row) +-- errors out because shard replication factor > 1 +SET citus.shard_replication_factor TO 2; +CREATE TABLE tenant_4.tbl_3 AS SELECT 1 AS a, 'text' as b; +ERROR: could not create single shard table: citus.shard_replication_factor is greater than 1 +HINT: Consider setting citus.shard_replication_factor to 1 and try again +SET citus.shard_replication_factor TO 1; -- verify that we allow creating tenant tables by using CREATE TABLE AS / SELECT INTO commands CREATE TABLE tenant_4.tbl_3 AS SELECT 1 AS a, 'text' as b; NOTICE: Copying data from local table... @@ -1439,6 +1445,11 @@ SELECT pg_reload_conf(); \c - - - :master_port SET search_path TO regular_schema; CREATE TABLE type_sing(a INT); +-- errors out because shard_replication_factor = 2 +SELECT create_distributed_table('type_sing', NULL, colocate_with:='none'); +ERROR: could not create single shard table: citus.shard_replication_factor is greater than 1 +HINT: Consider setting citus.shard_replication_factor to 1 and try again +SET citus.shard_replication_factor TO 1; SELECT create_distributed_table('type_sing', NULL, colocate_with:='none'); create_distributed_table --------------------------------------------------------------------- diff --git a/src/test/regress/expected/single_shard_table_udfs.out b/src/test/regress/expected/single_shard_table_udfs.out index 5d3314070..3b73473b0 100644 --- a/src/test/regress/expected/single_shard_table_udfs.out +++ b/src/test/regress/expected/single_shard_table_udfs.out @@ -1066,6 +1066,7 @@ SELECT tablename, indexname FROM pg_indexes WHERE schemaname = 'null_dist_key_ud SET search_path TO null_dist_key_udfs; --test isolate_tenant_to_new_shard CREATE TABLE iso_tbl (a INT); +SET citus.shard_replication_factor TO 1; SELECT create_distributed_table('iso_tbl', NULL, colocate_with:='none'); create_distributed_table --------------------------------------------------------------------- diff --git a/src/test/regress/spec/isolation_citus_schema_distribute_undistribute.spec b/src/test/regress/spec/isolation_citus_schema_distribute_undistribute.spec index 02a4cc829..bb40918f7 100644 --- a/src/test/regress/spec/isolation_citus_schema_distribute_undistribute.spec +++ b/src/test/regress/spec/isolation_citus_schema_distribute_undistribute.spec @@ -1,7 +1,7 @@ setup { SELECT citus_set_coordinator_host('localhost', 57636); - + SET citus.shard_replication_factor TO 1; CREATE SCHEMA tenant1; CREATE TABLE tenant1.table1(id int PRIMARY KEY, name text, col bigint); INSERT INTO tenant1.table1 SELECT i, 'asd', i*1000 FROM generate_series(11, 20) i; @@ -27,6 +27,7 @@ session "s1" step "s1-begin" { BEGIN; + SET citus.shard_replication_factor TO 1; } step "s1-schema-distribute" @@ -63,6 +64,7 @@ step "s2-rename-schema" step "s2-add-table" { + SET citus.shard_replication_factor TO 1; CREATE TABLE tenant1.table4(id int PRIMARY KEY, name text, col bigint); } diff --git a/src/test/regress/spec/isolation_schema_based_sharding.spec b/src/test/regress/spec/isolation_schema_based_sharding.spec index 2f6180538..6f3fe9dc5 100644 --- a/src/test/regress/spec/isolation_schema_based_sharding.spec +++ b/src/test/regress/spec/isolation_schema_based_sharding.spec @@ -1,6 +1,7 @@ setup { SET citus.enable_schema_based_sharding TO ON; + SET citus.shard_replication_factor TO 1; CREATE SCHEMA tenant_1; CREATE SCHEMA tenant_2; CREATE SCHEMA tenant_3; @@ -16,7 +17,7 @@ teardown session "s1" -step "s1-begin" { BEGIN; } +step "s1-begin" { BEGIN; SET citus.shard_replication_factor TO 1;} step "s1-tenant-1-create-table-1" { CREATE TABLE tenant_1.tbl_1 (a int); } step "s1-tenant-4-create-table-1" { CREATE TABLE tenant_4.tbl_1 (a int); } step "s1-tenant-2-create-table-1" { CREATE TABLE tenant_2.tbl_1 (a int); } @@ -24,7 +25,7 @@ step "s1-commit" { COMMIT; } session "s2" -step "s2-begin" { BEGIN; } +step "s2-begin" { BEGIN; SET citus.shard_replication_factor TO 1;} step "s2-tenant-1-create-table-2" { CREATE TABLE tenant_1.tbl_2 (a int); } step "s2-tenant-4-create-table-2" { CREATE TABLE tenant_4.tbl_2 (a int); } step "s2-tenant-1-verify-colocation" { SELECT COUNT(DISTINCT(colocationid))=1 FROM pg_dist_partition WHERE logicalrelid::text LIKE 'tenant_1.%'; } diff --git a/src/test/regress/sql/citus_stat_tenants.sql b/src/test/regress/sql/citus_stat_tenants.sql index 2a6a20335..9160b3499 100644 --- a/src/test/regress/sql/citus_stat_tenants.sql +++ b/src/test/regress/sql/citus_stat_tenants.sql @@ -316,6 +316,7 @@ SELECT tenant_attribute, query_count_in_this_period FROM citus_stat_tenants ORDE -- single shard distributed table, which is not part of a tenant schema SELECT citus_stat_tenants_reset(); +SET citus.shard_replication_factor TO 1; CREATE TABLE dist_tbl_text_single_shard(a text, b int); select create_distributed_table('dist_tbl_text_single_shard', NULL); diff --git a/src/test/regress/sql/insert_select_single_shard_table.sql b/src/test/regress/sql/insert_select_single_shard_table.sql index 4d1e1a73c..fb080d206 100644 --- a/src/test/regress/sql/insert_select_single_shard_table.sql +++ b/src/test/regress/sql/insert_select_single_shard_table.sql @@ -3,6 +3,7 @@ SET search_path TO insert_select_single_shard_table; SET citus.next_shard_id TO 1820000; SET citus.shard_count TO 32; +SET citus.shard_replication_factor TO 1; SET client_min_messages TO NOTICE; diff --git a/src/test/regress/sql/multi_extension.sql b/src/test/regress/sql/multi_extension.sql index aeef30938..72d939867 100644 --- a/src/test/regress/sql/multi_extension.sql +++ b/src/test/regress/sql/multi_extension.sql @@ -595,6 +595,7 @@ SELECT * FROM multi_extension.print_extension_changes(); ALTER EXTENSION citus UPDATE TO '12.0-1'; CREATE TABLE null_shard_key (x int, y int); +SET citus.shard_replication_factor TO 1; SELECT create_distributed_table('null_shard_key', null); -- Show that we cannot downgrade to 11.3-1 becuase the cluster has a diff --git a/src/test/regress/sql/multi_metadata_sync.sql b/src/test/regress/sql/multi_metadata_sync.sql index c1a0a6a9b..0529e1e1d 100644 --- a/src/test/regress/sql/multi_metadata_sync.sql +++ b/src/test/regress/sql/multi_metadata_sync.sql @@ -56,7 +56,6 @@ set citus.shard_count to 8; set citus.shard_replication_factor to 1; SELECT create_distributed_table('mx_test_table', 'col_1'); reset citus.shard_count; -reset citus.shard_replication_factor; -- Set the replication model of the test table to streaming replication so that it is -- considered as an MX table @@ -67,6 +66,8 @@ CREATE TABLE single_shard_tbl(a int); SELECT create_distributed_table('single_shard_tbl', null); INSERT INTO single_shard_tbl VALUES (1); +reset citus.shard_replication_factor; + -- Show that the created MX table is and its sequences are included in the activate node snapshot SELECT unnest(activate_node_snapshot()) order by 1; diff --git a/src/test/regress/sql/query_single_shard_table.sql b/src/test/regress/sql/query_single_shard_table.sql index b6002f8b1..c77d5b1dd 100644 --- a/src/test/regress/sql/query_single_shard_table.sql +++ b/src/test/regress/sql/query_single_shard_table.sql @@ -3,6 +3,7 @@ SET search_path TO query_single_shard_table; SET citus.next_shard_id TO 1620000; SET citus.shard_count TO 32; +SET citus.shard_replication_factor TO 1; SET client_min_messages TO NOTICE; @@ -24,6 +25,8 @@ CREATE TABLE nullkey_c3_t1(a int, b int); SELECT create_distributed_table('nullkey_c3_t1', null, colocate_with=>'none'); INSERT INTO nullkey_c3_t1 SELECT i, i FROM generate_series(1, 8) i; +RESET citus.shard_replication_factor; + CREATE TABLE reference_table(a int, b int); SELECT create_reference_table('reference_table'); INSERT INTO reference_table SELECT i, i FROM generate_series(0, 5) i; @@ -53,6 +56,7 @@ INSERT INTO articles_hash VALUES ( 4, 4, 'altdorfer', 14551),( 5, 5, 'aruru', (42, 2, 'ausable', 15885),(43, 3, 'affixal', 12723), (49, 9, 'anyone', 2681),(50, 10, 'anjanette', 19519); +SET citus.shard_replication_factor TO 1; SELECT create_distributed_table('articles_hash', null, colocate_with=>'none'); CREATE TABLE raw_events_first (user_id int, time timestamp, value_1 int, value_2 int, value_3 float, value_4 bigint, UNIQUE(user_id, value_1)); @@ -80,6 +84,8 @@ SELECT create_reference_table('modify_fast_path_reference'); CREATE TABLE bigserial_test (x int, y int, z bigserial); SELECT create_distributed_table('bigserial_test', null); +RESET citus.shard_replication_factor; + CREATE TABLE append_table (text_col text, a int); SELECT create_distributed_table('append_table', 'a', 'append'); SELECT master_create_empty_shard('append_table') AS shardid1 \gset @@ -112,6 +118,7 @@ INSERT INTO range_table VALUES (0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), ( \set users_table_data_file :abs_srcdir '/data/users_table.data' \set events_table_data_file :abs_srcdir '/data/events_table.data' +SET citus.shard_replication_factor TO 1; CREATE TABLE users_table (user_id int, time timestamp, value_1 int, value_2 int, value_3 float, value_4 bigint); SELECT create_distributed_table('users_table', null, colocate_with=>'none'); \set client_side_copy_command '\\copy users_table FROM ' :'users_table_data_file' ' WITH CSV;' diff --git a/src/test/regress/sql/schema_based_sharding.sql b/src/test/regress/sql/schema_based_sharding.sql index 0417c0e69..e02c68dee 100644 --- a/src/test/regress/sql/schema_based_sharding.sql +++ b/src/test/regress/sql/schema_based_sharding.sql @@ -273,6 +273,10 @@ SELECT EXISTS( inhparent = 'tenant_4.parent_attach_test'::regclass ) AS is_partition; +-- errors out because shard replication factor > 1 +SET citus.shard_replication_factor TO 2; +CREATE TABLE tenant_4.tbl_3 AS SELECT 1 AS a, 'text' as b; +SET citus.shard_replication_factor TO 1; -- verify that we allow creating tenant tables by using CREATE TABLE AS / SELECT INTO commands CREATE TABLE tenant_4.tbl_3 AS SELECT 1 AS a, 'text' as b; CREATE TEMP TABLE IF NOT EXISTS tenant_4.tbl_4 AS SELECT 1 as a, 'text' as b; @@ -974,6 +978,11 @@ SELECT pg_reload_conf(); SET search_path TO regular_schema; CREATE TABLE type_sing(a INT); + +-- errors out because shard_replication_factor = 2 +SELECT create_distributed_table('type_sing', NULL, colocate_with:='none'); + +SET citus.shard_replication_factor TO 1; SELECT create_distributed_table('type_sing', NULL, colocate_with:='none'); SET citus.enable_schema_based_sharding TO ON; diff --git a/src/test/regress/sql/single_shard_table_udfs.sql b/src/test/regress/sql/single_shard_table_udfs.sql index 0e516e107..615e566db 100644 --- a/src/test/regress/sql/single_shard_table_udfs.sql +++ b/src/test/regress/sql/single_shard_table_udfs.sql @@ -508,6 +508,7 @@ SET search_path TO null_dist_key_udfs; --test isolate_tenant_to_new_shard CREATE TABLE iso_tbl (a INT); +SET citus.shard_replication_factor TO 1; SELECT create_distributed_table('iso_tbl', NULL, colocate_with:='none'); SELECT isolate_tenant_to_new_shard('iso_tbl', 5);