Skip to content

Commit a38286b

Browse files
author
guoyz50
committed
HDFS-17772. The JournaledEditsCache has an int overflow issue, causing the maximum capacity to always be Integer MAX_VALUE
1 parent 71aa0e4 commit a38286b

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Diff for: hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/qjournal/server/JournaledEditsCache.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class JournaledEditsCache {
7979
private static final long INVALID_TXN_ID = -1;
8080

8181
/** The capacity, in bytes, of this cache. */
82-
private final int capacity;
82+
private final long capacity;
8383

8484
/**
8585
* Read/write lock pair wrapped in AutoCloseable; these refer to the same
@@ -117,7 +117,7 @@ class JournaledEditsCache {
117117
*/
118118
private long initialTxnId;
119119
/** The current total size of all buffers in this cache. */
120-
private int totalSize;
120+
private long totalSize;
121121

122122
// ** End lock-protected fields **
123123

@@ -128,8 +128,8 @@ class JournaledEditsCache {
128128
String.format("Cache config %s is set at %f, it should be a positive float value, " +
129129
"less than 1.0. The recommended value is less than 0.9.",
130130
DFSConfigKeys.DFS_JOURNALNODE_EDIT_CACHE_SIZE_FRACTION_KEY, fraction));
131-
capacity = conf.getInt(DFSConfigKeys.DFS_JOURNALNODE_EDIT_CACHE_SIZE_KEY,
132-
(int) (Runtime.getRuntime().maxMemory() * fraction));
131+
capacity = conf.getLong(DFSConfigKeys.DFS_JOURNALNODE_EDIT_CACHE_SIZE_KEY,
132+
(long) (Runtime.getRuntime().maxMemory() * fraction));
133133
if (capacity > 0.9 * Runtime.getRuntime().maxMemory()) {
134134
Journal.LOG.warn(String.format("Cache capacity is set at %d bytes but " +
135135
"maximum JVM memory is only %d bytes. It is recommended that you " +
@@ -424,7 +424,7 @@ long getCacheMissAmount() {
424424
}
425425

426426
@VisibleForTesting
427-
int getCapacity() {
427+
long getCapacity() {
428428
return capacity;
429429
}
430430

Diff for: hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/server/TestJournaledEditsCache.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public void testCacheSizeConfigs() {
226226
// Assert the default configs.
227227
Configuration config = new Configuration();
228228
cache = new JournaledEditsCache(config);
229-
assertEquals((int) (Runtime.getRuntime().maxMemory() * 0.5f), cache.getCapacity());
229+
assertEquals((long) (Runtime.getRuntime().maxMemory() * 0.5f), cache.getCapacity());
230230

231231
// Set dfs.journalnode.edit-cache-size.bytes.
232232
Configuration config1 = new Configuration();
@@ -239,7 +239,7 @@ public void testCacheSizeConfigs() {
239239
Configuration config2 = new Configuration();
240240
config2.setFloat(DFSConfigKeys.DFS_JOURNALNODE_EDIT_CACHE_SIZE_FRACTION_KEY, 0.1f);
241241
cache = new JournaledEditsCache(config2);
242-
assertEquals((int) (Runtime.getRuntime().maxMemory() * 0.1f), cache.getCapacity());
242+
assertEquals((long) (Runtime.getRuntime().maxMemory() * 0.1f), cache.getCapacity());
243243
}
244244

245245
private void storeEdits(int startTxn, int endTxn) throws Exception {

0 commit comments

Comments
 (0)