Mark hash distributed tables with replication factor = 1 as streaming replicated tables (repmodel=s).

This works only with `create_distributed_table` call.
pull/1045/head
Eren Basak 2016-12-14 11:17:59 +03:00
parent 6b947c4201
commit 61a1e487d0
5 changed files with 95 additions and 6 deletions

View File

@ -79,8 +79,7 @@ static void InsertIntoPgDistPartition(Oid relationId, char distributionMethod,
char replicationModel);
static void CreateHashDistributedTable(Oid relationId, char *distributionColumnName,
char *colocateWithTableName,
int shardCount, int replicationFactor,
char replicationModel);
int shardCount, int replicationFactor);
static Oid ColumnType(Oid relationId, char *columnName);
@ -172,8 +171,7 @@ create_distributed_table(PG_FUNCTION_ARGS)
/* use configuration values for shard count and shard replication factor */
CreateHashDistributedTable(relationId, distributionColumnName,
colocateWithTableName, ShardCount,
ShardReplicationFactor,
REPLICATION_MODEL_COORDINATOR);
ShardReplicationFactor);
PG_RETURN_VOID();
}
@ -953,17 +951,28 @@ CreateTruncateTrigger(Oid relationId)
static void
CreateHashDistributedTable(Oid relationId, char *distributionColumnName,
char *colocateWithTableName, int shardCount,
int replicationFactor, char replicationModel)
int replicationFactor)
{
Relation distributedRelation = NULL;
Relation pgDistColocation = NULL;
uint32 colocationId = INVALID_COLOCATION_ID;
Oid sourceRelationId = InvalidOid;
Oid distributionColumnType = InvalidOid;
char replicationModel = 0;
/* get an access lock on the relation to prevent DROP TABLE and ALTER TABLE */
distributedRelation = relation_open(relationId, AccessShareLock);
/* all hash-distributed tables with repfactor=1 are treated as MX tables */
if (replicationFactor == 1)
{
replicationModel = REPLICATION_MODEL_STREAMING;
}
else
{
replicationModel = REPLICATION_MODEL_COORDINATOR;
}
/*
* Get an exclusive lock on the colocation system catalog. Therefore, we
* can be sure that there will no modifications on the colocation table
@ -1004,7 +1013,7 @@ CreateHashDistributedTable(Oid relationId, char *distributionColumnName,
/* create distributed table metadata */
ConvertToDistributedTable(relationId, distributionColumnName, DISTRIBUTE_BY_HASH,
colocationId, REPLICATION_MODEL_COORDINATOR);
colocationId, replicationModel);
/* create shards */
if (sourceRelationId != InvalidOid)

View File

@ -371,6 +371,8 @@ SELECT create_distributed_table('table2_groupB', 'id');
(1 row)
UPDATE pg_dist_partition SET repmodel='c' WHERE logicalrelid='table1_groupB'::regclass;
UPDATE pg_dist_partition SET repmodel='c' WHERE logicalrelid='table2_groupB'::regclass;
-- revert back to default shard replication factor
SET citus.shard_replication_factor to DEFAULT;
-- change partition column type

View File

@ -137,3 +137,53 @@ SELECT master_create_distributed_table('supplier_single_shard', 's_suppkey', 'ap
(1 row)
-- Show that when a hash distributed table with replication factor=1 is created, it
-- automatically marked as streaming replicated
SET citus.shard_replication_factor TO 1;
CREATE TABLE mx_table_test (col1 int, col2 text);
SELECT create_distributed_table('mx_table_test', 'col1');
create_distributed_table
--------------------------
(1 row)
SELECT repmodel FROM pg_dist_partition WHERE logicalrelid='mx_table_test'::regclass;
repmodel
----------
s
(1 row)
DROP TABLE mx_table_test;
-- Show that it is not possible to create an mx table with the old
-- master_create_distributed_table function
CREATE TABLE mx_table_test (col1 int, col2 text);
SELECT master_create_distributed_table('mx_table_test', 'col1', 'hash');
master_create_distributed_table
---------------------------------
(1 row)
SELECT repmodel FROM pg_dist_partition WHERE logicalrelid='mx_table_test'::regclass;
repmodel
----------
c
(1 row)
DROP TABLE mx_table_test;
-- Show that when replication factor > 1 the table is created as coordinator-replicated
SET citus.shard_replication_factor TO 2;
CREATE TABLE mx_table_test (col1 int, col2 text);
SELECT create_distributed_table('mx_table_test', 'col1');
create_distributed_table
--------------------------
(1 row)
SELECT repmodel FROM pg_dist_partition WHERE logicalrelid='mx_table_test'::regclass;
repmodel
----------
c
(1 row)
DROP TABLE mx_table_test;
SET citus.shard_replication_factor TO default;

View File

@ -175,6 +175,9 @@ SELECT create_distributed_table('table1_groupB', 'id');
CREATE TABLE table2_groupB ( id int );
SELECT create_distributed_table('table2_groupB', 'id');
UPDATE pg_dist_partition SET repmodel='c' WHERE logicalrelid='table1_groupB'::regclass;
UPDATE pg_dist_partition SET repmodel='c' WHERE logicalrelid='table2_groupB'::regclass;
-- revert back to default shard replication factor
SET citus.shard_replication_factor to DEFAULT;

View File

@ -111,3 +111,28 @@ CREATE TABLE supplier_single_shard
s_comment varchar(101) not null
);
SELECT master_create_distributed_table('supplier_single_shard', 's_suppkey', 'append');
-- Show that when a hash distributed table with replication factor=1 is created, it
-- automatically marked as streaming replicated
SET citus.shard_replication_factor TO 1;
CREATE TABLE mx_table_test (col1 int, col2 text);
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 it is not possible to create an mx table with the old
-- master_create_distributed_table function
CREATE TABLE mx_table_test (col1 int, col2 text);
SELECT master_create_distributed_table('mx_table_test', 'col1', 'hash');
SELECT repmodel FROM pg_dist_partition WHERE logicalrelid='mx_table_test'::regclass;
DROP TABLE mx_table_test;
-- Show that when replication factor > 1 the table is created as coordinator-replicated
SET citus.shard_replication_factor TO 2;
CREATE TABLE mx_table_test (col1 int, col2 text);
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;
SET citus.shard_replication_factor TO default;