This is an automated email from the ASF dual-hosted git repository.
devmadhuu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new dbd49418db2 HDDS-17041. Retry of a failed NSSummaryTask applies
namespace summary deltas twice or skips them (#12000)
dbd49418db2 is described below
commit dbd49418db27b942a272a3912fe0849be723d750
Author: Arafat2198 <[email protected]>
AuthorDate: Tue Nov 17 12:56:59 2026 +0530
HDDS-17041. Retry of a failed NSSummaryTask applies namespace summary
deltas twice or skips them (#12000)
---
.../recon/tasks/NSSummaryTaskDbEventHandler.java | 10 +++-
.../ozone/recon/tasks/NSSummaryTaskWithFSO.java | 24 +++++-----
.../ozone/recon/tasks/NSSummaryTaskWithLegacy.java | 18 +++----
.../ozone/recon/tasks/NSSummaryTaskWithOBS.java | 8 ++--
.../ozone/recon/tasks/TestNSSummaryTask.java | 56 ++++++++++++++++++++--
.../recon/tasks/TestNSSummaryTaskWithFSO.java | 9 ++--
6 files changed, 87 insertions(+), 38 deletions(-)
diff --git
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskDbEventHandler.java
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskDbEventHandler.java
index d3ddf108f22..275394b08b2 100644
---
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskDbEventHandler.java
+++
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskDbEventHandler.java
@@ -386,10 +386,16 @@ protected void handleDeleteDirEvent(OmDirectoryInfo
directoryInfo,
}
}
+ /**
+ * Flush and commit NSSummary to DB.
+ *
+ * @param nsSummaryMap Map of objectId to NSSummary
+ * @return true if successful, false otherwise
+ */
protected boolean flushAndCommitNSToDB(Map<Long, NSSummary> nsSummaryMap) {
try {
updateNSSummariesToDB(nsSummaryMap, Collections.emptyList());
- } catch (IOException e) {
+ } catch (IOException | RuntimeException e) {
LOG.error("Unable to write Namespace Summary data in Recon DB.", e);
return false;
} finally {
@@ -409,7 +415,7 @@ protected boolean flushAndCommitUpdatedNSToDB(Map<Long,
NSSummary> nsSummaryMap,
Collection<Long>
objectIdsToBeDeleted) {
try {
updateNSSummariesToDB(nsSummaryMap, objectIdsToBeDeleted);
- } catch (IOException e) {
+ } catch (IOException | RuntimeException e) {
LOG.error("Unable to write Namespace Summary data in Recon DB.
batchSize={}", nsSummaryMap.size(), e);
return false;
} finally {
diff --git
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskWithFSO.java
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskWithFSO.java
index 9f281a908ee..aa1525a1204 100644
---
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskWithFSO.java
+++
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskWithFSO.java
@@ -115,21 +115,21 @@ public Pair<Integer, Boolean>
processWithFSO(OMUpdateEventBatch events,
// directory update on DirTable
handleUpdateOnDirTable(omdbUpdateEvent, action, nsSummaryMap);
}
- } catch (IOException ioEx) {
+ if (nsSummaryMap.size() >= nsSummaryFlushToDBMaxThreshold) {
+ // Deleting hard deleted directories also along with this flush
operation from NSSummary table
+ // Same list of objectIdsToBeDeleted is used for follow up flush
operation as well and done intentionally
+ // to make sure that after final flush all objectIds are deleted
from NSSummary table.
+ if (!flushAndCommitUpdatedNSToDB(nsSummaryMap,
objectIdsToBeDeleted)) {
+ return new ImmutablePair<>(seekPos, false);
+ }
+ seekPos = itrPos + eventCounter;
+ }
+ } catch (IOException | RuntimeException ex) {
LOG.error("Unable to process Namespace Summary data in Recon DB. ",
- ioEx);
+ ex);
nsSummaryMap.clear();
return new ImmutablePair<>(seekPos, false);
}
- if (nsSummaryMap.size() >= nsSummaryFlushToDBMaxThreshold) {
- // Deleting hard deleted directories also along with this flush
operation from NSSummary table
- // Same list of objectIdsToBeDeleted is used for follow up flush
operation as well and done intentionally
- // to make sure that after final flush all objectIds are deleted from
NSSummary table.
- if (!flushAndCommitUpdatedNSToDB(nsSummaryMap, objectIdsToBeDeleted)) {
- return new ImmutablePair<>(seekPos, false);
- }
- seekPos = eventCounter + 1;
- }
}
// flush and commit left out entries at end.
// Deleting hard deleted directories also along with this flush operation
from NSSummary table
@@ -140,7 +140,7 @@ public Pair<Integer, Boolean>
processWithFSO(OMUpdateEventBatch events,
}
LOG.debug("Completed a process run of NSSummaryTaskWithFSO");
- return new ImmutablePair<>(seekPos, true);
+ return new ImmutablePair<>(itrPos + eventCounter, true);
}
private void handleUpdateOnDirTable(OMDBUpdateEvent<String, ? extends
WithParentObjectId> omdbUpdateEvent,
diff --git
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskWithLegacy.java
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskWithLegacy.java
index 7a12c3e0b1e..a28757a06f7 100644
---
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskWithLegacy.java
+++
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskWithLegacy.java
@@ -137,18 +137,18 @@ public Pair<Integer, Boolean>
processWithLegacy(OMUpdateEventBatch events,
processWithObjectStoreLayout(updatedKeyInfo, oldKeyInfo, action,
nsSummaryMap);
}
- } catch (IOException ioEx) {
+ if (nsSummaryMap.size() >= nsSummaryFlushToDBMaxThreshold) {
+ if (!flushAndCommitNSToDB(nsSummaryMap)) {
+ return new ImmutablePair<>(seekPos, false);
+ }
+ seekPos = itrPos + eventCounter;
+ }
+ } catch (IOException | RuntimeException ex) {
LOG.error("Unable to process Namespace Summary data in Recon DB. ",
- ioEx);
+ ex);
nsSummaryMap.clear();
return new ImmutablePair<>(seekPos, false);
}
- if (nsSummaryMap.size() >= nsSummaryFlushToDBMaxThreshold) {
- if (!flushAndCommitNSToDB(nsSummaryMap)) {
- return new ImmutablePair<>(seekPos, false);
- }
- seekPos = eventCounter + 1;
- }
}
// flush and commit left out entries at end
@@ -157,7 +157,7 @@ public Pair<Integer, Boolean>
processWithLegacy(OMUpdateEventBatch events,
}
LOG.debug("Completed a process run of NSSummaryTaskWithLegacy");
- return new ImmutablePair<>(seekPos, true);
+ return new ImmutablePair<>(itrPos + eventCounter, true);
}
private void processWithFileSystemLayout(OmKeyInfo updatedKeyInfo,
diff --git
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskWithOBS.java
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskWithOBS.java
index 48ed4c50b93..bc7e195adf5 100644
---
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskWithOBS.java
+++
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskWithOBS.java
@@ -287,11 +287,11 @@ public Pair<Integer, Boolean>
processWithOBS(OMUpdateEventBatch events,
if (!flushAndCommitNSToDB(nsSummaryMap)) {
return new ImmutablePair<>(seekPos, false);
}
- seekPos = eventCounter + 1;
+ seekPos = itrPos + eventCounter;
}
- } catch (IOException ioEx) {
+ } catch (IOException | RuntimeException ex) {
LOG.error("Unable to process Namespace Summary data in Recon DB. ",
- ioEx);
+ ex);
nsSummaryMap.clear();
return new ImmutablePair<>(seekPos, false);
}
@@ -303,7 +303,7 @@ public Pair<Integer, Boolean>
processWithOBS(OMUpdateEventBatch events,
}
LOG.debug("Completed a process run of NSSummaryTaskWithOBS");
- return new ImmutablePair<>(seekPos, true);
+ return new ImmutablePair<>(itrPos + eventCounter, true);
}
}
diff --git
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTask.java
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTask.java
index 9d7d05405bb..f50f49c340c 100644
---
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTask.java
+++
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTask.java
@@ -19,10 +19,14 @@
import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.spy;
import java.io.File;
import java.io.IOException;
@@ -33,11 +37,13 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
import org.apache.hadoop.ozone.recon.ReconConstants;
import org.apache.hadoop.ozone.recon.api.types.NSSummary;
import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager;
+import org.apache.hadoop.ozone.recon.spi.ReconNamespaceSummaryManager;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
@@ -380,14 +386,14 @@ public void testIndependentSubTaskSeekPositions() throws
IOException {
nSSummaryTask.process(batch, legacySeekOnly);
assertTrue(result.isTaskSuccess());
- // Each sub-task reports its resume position independently. Legacy was
- // told to skip the first three stream indices; FSO/OBS consumed from 0.
+ // Each sub-task reports its resume position independently. A sub-task
+ // that succeeds reports the end of the batch, wherever it started from.
assertNotNull(result.getSubTaskSeekPositions());
- assertEquals(0, result.getSubTaskSeekPositions()
+ assertEquals(5, result.getSubTaskSeekPositions()
.get(NSSummaryTask.BucketType.FSO.name()).intValue());
- assertEquals(3, result.getSubTaskSeekPositions()
+ assertEquals(5, result.getSubTaskSeekPositions()
.get(NSSummaryTask.BucketType.LEGACY.name()).intValue());
- assertEquals(0, result.getSubTaskSeekPositions()
+ assertEquals(5, result.getSubTaskSeekPositions()
.get(NSSummaryTask.BucketType.OBS.name()).intValue());
// FSO/OBS processed from the start; Legacy only picked up the update.
@@ -403,6 +409,46 @@ public void testIndependentSubTaskSeekPositions() throws
IOException {
.getNSSummary(BUCKET_THREE_OBJECT_ID).getSizeOfFiles());
}
+ @Test
+ public void testRetryWithReturnedSeekPositionsDoesNotReapply() throws
IOException {
+ // A retry passes the seek positions of the failed attempt. Sub-tasks
that
+ // succeeded must not apply their events a second time.
+ OMUpdateEventBatch batch = new OMUpdateEventBatch(Arrays.asList(
+ legacyPutEvent(KEY_FIVE, KEY_FIVE_OBJECT_ID, KEY_FIVE_SIZE),
+ obsPutEvent(KEY_FOUR, KEY_FOUR_OBJECT_ID, KEY_FOUR_SIZE)),
+ 0L);
+
+ ReconOmTask.TaskResult result = nSSummaryTask.process(batch,
Collections.emptyMap());
+ assertTrue(result.isTaskSuccess());
+ assertTrue(nSSummaryTask.process(batch,
result.getSubTaskSeekPositions()).isTaskSuccess());
+
+ assertEquals(2, getReconNamespaceSummaryManager()
+ .getNSSummary(BUCKET_TWO_OBJECT_ID).getNumOfFiles());
+ assertEquals(2, getReconNamespaceSummaryManager()
+ .getNSSummary(BUCKET_THREE_OBJECT_ID).getNumOfFiles());
+ }
+
+ @Test
+ public void testRetryAfterFailedFinalFlushResumesAfterThresholdFlush()
throws IOException {
+ // With a flush threshold of 1 the put is committed by a threshold
flush, then the final flush fails
+ // before its commit. The failed attempt must report the committed
position so the retry skips the put.
+ ReconNamespaceSummaryManager failingManager =
spy(getReconNamespaceSummaryManager());
+ doCallRealMethod().doThrow(new
IllegalStateException("injected")).when(failingManager)
+ .commitBatchOperation(any());
+ OMUpdateEventBatch batch = new
OMUpdateEventBatch(Collections.singletonList(
+ obsPutEvent(KEY_FOUR, KEY_FOUR_OBJECT_ID, KEY_FOUR_SIZE)), 0L);
+
+ Pair<Integer, Boolean> result = new NSSummaryTaskWithOBS(failingManager,
getReconOMMetadataManager(),
+ 1, 5, 20, 2000).processWithOBS(batch, 0);
+ assertFalse(result.getRight());
+ assertEquals(1, result.getLeft());
+
+ assertTrue(new NSSummaryTaskWithOBS(getReconNamespaceSummaryManager(),
getReconOMMetadataManager(),
+ 1, 5, 20, 2000).processWithOBS(batch, result.getLeft()).getRight());
+ assertEquals(2, getReconNamespaceSummaryManager()
+ .getNSSummary(BUCKET_THREE_OBJECT_ID).getNumOfFiles());
+ }
+
@Test
public void testLegacySeekZeroAppliesAllLegacyEvents() throws IOException {
// Contrast with testIndependentSubTaskSeekPositions: without a Legacy
diff --git
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTaskWithFSO.java
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTaskWithFSO.java
index 133f55486cd..d60c0f57ea0 100644
---
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTaskWithFSO.java
+++
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTaskWithFSO.java
@@ -437,11 +437,8 @@ void testProcessWithFSOFlushAfterThresholdAndSuccess()
throws IOException {
// Assertions
Assertions.assertNotNull(result, "Result should not be null");
- // Why seekPos should be 7 ? because we have threshold value for flush
is set as 3,
- // and we have total 7 events, so nsSummaryMap will be flushed in 2
batches and
- // during second batch flush, eventCounter will be 6, then last event7
alone will
- // be flushed out of loop as remaining event. At every batch flush based
on threshold,
- // seekPos is set as equal to eventCounter + 1, so seekPos will be 7.
+ // Why seekPos should be 7 ? because all 7 events of the batch are
committed,
+ // so a retry has nothing left to apply.
Assertions.assertEquals(7, result.getLeft(), "seekPos should be 7");
Assertions.assertTrue(result.getRight(), "The processing should fail due
to flush failure");
}
@@ -517,7 +514,7 @@ void
testProcessWithFSOFlushAfterThresholdAndFailureOfLastElement()
// Assertions
Assertions.assertNotNull(result1, "Result should not be null");
- Assertions.assertEquals(0, result1.getLeft(), "seekPos should be 4");
+ Assertions.assertEquals(3, result1.getLeft(), "seekPos should be 3");
// Verify interactions
Mockito.verify(mockIterator, Mockito.times(3)).next();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]