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 @@ -555,6 +555,7 @@ public void startDaemon() {
ExitUtils.terminate(1, message, ex, LOG);
})
.build().newThread(startStateMachineTask);
stateMachineThread.setPriority(Thread.MAX_PRIORITY);
stateMachineThread.start();
}

Expand Down Expand Up @@ -678,6 +679,7 @@ private void initCommandHandlerThread(ConfigurationSource config) {

// We will have only one thread for command processing in a datanode.
cmdProcessThread = getCommandHandlerThread(processCommandQueue);
cmdProcessThread.setPriority(Thread.NORM_PRIORITY);
cmdProcessThread.start();
}

Expand Down Expand Up @@ -745,4 +747,15 @@ public DatanodeQueueMetrics getQueueMetrics() {
public ReconfigurationHandler getReconfigurationHandler() {
return reconfigurationHandler;
}

@VisibleForTesting
Copy link
Member

Choose a reason for hiding this comment

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

@VisibleForTesting can be removed form these two getter, as it's safe to access.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

public Thread getStateMachineThread() {
return stateMachineThread;
}

@VisibleForTesting
public Thread getCmdProcessThread() {
return cmdProcessThread;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,26 @@ public void testDatanodeStateMachineWithInvalidConfiguration()
});
}

@Test
public void testStateMachineThreadPriority() throws Exception {
DatanodeDetails datanodeDetails = getNewDatanodeDetails();
DatanodeDetails.Port port = DatanodeDetails.newStandalonePort(
OzoneConfigKeys.HDDS_CONTAINER_IPC_PORT_DEFAULT);
datanodeDetails.setPort(port);
try (DatanodeStateMachine stateMachine =
new DatanodeStateMachine(datanodeDetails, conf)) {
stateMachine.startDaemon();

// Wait for CmdProcessThread to initialize
GenericTestUtils.waitFor(()
-> stateMachine.getCmdProcessThread() != null, 100, 3000);
Thread stateMachineThread = stateMachine.getStateMachineThread();
Thread cmdProcessThread = stateMachine.getCmdProcessThread();
// stateMachineThread priority is higher than cmdProcessThread
assertTrue(stateMachineThread.getPriority() > cmdProcessThread.getPriority());
}
}

private DatanodeDetails getNewDatanodeDetails() {
DatanodeDetails.Port containerPort = DatanodeDetails.newStandalonePort(0);
DatanodeDetails.Port ratisPort = DatanodeDetails.newRatisPort(0);
Expand Down
Loading