DBZ-4276 Improve map initialization

This commit is contained in:
Chris Cranford 2021-11-16 10:31:03 -05:00 committed by Gunnar Morling
parent ca17352221
commit d1453eb954

View File

@ -7,6 +7,7 @@
import java.sql.SQLException;
import java.time.Instant;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@ -142,7 +143,7 @@ private void processRowLCR(RowLCR row) throws InterruptedException {
}
else {
// Since the row has no chunk data, it can be dispatched immediately.
dispatchDataChangeEvent(row, new HashMap<>());
dispatchDataChangeEvent(row, null);
}
}
@ -189,6 +190,12 @@ private void dispatchDataChangeEvent(RowLCR lcr, Map<String, Object> chunkValues
// marker object so its transformed correctly by the value converters.
if (connectorConfig.isLobEnabled()) {
LOGGER.trace("Inspecting table '{}' LOB columns for unavailable value sets.", table.id());
if (chunkValues == null) {
// Happens when dispatching an LCR without any chunk data.
// Initializing the chunk values map with 1 entries as a baseline.
// todo: would be useful in the future to track some type of "has-lob" flag on Table
chunkValues = new HashMap<>(0);
}
for (Column column : table.columns()) {
if (isLobColumn(column) && !chunkValues.containsKey(column.name())) {
// Column not supplied, initialize with unavailable value marker
@ -197,6 +204,10 @@ private void dispatchDataChangeEvent(RowLCR lcr, Map<String, Object> chunkValues
}
}
}
else if (chunkValues == null) {
// it's safe to initialize as an empty map if LOB support is disabled
chunkValues = Collections.emptyMap();
}
dispatcher.dispatchDataChangeEvent(
tableId,