You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by sz...@apache.org on 2019/03/20 07:34:15 UTC
[incubator-ratis] branch master updated: RATIS-505. In gRPC,
make Install Snapshot option configurable. Contributed by Hanisha
Koneru
This is an automated email from the ASF dual-hosted git repository.
szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ratis.git
The following commit(s) were added to refs/heads/master by this push:
new c4330f2 RATIS-505. In gRPC, make Install Snapshot option configurable. Contributed by Hanisha Koneru
c4330f2 is described below
commit c4330f2ef9f8b89e9819e364e41547bd8e230bf2
Author: Tsz Wo Nicholas Sze <sz...@apache.org>
AuthorDate: Wed Mar 20 15:33:25 2019 +0800
RATIS-505. In gRPC, make Install Snapshot option configurable. Contributed by Hanisha Koneru
---
.../java/org/apache/ratis/grpc/GrpcConfigKeys.java | 19 +++++++++++++++++++
.../org/apache/ratis/grpc/server/GrpcLogAppender.java | 17 +++++++++++++----
2 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcConfigKeys.java b/ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcConfigKeys.java
index 1f18810..08ca49e 100644
--- a/ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcConfigKeys.java
+++ b/ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcConfigKeys.java
@@ -159,6 +159,25 @@ public interface GrpcConfigKeys {
}
}
+ interface LogAppender {
+ Logger LOG = LoggerFactory.getLogger(Server.class);
+ static Consumer<String> getDefaultLog() {
+ return LOG::info;
+ }
+
+ String PREFIX = GrpcConfigKeys.PREFIX + ".log.appender";
+
+ String INSTALL_SNAPSHOT_ENABLED_KEY = PREFIX + ".install.snapshot.enabled";
+ boolean INSTALL_SNAPSHOT_ENABLED_DEFAULT = true;
+ static boolean installSnapshotEnabled(RaftProperties properties) {
+ return getBoolean(properties::getBoolean,
+ INSTALL_SNAPSHOT_ENABLED_KEY, INSTALL_SNAPSHOT_ENABLED_DEFAULT, getDefaultLog());
+ }
+ static void setInstallSnapshotEnabled(RaftProperties properties, boolean shouldInstallSnapshot) {
+ setBoolean(properties::setBoolean, INSTALL_SNAPSHOT_ENABLED_KEY, shouldInstallSnapshot);
+ }
+ }
+
String MESSAGE_SIZE_MAX_KEY = PREFIX + ".message.size.max";
SizeInBytes MESSAGE_SIZE_MAX_DEFAULT = SizeInBytes.valueOf("64MB");
static SizeInBytes messageSizeMax(RaftProperties properties, Consumer<String> logger) {
diff --git a/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcLogAppender.java b/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcLogAppender.java
index b2d2e45..da803c4 100644
--- a/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcLogAppender.java
+++ b/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcLogAppender.java
@@ -51,6 +51,7 @@ public class GrpcLogAppender extends LogAppender {
private final int maxPendingRequestsNum;
private long callId = 0;
private volatile boolean firstResponseReceived = false;
+ private final boolean installSnapshotEnabled;
private final TimeDuration requestTimeoutDuration;
private final TimeoutScheduler scheduler = TimeoutScheduler.newInstance(1);
@@ -67,6 +68,8 @@ public class GrpcLogAppender extends LogAppender {
server.getProxy().getProperties());
requestTimeoutDuration = RaftServerConfigKeys.Rpc.requestTimeout(server.getProxy().getProperties());
pendingRequests = new ConcurrentHashMap<>();
+ installSnapshotEnabled = GrpcConfigKeys.LogAppender.installSnapshotEnabled(
+ server.getProxy().getProperties());
}
private GrpcServerProtocolClient getClient() throws IOException {
@@ -86,12 +89,18 @@ public class GrpcLogAppender extends LogAppender {
@Override
protected void runAppenderImpl() throws IOException {
+ boolean shouldAppendLog;
for(; isAppenderRunning(); mayWait()) {
+ shouldAppendLog = true;
if (shouldSendRequest()) {
- SnapshotInfo snapshot = shouldInstallSnapshot();
- if (snapshot != null) {
- installSnapshot(snapshot);
- } else if (!shouldWait()) {
+ if (installSnapshotEnabled) {
+ SnapshotInfo snapshot = shouldInstallSnapshot();
+ if (snapshot != null) {
+ installSnapshot(snapshot);
+ shouldAppendLog = false;
+ }
+ }
+ if (shouldAppendLog && !shouldWait()) {
// keep appending log entries or sending heartbeats
appendLog();
}