mirror of https://github.com/citusdata/citus.git
indent
parent
d32e7263ae
commit
d13ecedcfa
|
@ -84,7 +84,8 @@ static void LocalCopyToShard(ShardCopyDestReceiver *copyDest, CopyOutState
|
|||
localCopyOutState);
|
||||
static void ConnectToRemoteAndStartCopy(ShardCopyDestReceiver *copyDest);
|
||||
static List * CreateCopyOptions(bool isBinaryCopy);
|
||||
static StringInfo ConstructShardTruncateStatement(List *destinationShardFullyQualifiedName);
|
||||
static StringInfo ConstructShardTruncateStatement(
|
||||
List *destinationShardFullyQualifiedName);
|
||||
|
||||
|
||||
static bool
|
||||
|
@ -114,8 +115,9 @@ ConnectToRemoteAndStartCopy(ShardCopyDestReceiver *copyDest)
|
|||
|
||||
SetupReplicationOriginRemoteSession(copyDest->connection);
|
||||
|
||||
// Construct and send the TRUNCATE statement to the remote node
|
||||
StringInfo truncateStatement = ConstructShardTruncateStatement(copyDest->destinationShardFullyQualifiedName);
|
||||
/* Construct and send the TRUNCATE statement to the remote node */
|
||||
StringInfo truncateStatement = ConstructShardTruncateStatement(
|
||||
copyDest->destinationShardFullyQualifiedName);
|
||||
|
||||
if (!SendRemoteCommand(copyDest->connection, truncateStatement->data))
|
||||
{
|
||||
|
@ -129,7 +131,7 @@ ConnectToRemoteAndStartCopy(ShardCopyDestReceiver *copyDest)
|
|||
}
|
||||
PQclear(truncateResult);
|
||||
|
||||
// Construct the COPY command and send it to the remote node
|
||||
/* Construct the COPY command and send it to the remote node */
|
||||
StringInfo copyStatement = ConstructShardCopyStatement(
|
||||
copyDest->destinationShardFullyQualifiedName,
|
||||
copyDest->copyOutState->binary,
|
||||
|
@ -544,14 +546,15 @@ CreateCopyOptions(bool isBinaryCopy)
|
|||
{
|
||||
List *options = NIL;
|
||||
|
||||
// Add the FREEZE option
|
||||
/* Add the FREEZE option */
|
||||
DefElem *freezeOption = makeDefElem("freeze", (Node *) makeInteger(true), -1);
|
||||
options = lappend(options, freezeOption);
|
||||
|
||||
// If binary format is used, add the binary format option
|
||||
/* If binary format is used, add the binary format option */
|
||||
if (isBinaryCopy)
|
||||
{
|
||||
DefElem *binaryFormatOption = makeDefElem("format", (Node *) makeString("binary"), -1);
|
||||
DefElem *binaryFormatOption = makeDefElem("format", (Node *) makeString("binary"),
|
||||
-1);
|
||||
options = lappend(options, binaryFormatOption);
|
||||
}
|
||||
|
||||
|
@ -579,33 +582,38 @@ LocalCopyToShard(ShardCopyDestReceiver *copyDest, CopyOutState localCopyOutState
|
|||
*/
|
||||
LocalCopyBuffer = localCopyOutState->fe_msgbuf;
|
||||
|
||||
// Extract schema and relation names
|
||||
char *destinationShardSchemaName = linitial(copyDest->destinationShardFullyQualifiedName);
|
||||
char *destinationShardRelationName = lsecond(copyDest->destinationShardFullyQualifiedName);
|
||||
/* Extract schema and relation names */
|
||||
char *destinationShardSchemaName = linitial(
|
||||
copyDest->destinationShardFullyQualifiedName);
|
||||
char *destinationShardRelationName = lsecond(
|
||||
copyDest->destinationShardFullyQualifiedName);
|
||||
|
||||
// Get OIDs for schema and shard
|
||||
/* Get OIDs for schema and shard */
|
||||
Oid destinationSchemaOid = get_namespace_oid(destinationShardSchemaName, false);
|
||||
Oid destinationShardOid = get_relname_relid(destinationShardRelationName, destinationSchemaOid);
|
||||
Oid destinationShardOid = get_relname_relid(destinationShardRelationName,
|
||||
destinationSchemaOid);
|
||||
|
||||
// Create options list for COPY command
|
||||
/* Create options list for COPY command */
|
||||
List *options = CreateCopyOptions(isBinaryCopy);
|
||||
|
||||
// Open the shard relation
|
||||
/* Open the shard relation */
|
||||
Relation shard = table_open(destinationShardOid, RowExclusiveLock);
|
||||
|
||||
// Create and configure parse state
|
||||
/* Create and configure parse state */
|
||||
ParseState *pState = make_parsestate(NULL);
|
||||
(void) addRangeTableEntryForRelation(pState, shard, AccessShareLock, NULL, false, false);
|
||||
(void) addRangeTableEntryForRelation(pState, shard, AccessShareLock, NULL, false,
|
||||
false);
|
||||
|
||||
// Begin and execute the COPY FROM operation
|
||||
CopyFromState cstate = BeginCopyFrom(pState, shard, NULL, NULL, false, ReadFromLocalBufferCallback, NULL, options);
|
||||
/* Begin and execute the COPY FROM operation */
|
||||
CopyFromState cstate = BeginCopyFrom(pState, shard, NULL, NULL, false,
|
||||
ReadFromLocalBufferCallback, NULL, options);
|
||||
CopyFrom(cstate);
|
||||
EndCopyFrom(cstate);
|
||||
|
||||
// Reset the local copy buffer
|
||||
/* Reset the local copy buffer */
|
||||
resetStringInfo(localCopyOutState->fe_msgbuf);
|
||||
|
||||
// Close the shard relation and free parse state
|
||||
/* Close the shard relation and free parse state */
|
||||
table_close(shard, NoLock);
|
||||
free_parsestate(pState);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue