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

Expand Down Expand Up @@ -682,6 +683,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 @@ -751,6 +753,14 @@ public ReconfigurationHandler getReconfigurationHandler() {
return reconfigurationHandler;
}

public Thread getStateMachineThread() {
return stateMachineThread;
}

public Thread getCmdProcessThread() {
return cmdProcessThread;
}

public VolumeChoosingPolicy getVolumeChoosingPolicy() {
return volumeChoosingPolicy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,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