Interface ReplicationConnection
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
PostgresReplicationConnection
A Postgres logical streaming replication connection. Replication connections are established for a slot and a given plugin
and WAL offset tracking is specific to the [database name, plugin name, slot name] triple.
- Author:
- Horia Chiorean (hchiorea@redhat.com)
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbuilder(PostgresConnectorConfig config) Creates a newReplicationConnection.Builderinstance which can be used for creating replication connections.Creates a new replication slot with the given option and returns the result of the command, which may contain results (depending on postgres versions)voidForces the connection to be created, is called by startStreaming, but can be called manually in cases where we want the connection but not to to start streaming yet.booleanChecks whether this connection is open or notvoidstartStreaming(Lsn offset, WalPositionLocator walPosition) Opens a stream for reading logical replication changes from a given LSN position.startStreaming(WalPositionLocator walPosition) Opens a stream for reading logical replication changes from the last known position of the slot for which the connection was opened.Methods inherited from interface java.lang.AutoCloseable
close
-
Method Details
-
startStreaming
ReplicationStream startStreaming(WalPositionLocator walPosition) throws SQLException, InterruptedException Opens a stream for reading logical replication changes from the last known position of the slot for which the connection was opened. The last known position is based on the server'sconfirmed_flush_lsnvalue from thepg_replication_slotstable.If there is no "last known value" (i.e. the connection is for a newly created slot) then the Postgres server will start streaming changes from that last position reported during this connection's creation.
- Returns:
- a
PGReplicationStreamfrom which data is read; never null - Throws:
SQLException- if there is a problem obtaining the replication streamInterruptedException
-
startStreaming
ReplicationStream startStreaming(Lsn offset, WalPositionLocator walPosition) throws SQLException, InterruptedException Opens a stream for reading logical replication changes from a given LSN position.Note that it is possible for a server to have recycled old WAL segments (see the
wal_keep_segmentssetting). If that is the case, then even though a LSN number may be valid, the server will not stream back any changes because they are not available.- Parameters:
offset- a value representing the WAL sequence number where replication should start from; if the value isnullor negative, this behaves exactly like#startStreaming().- Returns:
- a
PGReplicationStreamfrom which data is read; never null - Throws:
SQLException- if anything failsInterruptedException- See Also:
-
LogSequenceNumber
-
createReplicationSlot
Creates a new replication slot with the given option and returns the result of the command, which may contain results (depending on postgres versions)- Throws:
SQLException- if anything fails
-
initConnection
Forces the connection to be created, is called by startStreaming, but can be called manually in cases where we want the connection but not to to start streaming yet. Can be called multiple times- Throws:
SQLExceptionInterruptedException
-
isConnected
Checks whether this connection is open or not- Returns:
trueif this connection is open,falseotherwise- Throws:
SQLException- if anything unexpected fails
-
builder
Creates a newReplicationConnection.Builderinstance which can be used for creating replication connections.- Parameters:
config- aPostgresConnectorConfiginstance; may not be null- Returns:
- a builder, never null
-
reconnect
- Throws:
SQLException
-