diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java index 7e7dbc277722..fc6282d46d42 100644 --- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java @@ -258,15 +258,15 @@ public class OmMetadataManagerImpl implements OMMetadataManager, private Table userTable; private Table volumeTable; private Table bucketTable; - private Table keyTable; + private Table keyTable; private Table deletedTable; private Table openKeyTable; private Table multipartInfoTable; private Table s3SecretTable; private Table dTokenTable; private Table prefixTable; - private Table dirTable; - private Table fileTable; + private Table dirTable; + private Table fileTable; private Table openFileTable; private Table transactionInfoTable; private Table metaTable; @@ -968,7 +968,6 @@ public boolean isBucketEmpty(String volume, String bucket) return true; } - /** * Checks if a key starting with a given keyPrefix exists in the table cache. * @@ -976,22 +975,24 @@ public boolean isBucketEmpty(String volume, String bucket) * @param table - table to be searched. * @return true if the key is present in the cache. */ - private boolean isKeyPresentInTableCache(String keyPrefix, - Table table) { - Iterator, CacheValue>> iterator = + private boolean isKeyPresentInTableCache(String keyPrefix, + Table table) { + Iterator, CacheValue>> iterator = table.cacheIterator(); while (iterator.hasNext()) { - Map.Entry, CacheValue> entry = + Map.Entry, CacheValue> entry = iterator.next(); String key = entry.getKey().getCacheKey(); - OmKeyInfo omKeyInfo = entry.getValue().getCacheValue(); + Object value = entry.getValue().getCacheValue(); + // Making sure that entry is not for delete key request. - if (key.startsWith(keyPrefix) && omKeyInfo != null) { + if (key.startsWith(keyPrefix) && value != null) { return true; } } return false; } + /** * Checks if a key starts with the given prefix is present in the table. * @@ -1000,20 +1001,20 @@ private boolean isKeyPresentInTableCache(String keyPrefix, * @return true if the key is present in the table * @throws IOException */ - private boolean isKeyPresentInTable(String keyPrefix, - Table table) + private boolean isKeyPresentInTable(String keyPrefix, + Table table) throws IOException { - try (TableIterator> + try (TableIterator> keyIter = table.iterator()) { - KeyValue kv = keyIter.seek(keyPrefix); + KeyValue kv = keyIter.seek(keyPrefix); // Iterate through all the entries in the table which start with // the current bucket's prefix. while (kv != null && kv.getKey().startsWith(keyPrefix)) { // Check the entry in db is not marked for delete. This can happen // while entry is marked for delete, but it is not flushed to DB. - CacheValue cacheValue = - table.getCacheValue(new CacheKey(kv.getKey())); + CacheValue cacheValue = + table.getCacheValue(new CacheKey<>(kv.getKey())); // Case 1: We found an entry, but no cache entry. if (cacheValue == null) {