Class V3PGReplicationStream
- All Implemented Interfaces:
AutoCloseable,PGReplicationStream
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionV3PGReplicationStream(CopyDual copyDual, LogSequenceNumber startLSN, long updateIntervalMs, boolean automaticFlush, ReplicationType replicationType) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Stop replication changes from server and free resources.voidForce send last received, flushed and applied LSN status to backend.Last applied lsn sent in update message to backed.Last flushed LSN sent in update message to backend.Parameter updates by executePGReplicationStream.read()method.booleanisClosed()@Nullable ByteBufferread()Read next wal record from backend.@Nullable ByteBufferRead next WAL record from backend.voidsetAppliedLSN(LogSequenceNumber applied) Inform backend which LSN has been applied on standby.voidsetFlushedLSN(LogSequenceNumber flushed) Set flushed LSN.
-
Field Details
-
POSTGRES_EPOCH_2000_01_01
public static final long POSTGRES_EPOCH_2000_01_01- See Also:
-
-
Constructor Details
-
V3PGReplicationStream
public V3PGReplicationStream(CopyDual copyDual, LogSequenceNumber startLSN, long updateIntervalMs, boolean automaticFlush, ReplicationType replicationType) - Parameters:
copyDual- bidirectional copy protocolstartLSN- the position in the WAL that we want to initiate replication from usually the currentLSN returned by calling pg_current_wal_lsn()for v10 above or pg_current_xlog_location() depending on the version of the serverupdateIntervalMs- the number of millisecond between status packets sent back to the server. A value of zero disables the periodic status updates completely, although an update will still be sent when requested by the server, to avoid timeout disconnect.replicationType- LOGICAL or PHYSICAL
-
-
Method Details
-
read
Description copied from interface:PGReplicationStreamRead next wal record from backend. It method can be block until new message will not get from server.A single WAL record is never split across two XLogData messages. When a WAL record crosses a WAL page boundary, and is therefore already split using continuation records, it can be split at the page boundary. In other words, the first main WAL record and its continuation records can be sent in different XLogData messages.
- Specified by:
readin interfacePGReplicationStream- Returns:
- not null byte array received by replication protocol, return ByteBuffer wrap around
received byte array with use offset, so, use
ByteBuffer.array()carefully - Throws:
SQLException- when some internal exception occurs during read from stream
-
readPending
Description copied from interface:PGReplicationStreamRead next WAL record from backend. This method does not block and in contrast toPGReplicationStream.read(). If message from backend absent return null. It allow periodically check message in stream and if they absent sleep some time, but it time should be less thanCommonOptions.getStatusInterval()to avoid disconnect from the server.A single WAL record is never split across two XLogData messages. When a WAL record crosses a WAL page boundary, and is therefore already split using continuation records, it can be split at the page boundary. In other words, the first main WAL record and its continuation records can be sent in different XLogData messages.
- Specified by:
readPendingin interfacePGReplicationStream- Returns:
- byte array received by replication protocol or NULL if pending message from server
absent. Returns ByteBuffer wrap around received byte array with use offset, so, use
ByteBuffer.array()carefully. - Throws:
SQLException- when some internal exception occurs during read from stream
-
getLastReceiveLSN
Description copied from interface:PGReplicationStreamParameter updates by executePGReplicationStream.read()method.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
PGReplicationStream.read()orPGReplicationStream.readPending(), to get the LSN corresponding to the received record.- Specified by:
getLastReceiveLSNin interfacePGReplicationStream- Returns:
- NOT NULL LSN position that was receive last time via
PGReplicationStream.read()method
-
getLastFlushedLSN
Description copied from interface:PGReplicationStreamLast flushed LSN sent in update message to backend. Parameter updates only viaPGReplicationStream.setFlushedLSN(LogSequenceNumber)It is safe to call this method in a thread different than the main thread.
- Specified by:
getLastFlushedLSNin interfacePGReplicationStream- Returns:
- NOT NULL location of the last WAL flushed to disk in the standby.
-
getLastAppliedLSN
Description copied from interface:PGReplicationStreamLast applied lsn sent in update message to backed. Parameter updates only viaPGReplicationStream.setAppliedLSN(LogSequenceNumber)It is safe to call this method in a thread different than the main thread.
- Specified by:
getLastAppliedLSNin interfacePGReplicationStream- Returns:
- not null location of the last WAL applied in the standby.
-
setFlushedLSN
Description copied from interface:PGReplicationStreamSet flushed LSN. This parameter will be sent to backend on next update status iteration. Flushed LSN position help backend define which WAL can be recycled.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.
- Specified by:
setFlushedLSNin interfacePGReplicationStream- Parameters:
flushed- NOT NULL location of the last WAL flushed to disk in the standby.- See Also:
-
setAppliedLSN
Description copied from interface:PGReplicationStreamInform backend which LSN has been applied on standby. Feedback will send to backend on next update status iteration.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.
- Specified by:
setAppliedLSNin interfacePGReplicationStream- Parameters:
applied- NOT NULL location of the last WAL applied in the standby.- See Also:
-
forceUpdateStatus
Description copied from interface:PGReplicationStreamForce send last received, flushed and applied LSN status to backend. You cannot send LSN status explicitly becausePGReplicationStreamsends the status to backend periodically by configured interval viaCommonOptions.getStatusInterval()- Specified by:
forceUpdateStatusin interfacePGReplicationStream- Throws:
SQLException- when some internal exception occurs during read from stream- See Also:
-
isClosed
public boolean isClosed()- Specified by:
isClosedin interfacePGReplicationStream- Returns:
trueif replication stream was already close, otherwise returnfalse
-
close
Description copied from interface:PGReplicationStreamStop replication changes from server and free resources. After that connection can be reuse to another queries. Also after close current stream they cannot be used anymore.Note: This method can spend much time for logical replication stream on postgresql version 9.6 and lower, because postgresql have bug - during decode big transaction to logical form and during wait new changes postgresql ignore messages from client. As workaround you can close replication connection instead of close replication stream. For more information about it problem see mailing list thread Stopping logical replication protocol
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfacePGReplicationStream- Throws:
SQLException- when some internal exception occurs during end streaming
-