Skip to content

Commit

Permalink
indent
Browse files Browse the repository at this point in the history
  • Loading branch information
m7hm7t committed Sep 9, 2024
1 parent d32e726 commit d13eced
Showing 1 changed file with 85 additions and 77 deletions.
162 changes: 85 additions & 77 deletions src/backend/distributed/operations/worker_shard_copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ static int ReadFromLocalBufferCallback(void *outBuf, int minRead, int maxRead);
static void LocalCopyToShard(ShardCopyDestReceiver *copyDest, CopyOutState
localCopyOutState);
static void ConnectToRemoteAndStartCopy(ShardCopyDestReceiver *copyDest);
static List *CreateCopyOptions(bool isBinaryCopy);
static StringInfo ConstructShardTruncateStatement(List *destinationShardFullyQualifiedName);
static List * CreateCopyOptions(bool isBinaryCopy);
static StringInfo ConstructShardTruncateStatement(
List *destinationShardFullyQualifiedName);


static bool
Expand Down Expand Up @@ -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(

Check warning on line 119 in src/backend/distributed/operations/worker_shard_copy.c

View check run for this annotation

Codecov / codecov/patch

src/backend/distributed/operations/worker_shard_copy.c#L119

Added line #L119 was not covered by tests
copyDest->destinationShardFullyQualifiedName);

if (!SendRemoteCommand(copyDest->connection, truncateStatement->data))
{
Expand All @@ -127,9 +129,9 @@ ConnectToRemoteAndStartCopy(ShardCopyDestReceiver *copyDest)
{
ReportResultError(copyDest->connection, truncateResult, ERROR);

Check warning on line 130 in src/backend/distributed/operations/worker_shard_copy.c

View check run for this annotation

Codecov / codecov/patch

src/backend/distributed/operations/worker_shard_copy.c#L130

Added line #L130 was not covered by tests
}
PQclear(truncateResult);
PQclear(truncateResult);

Check warning on line 132 in src/backend/distributed/operations/worker_shard_copy.c

View check run for this annotation

Codecov / codecov/patch

src/backend/distributed/operations/worker_shard_copy.c#L132

Added line #L132 was not covered by tests

// 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,
Expand Down Expand Up @@ -478,31 +480,31 @@ ConstructShardTruncateStatement(List *destinationShardFullyQualifiedName)
*/
static StringInfo
ConstructShardCopyStatement(List *destinationShardFullyQualifiedName, bool
useBinaryFormat,
TupleDesc tupleDesc)
useBinaryFormat,
TupleDesc tupleDesc)
{
char *destinationShardSchemaName = linitial(destinationShardFullyQualifiedName);
char *destinationShardRelationName = lsecond(destinationShardFullyQualifiedName);
char *destinationShardSchemaName = linitial(destinationShardFullyQualifiedName);
char *destinationShardRelationName = lsecond(destinationShardFullyQualifiedName);

StringInfo command = makeStringInfo();
StringInfo command = makeStringInfo();

const char *columnList = CopyableColumnNamesFromTupleDesc(tupleDesc);
const char *columnList = CopyableColumnNamesFromTupleDesc(tupleDesc);

appendStringInfo(command, "COPY %s.%s (%s) FROM STDIN",
quote_identifier(destinationShardSchemaName),
quote_identifier(destinationShardRelationName),
columnList);
appendStringInfo(command, "COPY %s.%s (%s) FROM STDIN",
quote_identifier(destinationShardSchemaName),
quote_identifier(destinationShardRelationName),
columnList);

if (useBinaryFormat)
{
appendStringInfo(command, " WITH (format binary, FREEZE);");
}
else
{
appendStringInfo(command, " WITH (FREEZE);");
}
if (useBinaryFormat)
{
appendStringInfo(command, " WITH (format binary, FREEZE);");

Check warning on line 500 in src/backend/distributed/operations/worker_shard_copy.c

View check run for this annotation

Codecov / codecov/patch

src/backend/distributed/operations/worker_shard_copy.c#L500

Added line #L500 was not covered by tests
}
else
{
appendStringInfo(command, " WITH (FREEZE);");

Check warning on line 504 in src/backend/distributed/operations/worker_shard_copy.c

View check run for this annotation

Codecov / codecov/patch

src/backend/distributed/operations/worker_shard_copy.c#L504

Added line #L504 was not covered by tests
}

return command;
return command;
}


Expand Down Expand Up @@ -542,20 +544,21 @@ WriteLocalTuple(TupleTableSlot *slot, ShardCopyDestReceiver *copyDest)
static List *
CreateCopyOptions(bool isBinaryCopy)
{
List *options = NIL;
List *options = NIL;

// Add the FREEZE option
DefElem *freezeOption = makeDefElem("freeze", (Node *) makeInteger(true), -1);
options = lappend(options, freezeOption);
/* 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 (isBinaryCopy)
{
DefElem *binaryFormatOption = makeDefElem("format", (Node *) makeString("binary"), -1);
options = lappend(options, binaryFormatOption);
}
/* If binary format is used, add the binary format option */
if (isBinaryCopy)
{
DefElem *binaryFormatOption = makeDefElem("format", (Node *) makeString("binary"),
-1);
options = lappend(options, binaryFormatOption);
}

return options;
return options;
}


Expand All @@ -565,49 +568,54 @@ CreateCopyOptions(bool isBinaryCopy)
static void
LocalCopyToShard(ShardCopyDestReceiver *copyDest, CopyOutState localCopyOutState)
{
bool isBinaryCopy = localCopyOutState->binary;

if (isBinaryCopy)
{
AppendCopyBinaryFooters(localCopyOutState);
}

/*
* Set the buffer as a global variable to allow ReadFromLocalBufferCallback
* to read from it. We cannot pass additional arguments to
* ReadFromLocalBufferCallback.
*/
LocalCopyBuffer = localCopyOutState->fe_msgbuf;

// Extract schema and relation names
char *destinationShardSchemaName = linitial(copyDest->destinationShardFullyQualifiedName);
char *destinationShardRelationName = lsecond(copyDest->destinationShardFullyQualifiedName);

// Get OIDs for schema and shard
Oid destinationSchemaOid = get_namespace_oid(destinationShardSchemaName, false);
Oid destinationShardOid = get_relname_relid(destinationShardRelationName, destinationSchemaOid);

// Create options list for COPY command
List *options = CreateCopyOptions(isBinaryCopy);

// Open the shard relation
Relation shard = table_open(destinationShardOid, RowExclusiveLock);

// Create and configure parse state
ParseState *pState = make_parsestate(NULL);
(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);
CopyFrom(cstate);
EndCopyFrom(cstate);
bool isBinaryCopy = localCopyOutState->binary;

// Reset the local copy buffer
resetStringInfo(localCopyOutState->fe_msgbuf);
if (isBinaryCopy)
{
AppendCopyBinaryFooters(localCopyOutState);
}

// Close the shard relation and free parse state
table_close(shard, NoLock);
free_parsestate(pState);
/*
* Set the buffer as a global variable to allow ReadFromLocalBufferCallback
* to read from it. We cannot pass additional arguments to
* ReadFromLocalBufferCallback.
*/
LocalCopyBuffer = localCopyOutState->fe_msgbuf;

/* Extract schema and relation names */
char *destinationShardSchemaName = linitial(
copyDest->destinationShardFullyQualifiedName);
char *destinationShardRelationName = lsecond(
copyDest->destinationShardFullyQualifiedName);

/* Get OIDs for schema and shard */
Oid destinationSchemaOid = get_namespace_oid(destinationShardSchemaName, false);
Oid destinationShardOid = get_relname_relid(destinationShardRelationName,
destinationSchemaOid);

/* Create options list for COPY command */
List *options = CreateCopyOptions(isBinaryCopy);

/* Open the shard relation */
Relation shard = table_open(destinationShardOid, RowExclusiveLock);

/* Create and configure parse state */
ParseState *pState = make_parsestate(NULL);
(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);
CopyFrom(cstate);
EndCopyFrom(cstate);

/* Reset the local copy buffer */
resetStringInfo(localCopyOutState->fe_msgbuf);

/* Close the shard relation and free parse state */
table_close(shard, NoLock);
free_parsestate(pState);
}


Expand Down

0 comments on commit d13eced

Please sign in to comment.