mirror of https://github.com/citusdata/citus.git
Refactor
parent
686ce21e80
commit
2f3f212746
|
@ -57,6 +57,7 @@ static ShardInterval * CreateSplitOffShardFromTemplate(ShardInterval *shardTempl
|
||||||
Oid relationId);
|
Oid relationId);
|
||||||
static List * SplitOffCommandList(ShardInterval *sourceShard,
|
static List * SplitOffCommandList(ShardInterval *sourceShard,
|
||||||
ShardInterval *splitOffShard);
|
ShardInterval *splitOffShard);
|
||||||
|
static void ExecuteCommandListOnPlacements(List *commandList, List *placementList);
|
||||||
static void InsertSplitOffShardMetadata(List *splitOffShardList,
|
static void InsertSplitOffShardMetadata(List *splitOffShardList,
|
||||||
List *sourcePlacementList);
|
List *sourcePlacementList);
|
||||||
static void CreateForeignConstraints(List *splitOffShardList, List *sourcePlacementList);
|
static void CreateForeignConstraints(List *splitOffShardList, List *sourcePlacementList);
|
||||||
|
@ -551,6 +552,95 @@ SplitOffCommandList(ShardInterval *sourceShard, ShardInterval *splitOffShard)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ExecuteCommandListOnPlacements runs the given command list on the nodes of
|
||||||
|
* the given shard placement list. First, it creates connections. Then it sends
|
||||||
|
* commands one by one. For every command, first it send the command to all
|
||||||
|
* connections and then checks the results. This helps to run long running
|
||||||
|
* commands in parallel. Finally, it sends commit messages to all connections
|
||||||
|
* and close them.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ExecuteCommandListOnPlacements(List *commandList, List *placementList)
|
||||||
|
{
|
||||||
|
List *workerConnectionList = NIL;
|
||||||
|
ListCell *workerConnectionCell = NULL;
|
||||||
|
ListCell *shardPlacementCell = NULL;
|
||||||
|
ListCell *commandCell = NULL;
|
||||||
|
|
||||||
|
/* create connections and start transactions */
|
||||||
|
foreach(shardPlacementCell, placementList)
|
||||||
|
{
|
||||||
|
ShardPlacement *shardPlacement = (ShardPlacement *) lfirst(shardPlacementCell);
|
||||||
|
char *nodeName = shardPlacement->nodeName;
|
||||||
|
int32 nodePort = shardPlacement->nodePort;
|
||||||
|
|
||||||
|
int connectionFlags = FORCE_NEW_CONNECTION;
|
||||||
|
char *currentUser = CurrentUserName();
|
||||||
|
|
||||||
|
/* create a new connection */
|
||||||
|
MultiConnection *workerConnection = GetNodeUserDatabaseConnection(connectionFlags,
|
||||||
|
nodeName,
|
||||||
|
nodePort,
|
||||||
|
currentUser,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
/* mark connection as critical ans start transaction */
|
||||||
|
MarkRemoteTransactionCritical(workerConnection);
|
||||||
|
RemoteTransactionBegin(workerConnection);
|
||||||
|
|
||||||
|
/* add connection to the list */
|
||||||
|
workerConnectionList = lappend(workerConnectionList, workerConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* send and check results for every command one by one */
|
||||||
|
foreach(commandCell, commandList)
|
||||||
|
{
|
||||||
|
char *command = lfirst(commandCell);
|
||||||
|
|
||||||
|
/* first only send the command */
|
||||||
|
foreach(workerConnectionCell, workerConnectionList)
|
||||||
|
{
|
||||||
|
MultiConnection *workerConnection =
|
||||||
|
(MultiConnection *) lfirst(workerConnectionCell);
|
||||||
|
|
||||||
|
int querySent = SendRemoteCommand(workerConnection, command);
|
||||||
|
if (querySent == 0)
|
||||||
|
{
|
||||||
|
ReportConnectionError(workerConnection, ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* then check the result separately to run long running commands in parallel */
|
||||||
|
foreach(workerConnectionCell, workerConnectionList)
|
||||||
|
{
|
||||||
|
MultiConnection *workerConnection =
|
||||||
|
(MultiConnection *) lfirst(workerConnectionCell);
|
||||||
|
bool raiseInterrupts = true;
|
||||||
|
|
||||||
|
PGresult *result = GetRemoteCommandResult(workerConnection, raiseInterrupts);
|
||||||
|
if (!IsResponseOK(result))
|
||||||
|
{
|
||||||
|
ReportResultError(workerConnection, result, ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
PQclear(result);
|
||||||
|
ForgetResults(workerConnection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* finally commit each transaction and close connections */
|
||||||
|
foreach(workerConnectionCell, workerConnectionList)
|
||||||
|
{
|
||||||
|
MultiConnection *workerConnection =
|
||||||
|
(MultiConnection *) lfirst(workerConnectionCell);
|
||||||
|
|
||||||
|
RemoteTransactionCommit(workerConnection);
|
||||||
|
CloseConnection(workerConnection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* InsertSplitOffShardMetadata inserts new shard and shard placement data into
|
* InsertSplitOffShardMetadata inserts new shard and shard placement data into
|
||||||
* catolog tables both the coordinator and mx nodes.
|
* catolog tables both the coordinator and mx nodes.
|
||||||
|
|
|
@ -823,92 +823,3 @@ DropShardList(List *shardIntervalList)
|
||||||
DeleteShardRow(oldShardId);
|
DeleteShardRow(oldShardId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ExecuteCommandListOnPlacements runs the given command list on the nodes of
|
|
||||||
* the given shard placement list. First, it creates connections. Then it sends
|
|
||||||
* commands one by one. For every command, first it send the command to all
|
|
||||||
* connections and then checks the results. This helps to run long running
|
|
||||||
* commands in parallel. Finally, it sends commit messages to all connections
|
|
||||||
* and close them.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
ExecuteCommandListOnPlacements(List *commandList, List *placementList)
|
|
||||||
{
|
|
||||||
List *workerConnectionList = NIL;
|
|
||||||
ListCell *workerConnectionCell = NULL;
|
|
||||||
ListCell *shardPlacementCell = NULL;
|
|
||||||
ListCell *commandCell = NULL;
|
|
||||||
|
|
||||||
/* create connections and start transactions */
|
|
||||||
foreach(shardPlacementCell, placementList)
|
|
||||||
{
|
|
||||||
ShardPlacement *shardPlacement = (ShardPlacement *) lfirst(shardPlacementCell);
|
|
||||||
char *nodeName = shardPlacement->nodeName;
|
|
||||||
int32 nodePort = shardPlacement->nodePort;
|
|
||||||
|
|
||||||
int connectionFlags = FORCE_NEW_CONNECTION;
|
|
||||||
char *currentUser = CurrentUserName();
|
|
||||||
|
|
||||||
/* create a new connection */
|
|
||||||
MultiConnection *workerConnection = GetNodeUserDatabaseConnection(connectionFlags,
|
|
||||||
nodeName,
|
|
||||||
nodePort,
|
|
||||||
currentUser,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
/* mark connection as critical ans start transaction */
|
|
||||||
MarkRemoteTransactionCritical(workerConnection);
|
|
||||||
RemoteTransactionBegin(workerConnection);
|
|
||||||
|
|
||||||
/* add connection to the list */
|
|
||||||
workerConnectionList = lappend(workerConnectionList, workerConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* send and check results for every command one by one */
|
|
||||||
foreach(commandCell, commandList)
|
|
||||||
{
|
|
||||||
char *command = lfirst(commandCell);
|
|
||||||
|
|
||||||
/* first only send the command */
|
|
||||||
foreach(workerConnectionCell, workerConnectionList)
|
|
||||||
{
|
|
||||||
MultiConnection *workerConnection =
|
|
||||||
(MultiConnection *) lfirst(workerConnectionCell);
|
|
||||||
|
|
||||||
int querySent = SendRemoteCommand(workerConnection, command);
|
|
||||||
if (querySent == 0)
|
|
||||||
{
|
|
||||||
ReportConnectionError(workerConnection, ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* then check the result separately to run long running commands in parallel */
|
|
||||||
foreach(workerConnectionCell, workerConnectionList)
|
|
||||||
{
|
|
||||||
MultiConnection *workerConnection =
|
|
||||||
(MultiConnection *) lfirst(workerConnectionCell);
|
|
||||||
bool raiseInterrupts = true;
|
|
||||||
|
|
||||||
PGresult *result = GetRemoteCommandResult(workerConnection, raiseInterrupts);
|
|
||||||
if (!IsResponseOK(result))
|
|
||||||
{
|
|
||||||
ReportResultError(workerConnection, result, ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
PQclear(result);
|
|
||||||
ForgetResults(workerConnection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* finally commit each transaction and close connections */
|
|
||||||
foreach(workerConnectionCell, workerConnectionList)
|
|
||||||
{
|
|
||||||
MultiConnection *workerConnection =
|
|
||||||
(MultiConnection *) lfirst(workerConnectionCell);
|
|
||||||
|
|
||||||
RemoteTransactionCommit(workerConnection);
|
|
||||||
CloseConnection(workerConnection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -42,6 +42,5 @@ extern void SplitShard(SplitMode splitMode,
|
||||||
extern void ErrorIfCannotSplitShard(SplitOperation splitOperation,
|
extern void ErrorIfCannotSplitShard(SplitOperation splitOperation,
|
||||||
ShardInterval *sourceShard);
|
ShardInterval *sourceShard);
|
||||||
extern void DropShardList(List *shardIntervalList);
|
extern void DropShardList(List *shardIntervalList);
|
||||||
extern void ExecuteCommandListOnPlacements(List *commandList, List *placementList);
|
|
||||||
|
|
||||||
#endif /* SHARDSPLIT_H_ */
|
#endif /* SHARDSPLIT_H_ */
|
||||||
|
|
Loading…
Reference in New Issue