Skip to content
Open
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 @@ -285,6 +285,15 @@ public void notifyLeaderChanged(RaftGroupMemberId groupMemberId,
currentLeaderTerm.set(scm.getScmHAManager().getRatisServer().getDivision()
.getInfo().getCurrentTerm());

if (!refreshedAfterLeaderReady.get()) {
// refresh and validate safe mode rules if it can exit safe mode
// if being leader, all previous term transactions have been applied
// if other states, just refresh safe mode rules, and transaction keeps flushing from leader
// and does not depend on pending transactions.
refreshedAfterLeaderReady.set(true);
Comment on lines +288 to +293
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not atomic. Use

    if (refreshedAfterLeaderReady.compareAndSet(false, true)) {

scm.getScmSafeModeManager().refreshAndValidate();
}

if (!groupMemberId.getPeerId().equals(newLeaderId)) {
LOG.info("leader changed, yet current SCM is still follower.");
return;
Expand Down Expand Up @@ -355,12 +364,9 @@ public void notifyTermIndexUpdated(long term, long index) {
}

if (currentLeaderTerm.get() == term) {
// Means all transactions before this term have been applied.
// This means after a restart, all pending transactions have been applied.
// Perform
// 1. Refresh Safemode rules state.
// 2. Start DN Rpc server.
if (!refreshedAfterLeaderReady.get()) {
Comment on lines 366 to 368
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, it needs compareAndSet.

BTW, why refreshedAfterLeaderReady won't be set to false after set to true?

// Refresh Safemode rules state if not already done.
refreshedAfterLeaderReady.set(true);
scm.getScmSafeModeManager().refreshAndValidate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@
import org.apache.hadoop.hdds.scm.container.replication.ContainerReplicaPendingOps;
import org.apache.hadoop.hdds.scm.events.SCMEvents;
import org.apache.hadoop.hdds.scm.ha.SCMContext;
import org.apache.hadoop.hdds.scm.ha.SCMHAManager;
import org.apache.hadoop.hdds.scm.ha.SCMHAManagerStub;
import org.apache.hadoop.hdds.scm.ha.SCMRatisServer;
import org.apache.hadoop.hdds.scm.ha.SCMServiceManager;
import org.apache.hadoop.hdds.scm.ha.SCMStateMachine;
import org.apache.hadoop.hdds.scm.metadata.SCMMetadataStore;
import org.apache.hadoop.hdds.scm.metadata.SCMMetadataStoreImpl;
import org.apache.hadoop.hdds.scm.node.NodeManager;
Expand All @@ -67,6 +70,7 @@
import org.apache.hadoop.hdds.scm.pipeline.PipelineProvider;
import org.apache.hadoop.hdds.scm.server.SCMDatanodeHeartbeatDispatcher;
import org.apache.hadoop.hdds.scm.server.SCMDatanodeProtocolServer;
import org.apache.hadoop.hdds.scm.server.StorageContainerManager;
import org.apache.hadoop.hdds.server.events.EventQueue;
import org.apache.ozone.test.GenericTestUtils;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -177,6 +181,16 @@ public void testSafeModeExitRule() throws Exception {
}
ContainerManager containerManager = mock(ContainerManager.class);
when(containerManager.getContainers(ReplicationType.RATIS)).thenReturn(containers);

StorageContainerManager mockScmManager = mock(StorageContainerManager.class);
SCMHAManager mockScmhaManager = mock(SCMHAManager.class);
when(mockScmManager.getScmHAManager()).thenReturn(mockScmhaManager);
SCMRatisServer mockScmRatisServer = mock(SCMRatisServer.class);
when(mockScmhaManager.getRatisServer()).thenReturn(mockScmRatisServer);
SCMStateMachine mockScmStateMachine = mock(SCMStateMachine.class);
when(mockScmRatisServer.getSCMStateMachine()).thenReturn(mockScmStateMachine);
when((mockScmStateMachine.isRefreshedAfterLeaderReady())).thenReturn(true);
scmContext = new SCMContext.Builder().setSCM(mockScmManager).build();
Comment on lines +185 to +193
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't use mock. We need to a real cluster test which test SCM changing leader multiple times.

scmSafeModeManager = new SCMSafeModeManager(config, null, null, containerManager,
serviceManager, queue, scmContext);
scmSafeModeManager.start();
Expand Down Expand Up @@ -207,6 +221,7 @@ public void testSafeModeExitRule() throws Exception {
testContainerThreshold(containers.subList(75, 100), 1.0);
assertEquals(100, scmSafeModeManager.getSafeModeMetrics()
.getCurrentContainersWithOneReplicaReportedCount().value());
scmSafeModeManager.validateSafeModeExitRules(StateMachineReadyRule.class.getSimpleName());

GenericTestUtils.waitFor(() -> !scmSafeModeManager.getInSafeMode(),
100, 1000 * 5);
Expand Down