Skip to content
Permalink
Browse files

Add check on tiered storage configuration and avoid NPE

Fixes #9020 and
#8997

When users specify a unknown storage alias (e.g., "ssd" rather than
"SSD"), they will see the following error message on NPE:
```
2019-05-13 14:29:07,034 ERROR ProcessUtils - Uncaught exception while
stopping Alluxio worker, simply exiting.
java.lang.NullPointerException
at
alluxio.worker.block.DefaultBlockWorker.stop(DefaultBlockWorker.java:262)
at alluxio.Registry.stop(Registry.java:149)
at
alluxio.worker.AlluxioWorkerProcess.stopWorkers(AlluxioWorkerProcess.java:287)
at
alluxio.worker.AlluxioWorkerProcess.stop(AlluxioWorkerProcess.java:274)
at alluxio.ProcessUtils.run(ProcessUtils.java:41)
at alluxio.worker.AlluxioWorker.main(AlluxioWorker.java:69)
```

This PR makes alluxio service fail explicitly and early with the
following error message:

```
Exception in thread "main" java.lang.ExceptionInInitializerError
at alluxio.proxy.AlluxioProxy.main(AlluxioProxy.java:44)
Caused by: java.lang.IllegalStateException: Alias "ssd" on tier 0 on
worker (configured by alluxio.worker.tieredstore.level0.alias) is not
found in global tiered storage setting: MEM,SSD,HDD
at
com.google.common.base.Preconditions.checkState(Preconditions.java:862)
at
alluxio.conf.InstancedConfiguration.checkTieredStorage(InstancedConfiguration.java:544)
at
alluxio.conf.InstancedConfiguration.validate(InstancedConfiguration.java:363)
at
alluxio.util.ConfigurationUtils.reloadProperties(ConfigurationUtils.java:443)
at alluxio.conf.ServerConfiguration.reset(ServerConfiguration.java:68)
at
alluxio.conf.ServerConfiguration.<clinit>(ServerConfiguration.java:60)
... 1 more
```

pr-link: #9090
change-id: cid-48a08546422a9c9f3510f2315b23612e6ca38b05
  • Loading branch information...
apc999 authored and alluxio-bot committed May 15, 2019
1 parent 3a8d17f commit d460b7d5805c40b7d8913e5a4ea8f3ec9fb9464c
@@ -16,6 +16,7 @@
import alluxio.exception.PreconditionMessage;
import alluxio.util.FormatUtils;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
@@ -366,6 +367,7 @@ public void validate() {
checkUserFileBufferBytes();
checkZkConfiguration();
checkTieredLocality();
checkTieredStorage();
}

@Override
@@ -531,6 +533,34 @@ private void checkTieredLocality() {
}
}

/**
* Checks that tiered storage configuration on worker is consistent with the global configuration.
*
* @throws IllegalStateException if invalid tiered storage configuration is encountered
*/
@VisibleForTesting
void checkTieredStorage() {
int globalTiers = getInt(PropertyKey.MASTER_TIERED_STORE_GLOBAL_LEVELS);
Set<String> globalTierAliasSet = new HashSet<>();
for (int i = 0; i < globalTiers; i++) {
globalTierAliasSet
.add(get(PropertyKey.Template.MASTER_TIERED_STORE_GLOBAL_LEVEL_ALIAS.format(i)));
}
int workerTiers = getInt(PropertyKey.WORKER_TIERED_STORE_LEVELS);
Preconditions.checkState(workerTiers <= globalTiers,
"%s tiers on worker (configured by %s), larger than global %s tiers (configured by %s) ",
workerTiers, PropertyKey.WORKER_TIERED_STORE_LEVELS,
globalTiers, PropertyKey.MASTER_TIERED_STORE_GLOBAL_LEVELS);
for (int i = 0; i < workerTiers; i++) {
PropertyKey key = Template.WORKER_TIERED_STORE_LEVEL_ALIAS.format(i);
String alias = get(key);
Preconditions.checkState(globalTierAliasSet.contains(alias),
"Alias \"%s\" on tier %s on worker (configured by %s) is not found in global tiered "
+ "storage setting: %s",
alias, i, key, String.join(", ", globalTierAliasSet));
}
}

private class UnresolvablePropertyException extends Exception {

public UnresolvablePropertyException(String msg) {
@@ -43,6 +43,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@@ -52,7 +53,7 @@
/**
* Unit tests for the {@link alluxio.conf.InstancedConfiguration} class.
*/
public class ConfigurationTest {
public class InstancedConfigurationTest {

private InstancedConfiguration mConfiguration = ConfigurationTestUtils.defaults();
@Rule
@@ -982,4 +983,37 @@ public void testDeprecatedKeysNotLogged() {
mConfiguration.validate();
assertFalse(mLogger.wasLogged(" is deprecated"));
}

@Test
public void unknownTieredStorageAlias() throws Exception {
for (String alias : Arrays.asList("mem", "ssd", "hdd", "unknown")) {
try (Closeable p = new SystemPropertyRule("alluxio.worker.tieredstore.level0.alias", alias)
.toResource()) {
resetConf();
mConfiguration.validate();
fail("Should have thrown a runtime exception when using an unknown tier alias");
} catch (RuntimeException e) {
assertTrue(e.getMessage().contains(
String.format("Alias \"%s\" on tier 0 on worker (configured by %s) is not found "
+ "in global tiered", alias, Template.WORKER_TIERED_STORE_LEVEL_ALIAS.format(0))
));
}
}
}

@Test
public void wrongTieredStorageLevel() throws Exception {
try (Closeable p =
new SystemPropertyRule(ImmutableMap.of("alluxio.master.tieredstore.global.levels", "1",
"alluxio.worker.tieredstore.levels", "2")).toResource()) {
resetConf();
mConfiguration.validate();
fail("Should have thrown a runtime exception when setting an unknown tier level");
} catch (RuntimeException e) {
assertTrue(e.getMessage().contains(
String.format("%s tiers on worker (configured by %s), larger than global %s tiers "
+ "(configured by %s) ", 2, PropertyKey.WORKER_TIERED_STORE_LEVELS, 1,
PropertyKey.MASTER_TIERED_STORE_GLOBAL_LEVELS)));
}
}
}

0 comments on commit d460b7d

Please sign in to comment.
You can’t perform that action at this time.