Skip to content

Commit f3a0dbd

Browse files
authored
HDDS-10937. Ozone Recon - Handle startup failure and log reasons as error due to SCM non-HA scenario (#6752)
1 parent d2ee09f commit f3a0dbd

6 files changed

Lines changed: 153 additions & 48 deletions

File tree

‎hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/recon/TestReconScmHASnapshot.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
/**
3232
* Test Recon SCM HA Snapshot Download implementation.
3333
*/
34-
@Timeout(100)
34+
@Timeout(300)
3535
public class TestReconScmHASnapshot {
3636
private OzoneConfiguration conf;
3737
private MiniOzoneCluster ozoneCluster = null;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.ozone.recon;
19+
20+
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
21+
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
22+
import org.apache.hadoop.ozone.MiniOzoneCluster;
23+
import org.junit.jupiter.api.AfterEach;
24+
import org.junit.jupiter.api.BeforeEach;
25+
import org.junit.jupiter.api.Test;
26+
import org.junit.jupiter.api.Timeout;
27+
28+
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_HA_ENABLE_KEY;
29+
30+
/**
31+
* Test Recon SCM HA Snapshot Download implementation.
32+
*/
33+
@Timeout(300)
34+
public class TestReconScmNonHASnapshot {
35+
private OzoneConfiguration conf;
36+
private MiniOzoneCluster ozoneCluster = null;
37+
38+
@BeforeEach
39+
public void setup() throws Exception {
40+
conf = new OzoneConfiguration();
41+
conf.setBoolean(OZONE_SCM_HA_ENABLE_KEY, false);
42+
conf.setBoolean(
43+
ReconServerConfigKeys.OZONE_RECON_SCM_SNAPSHOT_ENABLED, true);
44+
conf.setInt(ReconServerConfigKeys.OZONE_RECON_SCM_CONTAINER_THRESHOLD, 0);
45+
conf.setInt(ScmConfigKeys.OZONE_DATANODE_PIPELINE_LIMIT, 5);
46+
ozoneCluster = MiniOzoneCluster.newBuilder(conf)
47+
.setNumDatanodes(4)
48+
.includeRecon(true)
49+
.build();
50+
ozoneCluster.waitForClusterToBeReady();
51+
}
52+
53+
@Test
54+
public void testScmNonHASnapshot() throws Exception {
55+
TestReconScmSnapshot.testSnapshot(ozoneCluster);
56+
}
57+
58+
@AfterEach
59+
public void shutdown() throws Exception {
60+
if (ozoneCluster != null) {
61+
ozoneCluster.shutdown();
62+
}
63+
}
64+
}

‎hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconContext.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ public enum ErrorCode {
125125
Arrays.asList("Recon health")),
126126
GET_OM_DB_SNAPSHOT_FAILED(
127127
"OM DB Snapshot sync failed !!!",
128-
Arrays.asList("Overview (OM Data)", "OM DB Insights"));
128+
Arrays.asList("Overview (OM Data)", "OM DB Insights")),
129+
GET_SCM_DB_SNAPSHOT_FAILED(
130+
"SCM DB Snapshot sync failed !!!",
131+
Arrays.asList("Containers", "Pipelines"));
129132

130133
private final String message;
131134
private final List<String> impacts;

‎hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconServer.java‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.hadoop.hdds.security.SecurityConfig;
3232
import org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClient;
3333
import org.apache.hadoop.ozone.recon.api.types.FeatureProvider;
34+
import org.apache.hadoop.ozone.recon.scm.ReconStorageContainerManagerFacade;
3435
import org.apache.hadoop.ozone.recon.security.ReconCertificateClient;
3536
import org.apache.hadoop.hdds.utils.HddsServerUtil;
3637
import org.apache.hadoop.ozone.OzoneSecurityUtil;
@@ -55,6 +56,7 @@
5556

5657
import java.io.IOException;
5758
import java.net.InetSocketAddress;
59+
import java.util.concurrent.atomic.AtomicBoolean;
5860

5961
import static org.apache.hadoop.hdds.ratis.RatisHelper.newJvmPauseMonitor;
6062
import static org.apache.hadoop.hdds.recon.ReconConfig.ConfigStrings.OZONE_RECON_KERBEROS_KEYTAB_FILE_KEY;
@@ -139,6 +141,7 @@ public Void call() throws Exception {
139141
injector.getInstance(ReconSchemaManager.class);
140142
LOG.info("Creating Recon Schema.");
141143
reconSchemaManager.createReconSchema();
144+
LOG.debug("Recon schema creation done.");
142145

143146
this.reconSafeModeMgr = injector.getInstance(ReconSafeModeManager.class);
144147
this.reconSafeModeMgr.setInSafeMode(true);
@@ -153,13 +156,20 @@ public Void call() throws Exception {
153156

154157
LOG.info("Initializing support of Recon Features...");
155158
FeatureProvider.initFeatureSupport(configuration);
159+
160+
LOG.debug("Now starting all services of Recon...");
161+
// Start all services
162+
start();
163+
isStarted = true;
156164
LOG.info("Recon server initialized successfully!");
157165
} catch (Exception e) {
166+
ReconStorageContainerManagerFacade reconStorageContainerManagerFacade =
167+
(ReconStorageContainerManagerFacade) this.getReconStorageContainerManager();
168+
ReconContext reconContext = reconStorageContainerManagerFacade.getReconContext();
169+
reconContext.updateHealthStatus(new AtomicBoolean(false));
170+
reconContext.getErrors().add(ReconContext.ErrorCode.INTERNAL_ERROR);
158171
LOG.error("Error during initializing Recon server.", e);
159172
}
160-
// Start all services
161-
start();
162-
isStarted = true;
163173

164174
ShutdownHookManager.get().addShutdownHook(() -> {
165175
try {

‎hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconStorageContainerManagerFacade.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,4 +745,8 @@ public ContainerSizeCountTask getContainerSizeCountTask() {
745745
public ContainerCountBySizeDao getContainerCountBySizeDao() {
746746
return containerCountBySizeDao;
747747
}
748+
749+
public ReconContext getReconContext() {
750+
return reconContext;
751+
}
748752
}

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

Lines changed: 67 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636
import java.util.List;
3737
import java.util.concurrent.ExecutionException;
3838
import java.util.concurrent.TimeUnit;
39+
import java.util.concurrent.atomic.AtomicBoolean;
3940

4041
import javax.inject.Inject;
42+
import javax.validation.constraints.NotNull;
4143

4244
import org.apache.commons.io.FileUtils;
4345
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
@@ -47,7 +49,6 @@
4749
import org.apache.hadoop.hdds.scm.container.ContainerInfo;
4850
import org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline;
4951
import org.apache.hadoop.hdds.scm.ha.InterSCMGrpcClient;
50-
import org.apache.hadoop.hdds.scm.ha.SCMHAUtils;
5152
import org.apache.hadoop.hdds.scm.ha.SCMSnapshotDownloader;
5253
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
5354
import org.apache.hadoop.hdds.scm.protocol.StorageContainerLocationProtocol;
@@ -57,6 +58,7 @@
5758
import org.apache.hadoop.hdds.utils.db.RocksDBCheckpoint;
5859
import org.apache.hadoop.hdfs.web.URLConnectionFactory;
5960
import org.apache.hadoop.ozone.ClientVersion;
61+
import org.apache.hadoop.ozone.recon.ReconContext;
6062
import org.apache.hadoop.ozone.recon.ReconUtils;
6163
import org.apache.hadoop.ozone.recon.scm.ReconStorageConfig;
6264
import org.apache.hadoop.ozone.recon.security.ReconCertificateClient;
@@ -82,13 +84,15 @@ public class StorageContainerServiceProviderImpl
8284
private URLConnectionFactory connectionFactory;
8385
private ReconUtils reconUtils;
8486
private ReconStorageConfig reconStorage;
87+
private ReconContext reconContext;
8588

8689
@Inject
8790
public StorageContainerServiceProviderImpl(
8891
StorageContainerLocationProtocol scmClient,
8992
ReconUtils reconUtils,
9093
OzoneConfiguration configuration,
91-
ReconStorageConfig reconStorage) {
94+
ReconStorageConfig reconStorage,
95+
ReconContext reconContext) {
9296

9397
int connectionTimeout = (int) configuration.getTimeDuration(
9498
OZONE_RECON_SCM_CONNECTION_TIMEOUT,
@@ -123,6 +127,7 @@ public StorageContainerServiceProviderImpl(
123127
this.scmClient = scmClient;
124128
this.configuration = configuration;
125129
this.reconStorage = reconStorage;
130+
this.reconContext = reconContext;
126131
}
127132

128133
@Override
@@ -178,59 +183,78 @@ public DBCheckpoint getSCMDBSnapshot() {
178183
String snapshotFileName = RECON_SCM_SNAPSHOT_DB + "_" +
179184
System.currentTimeMillis();
180185
File targetFile = new File(scmSnapshotDBParentDir, snapshotFileName +
181-
".tar");
182-
186+
".tar");
183187
try {
184-
if (!SCMHAUtils.isSCMHAEnabled(configuration)) {
185-
SecurityUtil.doAsLoginUser(() -> {
186-
try (InputStream inputStream = reconUtils.makeHttpCall(
187-
connectionFactory, getScmDBSnapshotUrl(),
188-
isOmSpnegoEnabled()).getInputStream()) {
189-
FileUtils.copyInputStreamToFile(inputStream, targetFile);
190-
}
191-
return null;
192-
});
193-
LOG.info("Downloaded SCM Snapshot from SCM");
194-
} else {
188+
try {
195189
List<String> ratisRoles = scmClient.getScmInfo().getRatisPeerRoles();
196-
for (String ratisRole: ratisRoles) {
190+
for (String ratisRole : ratisRoles) {
197191
String[] role = ratisRole.split(":");
198-
if (role[2].equals(RaftProtos.RaftPeerRole.LEADER.toString())) {
199-
String hostAddress = role[4].trim();
200-
int grpcPort = configuration.getInt(
201-
ScmConfigKeys.OZONE_SCM_GRPC_PORT_KEY,
202-
ScmConfigKeys.OZONE_SCM_GRPC_PORT_DEFAULT);
203-
204-
SecurityConfig secConf = new SecurityConfig(configuration);
205-
SCMSecurityProtocolClientSideTranslatorPB scmSecurityClient =
206-
getScmSecurityClientWithMaxRetry(
207-
configuration, getCurrentUser());
208-
try (ReconCertificateClient certClient =
209-
new ReconCertificateClient(
210-
secConf, scmSecurityClient, reconStorage, null, null);
211-
SCMSnapshotDownloader downloadClient = new InterSCMGrpcClient(
212-
hostAddress, grpcPort, configuration, certClient)) {
213-
downloadClient.download(targetFile.toPath()).get();
214-
} catch (ExecutionException | InterruptedException e) {
215-
LOG.error("Rocks DB checkpoint downloading failed", e);
216-
throw new IOException(e);
192+
// This explicit role length check is to support older versions where we cannot change the default value
193+
// without breaking backward compatibility during upgrade, because if Ratis is not enabled then the roles
194+
// command output is generated outside of Ratis. It will not have the Ratis terminologies.
195+
if (role.length > 2) {
196+
if (role[2].equals(RaftProtos.RaftPeerRole.LEADER.toString())) {
197+
String hostAddress = role[4].trim();
198+
int grpcPort = configuration.getInt(
199+
ScmConfigKeys.OZONE_SCM_GRPC_PORT_KEY,
200+
ScmConfigKeys.OZONE_SCM_GRPC_PORT_DEFAULT);
201+
202+
SecurityConfig secConf = new SecurityConfig(configuration);
203+
SCMSecurityProtocolClientSideTranslatorPB scmSecurityClient =
204+
getScmSecurityClientWithMaxRetry(
205+
configuration, getCurrentUser());
206+
try (ReconCertificateClient certClient =
207+
new ReconCertificateClient(
208+
secConf, scmSecurityClient, reconStorage, null, null);
209+
SCMSnapshotDownloader downloadClient = new InterSCMGrpcClient(
210+
hostAddress, grpcPort, configuration, certClient)) {
211+
downloadClient.download(targetFile.toPath()).get();
212+
} catch (ExecutionException | InterruptedException e) {
213+
LOG.error("Rocks DB checkpoint downloading failed: {}", e);
214+
throw new IOException(e);
215+
}
216+
LOG.info("Downloaded SCM Snapshot from Leader SCM");
217+
break;
217218
}
218-
LOG.info("Downloaded SCM Snapshot from Leader SCM");
219+
} else {
220+
fetchSCMDBSnapshotUsingHttpClient(targetFile);
221+
LOG.info("Downloaded SCM Snapshot from SCM");
219222
break;
220223
}
221224
}
225+
} catch (Throwable throwable) {
226+
LOG.error("Unexpected runtime error while downloading SCM Rocks DB snapshot/checkpoint : {}", throwable);
227+
throw throwable;
222228
}
223-
Path untarredDbDir = Paths.get(scmSnapshotDBParentDir.getAbsolutePath(),
224-
snapshotFileName);
225-
reconUtils.untarCheckpointFile(targetFile, untarredDbDir);
226-
FileUtils.deleteQuietly(targetFile);
227-
return new RocksDBCheckpoint(untarredDbDir);
228-
} catch (IOException e) {
229-
LOG.error("Unable to obtain SCM DB Snapshot. ", e);
229+
return getRocksDBCheckpoint(snapshotFileName, targetFile);
230+
} catch (Throwable e) {
231+
reconContext.updateHealthStatus(new AtomicBoolean(false));
232+
reconContext.getErrors().add(ReconContext.ErrorCode.GET_SCM_DB_SNAPSHOT_FAILED);
233+
LOG.error("Unable to obtain SCM DB Snapshot: {} ", e);
230234
}
231235
return null;
232236
}
233237

238+
private void fetchSCMDBSnapshotUsingHttpClient(File targetFile) throws IOException {
239+
SecurityUtil.doAsLoginUser(() -> {
240+
try (InputStream inputStream = reconUtils.makeHttpCall(
241+
connectionFactory, getScmDBSnapshotUrl(),
242+
isOmSpnegoEnabled()).getInputStream()) {
243+
FileUtils.copyInputStreamToFile(inputStream, targetFile);
244+
}
245+
return null;
246+
});
247+
}
248+
249+
@NotNull
250+
private RocksDBCheckpoint getRocksDBCheckpoint(String snapshotFileName, File targetFile) throws IOException {
251+
Path untarredDbDir = Paths.get(scmSnapshotDBParentDir.getAbsolutePath(),
252+
snapshotFileName);
253+
reconUtils.untarCheckpointFile(targetFile, untarredDbDir);
254+
FileUtils.deleteQuietly(targetFile);
255+
return new RocksDBCheckpoint(untarredDbDir);
256+
}
257+
234258
@Override
235259
public List<ContainerInfo> getListOfContainers(
236260
long startContainerID, int count, HddsProtos.LifeCycleState state)

0 commit comments

Comments
 (0)