Refactor SendQueryToPlacements api

pull/721/head
Murat Tuncer 2016-09-26 11:02:16 +03:00 committed by Jason Petersen
parent 6317bbe9a8
commit 902e68c9ef
No known key found for this signature in database
GPG Key ID: 9F1D3510D110ABA9
1 changed files with 22 additions and 33 deletions

View File

@ -59,8 +59,7 @@ static void LockShardsForModify(List *shardIntervalList);
static bool HasReplication(List *shardIntervalList);
static int SendQueryToShards(Query *query, List *shardIntervalList, Oid relationId);
static int SendQueryToPlacements(char *shardQueryString,
ShardConnections *shardConnections,
bool returnTupleCount);
ShardConnections *shardConnections);
PG_FUNCTION_INFO_V1(master_modify_multiple_shards);
@ -244,17 +243,9 @@ SendQueryToShards(Query *query, List *shardIntervalList, Oid relationId)
int affectedTupleCount = 0;
char *relationOwner = TableOwner(relationId);
ListCell *shardIntervalCell = NULL;
bool truncateCommand = false;
bool requestTupleCount = true;
OpenTransactionsToAllShardPlacements(shardIntervalList, relationOwner);
if (query->commandType == CMD_UTILITY && IsA(query->utilityStmt, TruncateStmt))
{
truncateCommand = true;
requestTupleCount = false;
}
foreach(shardIntervalCell, shardIntervalList)
{
ShardInterval *shardInterval = (ShardInterval *) lfirst(
@ -274,8 +265,7 @@ SendQueryToShards(Query *query, List *shardIntervalList, Oid relationId)
shardQueryStringData = shardQueryString->data;
shardAffectedTupleCount = SendQueryToPlacements(shardQueryStringData,
shardConnections,
requestTupleCount);
shardConnections);
affectedTupleCount += shardAffectedTupleCount;
}
@ -292,8 +282,7 @@ SendQueryToShards(Query *query, List *shardIntervalList, Oid relationId)
* should be called after all queries have been sent successfully.
*/
static int
SendQueryToPlacements(char *shardQueryString, ShardConnections *shardConnections,
bool returnTupleCount)
SendQueryToPlacements(char *shardQueryString, ShardConnections *shardConnections)
{
uint64 shardId = shardConnections->shardId;
List *connectionList = shardConnections->connectionList;
@ -302,11 +291,6 @@ SendQueryToPlacements(char *shardQueryString, ShardConnections *shardConnections
Assert(connectionList != NIL);
if (!returnTupleCount)
{
shardAffectedTupleCount = 0;
}
foreach(connectionCell, connectionList)
{
TransactionConnection *transactionConnection =
@ -328,10 +312,16 @@ SendQueryToPlacements(char *shardQueryString, ShardConnections *shardConnections
placementAffectedTupleString = PQcmdTuples(result);
if (returnTupleCount)
/* returned tuple count is empty for utility commands, use 0 as affected count */
if (*placementAffectedTupleString == '\0')
{
placementAffectedTupleCount = 0;
}
else
{
placementAffectedTupleCount = pg_atoi(placementAffectedTupleString,
sizeof(int32), 0);
}
if ((shardAffectedTupleCount == -1) ||
(shardAffectedTupleCount == placementAffectedTupleCount))
@ -346,7 +336,6 @@ SendQueryToPlacements(char *shardQueryString, ShardConnections *shardConnections
errdetail("Affected tuple counts at placements of shard "
UINT64_FORMAT " are different.", shardId)));
}
}
PQclear(result);