mirror of https://github.com/citusdata/citus.git
fixup! allow "alter table set schema" from any node for Postgres tables - citus managed local tables
merge codepathsddl-from-any-node-phase-1
parent
988ce89179
commit
f650f9ced4
|
|
@ -29,6 +29,7 @@
|
||||||
#include "distributed/worker_protocol.h"
|
#include "distributed/worker_protocol.h"
|
||||||
|
|
||||||
|
|
||||||
|
static void ReplicateCoordinatorPlacementData(uint64 shardId, List *targetNodeList);
|
||||||
static void CreateForeignKeysFromReferenceTablesOnShards(Oid noneDistTableId);
|
static void CreateForeignKeysFromReferenceTablesOnShards(Oid noneDistTableId);
|
||||||
static Oid ForeignConstraintGetReferencingTableId(const char *queryString);
|
static Oid ForeignConstraintGetReferencingTableId(const char *queryString);
|
||||||
static void EnsureNoneDistTableWithCoordinatorPlacement(Oid noneDistTableId);
|
static void EnsureNoneDistTableWithCoordinatorPlacement(Oid noneDistTableId);
|
||||||
|
|
@ -82,60 +83,14 @@ NoneDistTableReplicateCoordinatorPlacement(Oid noneDistTableId,
|
||||||
ShardPlacement *coordinatorPlacement =
|
ShardPlacement *coordinatorPlacement =
|
||||||
linitial(ActiveShardPlacementListOnGroup(shardId, COORDINATOR_GROUP_ID));
|
linitial(ActiveShardPlacementListOnGroup(shardId, COORDINATOR_GROUP_ID));
|
||||||
|
|
||||||
|
/* copy data from coordinator placement to new placements */
|
||||||
|
ReplicateCoordinatorPlacementData(shardId, targetNodeList);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The work done below to replicate the shard and
|
* CreateForeignKeysFromReferenceTablesOnShards
|
||||||
* CreateForeignKeysFromReferenceTablesOnShards() itself need to ignore the
|
* needs to ignore the local placement, hence we temporarily delete it.
|
||||||
* coordinator shard placement, hence we temporarily delete it using
|
|
||||||
* DeleteShardPlacementRowGlobally() before moving forward.
|
|
||||||
*/
|
*/
|
||||||
if (IsCoordinator())
|
DeleteShardPlacementRowGlobally(coordinatorPlacement->placementId);
|
||||||
{
|
|
||||||
/* TODOTASK: maybe remove this codepath? "else" can possibly handle coordinator-placement too */
|
|
||||||
|
|
||||||
/* fetch coordinator placement before deleting it */
|
|
||||||
Oid localPlacementTableId = GetTableLocalShardOid(noneDistTableId, shardId);
|
|
||||||
|
|
||||||
DeleteShardPlacementRowGlobally(coordinatorPlacement->placementId);
|
|
||||||
|
|
||||||
/* and copy data from local placement to new placements */
|
|
||||||
CopyFromLocalTableIntoDistTable(
|
|
||||||
localPlacementTableId, noneDistTableId
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DeleteShardPlacementRowGlobally(coordinatorPlacement->placementId);
|
|
||||||
|
|
||||||
List *taskList = NIL;
|
|
||||||
uint64 jobId = INVALID_JOB_ID;
|
|
||||||
uint32 taskId = 0;
|
|
||||||
foreach_declared_ptr(targetNode, targetNodeList)
|
|
||||||
{
|
|
||||||
Task *task = CitusMakeNode(Task);
|
|
||||||
task->jobId = jobId;
|
|
||||||
task->taskId = taskId++;
|
|
||||||
task->taskType = READ_TASK;
|
|
||||||
task->replicationModel = REPLICATION_MODEL_INVALID;
|
|
||||||
char *shardCopyCommand = CreateShardCopyCommand(LoadShardInterval(shardId),
|
|
||||||
targetNode);
|
|
||||||
SetTaskQueryStringList(task, list_make1(shardCopyCommand));
|
|
||||||
|
|
||||||
/* we already verified that coordinator is in the metadata */
|
|
||||||
WorkerNode *coordinatorNode = CoordinatorNodeIfAddedAsWorkerOrError();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Need execute the task at the source node as we'll copy the shard
|
|
||||||
* from there, i.e., the coordinator.
|
|
||||||
*/
|
|
||||||
ShardPlacement *taskPlacement = CitusMakeNode(ShardPlacement);
|
|
||||||
SetPlacementNodeMetadata(taskPlacement, coordinatorNode);
|
|
||||||
|
|
||||||
task->taskPlacementList = list_make1(taskPlacement);
|
|
||||||
taskList = lappend(taskList, task);
|
|
||||||
}
|
|
||||||
|
|
||||||
ExecuteTaskList(ROW_MODIFY_READONLY, taskList);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CreateShardsOnWorkers only creates the foreign keys where given relation
|
* CreateShardsOnWorkers only creates the foreign keys where given relation
|
||||||
|
|
@ -229,6 +184,50 @@ NoneDistTableDropCoordinatorPlacementTable(Oid noneDistTableId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ReplicateCoordinatorPlacementData copies data from the coordinator
|
||||||
|
* shard placement to the target nodes.
|
||||||
|
*
|
||||||
|
* Assumes that the shard placements already exist on the coordinator and
|
||||||
|
* target nodes.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
ReplicateCoordinatorPlacementData(uint64 shardId, List *targetNodeList)
|
||||||
|
{
|
||||||
|
List *taskList = NIL;
|
||||||
|
|
||||||
|
uint64 jobId = INVALID_JOB_ID;
|
||||||
|
uint32 taskId = 0;
|
||||||
|
WorkerNode *targetNode = NULL;
|
||||||
|
foreach_declared_ptr(targetNode, targetNodeList)
|
||||||
|
{
|
||||||
|
Task *task = CitusMakeNode(Task);
|
||||||
|
task->jobId = jobId;
|
||||||
|
task->taskId = taskId++;
|
||||||
|
task->taskType = READ_TASK;
|
||||||
|
task->replicationModel = REPLICATION_MODEL_INVALID;
|
||||||
|
char *shardCopyCommand = CreateShardCopyCommand(LoadShardInterval(shardId),
|
||||||
|
targetNode);
|
||||||
|
SetTaskQueryStringList(task, list_make1(shardCopyCommand));
|
||||||
|
|
||||||
|
/* we already verified that coordinator is in the metadata */
|
||||||
|
WorkerNode *coordinatorNode = CoordinatorNodeIfAddedAsWorkerOrError();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Need execute the task at the source node as we'll copy the shard
|
||||||
|
* from there, i.e., the coordinator.
|
||||||
|
*/
|
||||||
|
ShardPlacement *taskPlacement = CitusMakeNode(ShardPlacement);
|
||||||
|
SetPlacementNodeMetadata(taskPlacement, coordinatorNode);
|
||||||
|
|
||||||
|
task->taskPlacementList = list_make1(taskPlacement);
|
||||||
|
taskList = lappend(taskList, task);
|
||||||
|
}
|
||||||
|
|
||||||
|
ExecuteTaskList(ROW_MODIFY_READONLY, taskList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CreateForeignKeysFromReferenceTablesOnShards creates foreign keys on shards
|
* CreateForeignKeysFromReferenceTablesOnShards creates foreign keys on shards
|
||||||
* where given none-distributed table is the referenced table and the referencing
|
* where given none-distributed table is the referenced table and the referencing
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue