-
Notifications
You must be signed in to change notification settings - Fork 514
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
HDDS-11694. Safemode Improvement: Introduce factory class to create safemode rules. #7433
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7abb55a
HDDS-11694. Safemode Improvement: Introduce factory class to create s…
nandakumar131 05af954
Addressed integration test failures
nandakumar131 71d5e54
Fixed unit test failures
nandakumar131 2cfbc12
Added Jira IDs to the TODO list.
nandakumar131 3d56244
Merge remote-tracking branch 'origin/master' into HDDS-11694
adoroszlai e656e1b
Addressed review comments.
nandakumar131 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
...dds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/safemode/SafeModeRuleFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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.hdds.scm.safemode; | ||
|
||
|
||
import org.apache.hadoop.hdds.HddsConfigKeys; | ||
import org.apache.hadoop.hdds.conf.ConfigurationSource; | ||
import org.apache.hadoop.hdds.scm.container.ContainerManager; | ||
import org.apache.hadoop.hdds.scm.ha.SCMContext; | ||
import org.apache.hadoop.hdds.scm.pipeline.PipelineManager; | ||
import org.apache.hadoop.hdds.server.events.EventQueue; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Factory to create SafeMode rules. | ||
*/ | ||
public final class SafeModeRuleFactory { | ||
|
||
|
||
private static final Logger LOG = LoggerFactory.getLogger(SafeModeRuleFactory.class); | ||
|
||
// TODO: Move the rule names to respective rules. (HDDS-11798) | ||
private static final String CONT_EXIT_RULE = "ContainerSafeModeRule"; | ||
private static final String DN_EXIT_RULE = "DataNodeSafeModeRule"; | ||
private static final String HEALTHY_PIPELINE_EXIT_RULE = | ||
"HealthyPipelineSafeModeRule"; | ||
private static final String ATLEAST_ONE_DATANODE_REPORTED_PIPELINE_EXIT_RULE = | ||
"AtleastOneDatanodeReportedRule"; | ||
|
||
private final ConfigurationSource config; | ||
private final SCMContext scmContext; | ||
private final EventQueue eventQueue; | ||
|
||
// TODO: Remove dependency on safeModeManager (HDDS-11797) | ||
private final SCMSafeModeManager safeModeManager; | ||
private final PipelineManager pipelineManager; | ||
private final ContainerManager containerManager; | ||
|
||
private final List<SafeModeExitRule<?>> safeModeRules; | ||
private final List<SafeModeExitRule<?>> preCheckRules; | ||
|
||
private static SafeModeRuleFactory instance; | ||
|
||
private SafeModeRuleFactory(final ConfigurationSource config, | ||
final SCMContext scmContext, | ||
final EventQueue eventQueue, | ||
final SCMSafeModeManager safeModeManager, | ||
final PipelineManager pipelineManager, | ||
final ContainerManager containerManager) { | ||
this.config = config; | ||
this.scmContext = scmContext; | ||
this.eventQueue = eventQueue; | ||
this.safeModeManager = safeModeManager; | ||
this.pipelineManager = pipelineManager; | ||
this.containerManager = containerManager; | ||
this.safeModeRules = new ArrayList<>(); | ||
this.preCheckRules = new ArrayList<>(); | ||
loadRules(); | ||
} | ||
|
||
private void loadRules() { | ||
// TODO: Use annotation to load the rules. (HDDS-11730) | ||
safeModeRules.add(new ContainerSafeModeRule(CONT_EXIT_RULE, eventQueue, config, | ||
containerManager, safeModeManager)); | ||
SafeModeExitRule<?> dnRule = new DataNodeSafeModeRule(DN_EXIT_RULE, eventQueue, config, safeModeManager); | ||
safeModeRules.add(dnRule); | ||
preCheckRules.add(dnRule); | ||
|
||
// TODO: Move isRuleEnabled check to the Rule implementation. (HDDS-11799) | ||
if (config.getBoolean( | ||
HddsConfigKeys.HDDS_SCM_SAFEMODE_PIPELINE_AVAILABILITY_CHECK, | ||
HddsConfigKeys.HDDS_SCM_SAFEMODE_PIPELINE_AVAILABILITY_CHECK_DEFAULT) | ||
&& pipelineManager != null) { | ||
|
||
safeModeRules.add(new HealthyPipelineSafeModeRule(HEALTHY_PIPELINE_EXIT_RULE, | ||
eventQueue, pipelineManager, safeModeManager, config, scmContext)); | ||
safeModeRules.add(new OneReplicaPipelineSafeModeRule( | ||
ATLEAST_ONE_DATANODE_REPORTED_PIPELINE_EXIT_RULE, eventQueue, | ||
pipelineManager, safeModeManager, config)); | ||
} | ||
|
||
} | ||
|
||
public static SafeModeRuleFactory getInstance() { | ||
if (instance != null) { | ||
return instance; | ||
} | ||
throw new IllegalStateException("SafeModeRuleFactory not initialized," + | ||
" call initialize method before getInstance."); | ||
} | ||
|
||
// TODO: Refactor and reduce the arguments. (HDDS-11800) | ||
public static synchronized void initialize( | ||
final ConfigurationSource config, | ||
final SCMContext scmContext, | ||
final EventQueue eventQueue, | ||
final SCMSafeModeManager safeModeManager, | ||
final PipelineManager pipelineManager, | ||
final ContainerManager containerManager) { | ||
instance = new SafeModeRuleFactory(config, scmContext, eventQueue, | ||
safeModeManager, pipelineManager, containerManager); | ||
} | ||
|
||
public List<SafeModeExitRule<?>> getSafeModeRules() { | ||
return safeModeRules; | ||
} | ||
|
||
public List<SafeModeExitRule<?>> getPreCheckRules() { | ||
return preCheckRules; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For thread-safety,
getInstance()
should besynchronized
, ORinstance
should bevolatile
, and assigned to local variable firstThere 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.
Same suggestion.
Except this, others looks good to me.
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.
Not sure how I missed adding
synchronized
here. Thanks for the catch @adoroszlai & @ChenSammi.