diff --git a/src/backend/replication/logical/applyparallelworker.c b/src/backend/replication/logical/applyparallelworker.c index 7eed82ff41..9e35b2ecbe 100644 --- a/src/backend/replication/logical/applyparallelworker.c +++ b/src/backend/replication/logical/applyparallelworker.c @@ -136,11 +136,11 @@ * concurrently), if the shm_mq buffer between LA and PA-2 is full, LA has to * wait to send messages, and this wait doesn't appear in lmgr. * - * To resolve this issue, we use non-blocking write and wait with a timeout. If + * To avoid this wait, we use a non-blocking write and wait with a timeout. If * the timeout is exceeded, the LA will serialize the message to a file and * indicate PA-2 that it needs to read that file for the remaining messages. * Then LA will start waiting for commit which will detect deadlock if any. - * (See pa_send_data() and enum TransApplyAction) + * See pa_send_data() and enum TransApplyAction. * * 4) Lock types * @@ -691,10 +691,11 @@ pa_spooled_messages(void) SpinLockRelease(&MyParallelShared->mutex); /* - * If the leader apply worker is still (busy) serializing partial changes - * then the parallel apply worker acquires the stream lock now. Otherwise, - * it would not have a chance to receive a STREAM_STOP (and acquire the - * stream lock) until the leader had serialized all changes. + * If the leader apply worker is busy serializing the partial changes then + * acquire the stream lock now. Otherwise, the parallel apply worker won't + * get a chance to receive a STREAM_STOP (and acquire the stream lock) + * until the leader had serialized all changes which can lead to undetected + * deadlock. */ if (fileset_state == FS_BUSY) { @@ -1535,9 +1536,9 @@ pa_stream_abort(LogicalRepStreamAbortData *abort_data) } /* - * Set the fileset state for the given parallel apply worker. The - * stream_fileset of the leader apply worker will be written into the shared - * memory if the fileset_state is FS_READY. + * Set the fileset state for the given parallel apply worker. The fileset + * will be set once the leader worker reached the ready state so that it can + * be used by parallel apply worker. */ void pa_set_fileset_state(ParallelApplyWorkerShared *wshared, diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c index b8587dbe5c..606e4c6fb4 100644 --- a/src/backend/replication/logical/worker.c +++ b/src/backend/replication/logical/worker.c @@ -256,15 +256,16 @@ typedef struct ApplyErrorCallbackArg * * TRANS_LEADER_PARTIAL_SERIALIZE: * The action means that we are in the leader apply worker and have sent some - * changes directly to the parallel apply worker, due to timeout while sending - * data the remaining changes need to be serialized to a file. The parallel apply - * worker will apply these serialized changes when the final commit arrives. + * changes directly to the parallel apply worker and the remaining + * changes are serialized to a file, due to timeout while sending data. The + * parallel apply worker will apply these serialized changes when the final + * commit arrives. * - * LEADER_SERIALIZE could not be used for this case because, in addition to + * We can't use TRANS_LEADER_SERIALIZE for this case because, in addition to * serializing changes, the leader worker also needs to serialize the STREAM_XXX * message to a file, and wait for the parallel apply worker to finish the * transaction when processing the transaction finish command. So this new - * action was introduced to make the logic clearer. + * action was introduced to keep the code and logic clear. * * TRANS_LEADER_SEND_TO_PARALLEL: * The action means that we are in the leader apply worker and need to send the