Skip to content

Commit

Permalink
Fix: quorum read if safe read (#1618)
Browse files Browse the repository at this point in the history
Co-authored-by: vaughn.zhang <[email protected]>
  • Loading branch information
zyxxoo and zyxxoo authored Oct 15, 2021
1 parent 8eb7d0f commit 7512587
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private Object submitAndWait(StoreCommand command) {
}

private Object queryByRaft(Object query, Function<Object, Object> func) {
if (this.node().selfIsLeader() || !this.context.isSafeRead()) {
if (!this.context.isSafeRead()) {
return func.apply(query);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

import com.alipay.sofa.jraft.option.ReadOnlyOption;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;

Expand Down Expand Up @@ -258,6 +259,9 @@ public NodeOptions nodeOptions() throws IOException {
raftOptions.setReplicatorPipeline(
config.get(CoreOptions.RAFT_REPLICATOR_PIPELINE));
raftOptions.setOpenStatistics(false);
raftOptions.setReadOnlyOptions(
ReadOnlyOption.valueOf(
config.get(CoreOptions.RAFT_READ_STRATEGY)));

return nodeOptions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ public static synchronized CoreOptions instance() {
8
);

public static final ConfigOption<String> RAFT_READ_STRATEGY =
new ConfigOption<>(
"raft.read_strategy",
"The linearizability of read strategy.",
allowValues("ReadOnlyLeaseBased", "ReadOnlySafe"),
"ReadOnlyLeaseBased"
);

public static final ConfigOption<Integer> RAFT_APPLY_BATCH =
new ConfigOption<>(
"raft.apply_batch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ raft.election_timeout=10000
raft.snapshot_interval=3600
raft.backend_threads=48
raft.read_index_threads=8
raft.read_strategy=ReadOnlyLeaseBased
raft.queue_size=16384
raft.queue_publish_timeout=60
raft.apply_batch=1
Expand Down

0 comments on commit 7512587

Please sign in to comment.