This is an automated email from the ASF dual-hosted git repository. hexiaoqiao pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/trunk by this push: new 4235dc62687 HDFS-17772. Fix JournaledEditsCache int overflow while the maximum capacity to be Integer MAX_VALUE. (#7617). Contributed by Guo Wei. 4235dc62687 is described below commit 4235dc626874df852864e3689d93ec280f53c534 Author: YongZhuang Guo <76725986+gyz-...@users.noreply.github.com> AuthorDate: Mon Apr 21 12:04:29 2025 +0800 HDFS-17772. Fix JournaledEditsCache int overflow while the maximum capacity to be Integer MAX_VALUE. (#7617). Contributed by Guo Wei. Signed-off-by: He Xiaoqiao <hexiaoq...@apache.org> --- .../hadoop/hdfs/qjournal/server/JournaledEditsCache.java | 10 +++++----- .../hadoop/hdfs/qjournal/server/TestJournaledEditsCache.java | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/qjournal/server/JournaledEditsCache.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/qjournal/server/JournaledEditsCache.java index 339b7fa7b68..982fe59823e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/qjournal/server/JournaledEditsCache.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/qjournal/server/JournaledEditsCache.java @@ -79,7 +79,7 @@ class JournaledEditsCache { private static final long INVALID_TXN_ID = -1; /** The capacity, in bytes, of this cache. */ - private final int capacity; + private final long capacity; /** * Read/write lock pair wrapped in AutoCloseable; these refer to the same @@ -117,7 +117,7 @@ class JournaledEditsCache { */ private long initialTxnId; /** The current total size of all buffers in this cache. */ - private int totalSize; + private long totalSize; // ** End lock-protected fields ** @@ -128,8 +128,8 @@ class JournaledEditsCache { String.format("Cache config %s is set at %f, it should be a positive float value, " + "less than 1.0. The recommended value is less than 0.9.", DFSConfigKeys.DFS_JOURNALNODE_EDIT_CACHE_SIZE_FRACTION_KEY, fraction)); - capacity = conf.getInt(DFSConfigKeys.DFS_JOURNALNODE_EDIT_CACHE_SIZE_KEY, - (int) (Runtime.getRuntime().maxMemory() * fraction)); + capacity = conf.getLong(DFSConfigKeys.DFS_JOURNALNODE_EDIT_CACHE_SIZE_KEY, + (long) (Runtime.getRuntime().maxMemory() * fraction)); if (capacity > 0.9 * Runtime.getRuntime().maxMemory()) { Journal.LOG.warn(String.format("Cache capacity is set at %d bytes but " + "maximum JVM memory is only %d bytes. It is recommended that you " + @@ -424,7 +424,7 @@ long getCacheMissAmount() { } @VisibleForTesting - int getCapacity() { + long getCapacity() { return capacity; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/server/TestJournaledEditsCache.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/server/TestJournaledEditsCache.java index 82b8b587694..5567ff0a548 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/server/TestJournaledEditsCache.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/server/TestJournaledEditsCache.java @@ -226,7 +226,7 @@ public void testCacheSizeConfigs() { // Assert the default configs. Configuration config = new Configuration(); cache = new JournaledEditsCache(config); - assertEquals((int) (Runtime.getRuntime().maxMemory() * 0.5f), cache.getCapacity()); + assertEquals((long) (Runtime.getRuntime().maxMemory() * 0.5f), cache.getCapacity()); // Set dfs.journalnode.edit-cache-size.bytes. Configuration config1 = new Configuration(); @@ -239,7 +239,7 @@ public void testCacheSizeConfigs() { Configuration config2 = new Configuration(); config2.setFloat(DFSConfigKeys.DFS_JOURNALNODE_EDIT_CACHE_SIZE_FRACTION_KEY, 0.1f); cache = new JournaledEditsCache(config2); - assertEquals((int) (Runtime.getRuntime().maxMemory() * 0.1f), cache.getCapacity()); + assertEquals((long) (Runtime.getRuntime().maxMemory() * 0.1f), cache.getCapacity()); } private void storeEdits(int startTxn, int endTxn) throws Exception { --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org