umesh9794 commented on code in PR #10549:
URL: https://github.com/apache/ozone/pull/10549#discussion_r3542755105
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/ContainerHealthSchemaManager.java:
##########
@@ -179,6 +179,70 @@ public void batchDeleteSCMStatesForContainers(List<Long>
containerIds) {
totalDeleted, containerIds.size());
}
+ /**
+ * Atomically syncs unhealthy rows for a scan chunk: insert new
+ * (container_id, state) pairs, update existing pairs, and delete only stale
+ * pairs that are no longer unhealthy.
+ *
+ * <p>Unlike {@link #replaceUnhealthyContainerRecordsAtomically}, this does
not
+ * delete all SCM states for every container that previously had a row. It
+ * removes only keys present in {@code existingByKey} but absent from the
+ * desired scan result (containers that recovered or changed state).</p>
+ *
+ * @param existingByKey prior rows for this chunk, keyed by
+ * (container_id, container_state)
+ * @param desiredRecords unhealthy rows produced by the current scan
+ */
+ public void syncUnhealthyContainerRecordsAtomically(
+ Map<ContainerStateKey, Long> existingByKey,
+ List<UnhealthyContainerRecord> desiredRecords) {
+ if ((existingByKey == null || existingByKey.isEmpty())
+ && (desiredRecords == null || desiredRecords.isEmpty())) {
+ return;
+ }
+
+ Map<ContainerStateKey, UnhealthyContainerRecord> desiredByKey = new
HashMap<>();
+ if (desiredRecords != null) {
+ for (UnhealthyContainerRecord record : desiredRecords) {
+ desiredByKey.put(new ContainerStateKey(record.getContainerId(),
+ record.getContainerState()), record);
+ }
+ }
+
+ Map<ContainerStateKey, Long> existing =
+ existingByKey == null ? new HashMap<>() : existingByKey;
+
+ List<ContainerStateKey> staleKeys = new ArrayList<>();
+ List<UnhealthyContainerRecord> toInsert = new ArrayList<>();
+ List<UnhealthyContainerRecord> toUpdate = new ArrayList<>();
+
+ for (ContainerStateKey key : existing.keySet()) {
+ if (!desiredByKey.containsKey(key)) {
+ staleKeys.add(key);
+ }
+ }
+ for (UnhealthyContainerRecord record : desiredByKey.values()) {
+ ContainerStateKey key = new ContainerStateKey(record.getContainerId(),
+ record.getContainerState());
+ if (existing.containsKey(key)) {
+ toUpdate.add(record);
+ } else {
+ toInsert.add(record);
+ }
+ }
+
+ DSLContext dslContext = containerSchemaDefinition.getDSLContext();
+ dslContext.transaction(configuration -> {
+ DSLContext txContext = configuration.dsl();
+ deleteStaleUnhealthyRecords(txContext, staleKeys);
+ batchInsertInChunks(txContext, toInsert);
+ batchUpdateInChunks(txContext, toUpdate);
Review Comment:
`container_id + container_state` are the key.
`hasSameContent` compares the other five columns (in_state_since,
expected_replica_count, actual_replica_count, replica_delta, reason). So change
detection covers every non-key column now.
I hope this works better than simply checking the existence of the row for
updates.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]