From 4351a1e1257ab811e607ab4750f1a89b754c8c1d Mon Sep 17 00:00:00 2001 From: Asim R P Date: Sat, 31 Mar 2018 23:53:15 -0700 Subject: [PATCH] Use ereportif() where logging is predicated by a debug GUC. No change in functionality here. The ereportif() macro avoids ereport() invocation if the preficate is not true. Fixed indentation in a couple of places on the way. --- src/backend/access/transam/xact.c | 136 +++++++++++++++------------ src/backend/cdb/dispatcher/cdbgang.c | 3 +- 2 files changed, 79 insertions(+), 60 deletions(-) diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 64818f810c..99728ccf34 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -537,8 +537,9 @@ AssignTransactionId(TransactionState s) * the Xid as "running". See GetNewTransactionId. */ s->transactionId = GetNewTransactionId(isSubXact); - ereport((Debug_print_full_dtm ? LOG : DEBUG5), - (errmsg("AssignTransactionId(): assigned xid %u", s->transactionId))); + ereportif(Debug_print_full_dtm, LOG, + (errmsg("AssignTransactionId(): assigned xid %u", + s->transactionId))); if (isSubXact) { @@ -828,8 +829,9 @@ bool IsCurrentTransactionIdForReader(TransactionId xid) { */ if (TransactionIdEquals(xid, writer_xid)) { - ereport((Debug_print_full_dtm ? LOG : DEBUG5), - (errmsg("qExec Reader CheckSharedSnapshotForSubtransaction(xid = %u) = true -- TOP", xid))); + ereportif(Debug_print_full_dtm, LOG, + (errmsg("qExec Reader, xid = %d matches writer's top xid", + xid))); isCurrent = true; } else @@ -897,9 +899,9 @@ TransactionIdIsCurrentTransactionId(TransactionId xid) { isCurrentTransactionId = IsCurrentTransactionIdForReader(xid); - ereport((Debug_print_full_dtm ? LOG : DEBUG5), - (errmsg("qExec Reader CheckSharedSnapshotForSubtransaction(xid = %u) = %s -- Subtransaction", - xid, (isCurrentTransactionId ? "true" : "false")))); + ereportif(Debug_print_full_dtm, LOG, + (errmsg("qExec Reader xid = %u, is current = %s", + xid, (isCurrentTransactionId ? "true" : "false")))); return isCurrentTransactionId; } @@ -2003,11 +2005,11 @@ SetSharedTransactionId_writer(void) DistributedTransactionContext == DTX_CONTEXT_QE_TWO_PHASE_IMPLICIT_WRITER || DistributedTransactionContext == DTX_CONTEXT_QE_AUTO_COMMIT_IMPLICIT); - ereport((Debug_print_full_dtm ? LOG : DEBUG5), - (errmsg("%s setting shared xid %u -> %u", - DtxContextToString(DistributedTransactionContext), - SharedLocalSnapshotSlot->xid, - TopTransactionStateData.transactionId))); + ereportif(Debug_print_full_dtm, LOG, + (errmsg("%s setting shared xid %u -> %u", + DtxContextToString(DistributedTransactionContext), + SharedLocalSnapshotSlot->xid, + TopTransactionStateData.transactionId))); SharedLocalSnapshotSlot->xid = TopTransactionStateData.transactionId; } @@ -2026,10 +2028,12 @@ SetSharedTransactionId_reader(TransactionId xid, CommandId cid) */ TopTransactionStateData.transactionId = xid; currentCommandId = cid; - ereport((Debug_print_full_dtm ? LOG : DEBUG5), - (errmsg("qExec READER setting local xid=%u, cid=%u (distributedXid %u/%u)", - TopTransactionStateData.transactionId, currentCommandId, - QEDtxContextInfo.distributedXid, QEDtxContextInfo.segmateSync))); + ereportif(Debug_print_full_dtm, LOG, + (errmsg("qExec READER setting local xid=%u, cid=%u " + "(distributedXid %u/%u)", + TopTransactionStateData.transactionId, currentCommandId, + QEDtxContextInfo.distributedXid, + QEDtxContextInfo.segmateSync))); } /* @@ -2146,13 +2150,13 @@ StartTransaction(void) if (SharedLocalSnapshotSlot != NULL) { LWLockAcquire(SharedLocalSnapshotSlot->slotLock, LW_EXCLUSIVE); - TimestampTz oldStartTimestamp = SharedLocalSnapshotSlot->startTimestamp; + ereportif(Debug_print_full_dtm, LOG, + (errmsg("setting shared snapshot startTimestamp = " + INT64_FORMAT "[old=" INT64_FORMAT "])", + stmtStartTimestamp, + SharedLocalSnapshotSlot->startTimestamp))); SharedLocalSnapshotSlot->startTimestamp = stmtStartTimestamp; LWLockRelease(SharedLocalSnapshotSlot->slotLock); - - ereport((Debug_print_full_dtm ? LOG : DEBUG5), - (errmsg("setting SharedLocalSnapshotSlot->startTimestamp = " INT64_FORMAT "[old=" INT64_FORMAT "])", - stmtStartTimestamp, oldStartTimestamp))); } } break; @@ -2165,10 +2169,12 @@ StartTransaction(void) if (gp_enable_slow_writer_testmode) pg_usleep(500000); - if (QEDtxContextInfo.distributedXid == InvalidDistributedTransactionId) + if (QEDtxContextInfo.distributedXid == + InvalidDistributedTransactionId) { elog(ERROR, - "not tied to distributed transaction id, but still coordinated as a distributed transaction."); + "distributed transaction id is invalid in context %s", + DtxContextToString(DistributedTransactionContext)); } if (SharedLocalSnapshotSlot != NULL) @@ -2189,13 +2195,16 @@ StartTransaction(void) * will auto-commit, and then we will follow it with the real user * command. */ - if (DistributedTransactionContext == DTX_CONTEXT_QE_TWO_PHASE_EXPLICIT_WRITER || - DistributedTransactionContext == DTX_CONTEXT_QE_TWO_PHASE_IMPLICIT_WRITER) + if (DistributedTransactionContext == + DTX_CONTEXT_QE_TWO_PHASE_EXPLICIT_WRITER || + DistributedTransactionContext == + DTX_CONTEXT_QE_TWO_PHASE_IMPLICIT_WRITER) { currentDistribXid = QEDtxContextInfo.distributedXid; Assert(QEDtxContextInfo.distributedTimeStamp != 0); - Assert(QEDtxContextInfo.distributedXid != InvalidDistributedTransactionId); + Assert(QEDtxContextInfo.distributedXid != + InvalidDistributedTransactionId); /* * Update distributed XID info, this is only used for @@ -2217,15 +2226,19 @@ StartTransaction(void) SharedLocalSnapshotSlot->pid = MyProc->pid; SharedLocalSnapshotSlot->writer_proc = MyProc; - ereport((Debug_print_full_dtm ? LOG : DEBUG5), - (errmsg("qExec writer setting distributedXid: %d sharedQDxid %d (shared xid %u -> %u) ready %s (shared timeStamp = " INT64_FORMAT " -> " INT64_FORMAT ")", - QEDtxContextInfo.distributedXid, - SharedLocalSnapshotSlot->QDxid, - SharedLocalSnapshotSlot->xid, - s->transactionId, - SharedLocalSnapshotSlot->ready ? "true" : "false", - SharedLocalSnapshotSlot->startTimestamp, - xactStartTimestamp))); + ereportif(Debug_print_full_dtm, LOG, + (errmsg( + "qExec writer setting distributedXid: %d " + "sharedQDxid %d (shared xid %u -> %u) ready %s" + " (shared timeStamp = " INT64_FORMAT " -> " + INT64_FORMAT ")", + QEDtxContextInfo.distributedXid, + SharedLocalSnapshotSlot->QDxid, + SharedLocalSnapshotSlot->xid, + s->transactionId, + SharedLocalSnapshotSlot->ready ? "true" : "false", + SharedLocalSnapshotSlot->startTimestamp, + xactStartTimestamp))); LWLockRelease(SharedLocalSnapshotSlot->slotLock); } } @@ -2240,13 +2253,14 @@ StartTransaction(void) Assert (SharedLocalSnapshotSlot != NULL); currentDistribXid = QEDtxContextInfo.distributedXid; - ereport((Debug_print_full_dtm ? LOG : DEBUG5), - (errmsg("qExec reader: distributedXid %d currcid %d gxid = %u DtxContext '%s' sharedsnapshots: %s", - QEDtxContextInfo.distributedXid, - QEDtxContextInfo.curcid, - getDistributedTransactionId(), - DtxContextToString(DistributedTransactionContext), - SharedSnapshotDump()))); + ereportif(Debug_print_full_dtm, LOG, + (errmsg("qExec reader: distributedXid %d currcid %d " + "gxid = %u DtxContext '%s' sharedsnapshots: %s", + QEDtxContextInfo.distributedXid, + QEDtxContextInfo.curcid, + getDistributedTransactionId(), + DtxContextToString(DistributedTransactionContext), + SharedSnapshotDump()))); } break; @@ -2261,13 +2275,15 @@ StartTransaction(void) break; } - ereport((Debug_print_snapshot_dtm ? LOG : DEBUG5), - (errmsg("[Distributed Snapshot #%u] *StartTransaction* (gxid = %u, xid = %u, '%s')", - (!FirstSnapshotSet ? 0 : - GetTransactionSnapshot()->distribSnapshotWithLocalMapping.ds.distribSnapshotId), - getDistributedTransactionId(), - s->transactionId, - DtxContextToString(DistributedTransactionContext)))); + ereportif(Debug_print_snapshot_dtm, LOG, + (errmsg("[Distributed Snapshot #%u] *StartTransaction* " + "(gxid = %u, xid = %u, '%s')", + (!FirstSnapshotSet ? 0 : + GetTransactionSnapshot()-> + distribSnapshotWithLocalMapping.ds.distribSnapshotId), + getDistributedTransactionId(), + s->transactionId, + DtxContextToString(DistributedTransactionContext)))); /* * Assign a new LocalTransactionId, and combine it with the backendId to @@ -2349,10 +2365,10 @@ StartTransaction(void) ShowTransactionState("StartTransaction"); - ereport((Debug_print_full_dtm ? LOG : DEBUG5), - (errmsg("StartTransaction in DTX Context = '%s', %s", - DtxContextToString(DistributedTransactionContext), - LocalDistribXact_DisplayString(MyProc)))); + ereportif(Debug_print_full_dtm, LOG, + (errmsg("StartTransaction in DTX Context = '%s', %s", + DtxContextToString(DistributedTransactionContext), + LocalDistribXact_DisplayString(MyProc)))); } /* @@ -3232,10 +3248,12 @@ StartTransactionCommand(void) LWLockRelease(SharedLocalSnapshotSlot->slotLock); - ereport((Debug_print_full_dtm ? LOG : DEBUG3), - (errmsg("qExec WRITER updating shared xid: %u -> %u (StartTransactionCommand) timestamp: " INT64_FORMAT " -> " INT64_FORMAT ")", - oldXid, s->transactionId, - oldStartTimestamp, xactStartTimestamp))); + ereportif(Debug_print_full_dtm, LOG, + (errmsg("qExec WRITER updating shared xid: %u -> %u " + "(StartTransactionCommand) timestamp: " + INT64_FORMAT " -> " INT64_FORMAT ")", + oldXid, s->transactionId, + oldStartTimestamp, xactStartTimestamp))); } break; @@ -4920,8 +4938,8 @@ ExecutorMarkTransactionDoesWrites(void) // UNDONE: Verify we are in transaction... if (!TopTransactionStateData.executorSaysXactDoesWrites) { - ereport((Debug_print_full_dtm ? LOG : DEBUG5), - (errmsg("ExecutorMarkTransactionDoesWrites called"))); + ereportif(Debug_print_full_dtm, LOG, + (errmsg("ExecutorMarkTransactionDoesWrites called"))); TopTransactionStateData.executorSaysXactDoesWrites = true; } } diff --git a/src/backend/cdb/dispatcher/cdbgang.c b/src/backend/cdb/dispatcher/cdbgang.c index 73af4ba17f..78cdfd1d46 100644 --- a/src/backend/cdb/dispatcher/cdbgang.c +++ b/src/backend/cdb/dispatcher/cdbgang.c @@ -682,7 +682,8 @@ makeOptions(void) { struct config_generic *guc = gucs[i]; - if ((guc->flags & GUC_GPDB_ADDOPT) && (guc->context == PGC_USERSET || procRoleIsSuperuser())) + if ((guc->flags & GUC_GPDB_ADDOPT) && + (guc->context == PGC_USERSET || procRoleIsSuperuser())) addOneOption(&string, guc); } -- GitLab