Skip to content

Commit

Permalink
添加异步写配置asyncWrite
Browse files Browse the repository at this point in the history
  • Loading branch information
wenweihu86 committed Feb 27, 2018
1 parent 7a41b45 commit 8233516
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 89 deletions.
10 changes: 10 additions & 0 deletions raft-java-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ public void run() {
});
}

if (raftOptions.isAsyncWrite()) {
// 主节点写成功后,就返回。
return true;
}

// sync wait commitIndex >= newLastLogIndex
long startTime = System.currentTimeMillis();
while (lastAppliedIndex < newLastLogIndex) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package com.github.wenweihu86.raft;

import lombok.Getter;
import lombok.Setter;

/**
* raft配置选项
* Created by wenweihu86 on 2017/5/2.
*/
@Setter
@Getter
public class RaftOptions {

// A follower would become a candidate if it doesn't receive any message
Expand Down Expand Up @@ -32,95 +38,10 @@ public class RaftOptions {
// 与其他节点进行同步、选主等操作的线程池大小
private int raftConsensusThreadNum = 20;

// 是否异步写数据;true表示主节点保存后就返回,然后异步同步给从节点;
// false表示主节点同步给大多数从节点后才返回。
private boolean asyncWrite = false;

// raft的log和snapshot父目录,绝对路径
private String dataDir = System.getProperty("com.github.wenweihu86.raft.data.dir");

public int getElectionTimeoutMilliseconds() {
return electionTimeoutMilliseconds;
}

public void setElectionTimeoutMilliseconds(int electionTimeoutMilliseconds) {
this.electionTimeoutMilliseconds = electionTimeoutMilliseconds;
}

public int getHeartbeatPeriodMilliseconds() {
return heartbeatPeriodMilliseconds;
}

public void setHeartbeatPeriodMilliseconds(int heartbeatPeriodMilliseconds) {
this.heartbeatPeriodMilliseconds = heartbeatPeriodMilliseconds;
}

public int getSnapshotPeriodSeconds() {
return snapshotPeriodSeconds;
}

public void setSnapshotPeriodSeconds(int snapshotPeriodSeconds) {
this.snapshotPeriodSeconds = snapshotPeriodSeconds;
}

public int getSnapshotMinLogSize() {
return snapshotMinLogSize;
}

public void setSnapshotMinLogSize(int snapshotMinLogSize) {
this.snapshotMinLogSize = snapshotMinLogSize;
}

public int getMaxSnapshotBytesPerRequest() {
return maxSnapshotBytesPerRequest;
}

public void setMaxSnapshotBytesPerRequest(int maxSnapshotBytesPerRequest) {
this.maxSnapshotBytesPerRequest = maxSnapshotBytesPerRequest;
}

public int getMaxLogEntriesPerRequest() {
return maxLogEntriesPerRequest;
}

public void setMaxLogEntriesPerRequest(int maxLogEntriesPerRequest) {
this.maxLogEntriesPerRequest = maxLogEntriesPerRequest;
}

public int getMaxSegmentFileSize() {
return maxSegmentFileSize;
}

public void setMaxSegmentFileSize(int maxSegmentFileSize) {
this.maxSegmentFileSize = maxSegmentFileSize;
}

public long getCatchupMargin() {
return catchupMargin;
}

public void setCatchupMargin(long catchupMargin) {
this.catchupMargin = catchupMargin;
}

public long getMaxAwaitTimeout() {
return maxAwaitTimeout;
}

public void setMaxAwaitTimeout(long maxAwaitTimeout) {
this.maxAwaitTimeout = maxAwaitTimeout;
}

public int getRaftConsensusThreadNum() {
return raftConsensusThreadNum;
}

public void setRaftConsensusThreadNum(int raftConsensusThreadNum) {
this.raftConsensusThreadNum = raftConsensusThreadNum;
}

public String getDataDir() {
return dataDir;
}

public void setDataDir(String dataDir) {
this.dataDir = dataDir;
}

}

0 comments on commit 8233516

Please sign in to comment.