Fix hard coded formatting strings for 64 bit numbers (#1831)

Postgres provides OS agnosting formatting macros for
formatting 64 bit numbers. Replaced %ld %lu with
INT64_FORMAT and UINT64_FORMAT respectively.

Also found some incorrect usages of formatting
flags and fixed them.
pull/1854/head
Murat Tuncer 2017-12-04 14:11:06 +03:00 committed by GitHub
parent f77f8c30dc
commit 2d66bf5f16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 69 additions and 59 deletions

View File

@ -1261,13 +1261,13 @@ CopyLocalDataIntoShards(Oid distributedRelationId)
if (rowsCopied % 1000000 == 0) if (rowsCopied % 1000000 == 0)
{ {
ereport(DEBUG1, (errmsg("Copied %ld rows", rowsCopied))); ereport(DEBUG1, (errmsg("Copied " UINT64_FORMAT " rows", rowsCopied)));
} }
} }
if (rowsCopied % 1000000 != 0) if (rowsCopied % 1000000 != 0)
{ {
ereport(DEBUG1, (errmsg("Copied %ld rows", rowsCopied))); ereport(DEBUG1, (errmsg("Copied " UINT64_FORMAT " rows", rowsCopied)));
} }
MemoryContextSwitchTo(oldContext); MemoryContextSwitchTo(oldContext);

View File

@ -1156,7 +1156,7 @@ SendCopyDataToPlacement(StringInfo dataBuffer, int64 shardId, MultiConnection *c
if (!PutRemoteCopyData(connection, dataBuffer->data, dataBuffer->len)) if (!PutRemoteCopyData(connection, dataBuffer->data, dataBuffer->len))
{ {
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 " INT64_FORMAT " on %s:%d",
shardId, connection->hostname, connection->port), shardId, connection->hostname, connection->port),
errdetail("failed to send %d bytes %s", dataBuffer->len, errdetail("failed to send %d bytes %s", dataBuffer->len,
dataBuffer->data))); dataBuffer->data)));
@ -1183,13 +1183,15 @@ EndRemoteCopy(int64 shardId, List *connectionList, bool stopOnFailure)
/* end the COPY input */ /* end the COPY input */
if (!PutRemoteCopyEnd(connection, NULL)) if (!PutRemoteCopyEnd(connection, NULL))
{ {
if (stopOnFailure) if (!stopOnFailure)
{ {
ereport(ERROR, (errcode(ERRCODE_IO_ERROR), continue;
errmsg("failed to COPY to shard %ld on %s:%d",
shardId, connection->hostname, connection->port)));
} }
ereport(ERROR, (errcode(ERRCODE_IO_ERROR),
errmsg("failed to COPY to shard " INT64_FORMAT " on %s:%d",
shardId, connection->hostname, connection->port)));
continue; continue;
} }

View File

@ -511,10 +511,9 @@ FindPlacementListConnection(int flags, List *placementAccessList, const char *us
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_ACTIVE_SQL_TRANSACTION), (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
errmsg( errmsg("cannot perform DDL on placement " UINT64_FORMAT
"cannot perform DDL on placement %ld, which has been read over " ", which has been read over multiple connections",
"multiple connections", placement->placementId)));
placement->placementId)));
} }
else if (accessType == PLACEMENT_ACCESS_DDL && colocatedEntry != NULL && else if (accessType == PLACEMENT_ACCESS_DDL && colocatedEntry != NULL &&
colocatedEntry->hasSecondaryConnections) colocatedEntry->hasSecondaryConnections)
@ -530,8 +529,8 @@ FindPlacementListConnection(int flags, List *placementAccessList, const char *us
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_ACTIVE_SQL_TRANSACTION), (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
errmsg("cannot perform DDL on placement %ld since a co-located " errmsg("cannot perform DDL on placement " UINT64_FORMAT
"placement has been read over multiple connections", " since a co-located placement has been read over multiple connections",
placement->placementId))); placement->placementId)));
} }
else if (foundModifyingConnection) else if (foundModifyingConnection)
@ -584,8 +583,9 @@ FindPlacementListConnection(int flags, List *placementAccessList, const char *us
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_ACTIVE_SQL_TRANSACTION), (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
errmsg("cannot establish a new connection for placement %ld, since " errmsg("cannot establish a new connection for "
"DDL has been executed on a connection that is in use", "placement " UINT64_FORMAT
", since DDL has been executed on a connection that is in use",
placement->placementId))); placement->placementId)));
} }
else if (placementConnection->hadDML) else if (placementConnection->hadDML)
@ -606,8 +606,9 @@ FindPlacementListConnection(int flags, List *placementAccessList, const char *us
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_ACTIVE_SQL_TRANSACTION), (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
errmsg("cannot establish a new connection for placement %ld, since " errmsg("cannot establish a new connection for "
"DML has been executed on a connection that is in use", "placement " UINT64_FORMAT
", since DML has been executed on a connection that is in use",
placement->placementId))); placement->placementId)));
} }
else if (accessType == PLACEMENT_ACCESS_DDL) else if (accessType == PLACEMENT_ACCESS_DDL)

View File

@ -937,8 +937,8 @@ MultiClientWait(WaitInfo *waitInfo)
else if (rc == 0) else if (rc == 0)
{ {
ereport(DEBUG5, ereport(DEBUG5,
(errmsg("waiting for activity on tasks took longer than %ld ms", (errmsg("waiting for activity on tasks took longer than %d ms",
(long) RemoteTaskCheckInterval * 10))); (int) RemoteTaskCheckInterval * 10)));
} }
/* /*

View File

@ -585,7 +585,7 @@ TaskHashEnter(HTAB *taskHash, Task *task)
/* if same node appears twice, we error-out */ /* if same node appears twice, we error-out */
if (handleFound) if (handleFound)
{ {
ereport(ERROR, (errmsg("multiple entries for task: \"%d:%ld:%d\"", ereport(ERROR, (errmsg("multiple entries for task: \"%d:" UINT64_FORMAT ":%u\"",
task->taskType, task->jobId, task->taskId))); task->taskType, task->jobId, task->taskId)));
} }

View File

@ -311,8 +311,8 @@ ShardIntervalsOnWorkerGroup(WorkerNode *workerNode, Oid relationId)
if (metadataLock == false) if (metadataLock == false)
{ {
ereport(WARNING, (errcode(ERRCODE_LOCK_NOT_AVAILABLE), ereport(WARNING, (errcode(ERRCODE_LOCK_NOT_AVAILABLE),
errmsg("lock is not acquired, size of shard %ld " errmsg("lock is not acquired, size of shard "
"will be ignored", shardId))); UINT64_FORMAT " will be ignored", shardId)));
continue; continue;
} }
@ -436,8 +436,9 @@ TableShardReplicationFactor(Oid relationId)
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot find the replication factor of the " errmsg("cannot find the replication factor of the "
"table %s", relationName), "table %s", relationName),
errdetail("The shard %ld has different shards replication " errdetail("The shard " UINT64_FORMAT
"counts from other shards.", shardId))); " has different shards replication counts from "
"other shards.", shardId)));
} }
} }

View File

@ -614,7 +614,8 @@ ShardListInsertCommand(List *shardIntervalList)
} }
appendStringInfo(insertPlacementCommand, appendStringInfo(insertPlacementCommand,
"(%lu, 1, %lu, %d, %lu)", "(" UINT64_FORMAT ", 1, " UINT64_FORMAT ", %d, "
UINT64_FORMAT ")",
shardId, shardId,
placement->shardLength, placement->shardLength,
placement->groupId, placement->groupId,
@ -664,7 +665,7 @@ ShardListInsertCommand(List *shardIntervalList)
} }
appendStringInfo(insertShardCommand, appendStringInfo(insertShardCommand,
"(%s::regclass, %lu, '%c', %s, %s)", "(%s::regclass, " UINT64_FORMAT ", '%c', %s, %s)",
quote_literal_cstr(qualifiedRelationName), quote_literal_cstr(qualifiedRelationName),
shardId, shardId,
shardInterval->storageType, shardInterval->storageType,
@ -700,7 +701,7 @@ ShardDeleteCommandList(ShardInterval *shardInterval)
/* create command to delete shard placements */ /* create command to delete shard placements */
deletePlacementCommand = makeStringInfo(); deletePlacementCommand = makeStringInfo();
appendStringInfo(deletePlacementCommand, appendStringInfo(deletePlacementCommand,
"DELETE FROM pg_dist_placement WHERE shardid = %lu", "DELETE FROM pg_dist_placement WHERE shardid = " UINT64_FORMAT,
shardId); shardId);
commandList = lappend(commandList, deletePlacementCommand->data); commandList = lappend(commandList, deletePlacementCommand->data);
@ -708,7 +709,7 @@ ShardDeleteCommandList(ShardInterval *shardInterval)
/* create command to delete shard */ /* create command to delete shard */
deleteShardCommand = makeStringInfo(); deleteShardCommand = makeStringInfo();
appendStringInfo(deleteShardCommand, appendStringInfo(deleteShardCommand,
"DELETE FROM pg_dist_shard WHERE shardid = %lu", shardId); "DELETE FROM pg_dist_shard WHERE shardid = " UINT64_FORMAT, shardId);
commandList = lappend(commandList, deleteShardCommand->data); commandList = lappend(commandList, deleteShardCommand->data);

View File

@ -541,8 +541,9 @@ RouterModifyTaskForShardInterval(Query *originalQuery, ShardInterval *shardInter
/* ensure that we do not send queries where select is pruned away completely */ /* ensure that we do not send queries where select is pruned away completely */
if (list_length(selectPlacementList) == 0) if (list_length(selectPlacementList) == 0)
{ {
ereport(DEBUG2, (errmsg("Skipping target shard interval %ld since " ereport(DEBUG2, (errmsg("Skipping target shard interval " UINT64_FORMAT
"SELECT query for it pruned away", shardId))); " since SELECT query for it pruned away",
shardId)));
return NULL; return NULL;
} }
@ -562,7 +563,7 @@ RouterModifyTaskForShardInterval(Query *originalQuery, ShardInterval *shardInter
errmsg("cannot perform distributed planning for the given " errmsg("cannot perform distributed planning for the given "
"modification"), "modification"),
errdetail("Insert query cannot be executed on all placements " errdetail("Insert query cannot be executed on all placements "
"for shard %ld", shardId))); "for shard " UINT64_FORMAT "", shardId)));
} }

View File

@ -2398,8 +2398,8 @@ SubqueryTaskCreate(Query *originalQuery, ShardInterval *shardInterval,
/* ensure that we do not send queries where select is pruned away completely */ /* ensure that we do not send queries where select is pruned away completely */
if (list_length(selectPlacementList) == 0) if (list_length(selectPlacementList) == 0)
{ {
ereport(DEBUG2, (errmsg("Skipping the target shard interval %ld because " ereport(DEBUG2, (errmsg("Skipping the target shard interval " UINT64_FORMAT
"SELECT query is pruned away for the interval", " because SELECT query is pruned away for the interval",
shardId))); shardId)));
return NULL; return NULL;

View File

@ -599,7 +599,7 @@ LogCancellingBackend(TransactionNode *transactionNode)
appendStringInfo(logMessage, "Cancelling the following backend " appendStringInfo(logMessage, "Cancelling the following backend "
"to resolve distributed deadlock " "to resolve distributed deadlock "
"(transaction numner = %ld, pid = %d)", "(transaction numner = " UINT64_FORMAT ", pid = %d)",
transactionNode->transactionId.transactionNumber, transactionNode->transactionId.transactionNumber,
transactionNode->initiatorProc->pid); transactionNode->initiatorProc->pid);
@ -625,7 +625,8 @@ LogTransactionNode(TransactionNode *transactionNode)
logMessage = makeStringInfo(); logMessage = makeStringInfo();
transactionId = &(transactionNode->transactionId); transactionId = &(transactionNode->transactionId);
appendStringInfo(logMessage, "[DistributedTransactionId: (%d, %ld, %s)] = ", appendStringInfo(logMessage,
"[DistributedTransactionId: (%d, " UINT64_FORMAT ", %s)] = ",
transactionId->initiatorNodeIdentifier, transactionId->initiatorNodeIdentifier,
transactionId->transactionNumber, transactionId->transactionNumber,
timestamptz_to_str(transactionId->timestamp)); timestamptz_to_str(transactionId->timestamp));
@ -685,7 +686,7 @@ WaitsForToString(List *waitsFor)
appendStringInfoString(transactionIdStr, ","); appendStringInfoString(transactionIdStr, ",");
} }
appendStringInfo(transactionIdStr, "%ld", appendStringInfo(transactionIdStr, UINT64_FORMAT,
waitingNode->transactionId.transactionNumber); waitingNode->transactionId.transactionNumber);
} }

View File

@ -85,7 +85,8 @@ StartRemoteTransactionBegin(struct MultiConnection *connection)
*/ */
distributedTransactionId = GetCurrentDistributedTransactionId(); distributedTransactionId = GetCurrentDistributedTransactionId();
appendStringInfo(beginAndSetDistributedTransactionId, appendStringInfo(beginAndSetDistributedTransactionId,
"SELECT assign_distributed_transaction_id(%d, %ld, '%s');", "SELECT assign_distributed_transaction_id(%d, " UINT64_FORMAT
", '%s');",
distributedTransactionId->initiatorNodeIdentifier, distributedTransactionId->initiatorNodeIdentifier,
distributedTransactionId->transactionNumber, distributedTransactionId->transactionNumber,
timestamptz_to_str(distributedTransactionId->timestamp)); timestamptz_to_str(distributedTransactionId->timestamp));

View File

@ -70,10 +70,6 @@
#define WRITE_OID_FIELD(fldname) \ #define WRITE_OID_FIELD(fldname) \
appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname) appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
/* Write a long-integer field */
#define WRITE_LONG_FIELD(fldname) \
appendStringInfo(str, " :" CppAsString(fldname) " %ld", node->fldname)
/* Write a char field (ie, one ascii character) */ /* Write a char field (ie, one ascii character) */
#define WRITE_CHAR_FIELD(fldname) \ #define WRITE_CHAR_FIELD(fldname) \
appendStringInfo(str, " :" CppAsString(fldname) " %c", node->fldname) appendStringInfo(str, " :" CppAsString(fldname) " %c", node->fldname)

View File

@ -275,8 +275,9 @@ ErrorIfShardPlacementsNotColocated(Oid leftRelationId, Oid rightRelationId)
{ {
ereport(ERROR, (errmsg("cannot colocate tables %s and %s", ereport(ERROR, (errmsg("cannot colocate tables %s and %s",
leftRelationName, rightRelationName), leftRelationName, rightRelationName),
errdetail("Shard %ld of %s and shard %ld of %s " errdetail("Shard " UINT64_FORMAT
"have different number of shard placements.", " of %s and shard " UINT64_FORMAT
" of %s have different number of shard placements.",
leftShardId, leftRelationName, leftShardId, leftRelationName,
rightShardId, rightRelationName))); rightShardId, rightRelationName)));
} }
@ -307,8 +308,8 @@ ErrorIfShardPlacementsNotColocated(Oid leftRelationId, Oid rightRelationId)
{ {
ereport(ERROR, (errmsg("cannot colocate tables %s and %s", ereport(ERROR, (errmsg("cannot colocate tables %s and %s",
leftRelationName, rightRelationName), leftRelationName, rightRelationName),
errdetail("Shard %ld of %s and shard %ld of %s " errdetail("Shard " UINT64_FORMAT " of %s and shard "
"are not colocated.", UINT64_FORMAT " of %s are not colocated.",
leftShardId, leftRelationName, leftShardId, leftRelationName,
rightShardId, rightRelationName))); rightShardId, rightRelationName)));
} }

View File

@ -427,7 +427,8 @@ DeleteAllReferenceTablePlacementsFromNodeGroup(uint32 groupId)
DeleteShardPlacementRow(placement->placementId); DeleteShardPlacementRow(placement->placementId);
appendStringInfo(deletePlacementCommand, appendStringInfo(deletePlacementCommand,
"DELETE FROM pg_dist_placement WHERE placementid=%lu", "DELETE FROM pg_dist_placement WHERE placementid = "
UINT64_FORMAT,
placement->placementId); placement->placementId);
SendCommandToWorkers(WORKERS_WITH_METADATA, deletePlacementCommand->data); SendCommandToWorkers(WORKERS_WITH_METADATA, deletePlacementCommand->data);
} }

View File

@ -1380,10 +1380,10 @@ AlterSequenceMinMax(Oid sequenceId, char *schemaName, char *sequenceName)
* DefElem->arg can only hold literal ints up to int4, in order to represent * DefElem->arg can only hold literal ints up to int4, in order to represent
* larger numbers we need to construct a float represented as a string. * larger numbers we need to construct a float represented as a string.
*/ */
appendStringInfo(startNumericString, "%lu", startValue); appendStringInfo(startNumericString, INT64_FORMAT, startValue);
startFloatArg = (Node *) makeFloat(startNumericString->data); startFloatArg = (Node *) makeFloat(startNumericString->data);
appendStringInfo(maxNumericString, "%lu", maxValue); appendStringInfo(maxNumericString, INT64_FORMAT, maxValue);
maxFloatArg = (Node *) makeFloat(maxNumericString->data); maxFloatArg = (Node *) makeFloat(maxNumericString->data);
SetDefElemArg(alterSequenceStatement, "start", startFloatArg); SetDefElemArg(alterSequenceStatement, "start", startFloatArg);

View File

@ -72,9 +72,10 @@
#define CREATE_SCHEMA_COMMAND "CREATE SCHEMA IF NOT EXISTS %s AUTHORIZATION %s" #define CREATE_SCHEMA_COMMAND "CREATE SCHEMA IF NOT EXISTS %s AUTHORIZATION %s"
#define CREATE_EMPTY_SHARD_QUERY "SELECT master_create_empty_shard('%s')" #define CREATE_EMPTY_SHARD_QUERY "SELECT master_create_empty_shard('%s')"
#define FINALIZED_SHARD_PLACEMENTS_QUERY \ #define FINALIZED_SHARD_PLACEMENTS_QUERY \
"SELECT placementid, nodename, nodeport FROM pg_dist_shard_placement WHERE shardstate = 1 AND shardid = %ld" "SELECT placementid, nodename, nodeport FROM pg_dist_shard_placement WHERE shardstate = 1 AND shardid = " \
INT64_FORMAT
#define UPDATE_SHARD_STATISTICS_QUERY \ #define UPDATE_SHARD_STATISTICS_QUERY \
"SELECT master_update_shard_statistics(%ld)" "SELECT master_update_shard_statistics(" INT64_FORMAT ")"
#define PARTITION_METHOD_QUERY "SELECT part_method FROM master_get_table_metadata('%s');" #define PARTITION_METHOD_QUERY "SELECT part_method FROM master_get_table_metadata('%s');"
/* Enumeration that defines the shard placement policy to use while staging */ /* Enumeration that defines the shard placement policy to use while staging */

View File

@ -43,15 +43,18 @@ extern void CreateTableMetadataOnWorkers(Oid relationId);
"SELECT worker_drop_distributed_table(logicalrelid) FROM pg_dist_partition" "SELECT worker_drop_distributed_table(logicalrelid) FROM pg_dist_partition"
#define DISABLE_DDL_PROPAGATION "SET citus.enable_ddl_propagation TO 'off'" #define DISABLE_DDL_PROPAGATION "SET citus.enable_ddl_propagation TO 'off'"
#define WORKER_APPLY_SEQUENCE_COMMAND "SELECT worker_apply_sequence_command (%s)" #define WORKER_APPLY_SEQUENCE_COMMAND "SELECT worker_apply_sequence_command (%s)"
#define UPSERT_PLACEMENT "INSERT INTO pg_dist_placement " \ #define UPSERT_PLACEMENT \
"(shardid, shardstate, shardlength, " \ "INSERT INTO pg_dist_placement " \
"groupid, placementid) " \ "(shardid, shardstate, shardlength, " \
"VALUES (%lu, %d, %lu, %d, %lu) " \ "groupid, placementid) " \
"ON CONFLICT (placementid) DO UPDATE SET " \ "VALUES (" UINT64_FORMAT ", %d, " UINT64_FORMAT \
"shardid = EXCLUDED.shardid, " \ ", %d, " UINT64_FORMAT \
"shardstate = EXCLUDED.shardstate, " \ ") " \
"shardlength = EXCLUDED.shardlength, " \ "ON CONFLICT (placementid) DO UPDATE SET " \
"groupid = EXCLUDED.groupid" "shardid = EXCLUDED.shardid, " \
"shardstate = EXCLUDED.shardstate, " \
"shardlength = EXCLUDED.shardlength, " \
"groupid = EXCLUDED.groupid"
#endif /* METADATA_SYNC_H */ #endif /* METADATA_SYNC_H */