HDDS-1475 : Fix OzoneContainer start method. (#788)
This commit is contained in:
parent
7f0e2c67e0
commit
eb9c8900bc
@ -69,6 +69,7 @@ public final class XceiverServerGrpc extends XceiverServer {
|
|||||||
private UUID id;
|
private UUID id;
|
||||||
private Server server;
|
private Server server;
|
||||||
private final ContainerDispatcher storageContainer;
|
private final ContainerDispatcher storageContainer;
|
||||||
|
private boolean isStarted;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a Grpc server class.
|
* Constructs a Grpc server class.
|
||||||
@ -161,12 +162,18 @@ public HddsProtos.ReplicationType getServerType() {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() throws IOException {
|
public void start() throws IOException {
|
||||||
|
if (!isStarted) {
|
||||||
server.start();
|
server.start();
|
||||||
|
isStarted = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
|
if (isStarted) {
|
||||||
server.shutdown();
|
server.shutdown();
|
||||||
|
isStarted = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -111,6 +111,7 @@ private static long nextCallId() {
|
|||||||
private final ReplicationLevel replicationLevel;
|
private final ReplicationLevel replicationLevel;
|
||||||
private long nodeFailureTimeoutMs;
|
private long nodeFailureTimeoutMs;
|
||||||
private final long cacheEntryExpiryInteval;
|
private final long cacheEntryExpiryInteval;
|
||||||
|
private boolean isStarted = false;
|
||||||
|
|
||||||
private XceiverServerRatis(DatanodeDetails dd, int port,
|
private XceiverServerRatis(DatanodeDetails dd, int port,
|
||||||
ContainerDispatcher dispatcher, Configuration conf, StateContext
|
ContainerDispatcher dispatcher, Configuration conf, StateContext
|
||||||
@ -413,24 +414,30 @@ public static XceiverServerRatis newXceiverServerRatis(
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() throws IOException {
|
public void start() throws IOException {
|
||||||
|
if (!isStarted) {
|
||||||
LOG.info("Starting {} {} at port {}", getClass().getSimpleName(),
|
LOG.info("Starting {} {} at port {}", getClass().getSimpleName(),
|
||||||
server.getId(), getIPCPort());
|
server.getId(), getIPCPort());
|
||||||
chunkExecutor.prestartAllCoreThreads();
|
chunkExecutor.prestartAllCoreThreads();
|
||||||
server.start();
|
server.start();
|
||||||
|
isStarted = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
|
if (isStarted) {
|
||||||
try {
|
try {
|
||||||
// shutdown server before the executors as while shutting down,
|
// shutdown server before the executors as while shutting down,
|
||||||
// some of the tasks would be executed using the executors.
|
// some of the tasks would be executed using the executors.
|
||||||
server.close();
|
server.close();
|
||||||
chunkExecutor.shutdown();
|
chunkExecutor.shutdown();
|
||||||
executors.forEach(ExecutorService::shutdown);
|
executors.forEach(ExecutorService::shutdown);
|
||||||
|
isStarted = false;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getIPCPort() {
|
public int getIPCPort() {
|
||||||
|
@ -160,7 +160,9 @@ private void startContainerScrub() {
|
|||||||
LOG.info("Background container scrubber has been disabled by {}",
|
LOG.info("Background container scrubber has been disabled by {}",
|
||||||
HddsConfigKeys.HDDS_CONTAINERSCRUB_ENABLED);
|
HddsConfigKeys.HDDS_CONTAINERSCRUB_ENABLED);
|
||||||
} else {
|
} else {
|
||||||
|
if (this.scrubber == null) {
|
||||||
this.scrubber = new ContainerScrubber(containerSet, config);
|
this.scrubber = new ContainerScrubber(containerSet, config);
|
||||||
|
}
|
||||||
scrubber.up();
|
scrubber.up();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,6 +98,59 @@ public void testCreateOzoneContainer() throws Exception {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOzoneContainerStart() throws Exception {
|
||||||
|
OzoneConfiguration conf = newOzoneConfiguration();
|
||||||
|
MiniOzoneCluster cluster = null;
|
||||||
|
OzoneContainer container = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
cluster = MiniOzoneCluster.newBuilder(conf).build();
|
||||||
|
cluster.waitForClusterToBeReady();
|
||||||
|
|
||||||
|
Pipeline pipeline = ContainerTestHelper.createSingleNodePipeline();
|
||||||
|
conf.set(HDDS_DATANODE_DIR_KEY, tempFolder.getRoot().getPath());
|
||||||
|
conf.setInt(OzoneConfigKeys.DFS_CONTAINER_IPC_PORT,
|
||||||
|
pipeline.getFirstNode()
|
||||||
|
.getPort(DatanodeDetails.Port.Name.STANDALONE).getValue());
|
||||||
|
conf.setBoolean(
|
||||||
|
OzoneConfigKeys.DFS_CONTAINER_IPC_RANDOM_PORT, false);
|
||||||
|
|
||||||
|
|
||||||
|
DatanodeDetails datanodeDetails = TestUtils.randomDatanodeDetails();
|
||||||
|
StateContext context = Mockito.mock(StateContext.class);
|
||||||
|
DatanodeStateMachine dsm = Mockito.mock(DatanodeStateMachine.class);
|
||||||
|
Mockito.when(dsm.getDatanodeDetails()).thenReturn(datanodeDetails);
|
||||||
|
Mockito.when(context.getParent()).thenReturn(dsm);
|
||||||
|
container = new OzoneContainer(datanodeDetails, conf,
|
||||||
|
context, null);
|
||||||
|
|
||||||
|
String scmId = UUID.randomUUID().toString();
|
||||||
|
container.start(scmId);
|
||||||
|
try {
|
||||||
|
container.start(scmId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Assert.fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
container.stop();
|
||||||
|
try {
|
||||||
|
container.stop();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Assert.fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
if (container != null) {
|
||||||
|
container.stop();
|
||||||
|
}
|
||||||
|
if (cluster != null) {
|
||||||
|
cluster.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static OzoneConfiguration newOzoneConfiguration() {
|
static OzoneConfiguration newOzoneConfiguration() {
|
||||||
final OzoneConfiguration conf = new OzoneConfiguration();
|
final OzoneConfiguration conf = new OzoneConfiguration();
|
||||||
return conf;
|
return conf;
|
||||||
|
Loading…
Reference in New Issue
Block a user