Skip to content

Commit 518b2c3

Browse files
fix review comment
1 parent 8ef5301 commit 518b2c3

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

hadoop-hdds/common/src/main/java/org/apache/hadoop/utils/db/Table.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ default void addCacheEntry(CacheKey<KEY> cacheKey,
123123
throw new NotImplementedException("addCacheEntry is not implemented");
124124
}
125125

126+
/**
127+
* Get the cache value from table cache.
128+
* @param cacheKey
129+
*/
130+
default CacheValue<VALUE> getCacheValue(CacheKey<KEY> cacheKey) {
131+
throw new NotImplementedException("getCacheValue is not implemented");
132+
}
133+
126134
/**
127135
* Removes all the entries from the table cache which are having epoch value
128136
* less

hadoop-hdds/common/src/main/java/org/apache/hadoop/utils/db/TypedTable.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ public void addCacheEntry(CacheKey<KEY> cacheKey,
158158
cache.put(cacheKey, cacheValue);
159159
}
160160

161+
@Override
162+
public CacheValue<VALUE> getCacheValue(CacheKey<KEY> cacheKey) {
163+
return cache.get(cacheKey);
164+
}
165+
161166
public Iterator<Map.Entry<CacheKey<KEY>, CacheValue<VALUE>>> cacheIterator() {
162167
return cache.iterator();
163168
}

hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,18 @@ public boolean isVolumeEmpty(String volume) throws IOException {
473473
try (TableIterator<String, ? extends KeyValue<String, OmBucketInfo>>
474474
bucketIter = bucketTable.iterator()) {
475475
KeyValue<String, OmBucketInfo> kv = bucketIter.seek(volumePrefix);
476-
if (kv != null && kv.getKey().startsWith(volumePrefix)) {
477-
return false; // we found at least one bucket with this volume prefix.
476+
477+
if (kv != null) {
478+
// Check the entry in db is not marked for delete. This can happen
479+
// while entry is marked for delete, but it is not flushed to DB.
480+
CacheValue<OmBucketInfo> cacheValue =
481+
bucketTable.getCacheValue(new CacheKey(kv.getKey()));
482+
if (kv.getKey().startsWith(volumePrefix)
483+
&& cacheValue != null && cacheValue.getCacheValue() != null) {
484+
return false; // we found at least one bucket with this volume prefix.
485+
}
478486
}
487+
479488
}
480489
return true;
481490
}
@@ -509,9 +518,19 @@ public boolean isBucketEmpty(String volume, String bucket)
509518
try (TableIterator<String, ? extends KeyValue<String, OmKeyInfo>> keyIter =
510519
keyTable.iterator()) {
511520
KeyValue<String, OmKeyInfo> kv = keyIter.seek(keyPrefix);
512-
if (kv != null && kv.getKey().startsWith(keyPrefix)) {
513-
return false; // we found at least one key with this vol/bucket prefix.
521+
522+
if (kv != null) {
523+
// Check the entry in db is not marked for delete. This can happen
524+
// while entry is marked for delete, but it is not flushed to DB.
525+
CacheValue<OmKeyInfo> cacheValue =
526+
keyTable.getCacheValue(new CacheKey(kv.getKey()));
527+
if (kv.getKey().startsWith(keyPrefix)
528+
&& cacheValue != null && cacheValue.getCacheValue() != null) {
529+
return false; // we found at least one key with this vol/bucket
530+
// prefix.
531+
}
514532
}
533+
515534
}
516535
return true;
517536
}

0 commit comments

Comments
 (0)