Skip to content

Commit f865402

Browse files
bharatviswa504RogPodge
authored andcommitted
HDDS-2224. Fix loadup cache for cache cleanup policy NEVER. (apache#1567)
1 parent 358bef4 commit f865402

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public TypedTable(
104104
// We should build cache after OM restart when clean up policy is
105105
// NEVER. Setting epoch value -1, so that when it is marked for
106106
// delete, this will be considered for cleanup.
107-
cache.put(new CacheKey<>(kv.getKey()),
107+
cache.loadInitial(new CacheKey<>(kv.getKey()),
108108
new CacheValue<>(Optional.of(kv.getValue()), EPOCH_DEFAULT));
109109
}
110110
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ public interface TableCache<CACHEKEY extends CacheKey,
4343
*/
4444
CACHEVALUE get(CACHEKEY cacheKey);
4545

46+
/**
47+
* This method should be called for tables with cache cleanup policy
48+
* {@link TableCacheImpl.CacheCleanupPolicy#NEVER} after system restart to
49+
* fill up the cache.
50+
* @param cacheKey
51+
* @param cacheValue
52+
*/
53+
void loadInitial(CACHEKEY cacheKey, CACHEVALUE cacheValue);
54+
4655
/**
4756
* Add an entry to the cache, if the key already exists it overrides.
4857
* @param cacheKey

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ public CACHEVALUE get(CACHEKEY cachekey) {
7070
return cache.get(cachekey);
7171
}
7272

73+
@Override
74+
public void loadInitial(CACHEKEY cacheKey, CACHEVALUE cacheValue) {
75+
// No need to add entry to epochEntries. Adding to cache is required during
76+
// normal put operation.
77+
cache.put(cacheKey, cacheValue);
78+
}
79+
7380
@Override
7481
public void put(CACHEKEY cacheKey, CACHEVALUE value) {
7582
cache.put(cacheKey, value);

0 commit comments

Comments
 (0)