DBZ-623 Extract parsing code to a separate method
This commit is contained in:
parent
80c74a9d7c
commit
01e5f8da8c
@ -133,30 +133,7 @@ protected ServerInfo.ReplicationSlot readReplicationSlotInfo(String slotName, St
|
|||||||
}, rs -> {
|
}, rs -> {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
boolean active = rs.getBoolean("active");
|
boolean active = rs.getBoolean("active");
|
||||||
Long confirmedFlushedLSN = null;
|
Long confirmedFlushedLSN = parseConfirmedFlushLsn(slotName, pluginName, database, rs);
|
||||||
try {
|
|
||||||
String confirmedFlushLSNString = rs.getString("confirmed_flush_lsn");
|
|
||||||
if (confirmedFlushLSNString == null) {
|
|
||||||
throw new ConnectException("Value confirmed_flush_lsn is missing from the pg_replication_slots table for slot = '"
|
|
||||||
+ slotName + "', plugin = '"
|
|
||||||
+ database + "', database = '"
|
|
||||||
+ pluginName + "'. This is an abnormal situation and the database status should be checked.");
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
confirmedFlushedLSN = LogSequenceNumber.valueOf(confirmedFlushLSNString).asLong();
|
|
||||||
if (confirmedFlushedLSN == LogSequenceNumber.INVALID_LSN.asLong()) {
|
|
||||||
throw new ConnectException("Invalid LSN returned from database");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
throw new ConnectException("Value confirmed_flush_lsn in the pg_replication_slots table for slot = '"
|
|
||||||
+ slotName + "', plugin = '"
|
|
||||||
+ database + "', database = '"
|
|
||||||
+ pluginName + "' is not valid. This is an abnormal situation and the database status should be checked.");
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
// info not available, so we must be prior to PG 9.6
|
|
||||||
}
|
|
||||||
replicationSlotInfo.compareAndSet(null, new ServerInfo.ReplicationSlot(active, confirmedFlushedLSN));
|
replicationSlotInfo.compareAndSet(null, new ServerInfo.ReplicationSlot(active, confirmedFlushedLSN));
|
||||||
} else {
|
} else {
|
||||||
LOGGER.debug("No replication slot '{}' is present for plugin '{}' and database '{}'", slotName,
|
LOGGER.debug("No replication slot '{}' is present for plugin '{}' and database '{}'", slotName,
|
||||||
@ -168,6 +145,34 @@ protected ServerInfo.ReplicationSlot readReplicationSlotInfo(String slotName, St
|
|||||||
return replicationSlotInfo.get();
|
return replicationSlotInfo.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Long parseConfirmedFlushLsn(String slotName, String pluginName, String database, ResultSet rs) {
|
||||||
|
Long confirmedFlushedLSN = null;
|
||||||
|
try {
|
||||||
|
String confirmedFlushLSNString = rs.getString("confirmed_flush_lsn");
|
||||||
|
if (confirmedFlushLSNString == null) {
|
||||||
|
throw new ConnectException("Value confirmed_flush_lsn is missing from the pg_replication_slots table for slot = '"
|
||||||
|
+ slotName + "', plugin = '"
|
||||||
|
+ pluginName + "', database = '"
|
||||||
|
+ database + "'. This is an abnormal situation and the database status should be checked.");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
confirmedFlushedLSN = LogSequenceNumber.valueOf(confirmedFlushLSNString).asLong();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new ConnectException("Value confirmed_flush_lsn in the pg_replication_slots table for slot = '"
|
||||||
|
+ slotName + "', plugin = '"
|
||||||
|
+ pluginName + "', database = '"
|
||||||
|
+ database + "' is not valid. This is an abnormal situation and the database status should be checked.");
|
||||||
|
}
|
||||||
|
if (confirmedFlushedLSN == LogSequenceNumber.INVALID_LSN.asLong()) {
|
||||||
|
throw new ConnectException("Invalid LSN returned from database");
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// info not available, so we must be prior to PG 9.6
|
||||||
|
}
|
||||||
|
return confirmedFlushedLSN;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drops a replication slot that was created on the DB
|
* Drops a replication slot that was created on the DB
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user