From 0ea8f3a19cd0b841dda6ba5c4e19887d9fc9cbb4 Mon Sep 17 00:00:00 2001 From: Stephen O'Donnell Date: Thu, 16 Apr 2020 20:16:41 -0700 Subject: [PATCH] HDFS-15283. Cache pool MAXTTL is not persisted and restored on cluster restart. Contributed by Stephen O'Donnell. Signed-off-by: Wei-Chiu Chuang (cherry picked from commit 3481895f8a9ea9f6e217a0ba158c48da89b3faf2) (cherry picked from commit aaad947c740c91c36139f3f0569ae78b53bca682) (cherry picked from commit 041c93a26cd0ff705bea9d6283951702cf2cf1c2) --- .../apache/hadoop/hdfs/server/namenode/CacheManager.java | 8 ++++++++ .../hadoop/hdfs/server/namenode/TestCacheDirectives.java | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/CacheManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/CacheManager.java index ab026f01d0c..0816517aab6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/CacheManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/CacheManager.java @@ -1042,6 +1042,10 @@ public class CacheManager { if (p.getLimit() != null) b.setLimit(p.getLimit()); + if (p.getMaxRelativeExpiryMs() != null) { + b.setMaxRelativeExpiry(p.getMaxRelativeExpiryMs()); + } + pools.add(b.build()); } @@ -1107,6 +1111,10 @@ public class CacheManager { if (p.hasLimit()) info.setLimit(p.getLimit()); + if (p.hasMaxRelativeExpiry()) { + info.setMaxRelativeExpiryMs(p.getMaxRelativeExpiry()); + } + addCachePool(info); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCacheDirectives.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCacheDirectives.java index c58e0903330..613aedf3f85 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCacheDirectives.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCacheDirectives.java @@ -626,10 +626,12 @@ public class TestCacheDirectives { String groupName = "partygroup"; FsPermission mode = new FsPermission((short)0777); long limit = 747; + long maxExpiry = 1234567890; dfs.addCachePool(new CachePoolInfo(pool) .setGroupName(groupName) .setMode(mode) - .setLimit(limit)); + .setLimit(limit) + .setMaxRelativeExpiryMs(maxExpiry)); RemoteIterator pit = dfs.listCachePools(); assertTrue("No cache pools found", pit.hasNext()); CachePoolInfo info = pit.next().getInfo(); @@ -637,6 +639,7 @@ public class TestCacheDirectives { assertEquals(groupName, info.getGroupName()); assertEquals(mode, info.getMode()); assertEquals(limit, (long)info.getLimit()); + assertEquals(maxExpiry, (long)info.getMaxRelativeExpiryMs()); assertFalse("Unexpected # of cache pools found", pit.hasNext()); // Create some cache entries @@ -697,6 +700,7 @@ public class TestCacheDirectives { assertEquals(groupName, info.getGroupName()); assertEquals(mode, info.getMode()); assertEquals(limit, (long)info.getLimit()); + assertEquals(maxExpiry, (long)info.getMaxRelativeExpiryMs()); assertFalse("Unexpected # of cache pools found", pit.hasNext()); dit = dfs.listCacheDirectives(null);