diff --git a/src/backend/distributed/master/master_create_shards.c b/src/backend/distributed/master/master_create_shards.c index 7c5a21011..ecf3c97e7 100644 --- a/src/backend/distributed/master/master_create_shards.c +++ b/src/backend/distributed/master/master_create_shards.c @@ -97,6 +97,7 @@ CreateShardsWithRoundRobinPolicy(Oid distributedTableId, int32 shardCount, uint64 hashTokenIncrement = 0; List *existingShardList = NIL; int64 shardIndex = 0; + DistTableCacheEntry *cacheEntry = DistributedTableCacheEntry(distributedTableId); /* make sure table is hash partitioned */ CheckHashPartitionedTable(distributedTableId); @@ -138,6 +139,24 @@ CreateShardsWithRoundRobinPolicy(Oid distributedTableId, int32 shardCount, errmsg("replication_factor must be positive"))); } + /* make sure that RF=1 if the table is streaming replicated */ + if (cacheEntry->replicationModel == REPLICATION_MODEL_STREAMING && + replicationFactor > 1) + { + ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("using replication factor %d with streaming " + "replicated tables are not supported", + replicationFactor), + errdetail("When master_create_distributed_table is called with " + "citus.replication_model streaming, then the table is " + "marked for streaming replication and the shard " + "replication factor of streaming replicated tables " + "must be 1."), + errhint("Use replication factor 1 or set " + "citus.replication_model to streaming and recreate the " + "table"))); + } + /* calculate the split of the hash space */ hashTokenIncrement = HASH_TOKEN_COUNT / shardCount; diff --git a/src/test/regress/expected/multi_create_table.out b/src/test/regress/expected/multi_create_table.out index 266b1d794..3120c835d 100644 --- a/src/test/regress/expected/multi_create_table.out +++ b/src/test/regress/expected/multi_create_table.out @@ -160,6 +160,26 @@ SELECT repmodel FROM pg_dist_partition WHERE logicalrelid='mx_table_test'::regcl (1 row) DROP TABLE mx_table_test; +-- Show that master_create_distributed_table honors citus.replication_model GUC +CREATE TABLE s_table(a int); +SELECT master_create_distributed_table('s_table', 'a', 'hash'); + master_create_distributed_table +--------------------------------- + +(1 row) + +SELECT repmodel FROM pg_dist_partition WHERE logicalrelid='s_table'::regclass; + repmodel +---------- + s +(1 row) + +-- Show that master_create_worker_shards complains when RF>1 and replication model is streaming +SELECT master_create_worker_shards('s_table', 4, 2); +ERROR: using replication factor 2 with streaming replicated tables are not supported +DETAIL: When master_create_distributed_table is called with citus.replication_model streaming, then the table is marked for streaming replication and the shard replication factor of streaming replicated tables must be 1. +HINT: Use replication factor 1 or set citus.replication_model to streaming and recreate the table +DROP TABLE s_table; RESET citus.replication_model; -- Show that it is not possible to create an mx table with the old -- master_create_distributed_table function diff --git a/src/test/regress/sql/multi_create_table.sql b/src/test/regress/sql/multi_create_table.sql index 5bb175a3f..73b277a28 100644 --- a/src/test/regress/sql/multi_create_table.sql +++ b/src/test/regress/sql/multi_create_table.sql @@ -126,6 +126,16 @@ SELECT create_distributed_table('mx_table_test', 'col1'); SELECT repmodel FROM pg_dist_partition WHERE logicalrelid='mx_table_test'::regclass; DROP TABLE mx_table_test; +-- Show that master_create_distributed_table honors citus.replication_model GUC +CREATE TABLE s_table(a int); +SELECT master_create_distributed_table('s_table', 'a', 'hash'); +SELECT repmodel FROM pg_dist_partition WHERE logicalrelid='s_table'::regclass; + +-- Show that master_create_worker_shards complains when RF>1 and replication model is streaming +SELECT master_create_worker_shards('s_table', 4, 2); + +DROP TABLE s_table; + RESET citus.replication_model; -- Show that it is not possible to create an mx table with the old