Skip to content

Commit

Permalink
refactor: rename ioExecutor to blockIoExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
areyouok committed Jun 22, 2024
1 parent e40d311 commit 76a441e
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ protected PoolFactory createPoolFactory() {
@Override
protected void doStart() {
AtomicInteger count = new AtomicInteger();
ioExecutor = Executors.newFixedThreadPool(serverConfig.getIoThreads(),
ioExecutor = Executors.newFixedThreadPool(serverConfig.getBlockIoThreads(),
r -> new Thread(r, "raft-io-" + count.incrementAndGet()));
}

@Override
public ExecutorService createIoExecutor() {
public ExecutorService createBlockIoExecutor() {
return ioExecutor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.concurrent.ExecutorService;

public interface RaftFactory {
ExecutorService createIoExecutor();
ExecutorService createBlockIoExecutor();

StateMachine createStateMachine(RaftGroupConfigEx groupConfig);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class RaftGroupConfigEx extends RaftGroupConfig {

private Timestamp ts;
private RaftStatus raftStatus;
private ExecutorService ioExecutor;
private ExecutorService blockIoExecutor;
private FiberGroup fiberGroup;

public RaftGroupConfigEx(int groupId, String nodeIdOfMembers, String nodeIdOfObservers) {
Expand Down Expand Up @@ -58,11 +58,11 @@ public void setRaftStatus(RaftStatus raftStatus) {
this.raftStatus = raftStatus;
}

public ExecutorService getIoExecutor() {
return ioExecutor;
public ExecutorService getBlockIoExecutor() {
return blockIoExecutor;
}

public void setIoExecutor(ExecutorService ioExecutor) {
this.ioExecutor = ioExecutor;
public void setBlockIoExecutor(ExecutorService blockIoExecutor) {
this.blockIoExecutor = blockIoExecutor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ private RaftGroupConfigEx createGroupConfigEx(RaftGroupConfig rgc, RaftStatusImp
RaftGroupConfigEx rgcEx = (RaftGroupConfigEx) rgc;
rgcEx.setTs(raftStatus.getTs());
rgcEx.setRaftStatus(raftStatus);
rgcEx.setIoExecutor(raftFactory.createIoExecutor());
rgcEx.setBlockIoExecutor(raftFactory.createBlockIoExecutor());
rgcEx.setFiberGroup(fiberGroup);
return rgcEx;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class RaftServerConfig {

private boolean checkSelf = true;

private int ioThreads = Math.max(Runtime.getRuntime().availableProcessors() * 5, 30);
private int blockIoThreads = Math.min(Runtime.getRuntime().availableProcessors() * 2, 4);

private PoolFactory poolFactory = new DefaultPoolFactory();

Expand Down Expand Up @@ -118,11 +118,11 @@ public void setPoolFactory(PoolFactory poolFactory) {
this.poolFactory = poolFactory;
}

public int getIoThreads() {
return ioThreads;
public int getBlockIoThreads() {
return blockIoThreads;
}

public void setIoThreads(int ioThreads) {
this.ioThreads = ioThreads;
public void setBlockIoThreads(int blockIoThreads) {
this.blockIoThreads = blockIoThreads;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class DefaultSnapshotManager implements SnapshotManager {

public DefaultSnapshotManager(RaftGroupConfigEx groupConfig, StateMachine stateMachine) {
this.groupConfig = groupConfig;
this.ioExecutor = groupConfig.getIoExecutor();
this.ioExecutor = groupConfig.getBlockIoExecutor();
this.raftStatus = (RaftStatusImpl) groupConfig.getRaftStatus();
this.stateMachine = stateMachine;
this.saveLoopFrame = new SaveSnapshotLoopFrame();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public FileSnapshot(RaftGroupConfigEx groupConfig, SnapshotInfo si, File dataFil
HashSet<StandardOpenOption> options = new HashSet<>();
options.add(StandardOpenOption.READ);
AsynchronousFileChannel channel = AsynchronousFileChannel.open(dataFile.toPath(), options,
groupConfig.getIoExecutor());
groupConfig.getBlockIoExecutor());
this.dtFile = new DtFile(dataFile, channel, groupConfig.getFiberGroup());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public void completed(Integer result, Void v) {

private void submitForceTask() {
try {
ExecutorService executor = groupConfig.getIoExecutor();
ExecutorService executor = groupConfig.getBlockIoExecutor();
executor.execute(() -> {
try {
doForce();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ abstract class FileQueue {

public FileQueue(File dir, RaftGroupConfigEx groupConfig, long fileSize, boolean mainLogFile) {
this.dir = dir;
this.ioExecutor = groupConfig.getIoExecutor();
this.ioExecutor = groupConfig.getBlockIoExecutor();
this.groupConfig = groupConfig;
this.raftStatus = (RaftStatusImpl) groupConfig.getRaftStatus();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ private class SyncFrame extends ForceFrame {
private final long bytes;

public SyncFrame(WriteTask task, long perfStartTime, int count, long bytes) {
super(task.getDtFile().getChannel(), groupConfig.getIoExecutor(), false);
super(task.getDtFile().getChannel(), groupConfig.getBlockIoExecutor(), false);
this.task = task;
this.perfStartTime = perfStartTime;
this.count = count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void setup() throws Exception {
AsynchronousFileChannel channel = AsynchronousFileChannel.open(file.toPath(), s, fiberGroup.getExecutor());
dtFile = new DtFile(file, channel, fiberGroup);
groupConfig = new RaftGroupConfigEx(0, "1", "");
groupConfig.setIoExecutor(MockExecutors.ioExecutor());
groupConfig.setBlockIoExecutor(MockExecutors.ioExecutor());
groupConfig.setIoRetryInterval(new long[]{1});
groupConfig.setFiberGroup(fiberGroup);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void init() throws Exception {
config = new RaftGroupConfigEx(1, "1", "1");
config.setFiberGroup(fiberGroup);
config.setDataDir(dataDir);
config.setIoExecutor(MockExecutors.ioExecutor());
config.setBlockIoExecutor(MockExecutors.ioExecutor());
config.setTs(raftStatus.getTs());

raftStatus.setTailCache(new TailCache(config, raftStatus));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class FileQueueTest extends BaseFiberTest {
public void setup() {
File dir = TestDir.createTestDir(FileQueueTest.class.getSimpleName());
RaftGroupConfigEx c = new RaftGroupConfigEx(1, "1", "1");
c.setIoExecutor(MockExecutors.ioExecutor());
c.setBlockIoExecutor(MockExecutors.ioExecutor());
RaftStatusImpl raftStatus = new RaftStatusImpl(dispatcher.getTs());
raftStatus.setTailCache(new TailCache(c, raftStatus));
c.setRaftStatus(raftStatus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private IdxFileQueue createFileQueue() throws Exception {
RaftGroupConfigEx c = new RaftGroupConfigEx(1, "1", "1");
c.setIdxCacheSize(4);
c.setIdxFlushThreshold(2);
c.setIoExecutor(MockExecutors.ioExecutor());
c.setBlockIoExecutor(MockExecutors.ioExecutor());
raftStatus = new RaftStatusImpl(dispatcher.getTs());
raftStatus.setTailCache(new TailCache(c, raftStatus));
c.setRaftStatus(raftStatus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private void setup(long fileSize, int maxWriteBufferSize) throws Exception {
RaftServerConfig serverConfig = new RaftServerConfig();

config = new RaftGroupConfigEx(1, "1", "1");
config.setIoExecutor(MockExecutors.ioExecutor());
config.setBlockIoExecutor(MockExecutors.ioExecutor());
config.setFiberGroup(fiberGroup);
config.setTs(raftStatus.getTs());
config.setRaftStatus(raftStatus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class StatusFileTest extends BaseFiberTest {
private static RaftGroupConfigEx createGroupConfig() {
RaftGroupConfigEx groupConfig = new RaftGroupConfigEx(0, "1", "");
groupConfig.setFiberGroup(fiberGroup);
groupConfig.setIoExecutor(MockExecutors.ioExecutor());
groupConfig.setBlockIoExecutor(MockExecutors.ioExecutor());
return groupConfig;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void setup() {
groupConfig.setDataDir(dir.getAbsolutePath());
groupConfig.setStatusFile("status.test");
groupConfig.setRaftStatus(raftStatus);
groupConfig.setIoExecutor(MockExecutors.ioExecutor());
groupConfig.setBlockIoExecutor(MockExecutors.ioExecutor());
groupConfig.setFiberGroup(fiberGroup);
raftStatus.setTailCache(new TailCache(groupConfig, raftStatus));
statusManager = new StatusManager(groupConfig);
Expand Down

0 comments on commit 76a441e

Please sign in to comment.