public class PgOutputMessageDecoder extends AbstractMessageDecoder
| Modifier and Type | Class and Description |
|---|---|
static class |
PgOutputMessageDecoder.MessageType |
| Modifier and Type | Field and Description |
|---|---|
private Instant |
commitTimestamp |
private MessageDecoderConfig |
config |
private static org.slf4j.Logger |
LOGGER |
private static Instant |
PG_EPOCH |
private static byte |
SPACE |
private int |
transactionId |
| Constructor and Description |
|---|
PgOutputMessageDecoder(MessageDecoderConfig config) |
| Modifier and Type | Method and Description |
|---|---|
private void |
decodeDelete(ByteBuffer buffer,
TypeRegistry typeRegistry,
ReplicationStream.ReplicationMessageProcessor processor)
Callback handler for the 'D' delete replication stream message.
|
private void |
decodeInsert(ByteBuffer buffer,
TypeRegistry typeRegistry,
ReplicationStream.ReplicationMessageProcessor processor)
Callback handler for the 'I' insert replication stream message.
|
private void |
decodeTruncate(ByteBuffer buffer,
TypeRegistry typeRegistry,
ReplicationStream.ReplicationMessageProcessor processor)
Callback handler for the 'T' truncate replication stream message.
|
private void |
decodeUpdate(ByteBuffer buffer,
TypeRegistry typeRegistry,
ReplicationStream.ReplicationMessageProcessor processor)
Callback handler for the 'U' update replication stream message.
|
private Map<String,Boolean> |
getTableColumnOptionalityFromDatabase(DatabaseMetaData databaseMetadata,
String schemaName,
String tableName) |
private List<String> |
getTruncateOptions(int flag)
Convert truncate option bits to postgres syntax truncate options
|
private void |
handleBeginMessage(ByteBuffer buffer,
ReplicationStream.ReplicationMessageProcessor processor)
Callback handler for the 'B' begin replication message.
|
private void |
handleCommitMessage(ByteBuffer buffer,
ReplicationStream.ReplicationMessageProcessor processor)
Callback handler for the 'C' commit replication message.
|
private void |
handleRelationMessage(ByteBuffer buffer,
TypeRegistry typeRegistry)
Callback handler for the 'R' relation replication message.
|
private boolean |
isColumnInPrimaryKey(String schemaName,
String tableName,
String columnName,
List<String> primaryKeyColumns) |
org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder |
optionsWithMetadata(org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder builder)
Allows MessageDecoder to configure options with which the replication stream is started.
|
org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder |
optionsWithoutMetadata(org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder builder)
Allows MessageDecoder to configure options with which the replication stream is started.
|
void |
processNotEmptyMessage(ByteBuffer buffer,
ReplicationStream.ReplicationMessageProcessor processor,
TypeRegistry typeRegistry) |
private static String |
readColumnValueAsString(ByteBuffer buffer)
Reads the replication stream where the column stream specifies a length followed by the value.
|
private static String |
readString(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.
|
private Optional<Table> |
resolveRelation(int relationId)
Resolves a given replication message relation identifier to a
Table. |
private Table |
resolveRelationFromMetadata(PgOutputRelationMetaData metadata)
Constructs a
Table based on the supplied PgOutputRelationMetaData. |
boolean |
shouldMessageBeSkipped(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.
|
processMessageclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitsetContainsMetadataprivate static final org.slf4j.Logger LOGGER
private static final Instant PG_EPOCH
private static final byte SPACE
private Instant commitTimestamp
private int transactionId
private final MessageDecoderConfig config
public PgOutputMessageDecoder(MessageDecoderConfig config)
public boolean shouldMessageBeSkipped(ByteBuffer buffer, Lsn lastReceivedLsn, Lsn startLsn, WalPositionLocator walPosition)
MessageDecodershouldMessageBeSkipped in interface MessageDecodershouldMessageBeSkipped in class AbstractMessageDecoderbuffer - 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 resumetrue if the incoming message should be skipped, false otherwisepublic void processNotEmptyMessage(ByteBuffer buffer, ReplicationStream.ReplicationMessageProcessor processor, TypeRegistry typeRegistry) throws SQLException, InterruptedException
processNotEmptyMessage in class AbstractMessageDecoderSQLExceptionInterruptedExceptionpublic org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder optionsWithMetadata(org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder builder)
MessageDecoderpublic org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder optionsWithoutMetadata(org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder builder)
MessageDecoderprivate void handleBeginMessage(ByteBuffer buffer, ReplicationStream.ReplicationMessageProcessor processor) throws SQLException, InterruptedException
buffer - The replication stream bufferprocessor - The replication message processorSQLExceptionInterruptedExceptionprivate void handleCommitMessage(ByteBuffer buffer, ReplicationStream.ReplicationMessageProcessor processor) throws SQLException, InterruptedException
buffer - The replication stream bufferprocessor - The replication message processorSQLExceptionInterruptedExceptionprivate void handleRelationMessage(ByteBuffer buffer, TypeRegistry typeRegistry) throws SQLException
buffer - The replication stream buffertypeRegistry - The postgres type registrySQLExceptionprivate Map<String,Boolean> getTableColumnOptionalityFromDatabase(DatabaseMetaData databaseMetadata, String schemaName, String tableName)
private boolean isColumnInPrimaryKey(String schemaName, String tableName, String columnName, List<String> primaryKeyColumns)
private void decodeInsert(ByteBuffer buffer, TypeRegistry typeRegistry, ReplicationStream.ReplicationMessageProcessor processor) throws SQLException, InterruptedException
buffer - The replication stream buffertypeRegistry - The postgres type registryprocessor - The replication message processorSQLExceptionInterruptedExceptionprivate void decodeUpdate(ByteBuffer buffer, TypeRegistry typeRegistry, ReplicationStream.ReplicationMessageProcessor processor) throws SQLException, InterruptedException
buffer - The replication stream buffertypeRegistry - The postgres type registryprocessor - The replication message processorSQLExceptionInterruptedExceptionprivate void decodeDelete(ByteBuffer buffer, TypeRegistry typeRegistry, ReplicationStream.ReplicationMessageProcessor processor) throws SQLException, InterruptedException
buffer - The replication stream buffertypeRegistry - The postgres type registryprocessor - The replication message processorSQLExceptionInterruptedExceptionprivate void decodeTruncate(ByteBuffer buffer, TypeRegistry typeRegistry, ReplicationStream.ReplicationMessageProcessor processor) throws SQLException, InterruptedException
buffer - The replication stream buffertypeRegistry - The postgres type registryprocessor - The replication message processorSQLExceptionInterruptedExceptionprivate List<String> getTruncateOptions(int flag)
flag - truncate option bitsprivate Optional<Table> resolveRelation(int relationId)
Table.relationId - The replication message stream's relation identifierprivate Table resolveRelationFromMetadata(PgOutputRelationMetaData metadata)
Table based on the supplied PgOutputRelationMetaData.metadata - The relation metadata collected from previous 'R' replication stream messagesprivate static String readString(ByteBuffer buffer)
buffer - The replication stream bufferprivate static String readColumnValueAsString(ByteBuffer buffer)
buffer - The replication stream bufferprivate static List<ReplicationMessage.Column> resolveColumnsFromStreamTupleData(ByteBuffer buffer, TypeRegistry typeRegistry, Table table)
buffer - The replication stream buffertypeRegistry - The database type registrytable - The database tableCopyright © 2021 JBoss by Red Hat. All rights reserved.