mirror of https://github.com/citusdata/citus.git
Apply master_stage_protocol refactoring changes
parent
86a3dd5a90
commit
3fc7cdfe6d
|
@ -381,7 +381,6 @@ CreateAppendDistributedShardPlacements(Oid relationId, int64 shardId,
|
||||||
int placementsCreated = 0;
|
int placementsCreated = 0;
|
||||||
int attemptNumber = 0;
|
int attemptNumber = 0;
|
||||||
List *foreignConstraintCommandList = GetTableForeignConstraintCommands(relationId);
|
List *foreignConstraintCommandList = GetTableForeignConstraintCommands(relationId);
|
||||||
char *alterTableAttachPartitionCommand = NULL;
|
|
||||||
bool includeSequenceDefaults = false;
|
bool includeSequenceDefaults = false;
|
||||||
List *ddlCommandList = GetTableDDLEvents(relationId, includeSequenceDefaults);
|
List *ddlCommandList = GetTableDDLEvents(relationId, includeSequenceDefaults);
|
||||||
uint32 connectionFlag = FOR_DDL;
|
uint32 connectionFlag = FOR_DDL;
|
||||||
|
@ -416,8 +415,7 @@ CreateAppendDistributedShardPlacements(Oid relationId, int64 shardId,
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkerCreateShard(relationId, shardIndex, shardId, ddlCommandList,
|
WorkerCreateShard(relationId, shardIndex, shardId, ddlCommandList,
|
||||||
foreignConstraintCommandList, alterTableAttachPartitionCommand,
|
foreignConstraintCommandList, connection);
|
||||||
connection);
|
|
||||||
|
|
||||||
InsertShardPlacementRow(shardId, INVALID_PLACEMENT_ID, shardState, shardSize,
|
InsertShardPlacementRow(shardId, INVALID_PLACEMENT_ID, shardState, shardSize,
|
||||||
nodeGroupId);
|
nodeGroupId);
|
||||||
|
@ -499,7 +497,7 @@ CreateShardsOnWorkers(Oid distributedRelationId, List *shardPlacements,
|
||||||
ListCell *connectionCell = NULL;
|
ListCell *connectionCell = NULL;
|
||||||
ListCell *shardPlacementCell = NULL;
|
ListCell *shardPlacementCell = NULL;
|
||||||
int connectionFlags = FOR_DDL;
|
int connectionFlags = FOR_DDL;
|
||||||
char *alterTableAttachPartitionCommand = NULL;
|
bool partitionTable = PartitionTable(distributedRelationId);
|
||||||
|
|
||||||
if (useExclusiveConnection)
|
if (useExclusiveConnection)
|
||||||
{
|
{
|
||||||
|
@ -507,12 +505,6 @@ CreateShardsOnWorkers(Oid distributedRelationId, List *shardPlacements,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (PartitionTable(distributedRelationId))
|
|
||||||
{
|
|
||||||
alterTableAttachPartitionCommand =
|
|
||||||
GenerateAlterTableAttachPartitionCommand(distributedRelationId);
|
|
||||||
}
|
|
||||||
|
|
||||||
BeginOrContinueCoordinatedTransaction();
|
BeginOrContinueCoordinatedTransaction();
|
||||||
|
|
||||||
if (MultiShardCommitProtocol == COMMIT_PROTOCOL_2PC ||
|
if (MultiShardCommitProtocol == COMMIT_PROTOCOL_2PC ||
|
||||||
|
@ -527,7 +519,7 @@ CreateShardsOnWorkers(Oid distributedRelationId, List *shardPlacements,
|
||||||
RecordParallelDDLAccess(distributedRelationId);
|
RecordParallelDDLAccess(distributedRelationId);
|
||||||
|
|
||||||
/* we should mark the parent as well */
|
/* we should mark the parent as well */
|
||||||
if (alterTableAttachPartitionCommand != NULL)
|
if (partitionTable)
|
||||||
{
|
{
|
||||||
Oid parentRelationId = PartitionParentOid(distributedRelationId);
|
Oid parentRelationId = PartitionParentOid(distributedRelationId);
|
||||||
RecordParallelDDLAccess(parentRelationId);
|
RecordParallelDDLAccess(parentRelationId);
|
||||||
|
@ -552,8 +544,7 @@ CreateShardsOnWorkers(Oid distributedRelationId, List *shardPlacements,
|
||||||
* with DDL. This is only important for parallel relation access in transaction
|
* with DDL. This is only important for parallel relation access in transaction
|
||||||
* blocks, thus check useExclusiveConnection and transaction block as well.
|
* blocks, thus check useExclusiveConnection and transaction block as well.
|
||||||
*/
|
*/
|
||||||
if ((ShouldRecordRelationAccess() && useExclusiveConnection) &&
|
if (ShouldRecordRelationAccess() && useExclusiveConnection && partitionTable)
|
||||||
alterTableAttachPartitionCommand != NULL)
|
|
||||||
{
|
{
|
||||||
RelationShard *parentRelationShard = CitusMakeNode(RelationShard);
|
RelationShard *parentRelationShard = CitusMakeNode(RelationShard);
|
||||||
RelationShard *partitionRelationShard = CitusMakeNode(RelationShard);
|
RelationShard *partitionRelationShard = CitusMakeNode(RelationShard);
|
||||||
|
@ -589,8 +580,7 @@ CreateShardsOnWorkers(Oid distributedRelationId, List *shardPlacements,
|
||||||
MarkRemoteTransactionCritical(connection);
|
MarkRemoteTransactionCritical(connection);
|
||||||
|
|
||||||
WorkerCreateShard(distributedRelationId, shardIndex, shardId,
|
WorkerCreateShard(distributedRelationId, shardIndex, shardId,
|
||||||
ddlCommandList, foreignConstraintCommandList,
|
ddlCommandList, foreignConstraintCommandList, connection);
|
||||||
alterTableAttachPartitionCommand, connection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -613,8 +603,7 @@ CreateShardsOnWorkers(Oid distributedRelationId, List *shardPlacements,
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
WorkerCreateShard(Oid relationId, int shardIndex, uint64 shardId, List *ddlCommandList,
|
WorkerCreateShard(Oid relationId, int shardIndex, uint64 shardId, List *ddlCommandList,
|
||||||
List *foreignConstraintCommandList,
|
List *foreignConstraintCommandList, MultiConnection *connection)
|
||||||
char *alterTableAttachPartitionCommand, MultiConnection *connection)
|
|
||||||
{
|
{
|
||||||
Oid schemaId = get_rel_namespace(relationId);
|
Oid schemaId = get_rel_namespace(relationId);
|
||||||
char *schemaName = get_namespace_name(schemaId);
|
char *schemaName = get_namespace_name(schemaId);
|
||||||
|
@ -697,34 +686,11 @@ WorkerCreateShard(Oid relationId, int shardIndex, uint64 shardId, List *ddlComma
|
||||||
* If the shard is created for a partition, send the command to create the
|
* If the shard is created for a partition, send the command to create the
|
||||||
* partitioning hierarcy on the shard.
|
* partitioning hierarcy on the shard.
|
||||||
*/
|
*/
|
||||||
if (alterTableAttachPartitionCommand != NULL)
|
if (PartitionTable(relationId))
|
||||||
{
|
{
|
||||||
Oid parentRelationId = PartitionParentOid(relationId);
|
ShardInterval *shardInterval = LoadShardInterval(shardId);
|
||||||
uint64 correspondingParentShardId = InvalidOid;
|
char *attachPartitionCommand = GenerateAttachShardPartitionCommand(shardInterval);
|
||||||
StringInfo applyAttachPartitionCommand = makeStringInfo();
|
ExecuteCriticalRemoteCommand(connection, attachPartitionCommand);
|
||||||
|
|
||||||
Oid parentSchemaId = InvalidOid;
|
|
||||||
char *parentSchemaName = NULL;
|
|
||||||
char *escapedParentSchemaName = NULL;
|
|
||||||
char *escapedCommand = NULL;
|
|
||||||
|
|
||||||
Assert(PartitionTable(relationId));
|
|
||||||
|
|
||||||
parentSchemaId = get_rel_namespace(parentRelationId);
|
|
||||||
parentSchemaName = get_namespace_name(parentSchemaId);
|
|
||||||
escapedParentSchemaName = quote_literal_cstr(parentSchemaName);
|
|
||||||
escapedCommand = quote_literal_cstr(alterTableAttachPartitionCommand);
|
|
||||||
|
|
||||||
correspondingParentShardId = ColocatedShardIdInRelation(parentRelationId,
|
|
||||||
shardIndex);
|
|
||||||
|
|
||||||
appendStringInfo(applyAttachPartitionCommand,
|
|
||||||
WORKER_APPLY_INTER_SHARD_DDL_COMMAND, correspondingParentShardId,
|
|
||||||
escapedParentSchemaName, shardId, escapedSchemaName,
|
|
||||||
escapedCommand);
|
|
||||||
|
|
||||||
|
|
||||||
ExecuteCriticalRemoteCommand(connection, applyAttachPartitionCommand->data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,11 @@
|
||||||
#include "catalog/pg_constraint_fn.h"
|
#include "catalog/pg_constraint_fn.h"
|
||||||
#endif
|
#endif
|
||||||
#include "distributed/citus_ruleutils.h"
|
#include "distributed/citus_ruleutils.h"
|
||||||
|
#include "distributed/colocation_utils.h"
|
||||||
|
#include "distributed/master_metadata_utility.h"
|
||||||
|
#include "distributed/master_protocol.h"
|
||||||
#include "distributed/multi_partitioning_utils.h"
|
#include "distributed/multi_partitioning_utils.h"
|
||||||
|
#include "distributed/shardinterval_utils.h"
|
||||||
#include "lib/stringinfo.h"
|
#include "lib/stringinfo.h"
|
||||||
#include "nodes/pg_list.h"
|
#include "nodes/pg_list.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
|
@ -342,6 +346,50 @@ GeneratePartitioningInformation(Oid parentTableId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GenerateAttachShardPartitionCommand generates command to attach a child table
|
||||||
|
* table to its parent in a partitioning hierarchy.
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
GenerateAttachShardPartitionCommand(ShardInterval *shardInterval)
|
||||||
|
{
|
||||||
|
Oid schemaId = get_rel_namespace(shardInterval->relationId);
|
||||||
|
char *schemaName = get_namespace_name(schemaId);
|
||||||
|
char *escapedSchemaName = quote_literal_cstr(schemaName);
|
||||||
|
|
||||||
|
char *command = GenerateAlterTableAttachPartitionCommand(shardInterval->relationId);
|
||||||
|
char *escapedCommand = quote_literal_cstr(command);
|
||||||
|
int shardIndex = ShardIndex(shardInterval);
|
||||||
|
|
||||||
|
Oid parentSchemaId = InvalidOid;
|
||||||
|
char *parentSchemaName = NULL;
|
||||||
|
char *escapedParentSchemaName = NULL;
|
||||||
|
uint64 parentShardId = INVALID_SHARD_ID;
|
||||||
|
|
||||||
|
StringInfo attachPartitionCommand = makeStringInfo();
|
||||||
|
|
||||||
|
Oid parentRelationId = PartitionParentOid(shardInterval->relationId);
|
||||||
|
if (parentRelationId == InvalidOid)
|
||||||
|
{
|
||||||
|
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||||
|
errmsg("cannot attach partition"),
|
||||||
|
errdetail("Referenced relation cannot be found.")));
|
||||||
|
}
|
||||||
|
|
||||||
|
parentSchemaId = get_rel_namespace(parentRelationId);
|
||||||
|
parentSchemaName = get_namespace_name(parentSchemaId);
|
||||||
|
escapedParentSchemaName = quote_literal_cstr(parentSchemaName);
|
||||||
|
parentShardId = ColocatedShardIdInRelation(parentRelationId, shardIndex);
|
||||||
|
|
||||||
|
appendStringInfo(attachPartitionCommand,
|
||||||
|
WORKER_APPLY_INTER_SHARD_DDL_COMMAND, parentShardId,
|
||||||
|
escapedParentSchemaName, shardInterval->shardId,
|
||||||
|
escapedSchemaName, escapedCommand);
|
||||||
|
|
||||||
|
return attachPartitionCommand->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GenerateAlterTableAttachPartitionCommand returns the necessary command to
|
* GenerateAlterTableAttachPartitionCommand returns the necessary command to
|
||||||
* attach the given partition to its parent.
|
* attach the given partition to its parent.
|
||||||
|
|
|
@ -127,7 +127,6 @@ extern void CreateColocatedShards(Oid targetRelationId, Oid sourceRelationId,
|
||||||
extern void CreateReferenceTableShard(Oid distributedTableId);
|
extern void CreateReferenceTableShard(Oid distributedTableId);
|
||||||
extern void WorkerCreateShard(Oid relationId, int shardIndex, uint64 shardId,
|
extern void WorkerCreateShard(Oid relationId, int shardIndex, uint64 shardId,
|
||||||
List *ddlCommandList, List *foreignConstraintCommandList,
|
List *ddlCommandList, List *foreignConstraintCommandList,
|
||||||
char *alterTableAttachPartitionCommand,
|
|
||||||
MultiConnection *connection);
|
MultiConnection *connection);
|
||||||
extern Oid ForeignConstraintGetReferencedTableId(char *queryString);
|
extern Oid ForeignConstraintGetReferencedTableId(char *queryString);
|
||||||
extern void CheckHashPartitionedTable(Oid distributedTableId);
|
extern void CheckHashPartitionedTable(Oid distributedTableId);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#define MULTI_PARTITIONING_UTILS_H_
|
#define MULTI_PARTITIONING_UTILS_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include "distributed/master_metadata_utility.h"
|
||||||
#include "nodes/pg_list.h"
|
#include "nodes/pg_list.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,6 +21,7 @@ extern bool IsParentTable(Oid relationId);
|
||||||
extern Oid PartitionParentOid(Oid partitionOid);
|
extern Oid PartitionParentOid(Oid partitionOid);
|
||||||
extern List * PartitionList(Oid parentRelationId);
|
extern List * PartitionList(Oid parentRelationId);
|
||||||
extern char * GenerateDetachPartitionCommand(Oid partitionTableId);
|
extern char * GenerateDetachPartitionCommand(Oid partitionTableId);
|
||||||
|
extern char * GenerateAttachShardPartitionCommand(ShardInterval *shardInterval);
|
||||||
extern char * GenerateAlterTableAttachPartitionCommand(Oid partitionTableId);
|
extern char * GenerateAlterTableAttachPartitionCommand(Oid partitionTableId);
|
||||||
extern char * GeneratePartitioningInformation(Oid tableId);
|
extern char * GeneratePartitioningInformation(Oid tableId);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue