-
Notifications
You must be signed in to change notification settings - Fork 593
HDDS-14717. Improve test coverage for OzoneManagerStateMachine #9825
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
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 |
|---|---|---|
|
|
@@ -73,7 +73,6 @@ | |
| import org.apache.ratis.statemachine.SnapshotInfo; | ||
| import org.apache.ratis.statemachine.TransactionContext; | ||
| import org.apache.ratis.statemachine.impl.BaseStateMachine; | ||
| import org.apache.ratis.statemachine.impl.SimpleStateMachineStorage; | ||
| import org.apache.ratis.thirdparty.com.google.protobuf.ByteString; | ||
| import org.apache.ratis.util.ExitUtils; | ||
| import org.apache.ratis.util.IOUtils; | ||
|
|
@@ -94,8 +93,6 @@ public class OzoneManagerStateMachine extends BaseStateMachine { | |
| private static final String AUDIT_PARAM_PREVIOUS_LEADER = "previousLeader"; | ||
| private static final String AUDIT_PARAM_NEW_LEADER = "newLeader"; | ||
| private RaftPeerId previousLeaderId = null; | ||
| private final SimpleStateMachineStorage storage = | ||
| new SimpleStateMachineStorage(); | ||
| private final OzoneManager ozoneManager; | ||
| private RequestHandler handler; | ||
| private volatile OzoneManagerDoubleBuffer ozoneManagerDoubleBuffer; | ||
|
|
@@ -135,15 +132,32 @@ public OzoneManagerStateMachine(OzoneManagerRatisServer ratisServer, | |
| this.nettyMetrics = NettyMetrics.create(); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| OzoneManagerStateMachine(OzoneManager ozoneManager, | ||
| OzoneManagerDoubleBuffer doubleBuffer, | ||
| RequestHandler handler, | ||
| ExecutorService executorService, | ||
| NettyMetrics nettyMetrics) { | ||
| this.isTracingEnabled = false; | ||
| this.ozoneManager = ozoneManager; | ||
| this.threadPrefix = ""; | ||
| this.ozoneManagerDoubleBuffer = doubleBuffer; | ||
| this.handler = handler; | ||
| this.executorService = executorService; | ||
| ThreadFactory installSnapshotThreadFactory = new ThreadFactoryBuilder() | ||
| .setNameFormat("TestInstallSnapshotThread").build(); | ||
| this.installSnapshotExecutor = | ||
| HadoopExecutors.newSingleThreadExecutor(installSnapshotThreadFactory); | ||
| this.nettyMetrics = nettyMetrics; | ||
| } | ||
|
|
||
| /** | ||
| * Initializes the State Machine with the given server, group and storage. | ||
| */ | ||
| @Override | ||
| public void initialize(RaftServer server, RaftGroupId id, | ||
| RaftStorage raftStorage) throws IOException { | ||
| public void initialize(RaftServer server, RaftGroupId id, RaftStorage raftStorage) throws IOException { | ||
| getLifeCycle().startAndTransition(() -> { | ||
| super.initialize(server, id, raftStorage); | ||
| storage.init(raftStorage); | ||
|
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. why init() is removed here? its functional change, not just adding new tests
Contributor
Author
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. If you look through the earlier code, this storage variable was created and then never used outside of this call in the OM state machine. Based on all of this, I don't see a real use of the variable, and this seems to me dead code, please let me know if you disagree and/or if I am missing something.
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. @szetszwo Is
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.
|
||
| LOG.info("{}: initialize {} with {}", getId(), id, getLastAppliedTermIndex()); | ||
| }); | ||
| } | ||
|
|
@@ -419,7 +433,8 @@ public CompletableFuture<Message> applyTransaction(TransactionContext trx) { | |
| } | ||
| } | ||
|
|
||
| private Message processResponse(OMResponse omResponse) { | ||
| @VisibleForTesting | ||
| Message processResponse(OMResponse omResponse) { | ||
| if (!omResponse.getSuccess()) { | ||
| // INTERNAL_ERROR or METADATA_ERROR are considered as critical errors. | ||
| // In such cases, OM must be terminated instead of completing the future exceptionally, | ||
|
|
@@ -593,7 +608,8 @@ public void close() { | |
| * @param request OMRequest | ||
| * @return response from OM | ||
| */ | ||
| private OMResponse runCommand(OMRequest request, TermIndex termIndex) { | ||
| @VisibleForTesting | ||
| OMResponse runCommand(OMRequest request, TermIndex termIndex) { | ||
| try { | ||
| ExecutionContext context = ExecutionContext.of(termIndex.getIndex(), termIndex); | ||
| final OMClientResponse omClientResponse = handler.handleWriteRequest( | ||
|
|
@@ -617,7 +633,8 @@ private OMResponse runCommand(OMRequest request, TermIndex termIndex) { | |
| return null; | ||
| } | ||
|
|
||
| private OMResponse createErrorResponse( | ||
| @VisibleForTesting | ||
| OMResponse createErrorResponse( | ||
| OMRequest omRequest, IOException exception, TermIndex termIndex) { | ||
| OMResponse.Builder omResponseBuilder = OMResponse.newBuilder() | ||
| .setStatus(OzoneManagerRatisUtils.exceptionToResponseStatus(exception)) | ||
|
|
||
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.
👍 Good catch for removing this unused field.