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 @@ -69,16 +69,20 @@ public class ContainerOperationClient implements ScmClient {
private final StorageContainerLocationProtocol
storageContainerLocationClient;
private final boolean containerTokenEnabled;
private final OzoneConfiguration configuration;
private XceiverClientManager xceiverClientManager;

public XceiverClientManager getXceiverClientManager() {
public synchronized XceiverClientManager getXceiverClientManager()
throws IOException {
if (this.xceiverClientManager == null) {
this.xceiverClientManager = newXCeiverClientManager(configuration);
}
return xceiverClientManager;
}

private final XceiverClientManager xceiverClientManager;

public ContainerOperationClient(OzoneConfiguration conf) throws IOException {
public ContainerOperationClient(OzoneConfiguration conf) {
this.configuration = conf;
storageContainerLocationClient = newContainerRpcClient(conf);
this.xceiverClientManager = newXCeiverClientManager(conf);
containerSizeB = (int) conf.getStorageSize(OZONE_SCM_CONTAINER_SIZE,
OZONE_SCM_CONTAINER_SIZE_DEFAULT, StorageUnit.BYTES);
boolean useRatis = conf.getBoolean(
Expand Down Expand Up @@ -125,13 +129,14 @@ public static StorageContainerLocationProtocol newContainerRpcClient(
public ContainerWithPipeline createContainer(String owner)
throws IOException {
XceiverClientSpi client = null;
XceiverClientManager clientManager = getXceiverClientManager();
try {
ContainerWithPipeline containerWithPipeline =
storageContainerLocationClient.
allocateContainer(replicationType, replicationFactor, owner);

Pipeline pipeline = containerWithPipeline.getPipeline();
client = xceiverClientManager.acquireClient(pipeline);
client = clientManager.acquireClient(pipeline);

Preconditions.checkState(
pipeline.isOpen(),
Expand All @@ -143,7 +148,7 @@ public ContainerWithPipeline createContainer(String owner)
return containerWithPipeline;
} finally {
if (client != null) {
xceiverClientManager.releaseClient(client, false);
clientManager.releaseClient(client, false);
}
}
}
Expand Down Expand Up @@ -231,20 +236,21 @@ private void createPipeline(XceiverClientSpi client, Pipeline pipeline)
public ContainerWithPipeline createContainer(HddsProtos.ReplicationType type,
HddsProtos.ReplicationFactor factor, String owner) throws IOException {
XceiverClientSpi client = null;
XceiverClientManager clientManager = getXceiverClientManager();
try {
// allocate container on SCM.
ContainerWithPipeline containerWithPipeline =
storageContainerLocationClient.allocateContainer(type, factor,
owner);
Pipeline pipeline = containerWithPipeline.getPipeline();
// connect to pipeline leader and allocate container on leader datanode.
client = xceiverClientManager.acquireClient(pipeline);
client = clientManager.acquireClient(pipeline);
createContainer(client,
containerWithPipeline.getContainerInfo().getContainerID());
return containerWithPipeline;
} finally {
if (client != null) {
xceiverClientManager.releaseClient(client, false);
clientManager.releaseClient(client, false);
}
}
}
Expand Down Expand Up @@ -333,7 +339,12 @@ public void closePipeline(HddsProtos.PipelineID pipelineID)
@Override
public void close() {
try {
xceiverClientManager.close();
if (xceiverClientManager != null) {
xceiverClientManager.close();
}
if (storageContainerLocationClient != null) {
storageContainerLocationClient.close();
}
} catch (Exception ex) {
LOG.error("Can't close " + this.getClass().getSimpleName(), ex);
}
Expand All @@ -351,10 +362,11 @@ public void close() {
public void deleteContainer(long containerId, Pipeline pipeline,
boolean force) throws IOException {
XceiverClientSpi client = null;
XceiverClientManager clientManager = getXceiverClientManager();
try {
String encodedToken = getEncodedContainerToken(containerId);

client = xceiverClientManager.acquireClient(pipeline);
client = clientManager.acquireClient(pipeline);
ContainerProtocolCalls
.deleteContainer(client, containerId, force, encodedToken);
storageContainerLocationClient
Expand All @@ -365,7 +377,7 @@ public void deleteContainer(long containerId, Pipeline pipeline,
}
} finally {
if (client != null) {
xceiverClientManager.releaseClient(client, false);
clientManager.releaseClient(client, false);
}
}
}
Expand Down Expand Up @@ -409,11 +421,11 @@ public List<ContainerInfo> listContainer(long startContainerID,
@Override
public ContainerDataProto readContainer(long containerID,
Pipeline pipeline) throws IOException {
XceiverClientManager clientManager = getXceiverClientManager();
String encodedToken = getEncodedContainerToken(containerID);

XceiverClientSpi client = null;
try {
client = xceiverClientManager.acquireClientForReadData(pipeline);
client = clientManager.acquireClientForReadData(pipeline);
ReadContainerResponseProto response = ContainerProtocolCalls
.readContainer(client, containerID, encodedToken);
if (LOG.isDebugEnabled()) {
Expand All @@ -423,7 +435,7 @@ public ContainerDataProto readContainer(long containerID,
return response.getContainerData();
} finally {
if (client != null) {
xceiverClientManager.releaseClient(client, false);
clientManager.releaseClient(client, false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,12 @@ public class ScmOption {
private String scmServiceId;

public ScmClient createScmClient() {
try {
GenericParentCommand parent = (GenericParentCommand)
spec.root().userObject();
OzoneConfiguration conf = parent.createOzoneConfiguration();
checkAndSetSCMAddressArg(conf);
GenericParentCommand parent = (GenericParentCommand)
spec.root().userObject();
OzoneConfiguration conf = parent.createOzoneConfiguration();
checkAndSetSCMAddressArg(conf);

return new ContainerOperationClient(conf);
} catch (IOException ex) {
throw new IllegalArgumentException("Can't create SCM client", ex);
}
return new ContainerOperationClient(conf);
}

private void checkAndSetSCMAddressArg(MutableConfigurationSource conf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.apache.hadoop.ozone.insight;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -69,8 +68,7 @@ public List<LoggerSource> getRelatedLoggers(boolean verbose,
/**
* Create scm client.
*/
public ScmClient createScmClient(OzoneConfiguration ozoneConf)
throws IOException {
public ScmClient createScmClient(OzoneConfiguration ozoneConf) {
if (!HddsUtils.getHostNameFromConfigKeys(ozoneConf,
ScmConfigKeys.OZONE_SCM_CLIENT_ADDRESS_KEY).isPresent()) {

Expand Down