Skip to content

Commit

Permalink
refactor: simplification ChainWriter constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
areyouok committed Dec 22, 2024
1 parent 3eda5dd commit 2534abf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ public abstract class ChainWriter {

private final PerfCallback perfCallback;
private final RaftGroupConfigEx config;
private final int writePerfType1;
private final int writePerfType2;
private final int forcePerfType;

private int writePerfType1;
private int writePerfType2;
private int forcePerfType;

private final ByteBufferPool directPool;
private final LinkedList<WriteTask> writeTasks = new LinkedList<>();
private final LinkedList<WriteTask> forceTasks = new LinkedList<>();
Expand All @@ -60,13 +62,9 @@ public abstract class ChainWriter {

private boolean close;

public ChainWriter(RaftGroupConfigEx config, String fiberNamePrefix, int writePerfType1, int writePerfType2,
int forcePerfType) {
public ChainWriter(String fiberNamePrefix, RaftGroupConfigEx config) {
this.config = config;
this.perfCallback = config.getPerfCallback();
this.writePerfType1 = writePerfType1;
this.writePerfType2 = writePerfType2;
this.forcePerfType = forcePerfType;
DispatcherThread t = config.getFiberGroup().getThread();
this.directPool = t.getDirectPool();
this.needForceCondition = config.getFiberGroup().newCondition("needForceCond");
Expand Down Expand Up @@ -267,4 +265,15 @@ public boolean hasTask() {
return writeTaskCount > 0 || forceTaskCount > 0;
}

public void setWritePerfType1(int writePerfType1) {
this.writePerfType1 = writePerfType1;
}

public void setWritePerfType2(int writePerfType2) {
this.writePerfType2 = writePerfType2;
}

public void setForcePerfType(int forcePerfType) {
this.forcePerfType = forcePerfType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ public IdxFileQueue(File dir, StatusManager statusManager, RaftGroupConfigEx gro
this.needFlushCondition = groupConfig.getFiberGroup().newCondition("IdxNeedFlush-" + groupConfig.getGroupId());
this.flushDoneCondition = groupConfig.getFiberGroup().newCondition("IdxFlushDone-" + groupConfig.getGroupId());

this.chainWriter = new IdxChainWriter(groupConfig, 0, PerfConsts.RAFT_D_IDX_WRITE,
PerfConsts.RAFT_D_IDX_FORCE);
this.chainWriter = new IdxChainWriter(groupConfig);
chainWriter.setWritePerfType1(0);
chainWriter.setWritePerfType2(PerfConsts.RAFT_D_IDX_WRITE);
chainWriter.setForcePerfType(PerfConsts.RAFT_D_IDX_FORCE);
}

public FiberFrame<Pair<Long, Long>> initRestorePos() throws Exception {
Expand Down Expand Up @@ -171,8 +173,8 @@ protected FrameCallResult handle(Throwable ex) throws Throwable {

class IdxChainWriter extends ChainWriter {

public IdxChainWriter(RaftGroupConfigEx config, int writePerfType1, int writePerfType2, int forcePerfType) {
super(config, "IdxForce", writePerfType1, writePerfType2, forcePerfType);
public IdxChainWriter(RaftGroupConfigEx config) {
super("IdxForce", config);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,17 @@ public LogFileQueue(File dir, RaftGroupConfigEx groupConfig, IdxOps idxOps, long
this.heapPool = t.getHeapPool();
this.directPool = t.getDirectPool();

LogChainWriter chainWriter = new LogChainWriter(groupConfig, PerfConsts.RAFT_D_LOG_WRITE1,
PerfConsts.RAFT_D_LOG_WRITE2, PerfConsts.RAFT_D_LOG_SYNC);
LogChainWriter chainWriter = new LogChainWriter(groupConfig);
chainWriter.setWritePerfType1(PerfConsts.RAFT_D_LOG_WRITE1);
chainWriter.setWritePerfType2(PerfConsts.RAFT_D_LOG_WRITE2);
chainWriter.setForcePerfType(PerfConsts.RAFT_D_LOG_SYNC);
this.logAppender = new LogAppender(idxOps, this, groupConfig, chainWriter);
}

private class LogChainWriter extends ChainWriter {

public LogChainWriter(RaftGroupConfigEx config, int writePerfType1, int writePerfType2, int forcePerfType) {
super(config, "LogForce", writePerfType1, writePerfType2, forcePerfType);
public LogChainWriter(RaftGroupConfigEx config) {
super("LogForce", config);
}

@Override
Expand Down

0 comments on commit 2534abf

Please sign in to comment.