-
Notifications
You must be signed in to change notification settings - Fork 594
HDDS-14070. set statemachine ready on election performed for follower #9671
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -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); | ||
| scm.getScmSafeModeManager().refreshAndValidate(); | ||
| } | ||
|
|
||
| if (!groupMemberId.getPeerId().equals(newLeaderId)) { | ||
| LOG.info("leader changed, yet current SCM is still follower."); | ||
| return; | ||
|
|
@@ -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
Contributor
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. Similarly, it needs 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(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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; | ||
|
|
@@ -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
Contributor
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. 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(); | ||
|
|
@@ -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); | ||
|
|
||
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.
This is not atomic. Use