HDDS-624.PutBlock fails with Unexpected Storage Container Exception.

Contributed by  Arpit Agarwal.

(cherry picked from commit 02e1ef5e07)
This commit is contained in:
Anu Engineer 2018-10-12 14:22:46 -07:00
parent 252a44f8c1
commit 7daeaa9a98
4 changed files with 38 additions and 28 deletions

View File

@ -20,6 +20,7 @@ package org.apache.hadoop.utils;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.ozone.OzoneConfigKeys; import org.apache.hadoop.ozone.OzoneConfigKeys;
import org.iq80.leveldb.Options; import org.iq80.leveldb.Options;
import org.rocksdb.BlockBasedTableConfig; import org.rocksdb.BlockBasedTableConfig;
@ -30,6 +31,8 @@ import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Optional;
import java.util.function.Supplier;
import static org.apache.hadoop.ozone.OzoneConfigKeys import static org.apache.hadoop.ozone.OzoneConfigKeys
.OZONE_METADATA_STORE_IMPL_LEVELDB; .OZONE_METADATA_STORE_IMPL_LEVELDB;
@ -53,7 +56,7 @@ public class MetadataStoreBuilder {
private File dbFile; private File dbFile;
private long cacheSize; private long cacheSize;
private boolean createIfMissing = true; private boolean createIfMissing = true;
private Configuration conf; private Optional<Configuration> optionalConf = Optional.empty();
private String dbType; private String dbType;
public static MetadataStoreBuilder newBuilder() { public static MetadataStoreBuilder newBuilder() {
@ -76,7 +79,7 @@ public class MetadataStoreBuilder {
} }
public MetadataStoreBuilder setConf(Configuration configuration) { public MetadataStoreBuilder setConf(Configuration configuration) {
this.conf = configuration; this.optionalConf = Optional.of(configuration);
return this; return this;
} }
@ -98,13 +101,12 @@ public class MetadataStoreBuilder {
} }
// Build db store based on configuration // Build db store based on configuration
MetadataStore store = null; final Configuration conf = optionalConf.orElseGet(
() -> new OzoneConfiguration());
if(dbType == null) { if(dbType == null) {
LOG.debug("dbType is null, using "); LOG.debug("dbType is null, using ");
dbType = conf == null ? dbType = conf.getTrimmed(OzoneConfigKeys.OZONE_METADATA_STORE_IMPL,
OzoneConfigKeys.OZONE_METADATA_STORE_IMPL_DEFAULT :
conf.getTrimmed(OzoneConfigKeys.OZONE_METADATA_STORE_IMPL,
OzoneConfigKeys.OZONE_METADATA_STORE_IMPL_DEFAULT); OzoneConfigKeys.OZONE_METADATA_STORE_IMPL_DEFAULT);
LOG.debug("dbType is null, using dbType {} from ozone configuration", LOG.debug("dbType is null, using dbType {} from ozone configuration",
dbType); dbType);
@ -117,7 +119,7 @@ public class MetadataStoreBuilder {
if (cacheSize > 0) { if (cacheSize > 0) {
options.cacheSize(cacheSize); options.cacheSize(cacheSize);
} }
store = new LevelDBStore(dbFile, options); return new LevelDBStore(dbFile, options);
} else if (OZONE_METADATA_STORE_IMPL_ROCKSDB.equals(dbType)) { } else if (OZONE_METADATA_STORE_IMPL_ROCKSDB.equals(dbType)) {
org.rocksdb.Options opts = new org.rocksdb.Options(); org.rocksdb.Options opts = new org.rocksdb.Options();
opts.setCreateIfMissing(createIfMissing); opts.setCreateIfMissing(createIfMissing);
@ -128,10 +130,9 @@ public class MetadataStoreBuilder {
opts.setTableFormatConfig(tableConfig); opts.setTableFormatConfig(tableConfig);
} }
String rocksDbStat = conf == null ? String rocksDbStat = conf.getTrimmed(
OZONE_METADATA_STORE_ROCKSDB_STATISTICS_DEFAULT : OZONE_METADATA_STORE_ROCKSDB_STATISTICS,
conf.getTrimmed(OZONE_METADATA_STORE_ROCKSDB_STATISTICS, OZONE_METADATA_STORE_ROCKSDB_STATISTICS_DEFAULT);
OZONE_METADATA_STORE_ROCKSDB_STATISTICS_DEFAULT);
if (!rocksDbStat.equals(OZONE_METADATA_STORE_ROCKSDB_STATISTICS_OFF)) { if (!rocksDbStat.equals(OZONE_METADATA_STORE_ROCKSDB_STATISTICS_OFF)) {
Statistics statistics = new Statistics(); Statistics statistics = new Statistics();
@ -139,14 +140,13 @@ public class MetadataStoreBuilder {
opts = opts.setStatistics(statistics); opts = opts.setStatistics(statistics);
} }
store = new RocksDBStore(dbFile, opts); return new RocksDBStore(dbFile, opts);
} else {
throw new IllegalArgumentException("Invalid argument for "
+ OzoneConfigKeys.OZONE_METADATA_STORE_IMPL
+ ". Expecting " + OZONE_METADATA_STORE_IMPL_LEVELDB
+ " or " + OZONE_METADATA_STORE_IMPL_ROCKSDB
+ ", but met " + dbType);
} }
return store;
throw new IllegalArgumentException("Invalid argument for "
+ OzoneConfigKeys.OZONE_METADATA_STORE_IMPL
+ ". Expecting " + OZONE_METADATA_STORE_IMPL_LEVELDB
+ " or " + OZONE_METADATA_STORE_IMPL_ROCKSDB
+ ", but met " + dbType);
} }
} }

View File

@ -22,6 +22,7 @@ import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.ozone.OzoneConfigKeys; import org.apache.hadoop.ozone.OzoneConfigKeys;
import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import javax.management.MBeanServer; import javax.management.MBeanServer;
@ -32,15 +33,24 @@ import java.lang.management.ManagementFactory;
* Test the JMX interface for the rocksdb metastore implementation. * Test the JMX interface for the rocksdb metastore implementation.
*/ */
public class TestRocksDBStoreMBean { public class TestRocksDBStoreMBean {
Configuration conf;
@Before
public void init() throws Exception {
conf = new OzoneConfiguration();
conf.set(OzoneConfigKeys.OZONE_METADATA_STORE_IMPL,
OzoneConfigKeys.OZONE_METADATA_STORE_IMPL_ROCKSDB);
}
@Test @Test
public void testJmxBeans() throws Exception { public void testJmxBeans() throws Exception {
File testDir = File testDir =
GenericTestUtils.getTestDir(getClass().getSimpleName() + "-withstat"); GenericTestUtils.getTestDir(getClass().getSimpleName() + "-withstat");
Configuration conf = new OzoneConfiguration(); conf.set(OzoneConfigKeys.OZONE_METADATA_STORE_ROCKSDB_STATISTICS, "ALL");
conf.set(OzoneConfigKeys.OZONE_METADATA_STORE_IMPL,
OzoneConfigKeys.OZONE_METADATA_STORE_IMPL_ROCKSDB);
RocksDBStore metadataStore = RocksDBStore metadataStore =
(RocksDBStore) MetadataStoreBuilder.newBuilder().setConf(conf) (RocksDBStore) MetadataStoreBuilder.newBuilder().setConf(conf)
@ -72,9 +82,6 @@ public class TestRocksDBStoreMBean {
File testDir = GenericTestUtils File testDir = GenericTestUtils
.getTestDir(getClass().getSimpleName() + "-withoutstat"); .getTestDir(getClass().getSimpleName() + "-withoutstat");
Configuration conf = new OzoneConfiguration();
conf.set(OzoneConfigKeys.OZONE_METADATA_STORE_IMPL,
OzoneConfigKeys.OZONE_METADATA_STORE_IMPL_ROCKSDB);
conf.set(OzoneConfigKeys.OZONE_METADATA_STORE_ROCKSDB_STATISTICS, conf.set(OzoneConfigKeys.OZONE_METADATA_STORE_ROCKSDB_STATISTICS,
OzoneConfigKeys.OZONE_METADATA_STORE_ROCKSDB_STATISTICS_OFF); OzoneConfigKeys.OZONE_METADATA_STORE_ROCKSDB_STATISTICS_OFF);

View File

@ -123,10 +123,11 @@ public final class ContainerCache extends LRUMap {
* @param containerID - ID of the container. * @param containerID - ID of the container.
* @param containerDBType - DB type of the container. * @param containerDBType - DB type of the container.
* @param containerDBPath - DB path of the container. * @param containerDBPath - DB path of the container.
* @param conf - Hadoop Configuration.
* @return MetadataStore. * @return MetadataStore.
*/ */
public MetadataStore getDB(long containerID, String containerDBType, String public MetadataStore getDB(long containerID, String containerDBType,
containerDBPath) String containerDBPath, Configuration conf)
throws IOException { throws IOException {
Preconditions.checkState(containerID >= 0, Preconditions.checkState(containerID >= 0,
"Container ID cannot be negative."); "Container ID cannot be negative.");
@ -138,6 +139,7 @@ public final class ContainerCache extends LRUMap {
db = MetadataStoreBuilder.newBuilder() db = MetadataStoreBuilder.newBuilder()
.setDbFile(new File(containerDBPath)) .setDbFile(new File(containerDBPath))
.setCreateIfMissing(false) .setCreateIfMissing(false)
.setConf(conf)
.setDBType(containerDBType) .setDBType(containerDBType)
.build(); .build();
this.put(containerID, db); this.put(containerID, db);

View File

@ -75,7 +75,8 @@ public final class BlockUtils {
Preconditions.checkNotNull(containerData.getDbFile()); Preconditions.checkNotNull(containerData.getDbFile());
try { try {
return cache.getDB(containerData.getContainerID(), containerData return cache.getDB(containerData.getContainerID(), containerData
.getContainerDBType(), containerData.getDbFile().getAbsolutePath()); .getContainerDBType(), containerData.getDbFile().getAbsolutePath(),
conf);
} catch (IOException ex) { } catch (IOException ex) {
String message = String.format("Error opening DB. Container:%s " + String message = String.format("Error opening DB. Container:%s " +
"ContainerPath:%s", containerData.getContainerID(), containerData "ContainerPath:%s", containerData.getContainerID(), containerData