Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -258,7 +258,8 @@ public List<String> getRatisRoles() throws IOException {
peer.getAddress().concat(isLocal ?
":".concat(RaftProtos.RaftPeerRole.LEADER.toString()) :
":".concat(RaftProtos.RaftPeerRole.FOLLOWER.toString()))
.concat(":".concat(peer.getId().toString()))));
.concat(":".concat(peer.getId().toString()))
.concat(":".concat(peerInetAddress.getHostAddress()))));
}
return ratisRoles;
}
Expand Down
4 changes: 4 additions & 0 deletions hadoop-ozone/dist/src/main/compose/ozone-ha/docker-config
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ OZONE-SITE.XML_ozone.datanode.pipeline.limit=1
OZONE-SITE.XML_hdds.scmclient.max.retry.timeout=30s
OZONE-SITE.XML_ozone.scm.primordial.node.id=scm1
OZONE-SITE.XML_hdds.container.report.interval=60s
OZONE-SITE.XML_ozone.recon.db.dir=/data/metadata/recon
OZONE-SITE.XML_ozone.recon.address=recon:9891
OZONE-SITE.XML_ozone.recon.http-address=0.0.0.0:9888
OZONE-SITE.XML_ozone.recon.https-address=0.0.0.0:9889

OZONE_CONF_DIR=/etc/hadoop
OZONE_LOG_DIR=/var/log/hadoop
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/**
* 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.recon;

import org.apache.hadoop.hdds.client.RatisReplicationConfig;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
import org.apache.hadoop.hdds.scm.container.ContainerInfo;
import org.apache.hadoop.hdds.scm.container.ContainerManager;
import org.apache.hadoop.hdds.scm.pipeline.PipelineManager;
import org.apache.hadoop.ozone.MiniOzoneCluster;
import org.apache.hadoop.ozone.recon.scm.ReconNodeManager;
import org.apache.hadoop.ozone.recon.scm.ReconStorageContainerManagerFacade;
import org.apache.ozone.test.GenericTestUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
import org.slf4j.LoggerFactory;

import java.util.List;

import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_HA_ENABLE_KEY;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* Test Recon SCM HA Snapshot Download implementation.
*/
public class TestReconScmHASnapshot {

/**
* Set a timeout for each test.
*/
@Rule
public Timeout timeout = Timeout.seconds(100);
private static OzoneConfiguration conf;
private static MiniOzoneCluster cluster;

@BeforeClass
public static void setup() throws Exception {
conf = new OzoneConfiguration();
conf.setBoolean(OZONE_SCM_HA_ENABLE_KEY, true);
conf.setBoolean(
ReconServerConfigKeys.OZONE_RECON_SCM_SNAPSHOT_ENABLED, true);
conf.setInt(ReconServerConfigKeys.OZONE_RECON_SCM_CONTAINER_THRESHOLD, 0);
conf.setInt(ScmConfigKeys.OZONE_DATANODE_PIPELINE_LIMIT, 5);
cluster = MiniOzoneCluster.newBuilder(conf)
.setNumDatanodes(4)
.includeRecon(true)
.build();
cluster.waitForClusterToBeReady();
}

@Test
public void testScmHASnapshot() throws Exception {
GenericTestUtils.LogCapturer logCapturer = GenericTestUtils.LogCapturer
.captureLogs(LoggerFactory.getLogger(
ReconStorageContainerManagerFacade.class));

List<ContainerInfo> reconContainers = cluster.getReconServer()
.getReconStorageContainerManager().getContainerManager()
.getContainers();
assertEquals(0, reconContainers.size());

ReconNodeManager nodeManager;
nodeManager = (ReconNodeManager) cluster.getReconServer()
.getReconStorageContainerManager().getScmNodeManager();
long keyCountBefore = nodeManager.getNodeDBKeyCount();

//Stopping Recon to add Containers in SCM
cluster.stopRecon();

ContainerManager containerManager;
containerManager = cluster.getStorageContainerManager()
.getContainerManager();

for (int i = 0; i < 10; i++) {
containerManager.allocateContainer(new RatisReplicationConfig(
HddsProtos.ReplicationFactor.ONE), "testOwner");
}

cluster.startRecon();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this to a common initializer function shared between the TestReconScmHASnapshot.java and TestReconScmSnapshot.java, it will help reduce code duplication across the two files.


//ContainerCount after Recon DB is updated with SCM DB
containerManager = cluster.getStorageContainerManager()
.getContainerManager();
ContainerManager reconContainerManager = cluster.getReconServer()
.getReconStorageContainerManager().getContainerManager();
assertTrue(logCapturer.getOutput()
.contains("Downloaded SCM Snapshot from Leader SCM"));
assertTrue(logCapturer.getOutput()
.contains("Recon Container Count: " + reconContainers.size() +
", SCM Container Count: " + containerManager.getContainers().size()));
assertEquals(containerManager.getContainers().size(),
reconContainerManager.getContainers().size());

//PipelineCount after Recon DB is updated with SCM DB
PipelineManager scmPipelineManager = cluster.getStorageContainerManager()
.getPipelineManager();
PipelineManager reconPipelineManager = cluster.getReconServer()
.getReconStorageContainerManager().getPipelineManager();
assertEquals(scmPipelineManager.getPipelines().size(),
reconPipelineManager.getPipelines().size());

//NodeCount after Recon DB updated with SCM DB
nodeManager = (ReconNodeManager) cluster.getReconServer()
.getReconStorageContainerManager().getScmNodeManager();
long keyCountAfter = nodeManager.getNodeDBKeyCount();
assertEquals(keyCountAfter, keyCountBefore);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we extract this into a common assertion function shared between the HA and non HA variants of this test?

}

@AfterClass
public static void shutdown() throws Exception {
if (cluster != null) {
cluster.shutdown();
}
}
}
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
* <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.recon;

import org.apache.hadoop.hdds.client.RatisReplicationConfig;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.scm.container.ContainerInfo;
import org.apache.hadoop.hdds.scm.container.ContainerManager;
import org.apache.hadoop.hdds.scm.pipeline.PipelineManager;
import org.apache.hadoop.ozone.MiniOzoneCluster;
import org.apache.hadoop.ozone.recon.scm.ReconNodeManager;
import org.apache.hadoop.ozone.recon.scm.ReconStorageContainerManagerFacade;
import org.apache.ozone.test.GenericTestUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
import org.slf4j.LoggerFactory;

import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* Test Recon SCM Snapshot Download implementation.
*/
public class TestReconScmSnapshot {
/**
* Set a timeout for each test.
*/
@Rule
public Timeout timeout = Timeout.seconds(100);
private static OzoneConfiguration conf;
private static MiniOzoneCluster cluster;

@BeforeClass
public static void setup() throws Exception {
conf = new OzoneConfiguration();
conf.setBoolean(
ReconServerConfigKeys.OZONE_RECON_SCM_SNAPSHOT_ENABLED, true);
conf.setInt(ReconServerConfigKeys.OZONE_RECON_SCM_CONTAINER_THRESHOLD, 0);
cluster = MiniOzoneCluster.newBuilder(conf)
.setNumDatanodes(4)
.includeRecon(true)
.build();
cluster.waitForClusterToBeReady();
}

@Test
public void testScmSnapshot() throws Exception {
GenericTestUtils.LogCapturer logCapturer = GenericTestUtils.LogCapturer
.captureLogs(LoggerFactory.getLogger(
ReconStorageContainerManagerFacade.class));

List<ContainerInfo> reconContainers = cluster.getReconServer()
.getReconStorageContainerManager().getContainerManager()
.getContainers();
assertEquals(0, reconContainers.size());

ReconNodeManager nodeManager;
nodeManager = (ReconNodeManager) cluster.getReconServer()
.getReconStorageContainerManager().getScmNodeManager();
long keyCountBefore = nodeManager.getNodeDBKeyCount();

//Stopping Recon to add Containers in SCM
cluster.stopRecon();

ContainerManager containerManager;
containerManager = cluster.getStorageContainerManager()
.getContainerManager();

for (int i = 0; i < 10; i++) {
containerManager.allocateContainer(new RatisReplicationConfig(
HddsProtos.ReplicationFactor.ONE), "testOwner");
}

cluster.startRecon();

//ContainerCount after Recon DB is updated with SCM DB
containerManager = cluster.getStorageContainerManager()
.getContainerManager();
ContainerManager reconContainerManager = cluster.getReconServer()
.getReconStorageContainerManager().getContainerManager();
assertTrue(logCapturer.getOutput()
.contains("Recon Container Count: " + reconContainers.size() +
", SCM Container Count: " + containerManager.getContainers().size()));
assertEquals(containerManager.getContainers().size(),
reconContainerManager.getContainers().size());

//PipelineCount after Recon DB is updated with SCM DB
PipelineManager scmPipelineManager = cluster.getStorageContainerManager()
.getPipelineManager();
PipelineManager reconPipelineManager = cluster.getReconServer()
.getReconStorageContainerManager().getPipelineManager();
assertEquals(scmPipelineManager.getPipelines().size(),
reconPipelineManager.getPipelines().size());

//NodeCount after Recon DB updated with SCM DB
nodeManager = (ReconNodeManager) cluster.getReconServer()
.getReconStorageContainerManager().getScmNodeManager();
long keyCountAfter = nodeManager.getNodeDBKeyCount();
assertEquals(keyCountAfter, keyCountBefore);
}

@AfterClass
public static void shutdown() throws Exception {
if (cluster != null) {
cluster.shutdown();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Set;
import java.util.UUID;

import com.google.common.annotations.VisibleForTesting;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.LayoutVersionProto;
Expand Down Expand Up @@ -299,4 +300,9 @@ public void reinitialize(Table<UUID, DatanodeDetails> nodeTable) {
this.nodeDB = nodeTable;
loadExistingNodes();
}

@VisibleForTesting
public long getNodeDBKeyCount() throws IOException {
return nodeDB.getEstimatedKeyCount();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.apache.hadoop.hdds.scm.events.SCMEvents;
import org.apache.hadoop.hdds.scm.ha.MockSCMHAManager;
import org.apache.hadoop.hdds.scm.ha.SCMContext;
import org.apache.hadoop.hdds.scm.ha.SCMHAUtils;
import org.apache.hadoop.hdds.scm.ha.SCMNodeDetails;
import org.apache.hadoop.hdds.scm.ha.SCMHAManager;
import org.apache.hadoop.hdds.scm.ha.SequenceIdGenerator;
Expand Down Expand Up @@ -349,7 +350,13 @@ private void initializeSCMDB() {
}

public void updateReconSCMDBWithNewSnapshot() throws IOException {
DBCheckpoint dbSnapshot = scmServiceProvider.getSCMDBSnapshot();
DBCheckpoint dbSnapshot;
if(!SCMHAUtils.isSCMHAEnabled(ozoneConfiguration)) {
Comment thread
aswinshakil marked this conversation as resolved.
Outdated
dbSnapshot = scmServiceProvider.getSCMDBSnapshot();
} else {
dbSnapshot = scmServiceProvider.getSCMDBSnapshotHA();
LOG.info("Downloaded SCM Snapshot from Leader SCM");
}
if (dbSnapshot != null && dbSnapshot.getCheckpointLocation() != null) {
LOG.info("Got new checkpoint from SCM : " +
dbSnapshot.getCheckpointLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,10 @@ List<ContainerWithPipeline> getExistContainerWithPipelinesInBatch(
* @return DBCheckpoint from SCM.
*/
DBCheckpoint getSCMDBSnapshot();

/**
* Requests Leader SCM for DB Snapshot.
* @return DBCheckpoint from Leader SCM.
*/
DBCheckpoint getSCMDBSnapshotHA() throws IOException;
}
Loading