Skip to content

Commit

Permalink
add raftConsensusThreadNum RaftOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
wenweihu86 committed Jul 4, 2017
1 parent 460f425 commit a852b3b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public void init() {

// init thread pool
executorService = new ThreadPoolExecutor(
peerMap.size() * 2,
peerMap.size() * 4,
RaftOptions.raftConsensusThreadNum,
RaftOptions.raftConsensusThreadNum,
60,
TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class RaftOptions {
// replicate最大等待超时时间,单位ms
public static long maxAwaitTimeout = 1000;

// 与其他节点进行同步、选主等操作的线程池大小
public static int raftConsensusThreadNum = 20;

// raft的log和snapshot父目录,绝对路径
public static String dataDir = System.getProperty("com.github.wenweihu86.raft.data.dir");
}
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ public RaftMessage.LogMetaData readMetaData() {
String fileName = logDir + File.separator + "metadata";
File file = new File(fileName);
try (RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r")) {
RaftMessage.LogMetaData metadata = RaftFileUtils.readProtoFromFile(randomAccessFile, RaftMessage.LogMetaData.class);
RaftMessage.LogMetaData metadata = RaftFileUtils.readProtoFromFile(
randomAccessFile, RaftMessage.LogMetaData.class);
return metadata;
} catch (IOException ex) {
LOG.warn("meta file not exist, name={}", fileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static RandomAccessFile openFile(String dir, String fileName, String mode
return new RandomAccessFile(file, mode);
} catch (FileNotFoundException ex) {
LOG.warn("file not fount, file={}", fileName);
throw new RuntimeException("file not found, file={}" + fileName);
throw new RuntimeException("file not found, file=" + fileName);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.wenweihu86.raft.storage;

import com.github.wenweihu86.raft.RaftOptions;
import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -37,5 +38,7 @@ public void testReadSnapshotDataFiles() throws IOException {
System.out.println(snapshotFileMap.keySet());
Assert.assertTrue(snapshotFileMap.size() == 2);
Assert.assertTrue(snapshotFileMap.firstKey().equals("queue1.txt"));

Files.delete(link);
}
}

0 comments on commit a852b3b

Please sign in to comment.