hanishakoneru commented on a change in pull request #956: HDDS-1638. Implement Key Write Requests to use Cache and DoubleBuffer. URL: https://github.com/apache/hadoop/pull/956#discussion_r296041965
########## File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java ########## @@ -495,12 +495,27 @@ public boolean isVolumeEmpty(String volume) throws IOException { public boolean isBucketEmpty(String volume, String bucket) throws IOException { String keyPrefix = getBucketKey(volume, bucket); - //TODO: When Key ops are converted in to HA model, use cache also to - // determine bucket is empty or not. + + // First check in key table cache. + Iterator<Map.Entry<CacheKey<String>, CacheValue<OmKeyInfo>>> iterator = + ((TypedTable< String, OmKeyInfo>) keyTable).cacheIterator(); + while (iterator.hasNext()) { + Map.Entry< CacheKey<String>, CacheValue<OmKeyInfo>> entry = + iterator.next(); + String key = entry.getKey().getCacheKey(); + OmKeyInfo omKeyInfo = entry.getValue().getCacheValue(); + // Making sure that entry is not for delete key request. + if (key.startsWith(keyPrefix) && omKeyInfo != null) { + return false; + } + } try (TableIterator<String, ? extends KeyValue<String, OmKeyInfo>> keyIter = keyTable.iterator()) { KeyValue<String, OmKeyInfo> kv = keyIter.seek(keyPrefix); - if (kv != null && kv.getKey().startsWith(keyPrefix)) { + // During iteration from DB, check in mean time if this key is not + // marked for delete. + if (kv != null && kv.getKey().startsWith(keyPrefix) && + keyTable.get(kv.getKey()) != null) { Review comment: The keyTable.get(.. ) checks the cache and if no entry is available in cache, it gets from the DB. We can avoid the reading from the DB again here and check the cache alone. This is applicable for volumeEmpty check also but if we are going to maintain a full bucket table cache then it does not matter. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org