Skip to content

Commit 5e86c8e

Browse files
committed
HDDS-1297. Fix IllegalArgumentException thrown with MiniOzoneCluster Initialization. Contributed by Yiqun Lin.
1 parent 235cdc0 commit 5e86c8e

File tree

4 files changed

+102
-66
lines changed

4 files changed

+102
-66
lines changed

hadoop-hdds/container-service/src/main/java/org/apache/hadoop/hdds/scm/HddsServerUtil.java

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -252,25 +252,15 @@ public static long getStaleNodeInterval(Configuration conf) {
252252
//
253253
// Here we check that staleNodeInterval is at least five times more than the
254254
// frequency at which the accounting thread is going to run.
255-
try {
256-
sanitizeUserArgs(staleNodeIntervalMs, heartbeatThreadFrequencyMs,
257-
5, 1000);
258-
} catch (IllegalArgumentException ex) {
259-
LOG.error("Stale Node Interval is cannot be honored due to " +
260-
"mis-configured {}. ex: {}",
261-
OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL, ex);
262-
throw ex;
263-
}
255+
staleNodeIntervalMs = sanitizeUserArgs(OZONE_SCM_STALENODE_INTERVAL,
256+
staleNodeIntervalMs, OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL,
257+
heartbeatThreadFrequencyMs, 5, 1000);
264258

265259
// Make sure that stale node value is greater than configured value that
266260
// datanodes are going to send HBs.
267-
try {
268-
sanitizeUserArgs(staleNodeIntervalMs, heartbeatIntervalMs, 3, 1000);
269-
} catch (IllegalArgumentException ex) {
270-
LOG.error("Stale Node Interval MS is cannot be honored due to " +
271-
"mis-configured {}. ex: {}", HDDS_HEARTBEAT_INTERVAL, ex);
272-
throw ex;
273-
}
261+
staleNodeIntervalMs = sanitizeUserArgs(OZONE_SCM_STALENODE_INTERVAL,
262+
staleNodeIntervalMs, HDDS_HEARTBEAT_INTERVAL, heartbeatIntervalMs, 3,
263+
1000);
274264
return staleNodeIntervalMs;
275265
}
276266

@@ -289,16 +279,10 @@ public static long getDeadNodeInterval(Configuration conf) {
289279
OZONE_SCM_DEADNODE_INTERVAL_DEFAULT,
290280
TimeUnit.MILLISECONDS);
291281

292-
try {
293-
// Make sure that dead nodes Ms is at least twice the time for staleNodes
294-
// with a max of 1000 times the staleNodes.
295-
sanitizeUserArgs(deadNodeIntervalMs, staleNodeIntervalMs, 2, 1000);
296-
} catch (IllegalArgumentException ex) {
297-
LOG.error("Dead Node Interval MS is cannot be honored due to " +
298-
"mis-configured {}. ex: {}", OZONE_SCM_STALENODE_INTERVAL, ex);
299-
throw ex;
300-
}
301-
return deadNodeIntervalMs;
282+
// Make sure that dead nodes Ms is at least twice the time for staleNodes
283+
// with a max of 1000 times the staleNodes.
284+
return sanitizeUserArgs(OZONE_SCM_DEADNODE_INTERVAL, deadNodeIntervalMs,
285+
OZONE_SCM_STALENODE_INTERVAL, staleNodeIntervalMs, 2, 1000);
302286
}
303287

304288
/**

hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/ServerUtils.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,34 @@ private ServerUtils() {
4747
* For example, sanitizeUserArgs(17, 3, 5, 10)
4848
* ensures that 17 is greater/equal than 3 * 5 and less/equal to 3 * 10.
4949
*
50+
* @param key - config key of the value
5051
* @param valueTocheck - value to check
52+
* @param baseKey - config key of the baseValue
5153
* @param baseValue - the base value that is being used.
5254
* @param minFactor - range min - a 2 here makes us ensure that value
5355
* valueTocheck is at least twice the baseValue.
5456
* @param maxFactor - range max
5557
* @return long
5658
*/
57-
public static long sanitizeUserArgs(long valueTocheck, long baseValue,
58-
long minFactor, long maxFactor)
59-
throws IllegalArgumentException {
60-
if ((valueTocheck >= (baseValue * minFactor)) &&
61-
(valueTocheck <= (baseValue * maxFactor))) {
62-
return valueTocheck;
59+
public static long sanitizeUserArgs(String key, long valueTocheck,
60+
String baseKey, long baseValue, long minFactor, long maxFactor) {
61+
long minLimit = baseValue * minFactor;
62+
long maxLimit = baseValue * maxFactor;
63+
if (valueTocheck < minLimit) {
64+
LOG.warn(
65+
"{} value = {} is smaller than min = {} based on"
66+
+ " the key value of {}, reset to the min value {}.",
67+
key, valueTocheck, minLimit, baseKey, minLimit);
68+
valueTocheck = minLimit;
69+
} else if (valueTocheck > maxLimit) {
70+
LOG.warn(
71+
"{} value = {} is larger than max = {} based on"
72+
+ " the key value of {}, reset to the max value {}.",
73+
key, valueTocheck, maxLimit, baseKey, maxLimit);
74+
valueTocheck = maxLimit;
6375
}
64-
String errMsg = String.format("%d is not within min = %d or max = " +
65-
"%d", valueTocheck, baseValue * minFactor, baseValue * maxFactor);
66-
throw new IllegalArgumentException(errMsg);
76+
77+
return valueTocheck;
6778
}
6879

6980

hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/TestHddsServerUtils.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,29 @@
1919
package org.apache.hadoop.hdds.scm;
2020

2121
import org.apache.hadoop.conf.Configuration;
22+
import org.apache.hadoop.hdds.HddsConfigKeys;
2223
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
24+
import org.apache.hadoop.hdds.server.ServerUtils;
25+
import org.apache.hadoop.test.PathUtils;
26+
27+
import org.apache.commons.io.FileUtils;
28+
import static org.junit.Assert.assertTrue;
2329
import org.junit.Rule;
2430
import org.junit.Test;
2531
import org.junit.rules.ExpectedException;
2632
import org.junit.rules.Timeout;
2733
import org.slf4j.Logger;
2834
import org.slf4j.LoggerFactory;
2935

36+
import java.io.File;
3037
import java.net.InetSocketAddress;
38+
import java.util.concurrent.TimeUnit;
3139

3240
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_CLIENT_ADDRESS_KEY;
3341
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_DATANODE_ADDRESS_KEY;
3442
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_DATANODE_PORT_DEFAULT;
3543
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_NAMES;
44+
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_STALENODE_INTERVAL;
3645
import static org.junit.Assert.assertEquals;
3746

3847
/**
@@ -154,4 +163,67 @@ public void testClientFailsWithMultipleScmNames() {
154163
HddsServerUtil.getScmAddressForDataNodes(conf);
155164
}
156165

166+
/**
167+
* Test {@link ServerUtils#getScmDbDir}.
168+
*/
169+
@Test
170+
public void testGetScmDbDir() {
171+
final File testDir = PathUtils.getTestDir(TestHddsServerUtils.class);
172+
final File dbDir = new File(testDir, "scmDbDir");
173+
final File metaDir = new File(testDir, "metaDir"); // should be ignored.
174+
final Configuration conf = new OzoneConfiguration();
175+
conf.set(ScmConfigKeys.OZONE_SCM_DB_DIRS, dbDir.getPath());
176+
conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, metaDir.getPath());
177+
178+
try {
179+
assertEquals(dbDir, ServerUtils.getScmDbDir(conf));
180+
assertTrue(dbDir.exists()); // should have been created.
181+
} finally {
182+
FileUtils.deleteQuietly(dbDir);
183+
}
184+
}
185+
186+
/**
187+
* Test {@link ServerUtils#getScmDbDir} with fallback to OZONE_METADATA_DIRS
188+
* when OZONE_SCM_DB_DIRS is undefined.
189+
*/
190+
@Test
191+
public void testGetScmDbDirWithFallback() {
192+
final File testDir = PathUtils.getTestDir(TestHddsServerUtils.class);
193+
final File metaDir = new File(testDir, "metaDir");
194+
final Configuration conf = new OzoneConfiguration();
195+
conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, metaDir.getPath());
196+
try {
197+
assertEquals(metaDir, ServerUtils.getScmDbDir(conf));
198+
assertTrue(metaDir.exists()); // should have been created.
199+
} finally {
200+
FileUtils.deleteQuietly(metaDir);
201+
}
202+
}
203+
204+
@Test
205+
public void testNoScmDbDirConfigured() {
206+
thrown.expect(IllegalArgumentException.class);
207+
ServerUtils.getScmDbDir(new OzoneConfiguration());
208+
}
209+
210+
@Test
211+
public void testGetStaleNodeInterval() {
212+
final Configuration conf = new OzoneConfiguration();
213+
214+
// Reset OZONE_SCM_STALENODE_INTERVAL to 300s that
215+
// larger than max limit value.
216+
conf.setTimeDuration(OZONE_SCM_STALENODE_INTERVAL, 300, TimeUnit.SECONDS);
217+
conf.setInt(ScmConfigKeys.OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL, 100);
218+
// the max limit value will be returned
219+
assertEquals(100000, HddsServerUtil.getStaleNodeInterval(conf));
220+
221+
// Reset OZONE_SCM_STALENODE_INTERVAL to 10ms that
222+
// smaller than min limit value.
223+
conf.setTimeDuration(OZONE_SCM_STALENODE_INTERVAL, 10,
224+
TimeUnit.MILLISECONDS);
225+
conf.setInt(ScmConfigKeys.OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL, 100);
226+
// the min limit value will be returned
227+
assertEquals(90000, HddsServerUtil.getStaleNodeInterval(conf));
228+
}
157229
}

hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/node/TestSCMNodeManager.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -234,37 +234,6 @@ public void testScmHealthyNodeCount()
234234
}
235235
}
236236

237-
/**
238-
* Asserts that if user provides a value less than 5 times the heartbeat
239-
* interval as the StaleNode Value, we throw since that is a QoS that we
240-
* cannot maintain.
241-
*
242-
* @throws IOException
243-
* @throws InterruptedException
244-
* @throws TimeoutException
245-
*/
246-
247-
@Test
248-
public void testScmSanityOfUserConfig1()
249-
throws IOException, AuthenticationException {
250-
OzoneConfiguration conf = getConf();
251-
final int interval = 100;
252-
conf.setTimeDuration(OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL, interval,
253-
MILLISECONDS);
254-
conf.setTimeDuration(HDDS_HEARTBEAT_INTERVAL, 1, SECONDS);
255-
256-
// This should be 5 times more than OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL
257-
// and 3 times more than OZONE_SCM_HEARTBEAT_INTERVAL
258-
conf.setTimeDuration(OZONE_SCM_STALENODE_INTERVAL, interval, MILLISECONDS);
259-
260-
thrown.expect(IllegalArgumentException.class);
261-
262-
// This string is a multiple of the interval value
263-
thrown.expectMessage(
264-
startsWith("100 is not within min = 500 or max = 100000"));
265-
createNodeManager(conf);
266-
}
267-
268237
/**
269238
* Asserts that if Stale Interval value is more than 5 times the value of HB
270239
* processing thread it is a sane value.

0 commit comments

Comments
 (0)