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

Implementing Flexible Raft with NWR #1017

Merged
merged 102 commits into from
Oct 30, 2023
Merged
Changes from 1 commit
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
214ec93
feat(iterator):Auto commit mode for applying log iterator
1294566108 Apr 9, 2023
8ed148d
feat(iterator):Auto commit mode for applying log iterator
1294566108 Apr 10, 2023
21ac53a
feat(iterator):Correction parameter name
1294566108 Apr 10, 2023
e5d9986
feat(iterator):mvn compile
1294566108 Apr 11, 2023
8cdff52
feat(iterator):Modify comments and annotations
1294566108 Apr 12, 2023
88a6ce2
feat(iterator):Modify comments
1294566108 Apr 12, 2023
535d876
feat(iterator):Modify comments
1294566108 Apr 12, 2023
9034f71
feat(rfcs):Add rfcs for Flexible-Raft-with-NWR
1294566108 Jul 1, 2023
fce77c4
Merge branch 'sofastack:master' into master
1294566108 Jul 1, 2023
9e6a785
feat(rfcs):Add stepDown change logic and modify parameter name for rfcs
1294566108 Jul 3, 2023
9d14232
Merge remote-tracking branch 'origin/master'
1294566108 Jul 3, 2023
ffd2136
feat(rfcs):Modify factor calculation rules for rfcs
1294566108 Jul 4, 2023
9eec73b
feat(rfcs):Modify some language expressions
1294566108 Jul 6, 2023
0e75dbb
feat(rfcs):Implementing Flexible Raft with NWR
1294566108 Jul 6, 2023
f9e766f
feat(rfcs):compile project
1294566108 Jul 6, 2023
e7d657a
Merge remote-tracking branch 'origin/master'
1294566108 Jul 6, 2023
c4fd678
feat(rfcs):compile project
1294566108 Jul 6, 2023
46f95f1
feat(rfcs):Remove useless and redundant code
1294566108 Jul 6, 2023
11311de
feat(rfcs):Add rfcs
1294566108 Jul 7, 2023
5ed30b6
feat(flexible):add flexible mode fot Jraft
1294566108 Jul 18, 2023
f1c3647
feat(flexible):Modify rfc doc
1294566108 Jul 18, 2023
5d5dddc
feat(flexible):Modify quorum code design
1294566108 Jul 26, 2023
fdd1aca
feat(factor):Add ResetFactor API
1294566108 Jul 26, 2023
3627697
feat(flexible):compile code
1294566108 Jul 26, 2023
d4ae075
feat(flexible):modify code
1294566108 Jul 26, 2023
5fce197
feat(flexible):modify code
1294566108 Jul 26, 2023
2c10bf2
feat(flexible):compile code
1294566108 Jul 26, 2023
a6d904b
fix(flexible):modify raft.desc
1294566108 Jul 26, 2023
5f36899
fix(flexible):modify MarshallerHelper
1294566108 Jul 26, 2023
a8f1bd3
fix(flexible):modify MarshallerHelper
1294566108 Jul 26, 2023
790a3a2
fix(flexible):modify RAFT.DESC
1294566108 Jul 26, 2023
de1edf6
fix(flexible):Modifying comments and code formats
1294566108 Jul 26, 2023
c7ee54e
fix(flexible):Added factor persistence for log storage and Adapt to w…
1294566108 Jul 29, 2023
f7be903
fix(flexible):compile code
1294566108 Jul 29, 2023
1e376f3
fix(flexible):modify test
1294566108 Jul 29, 2023
e79a41a
fix(flexible):modify test
1294566108 Jul 29, 2023
f04018f
fix(flexible):modify code with proto version changing
1294566108 Aug 1, 2023
f5d2e52
fix(flexible):modify code with proto version changing
1294566108 Aug 1, 2023
02eba00
fix(flexible):modify code format
1294566108 Aug 1, 2023
72f67ab
fix(flexible):modify code format
1294566108 Aug 1, 2023
cf620cc
fix(flexible):change protoc version from 2.6.1 to 3.5.1
1294566108 Aug 2, 2023
2933732
fix(flexible):modify Class RaftError
1294566108 Aug 2, 2023
d7534d4
fix(flexible):modify Class format
1294566108 Aug 2, 2023
cc8959d
fix(flexible):modify Class format
1294566108 Aug 2, 2023
8032338
fix(flexible):modify Class format
1294566108 Aug 2, 2023
d255078
fix(flexible):change int64 to int32 in proto
1294566108 Aug 2, 2023
a43518e
fix(flexible):change int64 to int32 in proto
1294566108 Aug 2, 2023
e0c5b97
fix(flexible):avoid importing *
1294566108 Aug 2, 2023
7210bad
fix(flexible):change comment
1294566108 Aug 2, 2023
341377f
fix(flexible):add this for voteCtx and preVoteCtx
1294566108 Aug 2, 2023
2e4b3c9
fix(flexible):change import order
1294566108 Aug 2, 2023
840c2d8
fix(flexible):change import order
1294566108 Aug 2, 2023
a706938
feat(flexible):Place attributes such as quorum, factor, and isEnableF…
1294566108 Aug 17, 2023
90199f5
feat(flexible):check format
1294566108 Aug 17, 2023
566f755
feat(flexible):Add test code for resetFactor API
1294566108 Aug 18, 2023
4cb0e09
feat(flexible):modify code format
1294566108 Aug 18, 2023
1be0405
feat(flexible):enable flexible check
1294566108 Aug 18, 2023
f3ed97c
feat(flexible):comment useless code
1294566108 Aug 20, 2023
8261bcc
feat(flexible):modify code
1294566108 Aug 20, 2023
8448183
feat(flexible):Persisting the quorum attribute
1294566108 Aug 21, 2023
8075eb9
fix(flexible):Delete redundant haveFactor judgments
1294566108 Aug 22, 2023
6a54afb
fix(flexible):Add necessary null judgment
1294566108 Aug 22, 2023
31f8b98
fix(flexible):remove config null parameter
1294566108 Aug 22, 2023
3b6ebdd
fix(flexible):modify code
1294566108 Aug 22, 2023
b810708
fix(flexible):modify some logic mistakes、remove unused method and add…
1294566108 Aug 25, 2023
d534436
fix(flexible):modify config check
1294566108 Aug 26, 2023
4191811
fix(flexible):modify config check
1294566108 Aug 26, 2023
5d3a44b
fix(flexible):remove Redundant code
1294566108 Aug 26, 2023
f564dd1
fix(flexible):remove some check and add NodeOptions.setFactor method
1294566108 Aug 26, 2023
b0ebc3a
fix(flexible):remove redundant code
1294566108 Aug 26, 2023
51b64d9
fix(flexible):解决majority模式下,空指针异常问题
1294566108 Aug 28, 2023
c55dcc6
fix(flexible):修改部分set quorum逻辑,
1294566108 Sep 4, 2023
5c3341a
feature(flexible):添加flexible raft 测试模块
1294566108 Sep 10, 2023
e8ee175
feature(flexible):check code format
1294566108 Sep 11, 2023
2f4a6dd
feature(flexible):remove code
1294566108 Sep 11, 2023
e5e29a7
feature(flexible):remove redundant blank lines
1294566108 Sep 17, 2023
76043ad
feature(flexible):modify test module
1294566108 Sep 18, 2023
1c6d0cf
fix(LogManagerTest):modify code format
1294566108 Sep 19, 2023
462c18c
fix(LogManagerTest):modify code format
1294566108 Sep 19, 2023
cca6c1c
fix(LogManagerTest):modify code format
1294566108 Sep 19, 2023
4885aa0
feature(flexible):modify test module in core
1294566108 Sep 19, 2023
26014b5
fix(test_core):modify test—core code
1294566108 Sep 20, 2023
93ec6c2
fix(test_module):modify test_core
1294566108 Sep 21, 2023
381cdf6
fix(test_module):modify testTripleNodesV1V2Codec temporarily
1294566108 Sep 22, 2023
6a1bf03
fix(test_module):modify testTripleNodesV1V2Codec temporarily
1294566108 Sep 22, 2023
c55a1e6
fix(test_module):modify testTripleNodesV1V2Codec temporarily
1294566108 Sep 22, 2023
a568a35
fix(test_module):modify testTripleNodesV1V2Codec temporarily
1294566108 Sep 22, 2023
22162cf
fix(test_module):modify V1V2Codec error
1294566108 Sep 23, 2023
2e94d92
fix(test_module):modify V1V2Codec error
1294566108 Sep 23, 2023
dbbb321
fix(test_module):modify V1V2Codec error
1294566108 Sep 23, 2023
98552a0
fix(test_module):modify resetPeers error
1294566108 Sep 24, 2023
b4a995d
fix(test_module):modify changePeerChaps test error
1294566108 Sep 24, 2023
53ba339
fix(test_module):modify v1decoder error
1294566108 Sep 24, 2023
a3e87d6
fix(test_module):modify v1decoder error
1294566108 Sep 24, 2023
8270ce2
fix(test_module):modify storage test
1294566108 Sep 24, 2023
b1cfb1a
fix(test_module):modify storage test
1294566108 Sep 24, 2023
36bb588
fix(test_module):modify node test
1294566108 Sep 25, 2023
2049c01
Merge branch 'sofastack:master' into reset-factor
1294566108 Oct 25, 2023
42f2f6c
fix(test_module):modify node test
Oct 25, 2023
5ff9a11
modify code
1294566108 Oct 28, 2023
bbb3b88
modify code
1294566108 Oct 28, 2023
058d5d5
modify code
1294566108 Oct 30, 2023
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
Prev Previous commit
Next Next commit
feat(flexible):Modify rfc doc
  • Loading branch information
1294566108 committed Jul 18, 2023
commit f1c3647791e786e4d37d85bc495884cf7fde0320
34 changes: 17 additions & 17 deletions rfcs/0002-Flexible-Raft-with-NWR.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ JRaft支持成员变更,因此用户可以配置(0,1]范围内的小数来计

下图为NWR模型Quroum的设计思路:

- 抽离出抽象父类Quorum作为MajorityQuorum(多数派确认模型,原Ballot类)和NWRQuorum(NWR模型)的模板。
- 抽离出抽象父类Quorum作为MajorityQuorum(多数派确认模型,原Ballot类)和FlexibleQuorum(NWR模型)的模板。
- 用户首先需要在NodeOptions类中决定是否开启NWR模式,默认为多数派模型,用户手动设置读写Factor因子后,则视为开启了NWR模式。
- NodeImpl#init方法进行逻辑处理,判断是否开启了NWR模式,对读写因子进行校验与同步,然后构造对应的Quorum选票实例,例如MajorityQuorum与NWRQuorum。
- 在构建好选票实例之后,调用对应的方法可以进行选票的初始化(init)、投票(grant)等操作。
Expand Down Expand Up @@ -56,7 +56,7 @@ JRaft支持成员变更,因此用户可以配置(0,1]范围内的小数来计
*/
private Integer writeQuorumFactor;
/**
* Enable NWRMode or Not
* Enable FlexibleMode or Not
*/
private boolean enableFlexibleRaft = false;
```
Expand Down Expand Up @@ -142,17 +142,17 @@ private final Ballot prevVoteCtx = new Ballot();
添加NWR模型后,我们需要判断,到底是生成MajorityQuorum还是NWRQuorum。所以在对节点进行初始化时(NodeImpl#init),会根据NodeOptions判断是否开启NWR模型,进而构造对应实例。

```
prevVoteCtx = options.isEnableFlexibleRaft() ? new NWRQuorum(opts.getReadQuorumFactor(), opts.getWriteQuorumFactor())
prevVoteCtx = options.isEnableFlexibleRaft() ? new FlexibleQuorum(opts.getReadQuorumFactor(), opts.getWriteQuorumFactor())
: new MajorityQuorum();
voteCtx = options.isEnableFlexibleRaft() ? new NWRQuorum(opts.getReadQuorumFactor(), opts.getWriteQuorumFactor())
voteCtx = options.isEnableFlexibleRaft() ? new FlexibleQuorum(opts.getReadQuorumFactor(), opts.getWriteQuorumFactor())
: new MajorityQuorum();
```

### Quorum Detail

#### Quorum

Quorum作为NWRQuorum与MajorityQuorum的抽象父类,持有peers、oldPeers、quorum、oldQuorum几个公共属性。
Quorum作为FlexibleQuorum与MajorityQuorum的抽象父类,持有peers、oldPeers、quorum、oldQuorum几个公共属性。

```
protected final List<Quorum.UnfoundPeerId> peers = new ArrayList<>()
Expand Down Expand Up @@ -182,9 +182,9 @@ private UnfoundPeerId findPeer(final PeerId peerId, final List<UnfoundPeerId> pe
}
```

#### NWRQuorum
#### FlexibleQuorum

NWRQuorum作为NWR模型选票实现类,持有readFactor、writeFactor等几个属性,他们代表读写因子。
FlexibleQuorum作为NWR模型选票实现类,持有readFactor、writeFactor等几个属性,他们代表读写因子。

```
protected Integer readFactor; ---读因子
Expand All @@ -193,10 +193,10 @@ NWRQuorum作为NWR模型选票实现类,持有readFactor、writeFactor等几
private static final BigDecimal defaultDecimal = new BigDecimal(defaultDecimalFactor);
```

另外,我们提供了一个NWRQuorum的构造器用于构造NWRQuorum实例,需要传入writeFactor, readFactor两个参数。
另外,我们提供了一个FlexibleQuorum的构造器用于构造FlexibleQuorum实例,需要传入writeFactor, readFactor两个参数。

```
public NWRQuorum(Double writeFactor, Double readFactor) {
public FlexibleQuorum(Double writeFactor, Double readFactor) {
this.writeFactor = writeFactor;
this.readFactor = readFactor;
}
Expand All @@ -209,7 +209,7 @@ public boolean init(Configuration conf, Configuration oldConf) ---初始化选
public void grant(final PeerId peerId) ---节点投票
```

对于NWRQuorum的init()方法来讲,他对于quorum的计算与以往有所不同,代码如下:
对于FlexibleQuorum的init()方法来讲,他对于quorum的计算与以往有所不同,代码如下:

```
@Override
Expand Down Expand Up @@ -366,7 +366,7 @@ prevVoteCtx.init(this.conf.getConf(), this.conf.isStable() ? null : this.conf.ge
// 省略部分代码...
if (!this.ballotBox.appendPendingTask(this.conf.getConf(),
this.conf.isStable() ? null : this.conf.getOldConf(), task.done,options.isEnableFlexibleRaft() ?
QuorumFactory.createNWRQuorumConfiguration(options.getWriteQuorumFactor(), options.getReadQuorumFactor()):
QuorumFactory.createFlexibleQuorumConfiguration(options.getWriteQuorumFactor(), options.getReadQuorumFactor()):
QuorumFactory.createMajorityQuorumConfiguration())) {
ThreadPoolsFactory.runClosureInThread(this.groupId, task.done, new Status(RaftError.EINTERNAL, "Fail to append task."));
task.reset();
Expand All @@ -389,7 +389,7 @@ prevVoteCtx.init(this.conf.getConf(), this.conf.isStable() ? null : this.conf.ge
final boolean leaderStart) {
// 省略部分代码...
if (!this.ballotBox.appendPendingTask(newConf, oldConf, configurationChangeDone,options.isEnableFlexibleRaft() ?
QuorumFactory.createNWRQuorumConfiguration(options.getWriteQuorumFactor(), options.getReadQuorumFactor()):
QuorumFactory.createFlexibleQuorumConfiguration(options.getWriteQuorumFactor(), options.getReadQuorumFactor()):
QuorumFactory.createMajorityQuorumConfiguration())) {
ThreadPoolsFactory.runClosureInThread(this.groupId, configurationChangeDone, new Status(
RaftError.EINTERNAL, "Fail to append task."));
Expand All @@ -407,19 +407,19 @@ prevVoteCtx.init(this.conf.getConf(), this.conf.isStable() ? null : this.conf.ge

```
public final class QuorumFactory {
public static QuorumConfiguration createNWRQuorumConfiguration(Integer writeFactor,Integer readFactor) {
boolean isEnableNWR = true;
public static QuorumConfiguration createFlexibleQuorumConfiguration(Integer writeFactor,Integer readFactor) {
boolean isEnableFlexibleMode = true;
QuorumConfiguration quorumConfiguration = new QuorumConfiguration();
quorumConfiguration.setReadFactor(readFactor);
quorumConfiguration.setWriteFactor(writeFactor);
quorumConfiguration.setEnableNWR(isEnableNWR);
quorumConfiguration.setEnableFlexibleMode(isEnableFlexibleMode);
return quorumConfiguration;
}

public static QuorumConfiguration createMajorityQuorumConfiguration(){
boolean isEnableNWR = false;
boolean isEnableFlexibleMode = false;
QuorumConfiguration quorumConfiguration = new QuorumConfiguration();
quorumConfiguration.setEnableNWR(isEnableNWR);
quorumConfiguration.setEnableFlexibleMode(isEnableFlexibleMode);
return quorumConfiguration;
}
}
Expand Down