mirror of https://github.com/citusdata/citus.git
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
parent
6b947c4201
commit
61a1e487d0
|
@ -79,8 +79,7 @@ static void InsertIntoPgDistPartition(Oid relationId, char distributionMethod,
|
||||||
char replicationModel);
|
char replicationModel);
|
||||||
static void CreateHashDistributedTable(Oid relationId, char *distributionColumnName,
|
static void CreateHashDistributedTable(Oid relationId, char *distributionColumnName,
|
||||||
char *colocateWithTableName,
|
char *colocateWithTableName,
|
||||||
int shardCount, int replicationFactor,
|
int shardCount, int replicationFactor);
|
||||||
char replicationModel);
|
|
||||||
static Oid ColumnType(Oid relationId, char *columnName);
|
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 */
|
/* use configuration values for shard count and shard replication factor */
|
||||||
CreateHashDistributedTable(relationId, distributionColumnName,
|
CreateHashDistributedTable(relationId, distributionColumnName,
|
||||||
colocateWithTableName, ShardCount,
|
colocateWithTableName, ShardCount,
|
||||||
ShardReplicationFactor,
|
ShardReplicationFactor);
|
||||||
REPLICATION_MODEL_COORDINATOR);
|
|
||||||
|
|
||||||
PG_RETURN_VOID();
|
PG_RETURN_VOID();
|
||||||
}
|
}
|
||||||
|
@ -953,17 +951,28 @@ CreateTruncateTrigger(Oid relationId)
|
||||||
static void
|
static void
|
||||||
CreateHashDistributedTable(Oid relationId, char *distributionColumnName,
|
CreateHashDistributedTable(Oid relationId, char *distributionColumnName,
|
||||||
char *colocateWithTableName, int shardCount,
|
char *colocateWithTableName, int shardCount,
|
||||||
int replicationFactor, char replicationModel)
|
int replicationFactor)
|
||||||
{
|
{
|
||||||
Relation distributedRelation = NULL;
|
Relation distributedRelation = NULL;
|
||||||
Relation pgDistColocation = NULL;
|
Relation pgDistColocation = NULL;
|
||||||
uint32 colocationId = INVALID_COLOCATION_ID;
|
uint32 colocationId = INVALID_COLOCATION_ID;
|
||||||
Oid sourceRelationId = InvalidOid;
|
Oid sourceRelationId = InvalidOid;
|
||||||
Oid distributionColumnType = InvalidOid;
|
Oid distributionColumnType = InvalidOid;
|
||||||
|
char replicationModel = 0;
|
||||||
|
|
||||||
/* get an access lock on the relation to prevent DROP TABLE and ALTER TABLE */
|
/* get an access lock on the relation to prevent DROP TABLE and ALTER TABLE */
|
||||||
distributedRelation = relation_open(relationId, AccessShareLock);
|
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
|
* Get an exclusive lock on the colocation system catalog. Therefore, we
|
||||||
* can be sure that there will no modifications on the colocation table
|
* 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 */
|
/* create distributed table metadata */
|
||||||
ConvertToDistributedTable(relationId, distributionColumnName, DISTRIBUTE_BY_HASH,
|
ConvertToDistributedTable(relationId, distributionColumnName, DISTRIBUTE_BY_HASH,
|
||||||
colocationId, REPLICATION_MODEL_COORDINATOR);
|
colocationId, replicationModel);
|
||||||
|
|
||||||
/* create shards */
|
/* create shards */
|
||||||
if (sourceRelationId != InvalidOid)
|
if (sourceRelationId != InvalidOid)
|
||||||
|
|
|
@ -371,6 +371,8 @@ SELECT create_distributed_table('table2_groupB', 'id');
|
||||||
|
|
||||||
(1 row)
|
(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
|
-- revert back to default shard replication factor
|
||||||
SET citus.shard_replication_factor to DEFAULT;
|
SET citus.shard_replication_factor to DEFAULT;
|
||||||
-- change partition column type
|
-- change partition column type
|
||||||
|
|
|
@ -137,3 +137,53 @@ SELECT master_create_distributed_table('supplier_single_shard', 's_suppkey', 'ap
|
||||||
|
|
||||||
(1 row)
|
(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;
|
||||||
|
|
|
@ -175,6 +175,9 @@ SELECT create_distributed_table('table1_groupB', 'id');
|
||||||
CREATE TABLE table2_groupB ( id int );
|
CREATE TABLE table2_groupB ( id int );
|
||||||
SELECT create_distributed_table('table2_groupB', 'id');
|
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
|
-- revert back to default shard replication factor
|
||||||
SET citus.shard_replication_factor to DEFAULT;
|
SET citus.shard_replication_factor to DEFAULT;
|
||||||
|
|
||||||
|
|
|
@ -111,3 +111,28 @@ CREATE TABLE supplier_single_shard
|
||||||
s_comment varchar(101) not null
|
s_comment varchar(101) not null
|
||||||
);
|
);
|
||||||
SELECT master_create_distributed_table('supplier_single_shard', 's_suppkey', 'append');
|
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;
|
||||||
|
|
Loading…
Reference in New Issue