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

Add Flexible Mode For JRaft #1013

Closed
wants to merge 26 commits into from
Closed

Add Flexible Mode For JRaft #1013

wants to merge 26 commits into from

Conversation

1294566108
Copy link
Contributor

Motivation:

Implementing flexible raft by Integrating QuorumNWR for SOFA-JRaft

Modification:

  1. Add rfc docs
  2. Add FlexibleRaft-Mode For SOFA-JRaft

Result:

Fixes #1003 .

使用docker启动6个ubuntu容器进行jepsen测试,其中ubuntu-1作为control节点,ubuntu-2~6作为test节点,并通过mvn install自测试代码到本地仓库进行jepsen测试。

测试结果如下所示:

atomic.bridge:

image
image

atomic.configuration:

image
image

atomic.crash:

image
image

atomic.partition:

image
image

atomic.partition-majority:

image
image

atomic.pause:

image
image

1294566108 and others added 21 commits April 9, 2023 14:21
# Conflicts:
#	jraft-core/src/main/java/com/alipay/sofa/jraft/Quorum.java
#	jraft-core/src/main/java/com/alipay/sofa/jraft/core/BallotBox.java
#	jraft-core/src/main/java/com/alipay/sofa/jraft/core/NodeImpl.java
#	jraft-core/src/main/java/com/alipay/sofa/jraft/entity/MajorityQuorum.java
#	jraft-core/src/main/java/com/alipay/sofa/jraft/entity/NWRQuorum.java
#	jraft-core/src/main/java/com/alipay/sofa/jraft/entity/QuorumConfiguration.java
#	jraft-core/src/main/java/com/alipay/sofa/jraft/entity/QuorumFactory.java
#	jraft-core/src/main/java/com/alipay/sofa/jraft/option/NodeOptions.java
#	jraft-core/src/test/java/com/alipay/sofa/jraft/entity/NWRQuorumTest.java
@shihuili1218
Copy link
Collaborator

赞!我会尽快阅读。

Copy link
Collaborator

@shihuili1218 shihuili1218 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我提了一些建议,可以在讨论讨论


import com.alipay.sofa.jraft.conf.Configuration;
import com.alipay.sofa.jraft.entity.PeerId;
import org.slf4j.Logger;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

按照项目本身的import顺序,会更好。
java.*
javax.*
org.*
com.*
all other import
static all other import

this.oldQuorum = this.oldPeers.size() / 2 + 1;
return true;
}
public abstract void grant(final PeerId peerId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看代码,这个方法应该不用修饰为abstract

@@ -20,6 +20,8 @@

import javax.annotation.concurrent.ThreadSafe;

import com.alipay.sofa.jraft.Quorum;
import com.alipay.sofa.jraft.entity.*;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不建议使用import *
以及import顺序

* @param conf current configuration
* @param oldConf old configuration
* @param done callback
* @param quorumConfiguration quorum configuration
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format

public boolean appendPendingTask(final Configuration conf, final Configuration oldConf, final Closure done,
final QuorumConfiguration quorumConfiguration) {
final Quorum quorum;
quorum = quorumConfiguration.isEnableFlexibleMode() ? new FlexibleQuorum(quorumConfiguration.getWriteFactor(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个判断在这是很频繁的,而isEnableFlexibleMode变化只会在启动、配置变更时,因此这个判断是否应该考虑放在这些地方。

例如:

interface Quorum{
    int w(int n)
    int r(int n)
}
class FlexibleQuorum impl Quorum
class MajorityQuorum impl Quorum

启动时:
private Quorum quorum = isEnableFlexibleMode? FlexibleQuorum: MajorityQuorum

使用时:
Ballot ballot = BallotFactor.createWriteBallot(oldConfig, newConfig, quorum)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

下文用到的getReadQuorum,也可以这样获取

newConf,
oldConf,
configurationChangeDone,
options.isEnableFlexibleRaft() ? QuorumFactory.createFlexibleQuorumConfiguration(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同样的很频繁,得考虑重新组织代码

/**
* @author Akai
*/
public class FlexibleQuorum extends Quorum {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该是缺少一个实体。上文给过伪代码
一个用于计算,一个用于grant,Factory用于创建read、write

public class QuorumConfiguration {
private Integer readFactor;
private Integer writeFactor;
private boolean isEnableFlexibleMode;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enableFlexibleMode可能会更好。下方的isEnableFlexibleMode()不用修改


public void setWriteQuorumFactor(int writeQuorumFactor) {
this.writeQuorumFactor = writeQuorumFactor;
enableFlexibleRaft();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不建议在get/set放太多逻辑,重新生成就都覆盖了

return enableFlexibleRaft;
}

private void enableFlexibleRaft() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

提供这样方便使用的方法是好的,但是我觉得它仍然需要set方法

@1294566108 1294566108 closed this Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[OSPP开源之夏] 结合 NWR 实现 Flexible raft,用于自定义 Quorum 的大小
2 participants