Skip to content
Permalink
Browse files

Allow setFlushedLSN(lsn) and setAppliedLSN(lsn) from outside main loop (

#1329)

* Marking the fields holding the sequence numbers as  will allow the API user to call setFlushedLSN() and setAppliedLSN() (and also the getters) from a thread different than the thread doing the main loop. This is useful when doing a blocking read(), as it allows another thread to actually acknowledge an event as flushed/applied. Without this, one cannot combine read() and parallel processing of WAL events.

* Update javadocs to reflect updated concurrency.



* Fix javadocs
  • Loading branch information...
pbillen authored and davecramer committed Nov 26, 2018
1 parent c4656b3 commit 381cf45cd1029d53ef748731d93361a814f711b6
@@ -35,9 +35,9 @@
/**
* Last receive LSN + payload size.
*/
private LogSequenceNumber lastReceiveLSN = LogSequenceNumber.INVALID_LSN;
private LogSequenceNumber lastAppliedLSN = LogSequenceNumber.INVALID_LSN;
private LogSequenceNumber lastFlushedLSN = LogSequenceNumber.INVALID_LSN;
private volatile LogSequenceNumber lastReceiveLSN = LogSequenceNumber.INVALID_LSN;
private volatile LogSequenceNumber lastAppliedLSN = LogSequenceNumber.INVALID_LSN;
private volatile LogSequenceNumber lastFlushedLSN = LogSequenceNumber.INVALID_LSN;

/**
* @param copyDual bidirectional copy protocol
@@ -12,10 +12,11 @@
import java.sql.SQLException;

/**
* Not tread safe replication stream. After complete streaming should be close, for free resource on
* backend. Periodical status update work only when use {@link PGReplicationStream#read()} method.
* It means that process wal record should be fast as possible, because during process wal record
* lead to disconnect by timeout from server.
* Not tread safe replication stream (though certain methods can be safely called by different
* threads). After complete streaming should be close, for free resource on backend. Periodical
* status update work only when use {@link PGReplicationStream#read()} method. It means that
* process wal record should be fast as possible, because during process wal record lead to
* disconnect by timeout from server.
*/
public interface PGReplicationStream
//#if mvn.project.property.postgresql.jdbc.spec >= "JDBC4.1"
@@ -57,41 +58,55 @@
ByteBuffer readPending() throws SQLException;

/**
* Parameter updates by execute {@link PGReplicationStream#read()} method.
* <p>Parameter updates by execute {@link PGReplicationStream#read()} method.</p>
*
* <p>It is safe to call this method in a thread different than the main thread. However, usually this
* method is called in the main thread after a successful {@link PGReplicationStream#read()} or
* {@link PGReplicationStream#readPending()}, to get the LSN corresponding to the received record.</p>
*
* @return not null LSN position that was receive last time via {@link PGReplicationStream#read()}
* method
*/
LogSequenceNumber getLastReceiveLSN();

/**
* Last flushed lsn send in update message to backend. Parameter updates only via {@link
* PGReplicationStream#setFlushedLSN(LogSequenceNumber)}
* <p>Last flushed lsn send in update message to backend. Parameter updates only via {@link
* PGReplicationStream#setFlushedLSN(LogSequenceNumber)}</p>
*
* <p>It is safe to call this method in a thread different than the main thread.</p>
*
* @return not null location of the last WAL flushed to disk in the standby.
*/
LogSequenceNumber getLastFlushedLSN();

/**
* Last applied lsn send in update message to backed. Parameter updates only via {@link
* PGReplicationStream#setAppliedLSN(LogSequenceNumber)}
* <p>Last applied lsn send in update message to backed. Parameter updates only via {@link
* PGReplicationStream#setAppliedLSN(LogSequenceNumber)}</p>
*
* <p>It is safe to call this method in a thread different than the main thread.</p>
*
* @return not null location of the last WAL applied in the standby.
*/
LogSequenceNumber getLastAppliedLSN();

/**
* Set flushed LSN. It parameter will be send to backend on next update status iteration. Flushed
* LSN position help backend define which wal can be recycle.
* <p>Set flushed LSN. It parameter will be send to backend on next update status iteration. Flushed
* LSN position help backend define which wal can be recycle.</p>
*
* <p>It is safe to call this method in a thread different than the main thread. The updated value
* will be sent to the backend in the next status update run.</p>
*
* @param flushed not null location of the last WAL flushed to disk in the standby.
* @see PGReplicationStream#forceUpdateStatus()
*/
void setFlushedLSN(LogSequenceNumber flushed);

/**
* Parameter used only physical replication and define which lsn already was apply on standby.
* Feedback will send to backend on next update status iteration.
* <p>Parameter used only physical replication and define which lsn already was apply on standby.
* Feedback will send to backend on next update status iteration.</p>
*
* <p>It is safe to call this method in a thread different than the main thread. The updated value
* will be sent to the backend in the next status update run.</p>
*
* @param applied not null location of the last WAL applied in the standby.
* @see PGReplicationStream#forceUpdateStatus()

0 comments on commit 381cf45

Please sign in to comment.
You can’t perform that action at this time.