-
Notifications
You must be signed in to change notification settings - Fork 516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HDDS-10376. Add a Datanode API to supply a merkle tree for a given container. #6945
Changes from 8 commits
e600d15
737361f
76119bc
688353f
ca38c36
1737194
16a084a
46ddedb
e3afa53
6d55777
afac35a
7e57538
4ae022d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,122 @@ | ||||||
/* | ||||||
* 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 | ||||||
* <p> | ||||||
* http://www.apache.org/licenses/LICENSE-2.0 | ||||||
* <p> | ||||||
* 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.ozone.container.checksum; | ||||||
|
||||||
import com.google.common.collect.ImmutableList; | ||||||
import org.apache.hadoop.hdds.client.StandaloneReplicationConfig; | ||||||
import org.apache.hadoop.hdds.conf.ConfigurationSource; | ||||||
import org.apache.hadoop.hdds.protocol.DatanodeDetails; | ||||||
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos; | ||||||
import org.apache.hadoop.hdds.protocol.proto.HddsProtos; | ||||||
import org.apache.hadoop.hdds.scm.XceiverClientManager; | ||||||
import org.apache.hadoop.hdds.scm.XceiverClientSpi; | ||||||
import org.apache.hadoop.hdds.scm.client.ClientTrustManager; | ||||||
import org.apache.hadoop.hdds.scm.container.ContainerID; | ||||||
import org.apache.hadoop.hdds.scm.pipeline.Pipeline; | ||||||
import org.apache.hadoop.hdds.scm.pipeline.PipelineID; | ||||||
import org.apache.hadoop.hdds.scm.storage.ContainerProtocolCalls; | ||||||
import org.apache.hadoop.hdds.security.SecurityConfig; | ||||||
import org.apache.hadoop.hdds.security.symmetric.SecretKeySignerClient; | ||||||
import org.apache.hadoop.hdds.security.x509.certificate.client.CACertificateProvider; | ||||||
import org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClient; | ||||||
import org.apache.hadoop.hdds.utils.HAUtils; | ||||||
import org.apache.hadoop.ozone.OzoneSecurityUtil; | ||||||
import jakarta.annotation.Nonnull; | ||||||
import org.apache.hadoop.ozone.container.common.helpers.TokenHelper; | ||||||
import org.apache.hadoop.ozone.container.common.statemachine.DatanodeConfiguration; | ||||||
import org.apache.ratis.thirdparty.com.google.protobuf.ByteString; | ||||||
import org.slf4j.Logger; | ||||||
import org.slf4j.LoggerFactory; | ||||||
|
||||||
import java.io.IOException; | ||||||
|
||||||
import static org.apache.hadoop.ozone.container.common.helpers.TokenHelper.encode; | ||||||
|
||||||
/** | ||||||
* This class wraps necessary container-level rpc calls for container reconcilitaion. | ||||||
aswinshakil marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
* - GetContainerMerkleTree | ||||||
*/ | ||||||
public class DNContainerOperationClient implements AutoCloseable { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We want to keep this generic so that we can merge this with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can rename it then. |
||||||
|
||||||
private static final Logger LOG = | ||||||
LoggerFactory.getLogger(DNContainerOperationClient.class); | ||||||
private final TokenHelper tokenHelper; | ||||||
private final XceiverClientManager xceiverClientManager; | ||||||
|
||||||
public DNContainerOperationClient(ConfigurationSource conf, | ||||||
CertificateClient certificateClient, | ||||||
SecretKeySignerClient secretKeyClient) throws IOException { | ||||||
this.tokenHelper = new TokenHelper(new SecurityConfig(conf), secretKeyClient); | ||||||
this.xceiverClientManager = createClientManager(conf, certificateClient); | ||||||
} | ||||||
|
||||||
@Nonnull | ||||||
private static XceiverClientManager createClientManager( | ||||||
ConfigurationSource conf, CertificateClient certificateClient) | ||||||
throws IOException { | ||||||
ClientTrustManager trustManager = null; | ||||||
if (OzoneSecurityUtil.isSecurityEnabled(conf)) { | ||||||
CACertificateProvider localCaCerts = | ||||||
() -> HAUtils.buildCAX509List(certificateClient, conf); | ||||||
CACertificateProvider remoteCacerts = | ||||||
() -> HAUtils.buildCAX509List(null, conf); | ||||||
trustManager = new ClientTrustManager(remoteCacerts, localCaCerts); | ||||||
} | ||||||
DatanodeConfiguration dnConf = conf.getObject(DatanodeConfiguration.class); | ||||||
return new XceiverClientManager(conf, | ||||||
new XceiverClientManager.XceiverClientManagerConfigBuilder() | ||||||
.setMaxCacheSize(dnConf.getContainerClientCacheSize()) | ||||||
.setStaleThresholdMs(dnConf.getContainerClientCacheStaleThreshold()) | ||||||
Comment on lines
+83
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the expected behavior to cache clients ? Is the client per Datanode? We do not expect much concurrency on the client, so should the threshold be longer ? |
||||||
.build(), trustManager); | ||||||
} | ||||||
|
||||||
public XceiverClientManager getXceiverClientManager() { | ||||||
return xceiverClientManager; | ||||||
aswinshakil marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
|
||||||
public ByteString getContainerMerkleTree(long containerId, DatanodeDetails dn) | ||||||
throws IOException { | ||||||
XceiverClientSpi xceiverClient = this.xceiverClientManager.acquireClient(createSingleNodePipeline(dn)); | ||||||
try { | ||||||
String containerToken = encode(tokenHelper.getContainerToken( | ||||||
ContainerID.valueOf(containerId))); | ||||||
ContainerProtos.GetContainerMerkleTreeResponseProto response = | ||||||
ContainerProtocolCalls.getContainerMerkleTree(xceiverClient, | ||||||
containerId, containerToken); | ||||||
return response.getContainerMerkleTree(); | ||||||
} finally { | ||||||
this.xceiverClientManager.releaseClient(xceiverClient, false); | ||||||
} | ||||||
} | ||||||
|
||||||
private Pipeline createSingleNodePipeline(DatanodeDetails dn) { | ||||||
return Pipeline.newBuilder() | ||||||
.setNodes(ImmutableList.of(dn)) | ||||||
.setId(PipelineID.valueOf(dn.getUuid())) | ||||||
.setState(Pipeline.PipelineState.CLOSED) | ||||||
.setReplicationConfig(StandaloneReplicationConfig.getInstance( | ||||||
HddsProtos.ReplicationFactor.ONE)).build(); | ||||||
} | ||||||
|
||||||
@Override | ||||||
public void close() throws IOException { | ||||||
if (xceiverClientManager != null) { | ||||||
xceiverClientManager.close(); | ||||||
} | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not build it here, also this can be a WARN as post upgrade all containers won't have a checksum tree file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, building the tree would be handled in the layer above based on the result of this method. We can update the comment. I'm actually thinking we should debug log here because this will get printed for every container the scanner encounters in the first run.