mirror of https://github.com/citusdata/citus.git
Move multi_copy.c to interrupt aware libpq wrappers.
parent
0722b3f003
commit
a66ece75a0
|
@ -737,6 +737,7 @@ MasterPartitionMethod(RangeVar *relation)
|
||||||
{
|
{
|
||||||
char partitionMethod = '\0';
|
char partitionMethod = '\0';
|
||||||
PGresult *queryResult = NULL;
|
PGresult *queryResult = NULL;
|
||||||
|
bool raiseInterrupts = true;
|
||||||
|
|
||||||
char *relationName = relation->relname;
|
char *relationName = relation->relname;
|
||||||
char *schemaName = relation->schemaname;
|
char *schemaName = relation->schemaname;
|
||||||
|
@ -745,7 +746,11 @@ MasterPartitionMethod(RangeVar *relation)
|
||||||
StringInfo partitionMethodCommand = makeStringInfo();
|
StringInfo partitionMethodCommand = makeStringInfo();
|
||||||
appendStringInfo(partitionMethodCommand, PARTITION_METHOD_QUERY, qualifiedName);
|
appendStringInfo(partitionMethodCommand, PARTITION_METHOD_QUERY, qualifiedName);
|
||||||
|
|
||||||
queryResult = PQexec(masterConnection->pgConn, partitionMethodCommand->data);
|
if (!SendRemoteCommand(masterConnection, partitionMethodCommand->data))
|
||||||
|
{
|
||||||
|
ReportConnectionError(masterConnection, ERROR);
|
||||||
|
}
|
||||||
|
queryResult = GetRemoteCommandResult(masterConnection, raiseInterrupts);
|
||||||
if (PQresultStatus(queryResult) == PGRES_TUPLES_OK)
|
if (PQresultStatus(queryResult) == PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
char *partitionMethodString = PQgetvalue((PGresult *) queryResult, 0, 0);
|
char *partitionMethodString = PQgetvalue((PGresult *) queryResult, 0, 0);
|
||||||
|
@ -766,6 +771,9 @@ MasterPartitionMethod(RangeVar *relation)
|
||||||
|
|
||||||
PQclear(queryResult);
|
PQclear(queryResult);
|
||||||
|
|
||||||
|
queryResult = GetRemoteCommandResult(masterConnection, raiseInterrupts);
|
||||||
|
Assert(!queryResult);
|
||||||
|
|
||||||
return partitionMethod;
|
return partitionMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -814,6 +822,7 @@ OpenCopyConnections(CopyStmt *copyStatement, ShardConnections *shardConnections,
|
||||||
ListCell *placementCell = NULL;
|
ListCell *placementCell = NULL;
|
||||||
List *connectionList = NULL;
|
List *connectionList = NULL;
|
||||||
int64 shardId = shardConnections->shardId;
|
int64 shardId = shardConnections->shardId;
|
||||||
|
bool raiseInterrupts = true;
|
||||||
|
|
||||||
MemoryContext localContext = AllocSetContextCreate(CurrentMemoryContext,
|
MemoryContext localContext = AllocSetContextCreate(CurrentMemoryContext,
|
||||||
"OpenCopyConnections",
|
"OpenCopyConnections",
|
||||||
|
@ -871,15 +880,19 @@ OpenCopyConnections(CopyStmt *copyStatement, ShardConnections *shardConnections,
|
||||||
MarkRemoteTransactionCritical(connection);
|
MarkRemoteTransactionCritical(connection);
|
||||||
ClaimConnectionExclusively(connection);
|
ClaimConnectionExclusively(connection);
|
||||||
RemoteTransactionBeginIfNecessary(connection);
|
RemoteTransactionBeginIfNecessary(connection);
|
||||||
|
|
||||||
copyCommand = ConstructCopyStatement(copyStatement, shardConnections->shardId,
|
copyCommand = ConstructCopyStatement(copyStatement, shardConnections->shardId,
|
||||||
useBinaryCopyFormat);
|
useBinaryCopyFormat);
|
||||||
result = PQexec(connection->pgConn, copyCommand->data);
|
|
||||||
|
|
||||||
|
if (!SendRemoteCommand(connection, copyCommand->data))
|
||||||
|
{
|
||||||
|
ReportConnectionError(connection, ERROR);
|
||||||
|
}
|
||||||
|
result = GetRemoteCommandResult(connection, raiseInterrupts);
|
||||||
if (PQresultStatus(result) != PGRES_COPY_IN)
|
if (PQresultStatus(result) != PGRES_COPY_IN)
|
||||||
{
|
{
|
||||||
ReportResultError(connection, result, ERROR);
|
ReportResultError(connection, result, ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
PQclear(result);
|
PQclear(result);
|
||||||
connectionList = lappend(connectionList, connection);
|
connectionList = lappend(connectionList, connection);
|
||||||
}
|
}
|
||||||
|
@ -1013,11 +1026,16 @@ RemoteFinalizedShardPlacementList(uint64 shardId)
|
||||||
{
|
{
|
||||||
List *finalizedPlacementList = NIL;
|
List *finalizedPlacementList = NIL;
|
||||||
PGresult *queryResult = NULL;
|
PGresult *queryResult = NULL;
|
||||||
|
bool raiseInterrupts = true;
|
||||||
|
|
||||||
StringInfo shardPlacementsCommand = makeStringInfo();
|
StringInfo shardPlacementsCommand = makeStringInfo();
|
||||||
appendStringInfo(shardPlacementsCommand, FINALIZED_SHARD_PLACEMENTS_QUERY, shardId);
|
appendStringInfo(shardPlacementsCommand, FINALIZED_SHARD_PLACEMENTS_QUERY, shardId);
|
||||||
|
|
||||||
queryResult = PQexec(masterConnection->pgConn, shardPlacementsCommand->data);
|
if (!SendRemoteCommand(masterConnection, shardPlacementsCommand->data))
|
||||||
|
{
|
||||||
|
ReportConnectionError(masterConnection, ERROR);
|
||||||
|
}
|
||||||
|
queryResult = GetRemoteCommandResult(masterConnection, raiseInterrupts);
|
||||||
if (PQresultStatus(queryResult) == PGRES_TUPLES_OK)
|
if (PQresultStatus(queryResult) == PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
int rowCount = PQntuples(queryResult);
|
int rowCount = PQntuples(queryResult);
|
||||||
|
@ -1047,6 +1065,9 @@ RemoteFinalizedShardPlacementList(uint64 shardId)
|
||||||
}
|
}
|
||||||
|
|
||||||
PQclear(queryResult);
|
PQclear(queryResult);
|
||||||
|
queryResult = GetRemoteCommandResult(masterConnection, raiseInterrupts);
|
||||||
|
Assert(!queryResult);
|
||||||
|
|
||||||
return finalizedPlacementList;
|
return finalizedPlacementList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1128,8 +1149,7 @@ SendCopyDataToAll(StringInfo dataBuffer, int64 shardId, List *connectionList)
|
||||||
static void
|
static void
|
||||||
SendCopyDataToPlacement(StringInfo dataBuffer, int64 shardId, MultiConnection *connection)
|
SendCopyDataToPlacement(StringInfo dataBuffer, int64 shardId, MultiConnection *connection)
|
||||||
{
|
{
|
||||||
int copyResult = PQputCopyData(connection->pgConn, dataBuffer->data, dataBuffer->len);
|
if (!PutRemoteCopyData(connection, dataBuffer->data, dataBuffer->len))
|
||||||
if (copyResult != 1)
|
|
||||||
{
|
{
|
||||||
ereport(ERROR, (errcode(ERRCODE_IO_ERROR),
|
ereport(ERROR, (errcode(ERRCODE_IO_ERROR),
|
||||||
errmsg("failed to COPY to shard %ld on %s:%d",
|
errmsg("failed to COPY to shard %ld on %s:%d",
|
||||||
|
@ -1153,13 +1173,11 @@ EndRemoteCopy(int64 shardId, List *connectionList, bool stopOnFailure)
|
||||||
foreach(connectionCell, connectionList)
|
foreach(connectionCell, connectionList)
|
||||||
{
|
{
|
||||||
MultiConnection *connection = (MultiConnection *) lfirst(connectionCell);
|
MultiConnection *connection = (MultiConnection *) lfirst(connectionCell);
|
||||||
int copyEndResult = 0;
|
|
||||||
PGresult *result = NULL;
|
PGresult *result = NULL;
|
||||||
|
bool raiseInterrupts = true;
|
||||||
|
|
||||||
/* end the COPY input */
|
/* end the COPY input */
|
||||||
copyEndResult = PQputCopyEnd(connection->pgConn, NULL);
|
if (!PutRemoteCopyEnd(connection, NULL))
|
||||||
|
|
||||||
if (copyEndResult != 1)
|
|
||||||
{
|
{
|
||||||
if (stopOnFailure)
|
if (stopOnFailure)
|
||||||
{
|
{
|
||||||
|
@ -1172,7 +1190,7 @@ EndRemoteCopy(int64 shardId, List *connectionList, bool stopOnFailure)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check whether there were any COPY errors */
|
/* check whether there were any COPY errors */
|
||||||
result = PQgetResult(connection->pgConn);
|
result = GetRemoteCommandResult(connection, raiseInterrupts);
|
||||||
if (PQresultStatus(result) != PGRES_COMMAND_OK && stopOnFailure)
|
if (PQresultStatus(result) != PGRES_COMMAND_OK && stopOnFailure)
|
||||||
{
|
{
|
||||||
ReportCopyError(connection, result);
|
ReportCopyError(connection, result);
|
||||||
|
@ -1492,11 +1510,16 @@ RemoteCreateEmptyShard(char *relationName)
|
||||||
{
|
{
|
||||||
int64 shardId = 0;
|
int64 shardId = 0;
|
||||||
PGresult *queryResult = NULL;
|
PGresult *queryResult = NULL;
|
||||||
|
bool raiseInterrupts = true;
|
||||||
|
|
||||||
StringInfo createEmptyShardCommand = makeStringInfo();
|
StringInfo createEmptyShardCommand = makeStringInfo();
|
||||||
appendStringInfo(createEmptyShardCommand, CREATE_EMPTY_SHARD_QUERY, relationName);
|
appendStringInfo(createEmptyShardCommand, CREATE_EMPTY_SHARD_QUERY, relationName);
|
||||||
|
|
||||||
queryResult = PQexec(masterConnection->pgConn, createEmptyShardCommand->data);
|
if (!SendRemoteCommand(masterConnection, createEmptyShardCommand->data))
|
||||||
|
{
|
||||||
|
ReportConnectionError(masterConnection, ERROR);
|
||||||
|
}
|
||||||
|
queryResult = GetRemoteCommandResult(masterConnection, raiseInterrupts);
|
||||||
if (PQresultStatus(queryResult) == PGRES_TUPLES_OK)
|
if (PQresultStatus(queryResult) == PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
char *shardIdString = PQgetvalue((PGresult *) queryResult, 0, 0);
|
char *shardIdString = PQgetvalue((PGresult *) queryResult, 0, 0);
|
||||||
|
@ -1510,6 +1533,8 @@ RemoteCreateEmptyShard(char *relationName)
|
||||||
}
|
}
|
||||||
|
|
||||||
PQclear(queryResult);
|
PQclear(queryResult);
|
||||||
|
queryResult = GetRemoteCommandResult(masterConnection, raiseInterrupts);
|
||||||
|
Assert(!queryResult);
|
||||||
|
|
||||||
return shardId;
|
return shardId;
|
||||||
}
|
}
|
||||||
|
@ -1540,18 +1565,25 @@ static void
|
||||||
RemoteUpdateShardStatistics(uint64 shardId)
|
RemoteUpdateShardStatistics(uint64 shardId)
|
||||||
{
|
{
|
||||||
PGresult *queryResult = NULL;
|
PGresult *queryResult = NULL;
|
||||||
|
bool raiseInterrupts = true;
|
||||||
|
|
||||||
StringInfo updateShardStatisticsCommand = makeStringInfo();
|
StringInfo updateShardStatisticsCommand = makeStringInfo();
|
||||||
appendStringInfo(updateShardStatisticsCommand, UPDATE_SHARD_STATISTICS_QUERY,
|
appendStringInfo(updateShardStatisticsCommand, UPDATE_SHARD_STATISTICS_QUERY,
|
||||||
shardId);
|
shardId);
|
||||||
|
|
||||||
queryResult = PQexec(masterConnection->pgConn, updateShardStatisticsCommand->data);
|
if (!SendRemoteCommand(masterConnection, updateShardStatisticsCommand->data))
|
||||||
|
{
|
||||||
|
ReportConnectionError(masterConnection, ERROR);
|
||||||
|
}
|
||||||
|
queryResult = GetRemoteCommandResult(masterConnection, raiseInterrupts);
|
||||||
if (PQresultStatus(queryResult) != PGRES_TUPLES_OK)
|
if (PQresultStatus(queryResult) != PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
ereport(ERROR, (errmsg("could not update shard statistics")));
|
ereport(ERROR, (errmsg("could not update shard statistics")));
|
||||||
}
|
}
|
||||||
|
|
||||||
PQclear(queryResult);
|
PQclear(queryResult);
|
||||||
|
queryResult = GetRemoteCommandResult(masterConnection, raiseInterrupts);
|
||||||
|
Assert(!queryResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue