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