Browse Source

HDDS-2224. Fix loadup cache for cache cleanup policy NEVER. (#1567)

Bharat Viswanadham 5 years ago
parent
commit
53ed78bcdb

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

@@ -104,7 +104,7 @@ public class TypedTable<KEY, VALUE> implements Table<KEY, VALUE> {
           // We should build cache after OM restart when clean up policy is
           // NEVER. Setting epoch value -1, so that when it is marked for
           // delete, this will be considered for cleanup.
-          cache.put(new CacheKey<>(kv.getKey()),
+          cache.loadInitial(new CacheKey<>(kv.getKey()),
               new CacheValue<>(Optional.of(kv.getValue()), EPOCH_DEFAULT));
         }
       }

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

@@ -43,6 +43,15 @@ public interface TableCache<CACHEKEY extends CacheKey,
    */
   CACHEVALUE get(CACHEKEY cacheKey);
 
+  /**
+   * This method should be called for tables with cache cleanup policy
+   * {@link TableCacheImpl.CacheCleanupPolicy#NEVER} after system restart to
+   * fill up the cache.
+   * @param cacheKey
+   * @param cacheValue
+   */
+  void loadInitial(CACHEKEY cacheKey, CACHEVALUE cacheValue);
+
   /**
    * Add an entry to the cache, if the key already exists it overrides.
    * @param cacheKey

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

@@ -70,6 +70,13 @@ public class TableCacheImpl<CACHEKEY extends CacheKey,
     return cache.get(cachekey);
   }
 
+  @Override
+  public void loadInitial(CACHEKEY cacheKey, CACHEVALUE cacheValue) {
+    // No need to add entry to epochEntries. Adding to cache is required during
+    // normal put operation.
+    cache.put(cacheKey, cacheValue);
+  }
+
   @Override
   public void put(CACHEKEY cacheKey, CACHEVALUE value) {
     cache.put(cacheKey, value);