mirror of https://github.com/citusdata/citus.git
Merge pull request #816 from citusdata/mx/add_partition_column
Add replication model column to pg_dist_partitionpull/798/head
commit
4fae2133f1
|
@ -8,7 +8,7 @@ EXTENSION = citus
|
||||||
EXTVERSIONS = 5.0 5.0-1 5.0-2 \
|
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.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 \
|
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
|
# All citus--*.sql files in the source directory
|
||||||
DATA = $(patsubst $(citus_abs_srcdir)/%.sql,%.sql,$(wildcard $(citus_abs_srcdir)/$(EXTENSION)--*--*.sql))
|
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 $^ > $@
|
cat $^ > $@
|
||||||
$(EXTENSION)--6.0-2.sql: $(EXTENSION)--6.0-1.sql $(EXTENSION)--6.0-1--6.0-2.sql
|
$(EXTENSION)--6.0-2.sql: $(EXTENSION)--6.0-1.sql $(EXTENSION)--6.0-1--6.0-2.sql
|
||||||
cat $^ > $@
|
cat $^ > $@
|
||||||
|
$(EXTENSION)--6.0-3.sql: $(EXTENSION)--6.0-2.sql $(EXTENSION)--6.0-2--6.0-3.sql
|
||||||
|
cat $^ > $@
|
||||||
|
|
||||||
NO_PGXS = 1
|
NO_PGXS = 1
|
||||||
|
|
||||||
|
|
|
@ -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;
|
|
@ -1,6 +1,6 @@
|
||||||
# Citus extension
|
# Citus extension
|
||||||
comment = 'Citus distributed database'
|
comment = 'Citus distributed database'
|
||||||
default_version = '6.0-2'
|
default_version = '6.0-3'
|
||||||
module_pathname = '$libdir/citus'
|
module_pathname = '$libdir/citus'
|
||||||
relocatable = false
|
relocatable = false
|
||||||
schema = pg_catalog
|
schema = pg_catalog
|
||||||
|
|
|
@ -87,6 +87,7 @@ master_create_distributed_table(PG_FUNCTION_ARGS)
|
||||||
|
|
||||||
Relation pgDistPartition = NULL;
|
Relation pgDistPartition = NULL;
|
||||||
char distributionMethod = LookupDistributionMethod(distributionMethodOid);
|
char distributionMethod = LookupDistributionMethod(distributionMethodOid);
|
||||||
|
const char replicationModel = 'c';
|
||||||
char *distributionColumnName = text_to_cstring(distributionColumnText);
|
char *distributionColumnName = text_to_cstring(distributionColumnText);
|
||||||
Node *distributionKey = NULL;
|
Node *distributionKey = NULL;
|
||||||
Var *distributionColumn = NULL;
|
Var *distributionColumn = NULL;
|
||||||
|
@ -290,6 +291,7 @@ master_create_distributed_table(PG_FUNCTION_ARGS)
|
||||||
newValues[Anum_pg_dist_partition_partkey - 1] =
|
newValues[Anum_pg_dist_partition_partkey - 1] =
|
||||||
CStringGetTextDatum(distributionKeyString);
|
CStringGetTextDatum(distributionKeyString);
|
||||||
newValues[Anum_pg_dist_partition_colocationid - 1] = INVALID_COLOCATION_ID;
|
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);
|
newTuple = heap_form_tuple(RelationGetDescr(pgDistPartition), newValues, newNulls);
|
||||||
|
|
||||||
|
|
|
@ -221,6 +221,7 @@ LookupDistTableCacheEntry(Oid relationId)
|
||||||
char *partitionKeyString = NULL;
|
char *partitionKeyString = NULL;
|
||||||
char partitionMethod = 0;
|
char partitionMethod = 0;
|
||||||
uint64 colocationId = INVALID_COLOCATION_ID;
|
uint64 colocationId = INVALID_COLOCATION_ID;
|
||||||
|
char replicationModel = 0;
|
||||||
List *distShardTupleList = NIL;
|
List *distShardTupleList = NIL;
|
||||||
int shardIntervalArrayLength = 0;
|
int shardIntervalArrayLength = 0;
|
||||||
ShardInterval **shardIntervalArray = NULL;
|
ShardInterval **shardIntervalArray = NULL;
|
||||||
|
@ -258,6 +259,7 @@ LookupDistTableCacheEntry(Oid relationId)
|
||||||
Form_pg_dist_partition partitionForm =
|
Form_pg_dist_partition partitionForm =
|
||||||
(Form_pg_dist_partition) GETSTRUCT(distPartitionTuple);
|
(Form_pg_dist_partition) GETSTRUCT(distPartitionTuple);
|
||||||
Datum partitionKeyDatum = 0;
|
Datum partitionKeyDatum = 0;
|
||||||
|
Datum replicationModelDatum = 0;
|
||||||
MemoryContext oldContext = NULL;
|
MemoryContext oldContext = NULL;
|
||||||
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
||||||
bool isNull = false;
|
bool isNull = false;
|
||||||
|
@ -276,9 +278,16 @@ LookupDistTableCacheEntry(Oid relationId)
|
||||||
colocationId = INVALID_COLOCATION_ID;
|
colocationId = INVALID_COLOCATION_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
replicationModelDatum = heap_getattr(distPartitionTuple,
|
||||||
|
Anum_pg_dist_partition_repmodel,
|
||||||
|
tupleDescriptor,
|
||||||
|
&isNull);
|
||||||
|
Assert(!isNull);
|
||||||
|
|
||||||
oldContext = MemoryContextSwitchTo(CacheMemoryContext);
|
oldContext = MemoryContextSwitchTo(CacheMemoryContext);
|
||||||
partitionKeyString = TextDatumGetCString(partitionKeyDatum);
|
partitionKeyString = TextDatumGetCString(partitionKeyDatum);
|
||||||
partitionMethod = partitionForm->partmethod;
|
partitionMethod = partitionForm->partmethod;
|
||||||
|
replicationModel = DatumGetChar(replicationModelDatum);
|
||||||
|
|
||||||
MemoryContextSwitchTo(oldContext);
|
MemoryContextSwitchTo(oldContext);
|
||||||
|
|
||||||
|
@ -391,6 +400,7 @@ LookupDistTableCacheEntry(Oid relationId)
|
||||||
cacheEntry->partitionKeyString = partitionKeyString;
|
cacheEntry->partitionKeyString = partitionKeyString;
|
||||||
cacheEntry->partitionMethod = partitionMethod;
|
cacheEntry->partitionMethod = partitionMethod;
|
||||||
cacheEntry->colocationId = colocationId;
|
cacheEntry->colocationId = colocationId;
|
||||||
|
cacheEntry->replicationModel = replicationModel;
|
||||||
cacheEntry->shardIntervalArrayLength = shardIntervalArrayLength;
|
cacheEntry->shardIntervalArrayLength = shardIntervalArrayLength;
|
||||||
cacheEntry->sortedShardIntervalArray = sortedShardIntervalArray;
|
cacheEntry->sortedShardIntervalArray = sortedShardIntervalArray;
|
||||||
cacheEntry->shardIntervalCompareFunction = shardIntervalCompareFunction;
|
cacheEntry->shardIntervalCompareFunction = shardIntervalCompareFunction;
|
||||||
|
|
|
@ -39,6 +39,7 @@ typedef struct
|
||||||
char *partitionKeyString;
|
char *partitionKeyString;
|
||||||
char partitionMethod;
|
char partitionMethod;
|
||||||
uint64 colocationId;
|
uint64 colocationId;
|
||||||
|
char replicationModel;
|
||||||
|
|
||||||
/* pg_dist_shard metadata (variable-length ShardInterval array) for this table */
|
/* pg_dist_shard metadata (variable-length ShardInterval array) for this table */
|
||||||
int shardIntervalArrayLength;
|
int shardIntervalArrayLength;
|
||||||
|
|
|
@ -25,8 +25,9 @@ typedef struct FormData_pg_dist_partition
|
||||||
char partmethod; /* partition method; see codes below */
|
char partmethod; /* partition method; see codes below */
|
||||||
#ifdef CATALOG_VARLEN /* variable-length fields start here */
|
#ifdef CATALOG_VARLEN /* variable-length fields start here */
|
||||||
text partkey; /* partition key expression */
|
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
|
#endif
|
||||||
uint64 colocationid; /* id of the co-location group of particular table belongs to */
|
|
||||||
} FormData_pg_dist_partition;
|
} FormData_pg_dist_partition;
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
|
@ -40,11 +41,12 @@ typedef FormData_pg_dist_partition *Form_pg_dist_partition;
|
||||||
* compiler constants for pg_dist_partitions
|
* 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_logicalrelid 1
|
||||||
#define Anum_pg_dist_partition_partmethod 2
|
#define Anum_pg_dist_partition_partmethod 2
|
||||||
#define Anum_pg_dist_partition_partkey 3
|
#define Anum_pg_dist_partition_partkey 3
|
||||||
#define Anum_pg_dist_partition_colocationid 4
|
#define Anum_pg_dist_partition_colocationid 4
|
||||||
|
#define Anum_pg_dist_partition_repmodel 5
|
||||||
|
|
||||||
/* valid values for partmethod include append, hash, and range */
|
/* valid values for partmethod include append, hash, and range */
|
||||||
#define DISTRIBUTE_BY_APPEND 'a'
|
#define DISTRIBUTE_BY_APPEND 'a'
|
||||||
|
@ -52,5 +54,9 @@ typedef FormData_pg_dist_partition *Form_pg_dist_partition;
|
||||||
#define DISTRIBUTE_BY_RANGE 'r'
|
#define DISTRIBUTE_BY_RANGE 'r'
|
||||||
#define REDISTRIBUTE_BY_HASH 'x'
|
#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 */
|
#endif /* PG_DIST_PARTITION_H */
|
||||||
|
|
|
@ -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-3';
|
||||||
ALTER EXTENSION citus UPDATE TO '5.2-4';
|
ALTER EXTENSION citus UPDATE TO '5.2-4';
|
||||||
ALTER EXTENSION citus UPDATE TO '6.0-1';
|
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 an re-create in newest version
|
||||||
DROP EXTENSION citus;
|
DROP EXTENSION citus;
|
||||||
\c
|
\c
|
||||||
|
|
|
@ -48,8 +48,8 @@ SELECT 1 FROM master_create_empty_shard('testtableddl');
|
||||||
DROP TABLE testtableddl;
|
DROP TABLE testtableddl;
|
||||||
-- ensure no metadata of distributed tables are remaining
|
-- ensure no metadata of distributed tables are remaining
|
||||||
SELECT * FROM pg_dist_partition;
|
SELECT * FROM pg_dist_partition;
|
||||||
logicalrelid | partmethod | partkey | colocationid
|
logicalrelid | partmethod | partkey | colocationid | repmodel
|
||||||
--------------+------------+---------+--------------
|
--------------+------------+---------+--------------+----------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
SELECT * FROM pg_dist_shard;
|
SELECT * FROM pg_dist_shard;
|
||||||
|
|
|
@ -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-3';
|
||||||
ALTER EXTENSION citus UPDATE TO '5.2-4';
|
ALTER EXTENSION citus UPDATE TO '5.2-4';
|
||||||
ALTER EXTENSION citus UPDATE TO '6.0-1';
|
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 an re-create in newest version
|
||||||
DROP EXTENSION citus;
|
DROP EXTENSION citus;
|
||||||
|
|
Loading…
Reference in New Issue