Add replication model column to pg_dist_partition

pull/816/head
Marco Slot 2016-09-28 15:50:19 +02:00
parent 40d99d9845
commit 32b2bd4ed8
10 changed files with 35 additions and 6 deletions

View File

@ -8,7 +8,7 @@ EXTENSION = citus
EXTVERSIONS = 5.0 5.0-1 5.0-2 \
5.1-1 5.1-2 5.1-3 5.1-4 5.1-5 5.1-6 5.1-7 5.1-8 \
5.2-1 5.2-2 5.2-3 5.2-4 \
6.0-1 6.0-2
6.0-1 6.0-2 6.0-3
# All citus--*.sql files in the source directory
DATA = $(patsubst $(citus_abs_srcdir)/%.sql,%.sql,$(wildcard $(citus_abs_srcdir)/$(EXTENSION)--*--*.sql))
@ -62,6 +62,8 @@ $(EXTENSION)--6.0-1.sql: $(EXTENSION)--5.2-4.sql $(EXTENSION)--5.2-4--6.0-1.sql
cat $^ > $@
$(EXTENSION)--6.0-2.sql: $(EXTENSION)--6.0-1.sql $(EXTENSION)--6.0-1--6.0-2.sql
cat $^ > $@
$(EXTENSION)--6.0-3.sql: $(EXTENSION)--6.0-2.sql $(EXTENSION)--6.0-2--6.0-3.sql
cat $^ > $@
NO_PGXS = 1

View File

@ -0,0 +1,4 @@
/* citus--6.0-2--6.0-3.sql */
ALTER TABLE pg_catalog.pg_dist_partition
ADD COLUMN repmodel "char" DEFAULT 'c' NOT NULL;

View File

@ -1,6 +1,6 @@
# Citus extension
comment = 'Citus distributed database'
default_version = '6.0-2'
default_version = '6.0-3'
module_pathname = '$libdir/citus'
relocatable = false
schema = pg_catalog

View File

@ -87,6 +87,7 @@ master_create_distributed_table(PG_FUNCTION_ARGS)
Relation pgDistPartition = NULL;
char distributionMethod = LookupDistributionMethod(distributionMethodOid);
const char replicationModel = 'c';
char *distributionColumnName = text_to_cstring(distributionColumnText);
Node *distributionKey = NULL;
Var *distributionColumn = NULL;
@ -290,6 +291,7 @@ master_create_distributed_table(PG_FUNCTION_ARGS)
newValues[Anum_pg_dist_partition_partkey - 1] =
CStringGetTextDatum(distributionKeyString);
newValues[Anum_pg_dist_partition_colocationid - 1] = INVALID_COLOCATION_ID;
newValues[Anum_pg_dist_partition_repmodel - 1] = CharGetDatum(replicationModel);
newTuple = heap_form_tuple(RelationGetDescr(pgDistPartition), newValues, newNulls);

View File

@ -221,6 +221,7 @@ LookupDistTableCacheEntry(Oid relationId)
char *partitionKeyString = NULL;
char partitionMethod = 0;
uint64 colocationId = INVALID_COLOCATION_ID;
char replicationModel = 0;
List *distShardTupleList = NIL;
int shardIntervalArrayLength = 0;
ShardInterval **shardIntervalArray = NULL;
@ -258,6 +259,7 @@ LookupDistTableCacheEntry(Oid relationId)
Form_pg_dist_partition partitionForm =
(Form_pg_dist_partition) GETSTRUCT(distPartitionTuple);
Datum partitionKeyDatum = 0;
Datum replicationModelDatum = 0;
MemoryContext oldContext = NULL;
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
bool isNull = false;
@ -276,9 +278,16 @@ LookupDistTableCacheEntry(Oid relationId)
colocationId = INVALID_COLOCATION_ID;
}
replicationModelDatum = heap_getattr(distPartitionTuple,
Anum_pg_dist_partition_repmodel,
tupleDescriptor,
&isNull);
Assert(!isNull);
oldContext = MemoryContextSwitchTo(CacheMemoryContext);
partitionKeyString = TextDatumGetCString(partitionKeyDatum);
partitionMethod = partitionForm->partmethod;
replicationModel = DatumGetChar(replicationModelDatum);
MemoryContextSwitchTo(oldContext);
@ -391,6 +400,7 @@ LookupDistTableCacheEntry(Oid relationId)
cacheEntry->partitionKeyString = partitionKeyString;
cacheEntry->partitionMethod = partitionMethod;
cacheEntry->colocationId = colocationId;
cacheEntry->replicationModel = replicationModel;
cacheEntry->shardIntervalArrayLength = shardIntervalArrayLength;
cacheEntry->sortedShardIntervalArray = sortedShardIntervalArray;
cacheEntry->shardIntervalCompareFunction = shardIntervalCompareFunction;

View File

@ -39,6 +39,7 @@ typedef struct
char *partitionKeyString;
char partitionMethod;
uint64 colocationId;
char replicationModel;
/* pg_dist_shard metadata (variable-length ShardInterval array) for this table */
int shardIntervalArrayLength;

View File

@ -25,8 +25,9 @@ typedef struct FormData_pg_dist_partition
char partmethod; /* partition method; see codes below */
#ifdef CATALOG_VARLEN /* variable-length fields start here */
text partkey; /* partition key expression */
uint64 colocationid; /* id of the co-location group of particular table belongs to */
char repmodel; /* replication model; see codes below */
#endif
uint64 colocationid; /* id of the co-location group of particular table belongs to */
} FormData_pg_dist_partition;
/* ----------------
@ -40,11 +41,12 @@ typedef FormData_pg_dist_partition *Form_pg_dist_partition;
* compiler constants for pg_dist_partitions
* ----------------
*/
#define Natts_pg_dist_partition 4
#define Natts_pg_dist_partition 5
#define Anum_pg_dist_partition_logicalrelid 1
#define Anum_pg_dist_partition_partmethod 2
#define Anum_pg_dist_partition_partkey 3
#define Anum_pg_dist_partition_colocationid 4
#define Anum_pg_dist_partition_repmodel 5
/* valid values for partmethod include append, hash, and range */
#define DISTRIBUTE_BY_APPEND 'a'
@ -52,5 +54,9 @@ typedef FormData_pg_dist_partition *Form_pg_dist_partition;
#define DISTRIBUTE_BY_RANGE 'r'
#define REDISTRIBUTE_BY_HASH 'x'
/* valid values for repmodel are 'c' for coordinator and 's' for streaming */
#define REPLICATION_MODEL_COORDINATOR 'c'
#define REPLICATION_MODEL_STREAMING 's'
#endif /* PG_DIST_PARTITION_H */

View File

@ -27,6 +27,8 @@ ALTER EXTENSION citus UPDATE TO '5.2-2';
ALTER EXTENSION citus UPDATE TO '5.2-3';
ALTER EXTENSION citus UPDATE TO '5.2-4';
ALTER EXTENSION citus UPDATE TO '6.0-1';
ALTER EXTENSION citus UPDATE TO '6.0-2';
ALTER EXTENSION citus UPDATE TO '6.0-3';
-- drop extension an re-create in newest version
DROP EXTENSION citus;
\c

View File

@ -48,8 +48,8 @@ SELECT 1 FROM master_create_empty_shard('testtableddl');
DROP TABLE testtableddl;
-- ensure no metadata of distributed tables are remaining
SELECT * FROM pg_dist_partition;
logicalrelid | partmethod | partkey | colocationid
--------------+------------+---------+--------------
logicalrelid | partmethod | partkey | colocationid | repmodel
--------------+------------+---------+--------------+----------
(0 rows)
SELECT * FROM pg_dist_shard;

View File

@ -32,6 +32,8 @@ ALTER EXTENSION citus UPDATE TO '5.2-2';
ALTER EXTENSION citus UPDATE TO '5.2-3';
ALTER EXTENSION citus UPDATE TO '5.2-4';
ALTER EXTENSION citus UPDATE TO '6.0-1';
ALTER EXTENSION citus UPDATE TO '6.0-2';
ALTER EXTENSION citus UPDATE TO '6.0-3';
-- drop extension an re-create in newest version
DROP EXTENSION citus;