/* Flag set by signal handler of backends for replication */
static volatile sig_atomic_t replication_complete = false;
-static volatile sig_atomic_t replication_abort = false;
+static volatile sig_atomic_t exit_before_complete = false;
/* Signal handlers */
static void WalSndSigHupHandler(SIGNAL_ARGS);
* If the primary cannot work any longer, we don't return
* a success to the client
*/
- if (replication_abort)
- {
- replication_abort = false;
- ereport(FATAL,
- (errcode(ERRCODE_ADMIN_SHUTDOWN),
- errmsg("terminating connection due to administrator command "
- "and replication cancellation")));
- }
+ if (exit_before_complete)
+ return;
}
}
if (all_wakeup || XLByteLE(waiter->record, record))
{
- SetProcLatch(waiter->latch, abort ? PROCSIG_REPLICATION_ABORT :
+ SetProcLatch(waiter->latch, abort ? PROCSIG_EXIT_BEFORE_COMPLETE :
PROCSIG_REPLICATION_COMPLETE, waiter->backendId);
count++;
}
}
/*
- * This is called when PROCSIG_REPLICATION_ABORT is received.
+ * This is called when PROCSIG_EXIT_BEFORE_COMPLETE is received.
*/
void
-HandleReplicationAbort(void)
+HandleExitBeforeComplete(void)
+{
+ exit_before_complete = true;
+}
+
+/*
+ * Does the backend have to exit before returning a CommandComplete
+ * message to the client?
+ */
+bool
+NeedExitBeforeComplete(void)
{
- replication_abort = true;
+ return exit_before_complete;
}
if (CheckProcSignal(PROCSIG_REPLICATION_COMPLETE))
HandleReplicationComplete();
- if (CheckProcSignal(PROCSIG_REPLICATION_ABORT))
- HandleReplicationAbort();
+ if (CheckProcSignal(PROCSIG_EXIT_BEFORE_COMPLETE))
+ HandleExitBeforeComplete();
latch_sigusr1_handler();
#include "executor/tstoreReceiver.h"
#include "libpq/libpq.h"
#include "libpq/pqformat.h"
+#include "replication/walsender.h"
#include "utils/portal.h"
case DestRemoteExecute:
/*
+ * If the server is shutting down and we cannot ensure that
+ * the transaction has successfully been replicated, we exit
+ * before returning a "success" to the client.
+ */
+ if (NeedExitBeforeComplete())
+ ereport(FATAL,
+ (errcode(ERRCODE_ADMIN_SHUTDOWN),
+ errmsg("terminating connection due to administrator "
+ "command and replication cancellation")));
+
+ /*
* We assume the commandTag is plain ASCII and therefore requires
* no encoding conversion.
*/
extern void WaitXLogSend(XLogRecPtr record);
extern void HandleReplicationComplete(void);
-extern void HandleReplicationAbort(void);
+extern void HandleExitBeforeComplete(void);
+extern bool NeedExitBeforeComplete(void);
#endif /* _WALSENDER_H */
/* Replication interrupts */
PROCSIG_REPLICATION_COMPLETE,
- PROCSIG_REPLICATION_ABORT,
+ PROCSIG_EXIT_BEFORE_COMPLETE,
NUM_PROCSIGNALS /* Must be last! */
} ProcSignalReason;