sumitagrawl commented on code in PR #8823:
URL: https://github.com/apache/ozone/pull/8823#discussion_r2215604730
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskWithFSO.java:
##########
@@ -77,106 +80,159 @@ public Pair<Integer, Boolean>
processWithFSO(OMUpdateEventBatch events,
Map<Long, NSSummary> nsSummaryMap = new HashMap<>();
int eventCounter = 0;
- while (eventIterator.hasNext()) {
- OMDBUpdateEvent<String, ? extends
- WithParentObjectId> omdbUpdateEvent = eventIterator.next();
- OMDBUpdateEvent.OMDBUpdateAction action = omdbUpdateEvent.getAction();
- eventCounter++;
-
- // we only process updates on OM's FileTable and Dirtable
- String table = omdbUpdateEvent.getTable();
- boolean updateOnFileTable = table.equals(FILE_TABLE);
- if (!taskTables.contains(table)) {
- continue;
- }
+ try (RDBBatchOperation deleteRdbBatchOperation = new RDBBatchOperation()) {
+ while (eventIterator.hasNext()) {
+ OMDBUpdateEvent<String, ? extends
+ WithParentObjectId> omdbUpdateEvent = eventIterator.next();
+ OMDBUpdateEvent.OMDBUpdateAction action = omdbUpdateEvent.getAction();
+ eventCounter++;
- String updatedKey = omdbUpdateEvent.getKey();
-
- try {
- if (updateOnFileTable) {
- // key update on fileTable
- OMDBUpdateEvent<String, OmKeyInfo> keyTableUpdateEvent =
- (OMDBUpdateEvent<String, OmKeyInfo>) omdbUpdateEvent;
- OmKeyInfo updatedKeyInfo = keyTableUpdateEvent.getValue();
- OmKeyInfo oldKeyInfo = keyTableUpdateEvent.getOldValue();
-
- switch (action) {
- case PUT:
- handlePutKeyEvent(updatedKeyInfo, nsSummaryMap);
- break;
-
- case DELETE:
- handleDeleteKeyEvent(updatedKeyInfo, nsSummaryMap);
- break;
-
- case UPDATE:
- if (oldKeyInfo != null) {
- // delete first, then put
- handleDeleteKeyEvent(oldKeyInfo, nsSummaryMap);
- } else {
- LOG.warn("Update event does not have the old keyInfo for {}.",
- updatedKey);
- }
- handlePutKeyEvent(updatedKeyInfo, nsSummaryMap);
- break;
+ // we process updates on OM's FileTable, DirTable, DeletedTable and
DeletedDirTable
+ String table = omdbUpdateEvent.getTable();
+ boolean updateOnFileTable = table.equals(FILE_TABLE);
+ boolean updateOnDeletedTable = table.equals(DELETED_TABLE);
+ boolean updateOnDeletedDirTable = table.equals(DELETED_DIR_TABLE);
+ if (!taskTables.contains(table)) {
+ continue;
+ }
- default:
- LOG.debug("Skipping DB update event : {}",
- omdbUpdateEvent.getAction());
- }
+ String updatedKey = omdbUpdateEvent.getKey();
- } else {
- // directory update on DirTable
- OMDBUpdateEvent<String, OmDirectoryInfo> dirTableUpdateEvent =
- (OMDBUpdateEvent<String, OmDirectoryInfo>) omdbUpdateEvent;
- OmDirectoryInfo updatedDirectoryInfo =
dirTableUpdateEvent.getValue();
- OmDirectoryInfo oldDirectoryInfo = dirTableUpdateEvent.getOldValue();
-
- switch (action) {
- case PUT:
- handlePutDirEvent(updatedDirectoryInfo, nsSummaryMap);
- break;
-
- case DELETE:
- handleDeleteDirEvent(updatedDirectoryInfo, nsSummaryMap);
- break;
-
- case UPDATE:
- if (oldDirectoryInfo != null) {
- // delete first, then put
- handleDeleteDirEvent(oldDirectoryInfo, nsSummaryMap);
- } else {
- LOG.warn("Update event does not have the old dirInfo for {}.",
- updatedKey);
- }
- handlePutDirEvent(updatedDirectoryInfo, nsSummaryMap);
- break;
+ try {
+ if (updateOnFileTable) {
+ handleUpdateOnFileTable(omdbUpdateEvent, action, nsSummaryMap,
updatedKey);
- default:
- LOG.debug("Skipping DB update event : {}",
- omdbUpdateEvent.getAction());
+ } else if (updateOnDeletedDirTable) {
+ // Hard delete from deletedDirectoryTable - cleanup memory leak
for directories
+ handleUpdateOnDeletedDirTable((OMDBUpdateEvent<String, OmKeyInfo>)
omdbUpdateEvent, action, nsSummaryMap,
Review Comment:
can remove typecast here
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskWithFSO.java:
##########
@@ -77,106 +80,159 @@ public Pair<Integer, Boolean>
processWithFSO(OMUpdateEventBatch events,
Map<Long, NSSummary> nsSummaryMap = new HashMap<>();
int eventCounter = 0;
- while (eventIterator.hasNext()) {
- OMDBUpdateEvent<String, ? extends
- WithParentObjectId> omdbUpdateEvent = eventIterator.next();
- OMDBUpdateEvent.OMDBUpdateAction action = omdbUpdateEvent.getAction();
- eventCounter++;
-
- // we only process updates on OM's FileTable and Dirtable
- String table = omdbUpdateEvent.getTable();
- boolean updateOnFileTable = table.equals(FILE_TABLE);
- if (!taskTables.contains(table)) {
- continue;
- }
+ try (RDBBatchOperation deleteRdbBatchOperation = new RDBBatchOperation()) {
Review Comment:
move this at last when do delete
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskWithFSO.java:
##########
@@ -77,106 +80,159 @@ public Pair<Integer, Boolean>
processWithFSO(OMUpdateEventBatch events,
Map<Long, NSSummary> nsSummaryMap = new HashMap<>();
int eventCounter = 0;
- while (eventIterator.hasNext()) {
- OMDBUpdateEvent<String, ? extends
- WithParentObjectId> omdbUpdateEvent = eventIterator.next();
- OMDBUpdateEvent.OMDBUpdateAction action = omdbUpdateEvent.getAction();
- eventCounter++;
-
- // we only process updates on OM's FileTable and Dirtable
- String table = omdbUpdateEvent.getTable();
- boolean updateOnFileTable = table.equals(FILE_TABLE);
- if (!taskTables.contains(table)) {
- continue;
- }
+ try (RDBBatchOperation deleteRdbBatchOperation = new RDBBatchOperation()) {
+ while (eventIterator.hasNext()) {
+ OMDBUpdateEvent<String, ? extends
+ WithParentObjectId> omdbUpdateEvent = eventIterator.next();
+ OMDBUpdateEvent.OMDBUpdateAction action = omdbUpdateEvent.getAction();
+ eventCounter++;
- String updatedKey = omdbUpdateEvent.getKey();
-
- try {
- if (updateOnFileTable) {
- // key update on fileTable
- OMDBUpdateEvent<String, OmKeyInfo> keyTableUpdateEvent =
- (OMDBUpdateEvent<String, OmKeyInfo>) omdbUpdateEvent;
- OmKeyInfo updatedKeyInfo = keyTableUpdateEvent.getValue();
- OmKeyInfo oldKeyInfo = keyTableUpdateEvent.getOldValue();
-
- switch (action) {
- case PUT:
- handlePutKeyEvent(updatedKeyInfo, nsSummaryMap);
- break;
-
- case DELETE:
- handleDeleteKeyEvent(updatedKeyInfo, nsSummaryMap);
- break;
-
- case UPDATE:
- if (oldKeyInfo != null) {
- // delete first, then put
- handleDeleteKeyEvent(oldKeyInfo, nsSummaryMap);
- } else {
- LOG.warn("Update event does not have the old keyInfo for {}.",
- updatedKey);
- }
- handlePutKeyEvent(updatedKeyInfo, nsSummaryMap);
- break;
+ // we process updates on OM's FileTable, DirTable, DeletedTable and
DeletedDirTable
+ String table = omdbUpdateEvent.getTable();
+ boolean updateOnFileTable = table.equals(FILE_TABLE);
+ boolean updateOnDeletedTable = table.equals(DELETED_TABLE);
+ boolean updateOnDeletedDirTable = table.equals(DELETED_DIR_TABLE);
+ if (!taskTables.contains(table)) {
+ continue;
+ }
- default:
- LOG.debug("Skipping DB update event : {}",
- omdbUpdateEvent.getAction());
- }
+ String updatedKey = omdbUpdateEvent.getKey();
Review Comment:
can move inside the method.
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskWithFSO.java:
##########
@@ -175,10 +121,102 @@ public Pair<Integer, Boolean>
processWithFSO(OMUpdateEventBatch events,
if (!flushAndCommitNSToDB(nsSummaryMap)) {
return new ImmutablePair<>(seekPos, false);
}
+ // Delete hard deleted directories from NSSummary table
+ deleteNSSummariesFromDB(objectIdsToBeDeleted);
LOG.debug("Completed a process run of NSSummaryTaskWithFSO");
return new ImmutablePair<>(seekPos, true);
}
+ private void handleUpdateOnDirTable(OMDBUpdateEvent<String, ? extends
WithParentObjectId> omdbUpdateEvent,
+ OMDBUpdateEvent.OMDBUpdateAction action, Map<Long,
NSSummary> nsSummaryMap)
+ throws IOException {
+ OMDBUpdateEvent<String, OmDirectoryInfo> dirTableUpdateEvent =
+ (OMDBUpdateEvent<String, OmDirectoryInfo>) omdbUpdateEvent;
+ OmDirectoryInfo updatedDirectoryInfo = dirTableUpdateEvent.getValue();
+ OmDirectoryInfo oldDirectoryInfo = dirTableUpdateEvent.getOldValue();
+
+ switch (action) {
+ case PUT:
+ handlePutDirEvent(updatedDirectoryInfo, nsSummaryMap);
+ break;
+
+ case DELETE:
+ handleDeleteDirEvent(updatedDirectoryInfo, nsSummaryMap);
+ break;
+
+ case UPDATE:
+ if (oldDirectoryInfo != null) {
+ // delete first, then put
+ handleDeleteDirEvent(oldDirectoryInfo, nsSummaryMap);
+ } else {
+ LOG.warn("Update event does not have the old dirInfo for {}.",
oldDirectoryInfo.getName());
+ }
+ handlePutDirEvent(updatedDirectoryInfo, nsSummaryMap);
+ break;
+
+ default:
+ LOG.debug("Skipping DB update event : {}",
+ omdbUpdateEvent.getAction());
+ }
+ }
+
+ private void handleUpdateOnDeletedDirTable(OMDBUpdateEvent<String, ? extends
WithParentObjectId> omdbUpdateEvent,
+ OMDBUpdateEvent.OMDBUpdateAction
action, Map<Long, NSSummary> nsSummaryMap,
+ Collection<Long>
objectIdsToBeDeleted) {
+ OMDBUpdateEvent<String, OmKeyInfo> deletedDirTableUpdateEvent =
+ (OMDBUpdateEvent<String, OmKeyInfo>) omdbUpdateEvent;
+ OmKeyInfo deletedKeyInfo = deletedDirTableUpdateEvent.getValue();
+
+ switch (action) {
+ case DELETE:
+ // When entry is removed from deletedDirTable, remove from nsSummaryMap
to prevent memory leak
+ if (deletedKeyInfo != null) {
+ long objectId = deletedKeyInfo.getObjectID();
+ nsSummaryMap.remove(objectId);
+ LOG.debug("Removed hard deleted directory with objectId {} from
nsSummaryMap", objectId);
+ objectIdsToBeDeleted.add(objectId);
+ }
+ break;
+
+ default:
+ LOG.info("Skipping DB update event on deletedDirTable: {}", action);
Review Comment:
this can be debug log, as this frequency can be high for put
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskWithFSO.java:
##########
@@ -175,10 +121,102 @@ public Pair<Integer, Boolean>
processWithFSO(OMUpdateEventBatch events,
if (!flushAndCommitNSToDB(nsSummaryMap)) {
return new ImmutablePair<>(seekPos, false);
}
+ // Delete hard deleted directories from NSSummary table
+ deleteNSSummariesFromDB(objectIdsToBeDeleted);
Review Comment:
objectsToBedeleted can be part of flushAndCommitNSToDB(), so that flush can
be done togethere.
same list can be passed for both call to ensure its fully deleted.
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskWithFSO.java:
##########
@@ -17,6 +17,8 @@
package org.apache.hadoop.ozone.recon.tasks;
+import static
org.apache.hadoop.ozone.om.codec.OMDBDefinition.DELETED_DIR_TABLE;
+import static org.apache.hadoop.ozone.om.codec.OMDBDefinition.DELETED_TABLE;
Review Comment:
remove operation on deletedTable
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskWithFSO.java:
##########
@@ -77,106 +80,159 @@ public Pair<Integer, Boolean>
processWithFSO(OMUpdateEventBatch events,
Map<Long, NSSummary> nsSummaryMap = new HashMap<>();
int eventCounter = 0;
- while (eventIterator.hasNext()) {
- OMDBUpdateEvent<String, ? extends
- WithParentObjectId> omdbUpdateEvent = eventIterator.next();
- OMDBUpdateEvent.OMDBUpdateAction action = omdbUpdateEvent.getAction();
- eventCounter++;
-
- // we only process updates on OM's FileTable and Dirtable
- String table = omdbUpdateEvent.getTable();
- boolean updateOnFileTable = table.equals(FILE_TABLE);
- if (!taskTables.contains(table)) {
- continue;
- }
+ try (RDBBatchOperation deleteRdbBatchOperation = new RDBBatchOperation()) {
+ while (eventIterator.hasNext()) {
+ OMDBUpdateEvent<String, ? extends
+ WithParentObjectId> omdbUpdateEvent = eventIterator.next();
+ OMDBUpdateEvent.OMDBUpdateAction action = omdbUpdateEvent.getAction();
+ eventCounter++;
- String updatedKey = omdbUpdateEvent.getKey();
-
- try {
- if (updateOnFileTable) {
- // key update on fileTable
- OMDBUpdateEvent<String, OmKeyInfo> keyTableUpdateEvent =
- (OMDBUpdateEvent<String, OmKeyInfo>) omdbUpdateEvent;
- OmKeyInfo updatedKeyInfo = keyTableUpdateEvent.getValue();
- OmKeyInfo oldKeyInfo = keyTableUpdateEvent.getOldValue();
-
- switch (action) {
- case PUT:
- handlePutKeyEvent(updatedKeyInfo, nsSummaryMap);
- break;
-
- case DELETE:
- handleDeleteKeyEvent(updatedKeyInfo, nsSummaryMap);
- break;
-
- case UPDATE:
- if (oldKeyInfo != null) {
- // delete first, then put
- handleDeleteKeyEvent(oldKeyInfo, nsSummaryMap);
- } else {
- LOG.warn("Update event does not have the old keyInfo for {}.",
- updatedKey);
- }
- handlePutKeyEvent(updatedKeyInfo, nsSummaryMap);
- break;
+ // we process updates on OM's FileTable, DirTable, DeletedTable and
DeletedDirTable
+ String table = omdbUpdateEvent.getTable();
+ boolean updateOnFileTable = table.equals(FILE_TABLE);
Review Comment:
we can directly use equals in if, no need prepare it for all 3.
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskDbEventHandler.java:
##########
@@ -62,16 +63,38 @@ protected void writeNSSummariesToDB(Map<Long, NSSummary>
nsSummaryMap)
try (RDBBatchOperation rdbBatchOperation = new RDBBatchOperation()) {
for (Map.Entry<Long, NSSummary> entry : nsSummaryMap.entrySet()) {
try {
- reconNamespaceSummaryManager.batchStoreNSSummaries(rdbBatchOperation,
- entry.getKey(), entry.getValue());
+
reconNamespaceSummaryManager.batchStoreNSSummaries(rdbBatchOperation,
entry.getKey(), entry.getValue());
} catch (IOException e) {
- LOG.error("Unable to write Namespace Summary data in Recon DB.",
- e);
+ LOG.error("Unable to write Namespace Summary data in Recon DB.", e);
throw e;
}
}
reconNamespaceSummaryManager.commitBatchOperation(rdbBatchOperation);
}
+ LOG.debug("Successfully written Namespace Summary data in Recon DB.");
+ }
+
+ protected void deleteNSSummariesFromDB(Collection<Long>
objectIdsToBeDeleted) {
+ try {
+ addAndCommitToDeleteNSSummaries(objectIdsToBeDeleted);
Review Comment:
these 2 need refactor with flushAndCommitNSToDB() as comment given below and
can be combined.
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskWithLegacy.java:
##########
@@ -72,6 +74,11 @@ public NSSummaryTaskWithLegacy(ReconNamespaceSummaryManager
this.nsSummaryFlushToDBMaxThreshold = nsSummaryFlushToDBMaxThreshold;
}
+ // Listen to Legacy KeyTable and DeletedTable for hard delete cleanup
Review Comment:
revert change for Legacy and OBS, no change requried
--
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]