ivandika3 commented on code in PR #8961:
URL: https://github.com/apache/ozone/pull/8961#discussion_r2295057788


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java:
##########
@@ -1074,7 +1074,9 @@ public ListKeysResult listKeys(String volumeName, String 
bucketName,
           CacheValue<OmKeyInfo> cacheValue =
               keyTable.getCacheValue(new CacheKey<>(kv.getKey()));
           if (cacheValue == null || cacheValue.getCacheValue() != null) {
-            cacheKeyMap.put(kv.getKey(), kv.getValue());
+            // We use putIfAbsent since cache entry should be more up-to-date 
and should not be overwritten
+            //  by the outdated DB entry
+            cacheKeyMap.putIfAbsent(kv.getKey(), kv.getValue());
             currentCount++;

Review Comment:
   Thanks @smengcl for the review. Correct me if I'm wrong, the idea of the 
first `currentCount` is to keep track of the encountered the number of entries 
in the OM DB that will not be deleted so that we don't iterate in keyTable 
longer than we need. However since overwritten key is still a non-deleted key, 
`currentCount` should be incremented even if the key is overwritten in the 
cache. If we increment only when key is not overwritten, we might need to 
iterate more than we need.
   
   That being said, `currentCount` will be reinitialized to 0 later when 
building the `result` list. This would ensure the final list count is correct 
regardless whether we increment the `currentCount` during the overwrite.
   
   I added additional test cases to list less than the current number of keys.



-- 
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]

Reply via email to