Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.hdds.annotation.InterfaceStability;
import org.apache.hadoop.hdds.scm.DatanodeAdminError;
import org.apache.hadoop.hdds.scm.container.ContainerReplicaInfo;
import org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline;
import org.apache.hadoop.hdds.scm.container.ContainerInfo;
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
Expand Down Expand Up @@ -70,6 +71,16 @@ public interface ScmClient extends Closeable {
ContainerWithPipeline getContainerWithPipeline(long containerId)
throws IOException;

/**
* Gets the list of ReplicaInfo known by SCM for a given container.
* @param containerId - The Container ID
* @return List of ContainerReplicaInfo for the container or an empty list
* if none.
* @throws IOException
*/
List<ContainerReplicaInfo> getContainerReplicas(
long containerId) throws IOException;

/**
* Close a container.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hdds.scm.container;

import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;

import java.util.UUID;

/**
* Class which stores ContainerReplica details on the client.
*/
public final class ContainerReplicaInfo {

private long containerID;
private String state;
private DatanodeDetails datanodeDetails;
private UUID placeOfBirth;
private long sequenceId;
private long keyCount;
private long bytesUsed;

public static ContainerReplicaInfo fromProto(
HddsProtos.SCMContainerReplicaProto proto) {
ContainerReplicaInfo.Builder builder = new ContainerReplicaInfo.Builder();
builder.setContainerID(proto.getContainerID())
.setState(proto.getState())
.setDatanodeDetails(DatanodeDetails
.getFromProtoBuf(proto.getDatanodeDetails()))
.setPlaceOfBirth(UUID.fromString(proto.getPlaceOfBirth()))
.setSequenceId(proto.getSequenceID())
.setKeyCount(proto.getKeyCount())
.setBytesUsed(proto.getBytesUsed());
return builder.build();
}

private ContainerReplicaInfo() {
}

public long getContainerID() {
return containerID;
}

public String getState() {
return state;
}

public DatanodeDetails getDatanodeDetails() {
return datanodeDetails;
}

public UUID getPlaceOfBirth() {
return placeOfBirth;
}

public long getSequenceId() {
return sequenceId;
}

public long getKeyCount() {
return keyCount;
}

public long getBytesUsed() {
return bytesUsed;
}

/**
* Builder for ContainerReplicaInfo class.
*/
public static class Builder {

private final ContainerReplicaInfo subject = new ContainerReplicaInfo();

public Builder setContainerID(long containerID) {
subject.containerID = containerID;
return this;
}

public Builder setState(String state) {
subject.state = state;
return this;
}

public Builder setDatanodeDetails(DatanodeDetails datanodeDetails) {
subject.datanodeDetails = datanodeDetails;
return this;
}

public Builder setPlaceOfBirth(UUID placeOfBirth) {
subject.placeOfBirth = placeOfBirth;
return this;
}

public Builder setSequenceId(long sequenceId) {
subject.sequenceId = sequenceId;
return this;
}

public Builder setKeyCount(long keyCount) {
subject.keyCount = keyCount;
return this;
}

public Builder setBytesUsed(long bytesUsed) {
subject.bytesUsed = bytesUsed;
return this;
}

public ContainerReplicaInfo build() {
return subject;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ ContainerWithPipeline allocateContainer(
ContainerWithPipeline getContainerWithPipeline(long containerID)
throws IOException;

/**
* Gets the list of ReplicaInfo known by SCM for a given container.
* @param containerId ID of the container
* @return List of ReplicaInfo for the container or an empty list if none.
* @throws IOException
*/
List<HddsProtos.SCMContainerReplicaProto>
getContainerReplicas(long containerId) throws IOException;

/**
* Ask SCM the location of a batch of containers. SCM responds with a group of
* nodes where these containers and their replicas are located.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hdds.scm.container;

import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdds.protocol.MockDatanodeDetails;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.junit.Assert;
import org.junit.Test;

import java.util.UUID;

/**
* Test for the ContainerReplicaInfo class.
*/
public class TestContainerReplicaInfo {

@Test
public void testObjectCreatedFromProto() {
HddsProtos.SCMContainerReplicaProto proto =
HddsProtos.SCMContainerReplicaProto.newBuilder()
.setKeyCount(10)
.setBytesUsed(12345)
.setContainerID(567)
.setPlaceOfBirth(UUID.randomUUID().toString())
.setSequenceID(5)
.setDatanodeDetails(MockDatanodeDetails.randomDatanodeDetails()
.getProtoBufMessage())
.setState("OPEN")
.build();

ContainerReplicaInfo info = ContainerReplicaInfo.fromProto(proto);

Assert.assertEquals(proto.getContainerID(), info.getContainerID());
Assert.assertEquals(proto.getBytesUsed(), info.getBytesUsed());
Assert.assertEquals(proto.getKeyCount(), info.getKeyCount());
Assert.assertEquals(proto.getPlaceOfBirth(),
info.getPlaceOfBirth().toString());
Assert.assertEquals(DatanodeDetails.getFromProtoBuf(
proto.getDatanodeDetails()), info.getDatanodeDetails());
Assert.assertEquals(proto.getSequenceID(), info.getSequenceId());
Assert.assertEquals(proto.getState(), info.getState());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
Test cases for SCM container client classes.
*/
package org.apache.hadoop.hdds.scm.container;
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ForceExitSafeModeRequestProto;
import org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ForceExitSafeModeResponseProto;
import org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetContainerRequestProto;
import org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetContainerReplicasRequestProto;
import org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetContainerTokenRequestProto;
import org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetContainerTokenResponseProto;
import org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetContainerWithPipelineBatchRequestProto;
Expand Down Expand Up @@ -251,6 +252,26 @@ public ContainerWithPipeline getContainerWithPipeline(long containerID)

}

/**
* {@inheritDoc}
*/
@Override
public List<HddsProtos.SCMContainerReplicaProto>
getContainerReplicas(long containerID) throws IOException {
Preconditions.checkState(containerID >= 0,
"Container ID cannot be negative");

GetContainerReplicasRequestProto request =
GetContainerReplicasRequestProto.newBuilder()
.setTraceID(TracingUtil.exportCurrentSpan())
.setContainerID(containerID).build();

ScmContainerLocationResponse response =
submitRequest(Type.GetContainerReplicas,
(builder) -> builder.setGetContainerReplicasRequest(request));
return response.getGetContainerReplicasResponse().getContainerReplicaList();
}

/**
* {@inheritDoc}
*/
Expand Down
12 changes: 12 additions & 0 deletions hadoop-hdds/interface-admin/src/main/proto/ScmAdminProtocol.proto
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ message ScmContainerLocationRequest {
optional FinalizeScmUpgradeRequestProto finalizeScmUpgradeRequest = 36;
optional QueryUpgradeFinalizationProgressRequestProto queryUpgradeFinalizationProgressRequest = 37;
optional GetContainerCountRequestProto getContainerCountRequest = 38;
optional GetContainerReplicasRequestProto getContainerReplicasRequest = 39;
}

message ScmContainerLocationResponse {
Expand Down Expand Up @@ -121,6 +122,7 @@ message ScmContainerLocationResponse {
optional FinalizeScmUpgradeResponseProto finalizeScmUpgradeResponse = 36;
optional QueryUpgradeFinalizationProgressResponseProto queryUpgradeFinalizationProgressResponse = 37;
optional GetContainerCountResponseProto getContainerCountResponse = 38;
optional GetContainerReplicasResponseProto getContainerReplicasResponse = 39;

enum Status {
OK = 1;
Expand Down Expand Up @@ -165,6 +167,7 @@ enum Type {
FinalizeScmUpgrade = 31;
QueryUpgradeFinalizationProgress = 32;
GetContainerCount = 33;
GetContainerReplicas = 34;
}

/**
Expand Down Expand Up @@ -213,6 +216,15 @@ message GetContainerWithPipelineResponseProto {
required ContainerWithPipeline containerWithPipeline = 1;
}

message GetContainerReplicasRequestProto {
required int64 containerID = 1;
optional string traceID = 2;
}

message GetContainerReplicasResponseProto {
repeated SCMContainerReplicaProto containerReplica = 1;
}

message GetContainerWithPipelineBatchRequestProto {
repeated int64 containerIDs = 1;
optional string traceID = 2;
Expand Down
9 changes: 9 additions & 0 deletions hadoop-hdds/interface-client/src/main/proto/hdds.proto
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,12 @@ message ContainerReplicaHistoryProto {
required int64 bcsId = 4;
}

message SCMContainerReplicaProto {
required int64 containerID = 1;
required string state = 2;
required DatanodeDetailsProto datanodeDetails = 3;
required string placeOfBirth = 4;
required int64 sequenceID = 5;
required int64 keyCount = 6;
required int64 bytesUsed = 7;
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.FinalizeScmUpgradeResponseProto;
import org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ForceExitSafeModeRequestProto;
import org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ForceExitSafeModeResponseProto;
import org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetContainerReplicasRequestProto;
import org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetContainerReplicasResponseProto;
import org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetContainerRequestProto;
import org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetContainerResponseProto;
import org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetContainerTokenRequestProto;
Expand Down Expand Up @@ -405,6 +407,13 @@ public ScmContainerLocationResponse processRequest(
.setGetContainerCountResponse(getContainerCount(
request.getGetContainerCountRequest()))
.build();
case GetContainerReplicas:
return ScmContainerLocationResponse.newBuilder()
.setCmdType(request.getCmdType())
.setStatus(Status.OK)
.setGetContainerReplicasResponse(getContainerReplicas(
request.getGetContainerReplicasRequest()))
.build();
default:
throw new IllegalArgumentException(
"Unknown command type: " + request.getCmdType());
Expand All @@ -416,6 +425,14 @@ public ScmContainerLocationResponse processRequest(
}
}

public GetContainerReplicasResponseProto getContainerReplicas(
GetContainerReplicasRequestProto request) throws IOException {
List<HddsProtos.SCMContainerReplicaProto> replicas
= impl.getContainerReplicas(request.getContainerID());
return GetContainerReplicasResponseProto.newBuilder()
.addAllContainerReplica(replicas).build();
}

public ContainerResponseProto allocateContainer(ContainerRequestProto request,
int clientVersion) throws IOException {
ContainerWithPipeline cp = impl
Expand Down
Loading