public class PostgresReplicationConnection extends JdbcConnection implements ReplicationConnection
ReplicationConnection for Postgresql. Note that replication connections in PG cannot execute
regular statements but only a limited number of replication-related commands.| Modifier and Type | Class and Description |
|---|---|
protected static class |
PostgresReplicationConnection.ReplicationConnectionBuilder |
JdbcConnection.BlockingMultiResultSetConsumer, JdbcConnection.BlockingResultSetConsumer, JdbcConnection.CallPreparer, JdbcConnection.ConnectionFactory, JdbcConnection.MultiResultSetConsumer, JdbcConnection.Operations, JdbcConnection.ParameterResultSetConsumer, JdbcConnection.ResultSetConsumer, JdbcConnection.ResultSetMapper<T>, JdbcConnection.StatementFactory, JdbcConnection.StatementPreparerReplicationConnection.Builder| Modifier and Type | Field and Description |
|---|---|
private long |
defaultStartingPos |
private boolean |
dropSlotOnClose |
private boolean |
exportSnapshot |
private boolean |
hasInitedSlot |
private static org.slf4j.Logger |
LOGGER |
private MessageDecoder |
messageDecoder |
private Configuration |
originalConfig |
private PostgresConnectorConfig.LogicalDecoder |
plugin |
private String |
publicationName |
private SlotCreationResult |
slotCreationInfo |
private String |
slotName |
private Duration |
statusUpdateInterval |
private Properties |
streamParams |
private TypeRegistry |
typeRegistry |
| Modifier | Constructor and Description |
|---|---|
private |
PostgresReplicationConnection(Configuration config,
String slotName,
String publicationName,
PostgresConnectorConfig.LogicalDecoder plugin,
boolean dropSlotOnClose,
boolean exportSnapshot,
Duration statusUpdateInterval,
TypeRegistry typeRegistry,
Properties streamParams,
PostgresSchema schema)
Creates a new replication connection with the given params.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
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)
|
private ReplicationStream |
createReplicationStream(org.postgresql.replication.LogSequenceNumber startLsn,
boolean skipFirstFlushRecord) |
protected static void |
defaultSettings(Configuration.Builder builder) |
private ServerInfo.ReplicationSlot |
getSlotInfo() |
void |
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.
|
protected void |
initPublication() |
protected void |
initReplicationSlot() |
private SlotCreationResult |
parseSlotCreation(ResultSet rs) |
protected org.postgresql.jdbc.PgConnection |
pgConnection() |
private org.postgresql.replication.PGReplicationStream |
startPgReplicationStream(org.postgresql.replication.LogSequenceNumber lsn,
Function<org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder,org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder> configurator) |
ReplicationStream |
startStreaming()
creating a replication connection and starting to stream involves a few steps:
1.
|
ReplicationStream |
startStreaming(Long offset)
Opens a stream for reading logical replication changes from a given LSN position.
|
private boolean |
useTemporarySlot() |
call, columnsFor, columnsFor, commit, config, connect, connection, connection, connectionString, database, execute, execute, executeWithoutCommitting, isConnected, isNullable, parseSqlStatementString, patternBasedFactory, patternBasedFactory, prepareQuery, prepareQuery, prepareQuery, prepareQuery, prepareQueryAndMap, prepareQueryWithBlockingConsumer, prepareUpdate, print, print, query, query, queryAndMap, queryAndMap, queryWithBlockingConsumer, readAllCatalogNames, readAllSchemaNames, readAllTableNames, readPrimaryKeyNames, readPrimaryKeyOrUniqueIndexNames, readSchema, readTableColumn, readTableNames, readTableUniqueIndices, resolveJdbcType, resolveNativeType, setAutoCommit, tableTypes, usernameclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbuilder, format, isConnectedprivate static org.slf4j.Logger LOGGER
private final String slotName
private final String publicationName
private final PostgresConnectorConfig.LogicalDecoder plugin
private final boolean dropSlotOnClose
private final boolean exportSnapshot
private final Configuration originalConfig
private final Duration statusUpdateInterval
private final MessageDecoder messageDecoder
private final TypeRegistry typeRegistry
private final Properties streamParams
private long defaultStartingPos
private SlotCreationResult slotCreationInfo
private boolean hasInitedSlot
private PostgresReplicationConnection(Configuration config, String slotName, String publicationName, PostgresConnectorConfig.LogicalDecoder plugin, boolean dropSlotOnClose, boolean exportSnapshot, Duration statusUpdateInterval, TypeRegistry typeRegistry, Properties streamParams, PostgresSchema schema)
config - the JDBC configuration for the connection; may not be nullslotName - the name of the DB slot for logical replication; may not be nullpublicationName - the name of the DB publication for logical replication; may not be nullplugin - decoder matching the server side plug-in used for streaming changes; may not be nulldropSlotOnClose - whether the replication slot should be dropped once the connection is closedstatusUpdateInterval - the interval at which the replication connection should periodically send statusexportSnapshot - whether the replication should export a snapshot when createdtypeRegistry - registry with PostgreSQL typesstreamParams - additional parameters to pass to the replication streamschema - the schema; must not be null
updates to the serverprivate ServerInfo.ReplicationSlot getSlotInfo() throws SQLException, InterruptedException
SQLExceptionInterruptedExceptionprotected void initPublication()
protected void initReplicationSlot()
throws SQLException,
InterruptedException
SQLExceptionInterruptedExceptionprivate boolean useTemporarySlot()
throws SQLException
SQLExceptionpublic ReplicationStream startStreaming() throws SQLException, InterruptedException
startStreaming(Long), this method
delegates to that methodstartStreaming in interface ReplicationConnectionSQLExceptionInterruptedExceptionpublic ReplicationStream startStreaming(Long offset) throws SQLException, InterruptedException
ReplicationConnection
Note that it is possible for a server to have recycled old WAL segments (see the wal_keep_segments setting). 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.
startStreaming in interface ReplicationConnectionoffset - a value representing the WAL sequence number where replication should start from; if the value
is null or negative, this behaves exactly like ReplicationConnection.startStreaming().PGReplicationStream from which data is read; never nullSQLException - if anything failsInterruptedExceptionLogSequenceNumberpublic void initConnection()
throws SQLException,
InterruptedException
ReplicationConnectioninitConnection in interface ReplicationConnectionSQLExceptionInterruptedExceptionpublic Optional<SlotCreationResult> createReplicationSlot() throws SQLException
ReplicationConnectioncreateReplicationSlot in interface ReplicationConnectionSQLException - if anything failsprotected org.postgresql.jdbc.PgConnection pgConnection()
throws SQLException
SQLExceptionprivate SlotCreationResult parseSlotCreation(ResultSet rs)
private ReplicationStream createReplicationStream(org.postgresql.replication.LogSequenceNumber startLsn, boolean skipFirstFlushRecord) throws SQLException, InterruptedException
SQLExceptionInterruptedExceptionprivate org.postgresql.replication.PGReplicationStream startPgReplicationStream(org.postgresql.replication.LogSequenceNumber lsn,
Function<org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder,org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder> configurator)
throws SQLException
SQLExceptionpublic void close()
close in interface AutoCloseableclose in class JdbcConnectionprotected static void defaultSettings(Configuration.Builder builder)
Copyright © 2019 JBoss by Red Hat. All rights reserved.