Skip to content

Commit

Permalink
HDDS-9544. Incorrect pipeline ID and state for closed container. (apa…
Browse files Browse the repository at this point in the history
  • Loading branch information
aryangupta1998 authored Nov 21, 2023
1 parent 546c390 commit a2f5faa
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
.ContainerWithPipeline;

import com.google.common.base.Preconditions;
import org.apache.hadoop.hdds.scm.ha.SCMHAUtils;
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
import org.apache.hadoop.hdds.scm.pipeline.PipelineID;
import org.apache.hadoop.hdds.scm.pipeline.PipelineNotFoundException;
import org.apache.hadoop.hdds.server.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -90,12 +92,14 @@ public void execute(ScmClient scmClient) throws IOException {
if (container.getPipeline().size() != 0) {
ContainerWithPipelineAndReplicas wrapper =
new ContainerWithPipelineAndReplicas(container.getContainerInfo(),
container.getPipeline(), replicas);
container.getPipeline(), replicas,
container.getContainerInfo().getPipelineID());
LOG.info(JsonUtils.toJsonStringWithDefaultPrettyPrinter(wrapper));
} else {
ContainerWithoutDatanodes wrapper =
new ContainerWithoutDatanodes(container.getContainerInfo(),
container.getPipeline(), replicas);
container.getPipeline(), replicas,
container.getContainerInfo().getPipelineID());
LOG.info(JsonUtils.toJsonStringWithDefaultPrettyPrinter(wrapper));
}
} else {
Expand All @@ -109,6 +113,21 @@ public void execute(ScmClient scmClient) throws IOException {
} else {
LOG.info("Pipeline id: {}", container.getPipeline().getId().getId());
}
LOG.info("Write PipelineId: {}",
container.getContainerInfo().getPipelineID().getId());
try {
String pipelineState = scmClient.getPipeline(
container.getContainerInfo().getPipelineID().getProtobuf())
.getPipelineState().toString();
LOG.info("Write Pipeline State: {}", pipelineState);
} catch (IOException ioe) {
if (SCMHAUtils.unwrapException(
ioe) instanceof PipelineNotFoundException) {
LOG.info("Write Pipeline State: CLOSED");
} else {
LOG.error("Failed to retrieve pipeline info");
}
}
LOG.info("Container State: {}", container.getContainerInfo().getState());

// Print pipeline of an existing container.
Expand Down Expand Up @@ -149,12 +168,14 @@ private static class ContainerWithPipelineAndReplicas {
private ContainerInfo containerInfo;
private Pipeline pipeline;
private List<ContainerReplicaInfo> replicas;
private PipelineID writePipelineID;

ContainerWithPipelineAndReplicas(ContainerInfo container, Pipeline pipeline,
List<ContainerReplicaInfo> replicas) {
List<ContainerReplicaInfo> replicas, PipelineID pipelineID) {
this.containerInfo = container;
this.pipeline = pipeline;
this.replicas = replicas;
this.writePipelineID = pipelineID;
}

public ContainerInfo getContainerInfo() {
Expand All @@ -168,19 +189,26 @@ public Pipeline getPipeline() {
public List<ContainerReplicaInfo> getReplicas() {
return replicas;
}

public PipelineID getWritePipelineID() {
return writePipelineID;
}

}

private static class ContainerWithoutDatanodes {

private ContainerInfo containerInfo;
private PipelineWithoutDatanodes pipeline;
private List<ContainerReplicaInfo> replicas;
private PipelineID writePipelineId;

ContainerWithoutDatanodes(ContainerInfo container, Pipeline pipeline,
List<ContainerReplicaInfo> replicas) {
List<ContainerReplicaInfo> replicas, PipelineID pipelineID) {
this.containerInfo = container;
this.pipeline = new PipelineWithoutDatanodes(pipeline);
this.replicas = replicas;
this.writePipelineId = pipelineID;
}

public ContainerInfo getContainerInfo() {
Expand All @@ -194,6 +222,10 @@ public PipelineWithoutDatanodes getPipeline() {
public List<ContainerReplicaInfo> getReplicas() {
return replicas;
}

public PipelineID getWritePipelineId() {
return writePipelineId;
}
}

// All Pipeline information except the ones dependent on datanodes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline;
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
import org.apache.hadoop.hdds.scm.pipeline.PipelineID;
import org.apache.hadoop.hdds.scm.pipeline.PipelineNotFoundException;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
Expand All @@ -49,6 +50,7 @@
import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState.CLOSED;
import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor.THREE;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;

/**
Expand Down Expand Up @@ -95,6 +97,8 @@ private void testReplicaIncludedInOutput(boolean includeIndex)
throws IOException {
Mockito.when(scmClient.getContainerReplicas(anyLong()))
.thenReturn(getReplicas(includeIndex));
Mockito.when(scmClient.getPipeline(any()))
.thenThrow(new PipelineNotFoundException("Pipeline not found."));
cmd = new InfoSubcommand();
CommandLine c = new CommandLine(cmd);
c.parseArgs("1");
Expand Down Expand Up @@ -135,6 +139,8 @@ private void testReplicaIncludedInOutput(boolean includeIndex)
public void testReplicasNotOutputIfError() throws IOException {
Mockito.when(scmClient.getContainerReplicas(anyLong()))
.thenThrow(new IOException("Error getting Replicas"));
Mockito.when(scmClient.getPipeline(any()))
.thenThrow(new PipelineNotFoundException("Pipeline not found."));
cmd = new InfoSubcommand();
CommandLine c = new CommandLine(cmd);
c.parseArgs("1");
Expand Down

0 comments on commit a2f5faa

Please sign in to comment.