Skip to content

Commit 14db15c

Browse files
HDDS-12376. Remove scmRatisEnabled from ScmInfo. (#7931)
1 parent 7d31d9e commit 14db15c

10 files changed

Lines changed: 44 additions & 160 deletions

File tree

hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/ScmInfo.java

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public final class ScmInfo {
2929
private final String clusterId;
3030
private final String scmId;
3131
private final List<String> peerRoles;
32-
private final boolean scmRatisEnabled;
3332

3433
/**
3534
* Builder for ScmInfo.
@@ -38,7 +37,6 @@ public static class Builder {
3837
private String clusterId;
3938
private String scmId;
4039
private final List<String> peerRoles;
41-
private boolean scmRatisEnabled;
4240

4341
public Builder() {
4442
peerRoles = new ArrayList<>();
@@ -66,36 +64,23 @@ public Builder setScmId(String id) {
6664

6765
/**
6866
* Set peer address in Scm HA.
69-
* @param roles ratis peer address in the format of [ip|hostname]:port
67+
* @param roles peer address in the format of [ip|hostname]:port
7068
* @return Builder for scmInfo
7169
*/
72-
public Builder setRatisPeerRoles(List<String> roles) {
70+
public Builder setPeerRoles(List<String> roles) {
7371
peerRoles.addAll(roles);
7472
return this;
7573
}
7674

77-
/**
78-
* Set whether SCM enables Ratis.
79-
*
80-
* @param ratisEnabled If it is true, it means that the Ratis mode is turned on.
81-
* If it is false, it means that the Ratis mode is not turned on.
82-
* @return Builder for scmInfo
83-
*/
84-
public Builder setScmRatisEnabled(boolean ratisEnabled) {
85-
scmRatisEnabled = ratisEnabled;
86-
return this;
87-
}
88-
8975
public ScmInfo build() {
90-
return new ScmInfo(clusterId, scmId, peerRoles, scmRatisEnabled);
76+
return new ScmInfo(clusterId, scmId, peerRoles);
9177
}
9278
}
9379

94-
private ScmInfo(String clusterId, String scmId, List<String> peerRoles, boolean ratisEnabled) {
80+
private ScmInfo(String clusterId, String scmId, List<String> peerRoles) {
9581
this.clusterId = clusterId;
9682
this.scmId = scmId;
9783
this.peerRoles = Collections.unmodifiableList(peerRoles);
98-
this.scmRatisEnabled = ratisEnabled;
9984
}
10085

10186
/**
@@ -115,14 +100,11 @@ public String getScmId() {
115100
}
116101

117102
/**
118-
* Gets the list of peer roles (currently address) in Scm HA.
103+
* Gets the list of peer roles (currently address) in SCM.
119104
* @return List of peer address
120105
*/
121-
public List<String> getRatisPeerRoles() {
106+
public List<String> getPeerRoles() {
122107
return peerRoles;
123108
}
124109

125-
public boolean getScmRatisEnabled() {
126-
return scmRatisEnabled;
127-
}
128110
}

hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/client/ScmClient.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -389,18 +389,9 @@ StartContainerBalancerResponseProto startContainerBalancer(
389389
ContainerBalancerStatusInfoResponseProto getContainerBalancerStatusInfo() throws IOException;
390390

391391
/**
392-
* returns the list of ratis peer roles. Currently only include peer address.
392+
* returns the list of SCM peer roles. Currently only include peer address.
393393
*/
394-
List<String> getScmRatisRoles() throws IOException;
395-
396-
/**
397-
* Get the current SCM mode.
398-
*
399-
* @return `true` indicates that it is in RATIS mode,
400-
* while `false` indicates that it is in STANDALONE mode.
401-
* @throws IOException an I/O exception of some sort has occurred.
402-
*/
403-
boolean isScmRatisEnable() throws IOException;
394+
List<String> getScmRoles() throws IOException;
404395

405396
/**
406397
* Force generates new secret keys (rotate).

hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/scm/protocolPB/StorageContainerLocationProtocolClientSideTranslatorPB.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -771,24 +771,7 @@ public ScmInfo getScmInfo() throws IOException {
771771
ScmInfo.Builder builder = new ScmInfo.Builder()
772772
.setClusterId(resp.getClusterId())
773773
.setScmId(resp.getScmId())
774-
.setRatisPeerRoles(resp.getPeerRolesList());
775-
776-
// By default, we assume that SCM Ratis is not enabled.
777-
778-
// If the response contains the `ScmRatisEnabled` field,
779-
// we will set it directly; otherwise,
780-
// we will determine if Ratis is enabled based on
781-
// whether the `peerRolesList` contains the keywords 'leader' or 'follower'.
782-
if (resp.hasScmRatisEnabled()) {
783-
builder.setScmRatisEnabled(resp.getScmRatisEnabled());
784-
} else {
785-
List<String> peerRolesList = resp.getPeerRolesList();
786-
if (!peerRolesList.isEmpty()) {
787-
boolean containsScmRoles = peerRolesList.stream().map(String::toLowerCase)
788-
.anyMatch(scmRatisRolesToCheck::contains);
789-
builder.setScmRatisEnabled(containsScmRoles);
790-
}
791-
}
774+
.setPeerRoles(resp.getPeerRolesList());
792775
return builder.build();
793776
}
794777

hadoop-hdds/interface-client/src/main/proto/hdds.proto

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ message GetScmInfoResponseProto {
269269
required string clusterId = 1;
270270
required string scmId = 2;
271271
repeated string peerRoles = 3;
272-
optional bool scmRatisEnabled = 4;
273272
}
274273

275274
message AddScmRequestProto {

hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/protocol/StorageContainerLocationProtocolServerSideTranslatorPB.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,8 +1000,7 @@ public HddsProtos.GetScmInfoResponseProto getScmInfo(
10001000
return HddsProtos.GetScmInfoResponseProto.newBuilder()
10011001
.setClusterId(scmInfo.getClusterId())
10021002
.setScmId(scmInfo.getScmId())
1003-
.addAllPeerRoles(scmInfo.getRatisPeerRoles())
1004-
.setScmRatisEnabled(scmInfo.getScmRatisEnabled())
1003+
.addAllPeerRoles(scmInfo.getPeerRoles())
10051004
.build();
10061005
}
10071006

hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMClientProtocolServer.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import java.net.InetSocketAddress;
4040
import java.time.Duration;
4141
import java.util.ArrayList;
42-
import java.util.Arrays;
4342
import java.util.Collections;
4443
import java.util.HashMap;
4544
import java.util.List;
@@ -812,20 +811,8 @@ public ScmInfo getScmInfo() {
812811
ScmInfo.Builder builder =
813812
new ScmInfo.Builder()
814813
.setClusterId(scm.getScmStorageConfig().getClusterID())
815-
.setScmId(scm.getScmStorageConfig().getScmId());
816-
if (scm.getScmHAManager().getRatisServer() != null) {
817-
builder.setRatisPeerRoles(
818-
scm.getScmHAManager().getRatisServer().getRatisRoles());
819-
builder.setScmRatisEnabled(true);
820-
} else {
821-
// In case, there is no ratis, there is no ratis role.
822-
// This will just print the hostname with ratis port as the default
823-
// behaviour.
824-
String address = scm.getSCMHANodeDetails().getLocalNodeDetails()
825-
.getRatisHostPortStr();
826-
builder.setRatisPeerRoles(Arrays.asList(address));
827-
builder.setScmRatisEnabled(false);
828-
}
814+
.setScmId(scm.getScmStorageConfig().getScmId())
815+
.setPeerRoles(scm.getScmHAManager().getRatisServer().getRatisRoles());
829816
return builder.build();
830817
} catch (Exception ex) {
831818
auditSuccess = false;

hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/ContainerOperationClient.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -532,13 +532,8 @@ public ContainerBalancerStatusInfoResponseProto getContainerBalancerStatusInfo()
532532
}
533533

534534
@Override
535-
public List<String> getScmRatisRoles() throws IOException {
536-
return storageContainerLocationClient.getScmInfo().getRatisPeerRoles();
537-
}
538-
539-
@Override
540-
public boolean isScmRatisEnable() throws IOException {
541-
return storageContainerLocationClient.getScmInfo().getScmRatisEnabled();
535+
public List<String> getScmRoles() throws IOException {
536+
return storageContainerLocationClient.getScmInfo().getPeerRoles();
542537
}
543538

544539
@Override

hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/StorageContainerServiceProviderImpl.java

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
import java.io.File;
3131
import java.io.IOException;
32-
import java.io.InputStream;
3332
import java.nio.file.Path;
3433
import java.nio.file.Paths;
3534
import java.util.List;
@@ -60,7 +59,6 @@
6059
import org.apache.hadoop.ozone.recon.scm.ReconStorageConfig;
6160
import org.apache.hadoop.ozone.recon.security.ReconCertificateClient;
6261
import org.apache.hadoop.ozone.recon.spi.StorageContainerServiceProvider;
63-
import org.apache.hadoop.security.SecurityUtil;
6462
import org.apache.ratis.proto.RaftProtos;
6563
import org.slf4j.Logger;
6664
import org.slf4j.LoggerFactory;
@@ -184,39 +182,30 @@ public DBCheckpoint getSCMDBSnapshot() {
184182
".tar");
185183
try {
186184
try {
187-
List<String> ratisRoles = scmClient.getScmInfo().getRatisPeerRoles();
185+
List<String> ratisRoles = scmClient.getScmInfo().getPeerRoles();
188186
for (String ratisRole : ratisRoles) {
189187
String[] role = ratisRole.split(":");
190-
// This explicit role length check is to support older versions where we cannot change the default value
191-
// without breaking backward compatibility during upgrade, because if Ratis is not enabled then the roles
192-
// command output is generated outside of Ratis. It will not have the Ratis terminologies.
193-
if (role.length > 2) {
194-
if (role[2].equals(RaftProtos.RaftPeerRole.LEADER.toString())) {
195-
String hostAddress = role[4].trim();
196-
int grpcPort = configuration.getInt(
197-
ScmConfigKeys.OZONE_SCM_GRPC_PORT_KEY,
198-
ScmConfigKeys.OZONE_SCM_GRPC_PORT_DEFAULT);
199-
200-
SecurityConfig secConf = new SecurityConfig(configuration);
201-
SCMSecurityProtocolClientSideTranslatorPB scmSecurityClient =
202-
getScmSecurityClientWithMaxRetry(
203-
configuration, getCurrentUser());
204-
try (ReconCertificateClient certClient =
205-
new ReconCertificateClient(
206-
secConf, scmSecurityClient, reconStorage, null, null);
207-
SCMSnapshotDownloader downloadClient = new InterSCMGrpcClient(
208-
hostAddress, grpcPort, configuration, certClient)) {
209-
downloadClient.download(targetFile.toPath()).get();
210-
} catch (ExecutionException | InterruptedException e) {
211-
LOG.error("Rocks DB checkpoint downloading failed: {}", e);
212-
throw new IOException(e);
213-
}
214-
LOG.info("Downloaded SCM Snapshot from Leader SCM");
215-
break;
188+
if (role[2].equals(RaftProtos.RaftPeerRole.LEADER.toString())) {
189+
String hostAddress = role[4].trim();
190+
int grpcPort = configuration.getInt(
191+
ScmConfigKeys.OZONE_SCM_GRPC_PORT_KEY,
192+
ScmConfigKeys.OZONE_SCM_GRPC_PORT_DEFAULT);
193+
194+
SecurityConfig secConf = new SecurityConfig(configuration);
195+
SCMSecurityProtocolClientSideTranslatorPB scmSecurityClient =
196+
getScmSecurityClientWithMaxRetry(
197+
configuration, getCurrentUser());
198+
try (ReconCertificateClient certClient =
199+
new ReconCertificateClient(
200+
secConf, scmSecurityClient, reconStorage, null, null);
201+
SCMSnapshotDownloader downloadClient = new InterSCMGrpcClient(
202+
hostAddress, grpcPort, configuration, certClient)) {
203+
downloadClient.download(targetFile.toPath()).get();
204+
} catch (ExecutionException | InterruptedException e) {
205+
LOG.error("Rocks DB checkpoint downloading failed: {}", e);
206+
throw new IOException(e);
216207
}
217-
} else {
218-
fetchSCMDBSnapshotUsingHttpClient(targetFile);
219-
LOG.info("Downloaded SCM Snapshot from SCM");
208+
LOG.info("Downloaded SCM Snapshot from Leader SCM");
220209
break;
221210
}
222211
}
@@ -233,17 +222,6 @@ public DBCheckpoint getSCMDBSnapshot() {
233222
return null;
234223
}
235224

236-
private void fetchSCMDBSnapshotUsingHttpClient(File targetFile) throws IOException {
237-
SecurityUtil.doAsLoginUser(() -> {
238-
try (InputStream inputStream = reconUtils.makeHttpCall(
239-
connectionFactory, getScmDBSnapshotUrl(),
240-
isOmSpnegoEnabled()).getInputStream()) {
241-
FileUtils.copyInputStreamToFile(inputStream, targetFile);
242-
}
243-
return null;
244-
});
245-
}
246-
247225
@NotNull
248226
private RocksDBCheckpoint getRocksDBCheckpoint(String snapshotFileName, File targetFile) throws IOException {
249227
Path untarredDbDir = Paths.get(scmSnapshotDBParentDir.getAbsolutePath(),

hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/scm/GetScmRatisRolesSubcommand.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,21 @@ public class GetScmRatisRolesSubcommand extends ScmSubcommand {
5858

5959
private static final String SCM_ROLES_TITLE = "Storage Container Manager Roles";
6060

61-
private static final List<String> RATIS_SCM_ROLES_HEADER = Arrays.asList(
61+
private static final List<String> SCM_ROLES_HEADER = Arrays.asList(
6262
"Host Name", "Ratis Port", "Role", "Node ID", "Host Address");
6363

64-
private static final List<String> STANDALONE_SCM_ROLES_HEADER = Arrays.asList("Host Name", "Port");
65-
6664
@Override
6765
public void execute(ScmClient scmClient) throws IOException {
68-
List<String> ratisRoles = scmClient.getScmRatisRoles();
69-
boolean isRatisEnabled = scmClient.isScmRatisEnable();
66+
List<String> peerRoles = scmClient.getScmRoles();
7067
if (json) {
71-
Map<String, Map<String, String>> scmRoles = parseScmRoles(ratisRoles);
68+
Map<String, Map<String, String>> scmRoles = parseScmRoles(peerRoles);
7269
System.out.print(
7370
JsonUtils.toJsonStringWithDefaultPrettyPrinter(scmRoles));
7471
} else if (table) {
7572
FormattingCLIUtils formattingCLIUtils = new FormattingCLIUtils(SCM_ROLES_TITLE);
73+
formattingCLIUtils.addHeaders(SCM_ROLES_HEADER);
7674

77-
// Determine which header to use based on whether Ratis is enabled or not.
78-
if (isRatisEnabled) {
79-
formattingCLIUtils.addHeaders(RATIS_SCM_ROLES_HEADER);
80-
} else {
81-
formattingCLIUtils.addHeaders(STANDALONE_SCM_ROLES_HEADER);
82-
}
83-
84-
for (String role : ratisRoles) {
75+
for (String role : peerRoles) {
8576
String[] roleItems = role.split(":");
8677
if (roleItems.length < 2) {
8778
err.println("Invalid response received for ScmRatisRoles.");
@@ -90,16 +81,16 @@ public void execute(ScmClient scmClient) throws IOException {
9081
}
9182
System.out.println(formattingCLIUtils.render());
9283
} else {
93-
for (String role: ratisRoles) {
84+
for (String role: peerRoles) {
9485
System.out.println(role);
9586
}
9687
}
9788
}
9889

9990
private Map<String, Map<String, String>> parseScmRoles(
100-
List<String> ratisRoles) {
91+
List<String> peerRoles) {
10192
Map<String, Map<String, String>> allRoles = new HashMap<>();
102-
for (String role : ratisRoles) {
93+
for (String role : peerRoles) {
10394
Map<String, String> roleDetails = new HashMap<>();
10495
String[] roles = role.split(":");
10596
if (roles.length < 2) {

hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/scm/TestGetScmRatisRolesSubcommand.java

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ public void testGetScmHARatisRoles() throws Exception {
4747
result.add("bigdata-ozone-online32:9894:LEADER:e428ca07-b2a3-4756-bf9b-a4abb033c7d1:100.3.192.89");
4848
result.add("bigdata-ozone-online30:9894:FOLLOWER:41f90734-b3ee-4284-ad96-40a286654952:100.3.196.51");
4949

50-
when(client.getScmRatisRoles()).thenAnswer(invocation -> result);
51-
when(client.isScmRatisEnable()).thenAnswer(invocation -> true);
50+
when(client.getScmRoles()).thenAnswer(invocation -> result);
5251

5352
try (GenericTestUtils.SystemOutCapturer capture =
5453
new GenericTestUtils.SystemOutCapturer()) {
@@ -62,24 +61,4 @@ public void testGetScmHARatisRoles() throws Exception {
6261
}
6362
}
6463

65-
@Test
66-
public void testGetScmStandAloneRoles() throws Exception {
67-
68-
GetScmRatisRolesSubcommand cmd = new GetScmRatisRolesSubcommand();
69-
ScmClient client = mock(ScmClient.class);
70-
CommandLine c = new CommandLine(cmd);
71-
c.parseArgs("--table");
72-
73-
List<String> result = new ArrayList<>();
74-
result.add("bigdata-ozone-online31:9894");
75-
76-
when(client.getScmRatisRoles()).thenAnswer(invocation -> result);
77-
when(client.isScmRatisEnable()).thenAnswer(invocation -> false);
78-
79-
try (GenericTestUtils.SystemOutCapturer capture =
80-
new GenericTestUtils.SystemOutCapturer()) {
81-
cmd.execute(client);
82-
assertThat(capture.getOutput()).contains("| bigdata-ozone-online31 | 9894 |");
83-
}
84-
}
8564
}

0 commit comments

Comments
 (0)