Class PgOutputMessageDecoder
java.lang.Object
io.debezium.connector.postgresql.connection.AbstractMessageDecoder
io.debezium.connector.postgresql.connection.pgoutput.PgOutputMessageDecoder
- All Implemented Interfaces:
MessageDecoder
Decodes messages from the PG logical replication plug-in ("pgoutput").
See https://www.postgresql.org/docs/10/protocol-logicalrep-message-formats.html for the protocol specification.
- Author:
- Gunnar Morling, Chris Cranford
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Instantprivate final PostgresConnectionprivate final MessageDecoderContextprivate static final org.slf4j.Loggerprivate static final Instantprivate static final byteprivate LongWill be null for a non-transactional decoding message -
Constructor Summary
ConstructorsConstructorDescriptionPgOutputMessageDecoder(MessageDecoderContext decoderContext, PostgresConnection connection) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this decoder, freeing and/or closing all resources it may potentially hold.private voiddecodeDelete(ByteBuffer buffer, TypeRegistry typeRegistry, ReplicationStream.ReplicationMessageProcessor processor) Callback handler for the 'D' delete replication stream message.private voiddecodeInsert(ByteBuffer buffer, TypeRegistry typeRegistry, ReplicationStream.ReplicationMessageProcessor processor) Callback handler for the 'I' insert replication stream message.private voiddecodeTruncate(ByteBuffer buffer, TypeRegistry typeRegistry, ReplicationStream.ReplicationMessageProcessor processor) Callback handler for the 'T' truncate replication stream message.private voiddecodeUpdate(ByteBuffer buffer, TypeRegistry typeRegistry, ReplicationStream.ReplicationMessageProcessor processor) Callback handler for the 'U' update replication stream message.org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilderdefaultOptions(org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder builder, Function<Integer, Boolean> hasMinimumServerVersion) Allows MessageDecoder to configure options with which the replication stream is started.getTableColumnsFromDatabase(PostgresConnection connection, DatabaseMetaData databaseMetadata, TableId tableId) getTruncateOptions(int flag) Convert truncate option bits to postgres syntax truncate optionsprivate voidhandleBeginMessage(ByteBuffer buffer, ReplicationStream.ReplicationMessageProcessor processor) Callback handler for the 'B' begin replication message.private voidhandleCommitMessage(ByteBuffer buffer, ReplicationStream.ReplicationMessageProcessor processor) Callback handler for the 'C' commit replication message.private voidhandleLogicalDecodingMessage(ByteBuffer buffer, ReplicationStream.ReplicationMessageProcessor processor) Callback handler for the 'M' logical decoding messageprivate voidhandleRelationMessage(ByteBuffer buffer, TypeRegistry typeRegistry) Callback handler for the 'R' relation replication message.private booleanisColumnInPrimaryKey(String schemaName, String tableName, String columnName, List<String> primaryKeyColumns) private booleanvoidprocessNotEmptyMessage(ByteBuffer buffer, ReplicationStream.ReplicationMessageProcessor processor, TypeRegistry typeRegistry) private static StringreadColumnValueAsString(ByteBuffer buffer) Reads the replication stream where the column stream specifies a length followed by the value.private static StringreadString(ByteBuffer buffer) Reads the replication stream up to the next null-terminator byte and returns the contents as a string.private static List<ReplicationMessage.Column> resolveColumnsFromStreamTupleData(ByteBuffer buffer, TypeRegistry typeRegistry, Table table) Resolve the replication stream's tuple data to a list of replication message columns.resolveRelation(int relationId) Resolves a given replication message relation identifier to aTable.private TableConstructs aTablebased on the suppliedPgOutputRelationMetaData.booleanshouldMessageBeSkipped(ByteBuffer buffer, Lsn lastReceivedLsn, Lsn startLsn, WalPositionLocator walPosition) A callback into the decoder allowing it to decide whether the supplied message should be processed by the decoder or whether it can be skipped.Methods inherited from class io.debezium.connector.postgresql.connection.AbstractMessageDecoder
processMessage
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
PG_EPOCH
-
SPACE
private static final byte SPACE- See Also:
-
decoderContext
-
connection
-
commitTimestamp
-
transactionId
Will be null for a non-transactional decoding message
-
-
Constructor Details
-
PgOutputMessageDecoder
-
-
Method Details
-
shouldMessageBeSkipped
public boolean shouldMessageBeSkipped(ByteBuffer buffer, Lsn lastReceivedLsn, Lsn startLsn, WalPositionLocator walPosition) Description copied from interface:MessageDecoderA callback into the decoder allowing it to decide whether the supplied message should be processed by the decoder or whether it can be skipped.- Specified by:
shouldMessageBeSkippedin interfaceMessageDecoder- Overrides:
shouldMessageBeSkippedin classAbstractMessageDecoder- Parameters:
buffer- the replication stream bufferlastReceivedLsn- the last LSN reported by the replication streamstartLsn- the starting LSN reported by the streaming producerwalPosition- wal position from which the streaming should resume- Returns:
trueif the incoming message should be skipped,falseotherwise
-
processNotEmptyMessage
public void processNotEmptyMessage(ByteBuffer buffer, ReplicationStream.ReplicationMessageProcessor processor, TypeRegistry typeRegistry) throws SQLException, InterruptedException - Specified by:
processNotEmptyMessagein classAbstractMessageDecoder- Throws:
SQLExceptionInterruptedException
-
defaultOptions
public org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder defaultOptions(org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder builder, Function<Integer, Boolean> hasMinimumServerVersion) Description copied from interface:MessageDecoderAllows MessageDecoder to configure options with which the replication stream is started. See PostgreSQL command START_REPLICATION SLOT for more details.- Parameters:
builder-- Returns:
- the builder instance
-
isTruncateEventsIncluded
private boolean isTruncateEventsIncluded() -
handleBeginMessage
private void handleBeginMessage(ByteBuffer buffer, ReplicationStream.ReplicationMessageProcessor processor) throws SQLException, InterruptedException Callback handler for the 'B' begin replication message.- Parameters:
buffer- The replication stream bufferprocessor- The replication message processor- Throws:
SQLExceptionInterruptedException
-
handleCommitMessage
private void handleCommitMessage(ByteBuffer buffer, ReplicationStream.ReplicationMessageProcessor processor) throws SQLException, InterruptedException Callback handler for the 'C' commit replication message.- Parameters:
buffer- The replication stream bufferprocessor- The replication message processor- Throws:
SQLExceptionInterruptedException
-
handleRelationMessage
private void handleRelationMessage(ByteBuffer buffer, TypeRegistry typeRegistry) throws SQLException Callback handler for the 'R' relation replication message.- Parameters:
buffer- The replication stream buffertypeRegistry- The postgres type registry- Throws:
SQLException
-
getTableColumnsFromDatabase
private List<Column> getTableColumnsFromDatabase(PostgresConnection connection, DatabaseMetaData databaseMetadata, TableId tableId) throws SQLException - Throws:
SQLException
-
isColumnInPrimaryKey
-
decodeInsert
private void decodeInsert(ByteBuffer buffer, TypeRegistry typeRegistry, ReplicationStream.ReplicationMessageProcessor processor) throws SQLException, InterruptedException Callback handler for the 'I' insert replication stream message.- Parameters:
buffer- The replication stream buffertypeRegistry- The postgres type registryprocessor- The replication message processor- Throws:
SQLExceptionInterruptedException
-
decodeUpdate
private void decodeUpdate(ByteBuffer buffer, TypeRegistry typeRegistry, ReplicationStream.ReplicationMessageProcessor processor) throws SQLException, InterruptedException Callback handler for the 'U' update replication stream message.- Parameters:
buffer- The replication stream buffertypeRegistry- The postgres type registryprocessor- The replication message processor- Throws:
SQLExceptionInterruptedException
-
decodeDelete
private void decodeDelete(ByteBuffer buffer, TypeRegistry typeRegistry, ReplicationStream.ReplicationMessageProcessor processor) throws SQLException, InterruptedException Callback handler for the 'D' delete replication stream message.- Parameters:
buffer- The replication stream buffertypeRegistry- The postgres type registryprocessor- The replication message processor- Throws:
SQLExceptionInterruptedException
-
decodeTruncate
private void decodeTruncate(ByteBuffer buffer, TypeRegistry typeRegistry, ReplicationStream.ReplicationMessageProcessor processor) throws SQLException, InterruptedException Callback handler for the 'T' truncate replication stream message.- Parameters:
buffer- The replication stream buffertypeRegistry- The postgres type registryprocessor- The replication message processor- Throws:
SQLExceptionInterruptedException
-
getTruncateOptions
Convert truncate option bits to postgres syntax truncate options- Parameters:
flag- truncate option bits- Returns:
- truncate flags
-
handleLogicalDecodingMessage
private void handleLogicalDecodingMessage(ByteBuffer buffer, ReplicationStream.ReplicationMessageProcessor processor) throws SQLException, InterruptedException Callback handler for the 'M' logical decoding message- Parameters:
buffer- The replication stream bufferprocessor- The replication message processor- Throws:
SQLExceptionInterruptedException
-
resolveRelation
Resolves a given replication message relation identifier to aTable.- Parameters:
relationId- The replication message stream's relation identifier- Returns:
- table resolved from a prior relation message or direct lookup from the schema or empty when the table is filtered
-
resolveRelationFromMetadata
Constructs aTablebased on the suppliedPgOutputRelationMetaData.- Parameters:
metadata- The relation metadata collected from previous 'R' replication stream messages- Returns:
- table based on a prior replication relation message
-
readString
Reads the replication stream up to the next null-terminator byte and returns the contents as a string.- Parameters:
buffer- The replication stream buffer- Returns:
- string read from the replication stream
-
readColumnValueAsString
Reads the replication stream where the column stream specifies a length followed by the value.- Parameters:
buffer- The replication stream buffer- Returns:
- the column value as a string read from the replication stream
-
resolveColumnsFromStreamTupleData
private static List<ReplicationMessage.Column> resolveColumnsFromStreamTupleData(ByteBuffer buffer, TypeRegistry typeRegistry, Table table) Resolve the replication stream's tuple data to a list of replication message columns.- Parameters:
buffer- The replication stream buffertypeRegistry- The database type registrytable- The database table- Returns:
- list of replication message columns
-
close
public void close()Description copied from interface:MessageDecoderCloses this decoder, freeing and/or closing all resources it may potentially hold.- Specified by:
closein interfaceMessageDecoder- Overrides:
closein classAbstractMessageDecoder
-