Interface ReplicationConnection
-
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
PostgresReplicationConnection
@NotThreadSafe public interface ReplicationConnection extends AutoCloseable
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 Modifier and Type Interface Description static interfaceReplicationConnection.BuilderA builder forReplicationConnection
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static ReplicationConnection.Builderbuilder(PostgresConnectorConfig config)Creates a newReplicationConnection.Builderinstance which can be used for creating replication connections.Optional<SlotCreationResult>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)voidinitConnection()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.booleanisConnected()Checks whether this connection is open or notvoidreconnect()ReplicationStreamstartStreaming(Lsn offset, WalPositionLocator walPosition)Opens a stream for reading logical replication changes from a given LSN position.ReplicationStreamstartStreaming(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 Detail
-
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
Optional<SlotCreationResult> createReplicationSlot() throws SQLException
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
void initConnection() throws SQLException, InterruptedExceptionForces 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
boolean isConnected() throws SQLExceptionChecks whether this connection is open or not- Returns:
trueif this connection is open,falseotherwise- Throws:
SQLException- if anything unexpected fails
-
builder
static ReplicationConnection.Builder builder(PostgresConnectorConfig config)
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
void reconnect() throws SQLException- Throws:
SQLException
-
-