Repository navigation
RATIS-2787. Spread appendEntries between two servers over more than one connection #1679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f02f9c9
8694406
4bc69fe
d421fe6
0776bb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ | |
| import org.apache.ratis.server.protocol.TermIndex; | ||
| import org.apache.ratis.server.raftlog.RaftLog; | ||
| import org.apache.ratis.server.util.ServerStringUtils; | ||
| import org.apache.ratis.thirdparty.com.google.common.annotations.VisibleForTesting; | ||
| import org.apache.ratis.thirdparty.io.grpc.StatusRuntimeException; | ||
| import org.apache.ratis.thirdparty.io.grpc.stub.CallStreamObserver; | ||
| import org.apache.ratis.thirdparty.io.grpc.stub.StreamObserver; | ||
|
|
@@ -163,6 +164,8 @@ synchronized int process(Event event) { | |
| private final TimeoutExecutor scheduler = TimeoutExecutor.getInstance(); | ||
| @SuppressWarnings({"squid:S3077"}) // Suppress volatile for generic type | ||
| private volatile StreamObservers appendLogRequestObserver; | ||
| // the appendEntries channel of this appender, taken when it creates its first stream; guarded by the write lock | ||
| private int appendEntriesIndex = -1; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| private final boolean useSeparateHBChannel; | ||
|
|
||
| private final GrpcServerMetrics grpcServerMetrics; | ||
|
|
@@ -389,10 +392,10 @@ static class StreamObservers { | |
| private final TimeDuration waitForReady; | ||
| private volatile boolean running = true; | ||
|
|
||
| StreamObservers(GrpcServerProtocolClient client, AppendLogResponseHandler handler, boolean separateHeartbeat, | ||
| TimeDuration waitTimeMin) { | ||
| this.appendLog = client.appendEntries(handler, false); | ||
| this.heartbeat = separateHeartbeat? client.appendEntries(handler, true): null; | ||
| StreamObservers(GrpcServerProtocolClient client, int appendEntriesIndex, AppendLogResponseHandler handler, | ||
| boolean separateHeartbeat, TimeDuration waitTimeMin) { | ||
| this.appendLog = client.appendEntries(appendEntriesIndex, handler, false); | ||
| this.heartbeat = separateHeartbeat? client.appendEntries(appendEntriesIndex, handler, true): null; | ||
| this.waitForReady = waitTimeMin.isPositive()? waitTimeMin: TimeDuration.ONE_MILLISECOND; | ||
| } | ||
|
|
||
|
|
@@ -422,6 +425,13 @@ void onCompleted() { | |
| } | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| int getAppendEntriesIndex() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is better to call it getAppendEntriesIndexForTesting instead of using VisibleForTesting.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice naming actually. |
||
| try (AutoCloseableLock readLock = lock.readLock(caller, LOG::trace)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a testing only call, so the readlock has no performance impact for production. |
||
| return appendEntriesIndex; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public long getCallId() { | ||
| return callId.get(); | ||
|
|
@@ -448,8 +458,12 @@ void appendLog(boolean heartbeat) throws IOException { | |
| notifyAppendEntriesListener(l -> l.onRequest(pending)); | ||
| increaseNextIndex(pending); | ||
| if (appendLogRequestObserver == null) { | ||
| appendLogRequestObserver = new StreamObservers( | ||
| getClient(), new AppendLogResponseHandler(), useSeparateHBChannel, getWaitTimeMin()); | ||
| final GrpcServerProtocolClient client = getClient(); | ||
| if (appendEntriesIndex < 0) { | ||
| appendEntriesIndex = client.nextAppendEntriesIndex(); | ||
| } | ||
| appendLogRequestObserver = new StreamObservers(client, appendEntriesIndex, | ||
| new AppendLogResponseHandler(), useSeparateHBChannel, getWaitTimeMin()); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already has
raft.grpc.server.log.appender.listener.factory. This new conf should use the sameraft.grpc.server.log.appenderprefix.