Skip to content

Commit b03fba9

Browse files
committed
Replace asserts in pg_dtm with error reporting
1 parent 19cc584 commit b03fba9

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

contrib/pg_dtm/pg_dtm.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,9 @@ DtmGetNewTransactionId(bool isSubXact)
352352
TransactionId xid;
353353

354354
XTM_INFO("%d: GetNewTransactionId\n", getpid());
355-
Assert(!DtmGlobalXidAssigned); /* We should not assign new Xid if we do not use previous one */
356-
355+
if (DtmGlobalXidAssigned) { /* We should not assign new Xid if we do not use previous one */
356+
elog(ERROR, "dtm_begin/join_transaction should be called prior to begin of global transaction");
357+
}
357358
/*
358359
* Workers synchronize transaction state at the beginning of each parallel
359360
* operation, so we can't account for new XIDs after that point.
@@ -856,12 +857,16 @@ dtm_get_current_snapshot_xcnt(PG_FUNCTION_ARGS)
856857
Datum
857858
dtm_begin_transaction(PG_FUNCTION_ARGS)
858859
{
859-
Assert(!TransactionIdIsValid(DtmNextXid));
860+
if (TransactionIdIsValid(DtmNextXid)) {
861+
elog(ERROR, "dtm_begin/join_transaction should be called only once for global transaction");
862+
}
860863
if (dtm == NULL) {
861864
elog(ERROR, "DTM is not properly initialized, please check that pg_dtm plugin was added to shared_preload_libraries list in postgresql.conf");
862865
}
863866
DtmNextXid = DtmGlobalStartTransaction(&DtmSnapshot, &dtm->minXid);
864-
Assert(TransactionIdIsValid(DtmNextXid));
867+
if (!TransactionIdIsValid(DtmNextXid)) {
868+
elog(ERROR, "Arbiter was not able to assign XID");
869+
}
865870
XTM_INFO("%d: Start global transaction %d, dtm->minXid=%d\n", getpid(), DtmNextXid, dtm->minXid);
866871

867872
DtmHasGlobalSnapshot = true;
@@ -873,9 +878,13 @@ dtm_begin_transaction(PG_FUNCTION_ARGS)
873878

874879
Datum dtm_join_transaction(PG_FUNCTION_ARGS)
875880
{
876-
Assert(!TransactionIdIsValid(DtmNextXid));
881+
if (TransactionIdIsValid(DtmNextXid)) {
882+
elog(ERROR, "dtm_begin/join_transaction should be called only once for global transaction");
883+
}
877884
DtmNextXid = PG_GETARG_INT32(0);
878-
Assert(TransactionIdIsValid(DtmNextXid));
885+
if (!TransactionIdIsValid(DtmNextXid)) {
886+
elog(ERROR, "Arbiter was not able to assign XID");
887+
}
879888

880889
DtmGlobalGetSnapshot(DtmNextXid, &DtmSnapshot, &dtm->minXid);
881890
XTM_INFO("%d: Join global transaction %d, dtm->minXid=%d\n", getpid(), DtmNextXid, dtm->minXid);

0 commit comments

Comments
 (0)