HDDS-1684. OM should create Ratis related dirs only if ratis is enabled (#965)

This commit is contained in:
Hanisha Koneru 2019-06-18 16:08:48 -07:00 committed by GitHub
parent 37bd5bb342
commit 2dfa932818
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 50 deletions

View File

@ -74,12 +74,12 @@ public class TestHddsDispatcher {
String testDir = GenericTestUtils.getTempPath(
TestHddsDispatcher.class.getSimpleName());
OzoneConfiguration conf = new OzoneConfiguration();
conf.set(HDDS_DATANODE_DIR_KEY, testDir);
DatanodeDetails dd = randomDatanodeDetails();
VolumeSet volumeSet = new VolumeSet(dd.getUuidString(), conf);
try {
UUID scmId = UUID.randomUUID();
conf.set(HDDS_DATANODE_DIR_KEY, testDir);
ContainerSet containerSet = new ContainerSet();
DatanodeStateMachine stateMachine = Mockito.mock(

View File

@ -85,7 +85,6 @@ import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_OPEN_KEY_EXPIRE_THRE
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_ADDRESS_KEY;
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.VOLUME_NOT_FOUND;
import org.apache.ratis.util.LifeCycle;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@ -1365,27 +1364,6 @@ public class TestOzoneManager {
conf.get(OZONE_SCM_CLIENT_ADDRESS_KEY)), scmAddress);
}
/**
* Test that OM Ratis server is started only when OZONE_OM_RATIS_ENABLE_KEY is
* set to true.
*/
@Test
public void testRatisServerOnOMInitialization() throws IOException {
// OM Ratis server should not be started when OZONE_OM_RATIS_ENABLE_KEY
// is not set to true
Assert.assertNull("OM Ratis server started though OM Ratis is disabled.",
cluster.getOzoneManager().getOmRatisServerState());
// Enable OM Ratis and restart OM
conf.setBoolean(OMConfigKeys.OZONE_OM_RATIS_ENABLE_KEY, true);
cluster.restartOzoneManager();
// On enabling OM Ratis, the Ratis server should be started
Assert.assertEquals("OM Ratis server did not start",
LifeCycle.State.RUNNING,
cluster.getOzoneManager().getOmRatisServerState());
}
@Test
public void testVersion() {
String expectedVersion = OzoneVersionInfo.OZONE_VERSION_INFO.getVersion();

View File

@ -63,6 +63,7 @@ public class TestOzoneManagerSnapshotProvider {
clusterId = UUID.randomUUID().toString();
scmId = UUID.randomUUID().toString();
conf.setBoolean(OMConfigKeys.OZONE_OM_HTTP_ENABLED_KEY, true);
conf.setBoolean(OMConfigKeys.OZONE_OM_RATIS_ENABLE_KEY, true);
cluster = (MiniOzoneHAClusterImpl) MiniOzoneCluster.newHABuilder(conf)
.setClusterId(clusterId)
.setScmId(scmId)

View File

@ -313,12 +313,33 @@ public final class OzoneManager extends ServiceRuntimeInfoImpl
ProtobufRpcEngine.class);
metadataManager = new OmMetadataManagerImpl(configuration);
// This is a temporary check. Once fully implemented, all OM state change
// should go through Ratis - be it standalone (for non-HA) or replicated
// (for HA).
isRatisEnabled = configuration.getBoolean(
OMConfigKeys.OZONE_OM_RATIS_ENABLE_KEY,
OMConfigKeys.OZONE_OM_RATIS_ENABLE_DEFAULT);
startRatisServer();
startRatisClient();
if (peerNodes != null && !peerNodes.isEmpty()) {
this.omSnapshotProvider = new OzoneManagerSnapshotProvider(configuration,
omRatisSnapshotDir, peerNodes);
if (isRatisEnabled) {
// Create Ratis storage dir
String omRatisDirectory = OmUtils.getOMRatisDirectory(configuration);
if (omRatisDirectory == null || omRatisDirectory.isEmpty()) {
throw new IllegalArgumentException(HddsConfigKeys.OZONE_METADATA_DIRS +
" must be defined.");
}
OmUtils.createOMDir(omRatisDirectory);
// Create Ratis snapshot dir
omRatisSnapshotDir = OmUtils.createOMDir(
OmUtils.getOMRatisSnapshotDirectory(configuration));
if (peerNodes != null && !peerNodes.isEmpty()) {
this.omSnapshotProvider = new OzoneManagerSnapshotProvider(
configuration, omRatisSnapshotDir, peerNodes);
}
}
this.ratisSnapshotFile = new File(omStorage.getCurrentDir(),
@ -542,18 +563,6 @@ public final class OzoneManager extends ServiceRuntimeInfoImpl
configuration.set(OZONE_OM_ADDRESS_KEY,
NetUtils.getHostPortString(rpcAddress));
// Create Ratis storage dir
String omRatisDirectory = OmUtils.getOMRatisDirectory(configuration);
if (omRatisDirectory == null || omRatisDirectory.isEmpty()) {
throw new IllegalArgumentException(HddsConfigKeys.OZONE_METADATA_DIRS +
" must be defined.");
}
OmUtils.createOMDir(omRatisDirectory);
// Create Ratis snapshot dir
omRatisSnapshotDir = OmUtils.createOMDir(
OmUtils.getOMRatisSnapshotDirectory(configuration));
// Get and set Http(s) address of local node. If base config keys are
// not set, check for keys suffixed with OM serivce ID and node ID.
setOMNodeSpecificConfigs(serviceId, nodeId);
@ -1253,12 +1262,6 @@ public final class OzoneManager extends ServiceRuntimeInfoImpl
* Creates an instance of ratis server.
*/
private void startRatisServer() throws IOException {
// This is a temporary check. Once fully implemented, all OM state change
// should go through Ratis - be it standalone (for non-HA) or replicated
// (for HA).
isRatisEnabled = configuration.getBoolean(
OMConfigKeys.OZONE_OM_RATIS_ENABLE_KEY,
OMConfigKeys.OZONE_OM_RATIS_ENABLE_DEFAULT);
if (isRatisEnabled) {
if (omRatisServer == null) {
omRatisServer = OzoneManagerRatisServer.newOMRatisServer(
@ -1277,12 +1280,6 @@ public final class OzoneManager extends ServiceRuntimeInfoImpl
* Creates an instance of ratis client.
*/
private void startRatisClient() throws IOException {
// This is a temporary check. Once fully implemented, all OM state change
// should go through Ratis - be it standalone (for non-HA) or replicated
// (for HA).
isRatisEnabled = configuration.getBoolean(
OMConfigKeys.OZONE_OM_RATIS_ENABLE_KEY,
OMConfigKeys.OZONE_OM_RATIS_ENABLE_DEFAULT);
if (isRatisEnabled) {
if (omRatisClient == null) {
omRatisClient = OzoneManagerRatisClient.newOzoneManagerRatisClient(