public class V3PGReplicationStream extends Object implements PGReplicationStream
| Modifier and Type | Field and Description |
|---|---|
static long |
POSTGRES_EPOCH_2000_01_01 |
| Constructor and Description |
|---|
V3PGReplicationStream(CopyDual copyDual,
LogSequenceNumber startLSN,
long updateIntervalMs,
ReplicationType replicationType) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Stop replication changes from server and free resources.
|
void |
forceUpdateStatus()
Force send to backend status about last received, flushed and applied LSN.
|
LogSequenceNumber |
getLastAppliedLSN()
Last applied lsn send in update message to backed.
|
LogSequenceNumber |
getLastFlushedLSN()
Last flushed lsn send in update message to backend.
|
LogSequenceNumber |
getLastReceiveLSN()
Parameter updates by execute
PGReplicationStream.read() method. |
boolean |
isClosed() |
ByteBuffer |
read()
Read next wal record from backend.
|
ByteBuffer |
readPending()
Read next wal record from backend.
|
void |
setAppliedLSN(LogSequenceNumber applied)
Parameter used only physical replication and define which lsn already was apply on standby.
|
void |
setFlushedLSN(LogSequenceNumber flushed)
Set flushed LSN.
|
public static final long POSTGRES_EPOCH_2000_01_01
public V3PGReplicationStream(CopyDual copyDual, LogSequenceNumber startLSN, long updateIntervalMs, ReplicationType replicationType)
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 PHYSICALpublic ByteBuffer read() throws SQLException
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.
read in interface PGReplicationStreamByteBuffer.array() carefullySQLException - when some internal exception occurs during read from streampublic ByteBuffer readPending() throws SQLException
PGReplicationStreamRead next wal record from backend. It method can't be block and in contrast to PGReplicationStream.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 than
CommonOptions.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.
readPending in interface PGReplicationStreamByteBuffer.array() carefully.SQLException - when some internal exception occurs during read from streampublic LogSequenceNumber getLastReceiveLSN()
PGReplicationStreamPGReplicationStream.read() method.getLastReceiveLSN in interface PGReplicationStreamPGReplicationStream.read()
methodpublic LogSequenceNumber getLastFlushedLSN()
PGReplicationStreamPGReplicationStream.setFlushedLSN(LogSequenceNumber)getLastFlushedLSN in interface PGReplicationStreampublic LogSequenceNumber getLastAppliedLSN()
PGReplicationStreamPGReplicationStream.setAppliedLSN(LogSequenceNumber)getLastAppliedLSN in interface PGReplicationStreampublic void setFlushedLSN(LogSequenceNumber flushed)
PGReplicationStreamsetFlushedLSN in interface PGReplicationStreamflushed - not null location of the last WAL flushed to disk in the standby.PGReplicationStream.forceUpdateStatus()public void setAppliedLSN(LogSequenceNumber applied)
PGReplicationStreamsetAppliedLSN in interface PGReplicationStreamapplied - not null location of the last WAL applied in the standby.PGReplicationStream.forceUpdateStatus()public void forceUpdateStatus()
throws SQLException
PGReplicationStreamPGReplicationStream send status to backend periodical by
configured interval via CommonOptions.getStatusInterval()forceUpdateStatus in interface PGReplicationStreamSQLException - when some internal exception occurs during read from streamCommonOptions.getStatusInterval()public boolean isClosed()
isClosed in interface PGReplicationStreamtrue if replication stream was already close, otherwise return falsepublic void close()
throws SQLException
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
close in interface PGReplicationStreamSQLException - when some internal exception occurs during end streamingCopyright © 2023 openGauss. All rights reserved.