This is an automated email from the ASF dual-hosted git repository.

zitadombi 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 74dc25b1cc HDDS-9530. Recon - NPE in handling deleteKey event in 
NSSummaryFSO task. (#5490)
74dc25b1cc is described below

commit 74dc25b1ccc43add843b62e57c1cc13eb11e6431
Author: Devesh Kumar Singh <[email protected]>
AuthorDate: Fri Dec 1 17:06:00 2023 +0530

    HDDS-9530. Recon - NPE in handling deleteKey event in NSSummaryFSO task. 
(#5490)
---
 .../ozone/recon/tasks/OMDBUpdatesHandler.java      | 47 ++++++++++++++--------
 .../ozone/recon/tasks/TestOMDBUpdatesHandler.java  | 19 ++-------
 2 files changed, 34 insertions(+), 32 deletions(-)

diff --git 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/OMDBUpdatesHandler.java
 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/OMDBUpdatesHandler.java
index 944ae32244..cfaf4bb60a 100644
--- 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/OMDBUpdatesHandler.java
+++ 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/OMDBUpdatesHandler.java
@@ -81,12 +81,13 @@ public class OMDBUpdatesHandler extends 
ManagedWriteBatch.Handler {
   }
 
   /**
+   * Processes an OM DB update event based on the provided parameters.
    *
-   * @param cfIndex
-   * @param keyBytes
-   * @param valueBytes
-   * @param action
-   * @throws IOException
+   * @param cfIndex     Index of the column family.
+   * @param keyBytes    Serialized key bytes.
+   * @param valueBytes  Serialized value bytes.
+   * @param action      Type of the database action (e.g., PUT, DELETE).
+   * @throws IOException If an I/O error occurs.
    */
   private void processEvent(int cfIndex, byte[] keyBytes, byte[]
       valueBytes, OMDBUpdateEvent.OMDBUpdateAction action)
@@ -111,10 +112,12 @@ public class OMDBUpdatesHandler extends 
ManagedWriteBatch.Handler {
       final Object key = cf.getKeyCodec().fromPersistedFormat(keyBytes);
       builder.setKey(key);
 
-      // Put new
-      // Put existing --> Update
-      // Delete existing
-      // Delete non-existing
+      // Handle the event based on its type:
+      // - PUT with a new key: Insert the new value.
+      // - PUT with an existing key: Update the existing value.
+      // - DELETE with an existing key: Remove the value.
+      // - DELETE with a non-existing key: No action, log a warning if
+      // necessary.
       Table table = omMetadataManager.getTable(tableName);
 
       OMDBUpdateEvent latestEvent = omdbLatestUpdateEvents.get(key);
@@ -127,7 +130,7 @@ public class OMDBUpdatesHandler extends 
ManagedWriteBatch.Handler {
         oldValue = table.getSkipCache(key);
       }
 
-      if (action == PUT) {
+      if (action.equals(PUT)) {
         final Object value = 
cf.getValueCodec().fromPersistedFormat(valueBytes);
 
         // If the updated value is not valid for this event, we skip it.
@@ -137,8 +140,7 @@ public class OMDBUpdatesHandler extends 
ManagedWriteBatch.Handler {
         }
 
         builder.setValue(value);
-        // If a PUT operation happens on an existing Key, it is tagged
-        // as an "UPDATE" event.
+        // Tag PUT operations on existing keys as "UPDATE" events.
         if (oldValue != null) {
 
           // If the oldValue is not valid for this event, we skip it.
@@ -153,8 +155,22 @@ public class OMDBUpdatesHandler extends 
ManagedWriteBatch.Handler {
           }
         }
       } else if (action.equals(DELETE)) {
-        if (oldValue != null && !omUpdateEventValidator.isValidEvent(tableName,
-            oldValue, key, action)) {
+        if (null == oldValue) {
+          String keyStr = (key instanceof String) ? key.toString() : "";
+          if (keyStr.isEmpty()) {
+            LOG.warn(
+                "Only DTOKEN_TABLE table uses OzoneTokenIdentifier as key " +
+                    "instead of String. Event on any other table in this " +
+                    "condition may need to be investigated. This DELETE " +
+                    "event is on {} table which is not useful for Recon to " +
+                    "capture.", tableName);
+          }
+          LOG.warn("Old Value of Key: {} in table: {} should not be null " +
+              "for DELETE event ", keyStr, tableName);
+          return;
+        }
+        if (!omUpdateEventValidator.isValidEvent(tableName, oldValue, key,
+            action)) {
           return;
         }
         // When you delete a Key, we add the old value to the event so that
@@ -170,8 +186,7 @@ public class OMDBUpdatesHandler extends 
ManagedWriteBatch.Handler {
       omdbUpdateEvents.add(event);
       omdbLatestUpdateEvents.put(key, event);
     } else {
-      // key type or value type cannot be determined for this table.
-      // log a warn message and ignore the update.
+      // Log and ignore events if key or value types are undetermined.
       if (LOG.isWarnEnabled()) {
         LOG.warn(String.format("KeyType or ValueType could not be determined" +
             " for table %s. Ignoring the event.", tableName));
diff --git 
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestOMDBUpdatesHandler.java
 
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestOMDBUpdatesHandler.java
index 9ece45df95..dca0da341a 100644
--- 
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestOMDBUpdatesHandler.java
+++ 
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestOMDBUpdatesHandler.java
@@ -150,8 +150,6 @@ public class TestOMDBUpdatesHandler {
   public void testDelete() throws Exception {
     // Write 1 volume, 1 key into source and target OM DBs.
     String volumeKey = omMetadataManager.getVolumeKey("sampleVol");
-    String nonExistVolumeKey = omMetadataManager
-        .getVolumeKey("nonExistingVolume");
     OmVolumeArgs args =
         OmVolumeArgs.newBuilder()
             .setVolume("sampleVol")
@@ -181,7 +179,9 @@ public class TestOMDBUpdatesHandler {
     OMDBUpdatesHandler omdbUpdatesHandler = captureEvents(writeBatches);
 
     List<OMDBUpdateEvent> events = omdbUpdatesHandler.getEvents();
-    assertEquals(4, events.size());
+
+    // Assert for non existent keys, no events will be captured and handled.
+    assertEquals(2, events.size());
 
     OMDBUpdateEvent keyEvent = events.get(0);
     assertEquals(OMDBUpdateEvent.OMDBUpdateAction.DELETE, 
keyEvent.getAction());
@@ -194,19 +194,6 @@ public class TestOMDBUpdatesHandler {
     assertNotNull(volEvent.getValue());
     OmVolumeArgs volumeInfo = (OmVolumeArgs) volEvent.getValue();
     assertEquals("sampleVol", volumeInfo.getVolume());
-
-    // Assert the values of non existent keys are set to null.
-    OMDBUpdateEvent nonExistKey = events.get(2);
-    assertEquals(OMDBUpdateEvent.OMDBUpdateAction.DELETE,
-        nonExistKey.getAction());
-    assertEquals("/sampleVol/bucketOne/key_two", nonExistKey.getKey());
-    assertNull(nonExistKey.getValue());
-
-    OMDBUpdateEvent nonExistVolume = events.get(3);
-    assertEquals(OMDBUpdateEvent.OMDBUpdateAction.DELETE,
-        nonExistVolume.getAction());
-    assertEquals(nonExistVolumeKey, nonExistVolume.getKey());
-    assertNull(nonExistVolume.getValue());
   }
 
   @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to