Skip to content
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

Fix: quorum read if safe read #1618

Merged
merged 3 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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