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

Impl learner for jraft, #8 #312

Merged
merged 12 commits into from
Nov 5, 2019
Merged

Impl learner for jraft, #8 #312

merged 12 commits into from
Nov 5, 2019

Conversation

killme2008
Copy link
Contributor

@killme2008 killme2008 commented Oct 24, 2019

Motivation:

Impl read-only member(learner) for jraft, #8

Modification:

  • Deprecated LogEntry v1 serialization.
  • Supports learner in configuration.
  • Learner configuration change.
  • log replication for learner.
  • RPC protobuf modification for learners.
  • Learner test
  • New Node APIs to query/modify learners info.
  • New CliService APIs to query/modify learners info.

Result:

Fixes #8 .

Don't merge this PR, it's still in development.

@killme2008
Copy link
Contributor Author

@fengjiachun @SteNicholas This PR is ready to be reviewed.

@killme2008 killme2008 changed the title [WIP] Impl learner for jraft, #8 Impl learner for jraft, #8 Oct 26, 2019
@killme2008
Copy link
Contributor Author

@fengjiachun @SteNicholas @masaimu 这个 PR 有空帮忙 review 下。

@killme2008
Copy link
Contributor Author

@fengjiachun fixed all, please review it again.

jraft-core/src/main/java/com/alipay/sofa/jraft/Node.java Outdated Show resolved Hide resolved
jraft-core/src/main/java/com/alipay/sofa/jraft/Node.java Outdated Show resolved Hide resolved
jraft-core/src/main/java/com/alipay/sofa/jraft/Node.java Outdated Show resolved Hide resolved
import com.google.protobuf.Message;

/**
* RemoveLearners request processor.
Copy link
Contributor

Choose a reason for hiding this comment

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

Reset learners request processor.

Copy link
Contributor

@masaimu masaimu Nov 5, 2019

Choose a reason for hiding this comment

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

注释有误:Reset learners request processor.

* @since 1.3.0
* @return the learners set
*/
LinkedHashSet<PeerId> listLearners();
Copy link
Contributor

Choose a reason for hiding this comment

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

这里之所以返回 LinkedHashSet 是我理解为了保序, List 同样保序,使用 List 与 listPeers 保持风格一致,这个我来改一下吧

* @since 1.3.0
* @return the alive learners set
*/
LinkedHashSet<PeerId> listAliveLearners();
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

@masaimu masaimu self-requested a review November 5, 2019 02:41
* (feat) minor change for learners

* (feat) minor change for learners

* typo

* typo

* typo
*
* @param groupId the raft group id
* @param conf current configuration
* @param learners learner peers to add
Copy link
Contributor

Choose a reason for hiding this comment

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

参数注释没对齐。

*
* @param groupId the raft group id
* @param conf current configuration
* @param learners learner peers to remove
Copy link
Contributor

Choose a reason for hiding this comment

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

同上~

Copy link
Contributor

Choose a reason for hiding this comment

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

这个我改了

*
* @param groupId the raft group id
* @param conf current configuration
* @param learners learner peers to set
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

Copy link
Contributor

Choose a reason for hiding this comment

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

这个我改了

// The peer set and learner set should not have intersection set.
Set<PeerId> intersection = listPeers();
intersection.retainAll(listLearners());
if (intersection.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

这边可以直接return intersection.isEmpty()是不是更好点?

Copy link
Contributor

Choose a reason for hiding this comment

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

不能直接 return,因为 false 的情况需要打印日志

return processLearnersOpResponse(groupId, result, "adding learners: %s", learners);

} catch (final Exception e) {
return new Status(-1, e.getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

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

这边需要打印下异常日志吗?

Copy link
Contributor

Choose a reason for hiding this comment

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

status 包含异常信息,返回给调用者了

return processLearnersOpResponse(groupId, result, "addindg learners: %s", learners);

} catch (final Exception e) {
return new Status(-1, e.getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

Copy link
Contributor

Choose a reason for hiding this comment

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

status 包含异常信息,返回给调用者了

@@ -496,7 +638,8 @@ private PeerId findTargetPeer(final PeerId self, final String groupId, final Con
if (result instanceof GetPeersResponse) {
final GetPeersResponse resp = (GetPeersResponse) result;
final List<PeerId> peerIdList = new ArrayList<>();
for (final String peerIdStr : resp.getPeersList()) {
ProtocolStringList responsePeers = returnLearners ? resp.getLearnersList() : resp.getPeersList();
Copy link
Contributor

Choose a reason for hiding this comment

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

缺少final关键字~

Copy link
Contributor

Choose a reason for hiding this comment

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

这个我改过了

@@ -845,7 +861,7 @@ public static void waitForCaughtUp(final ThreadId id, final long maxMargin, fina
@Override
public String toString() {
return "Replicator [state=" + this.state + ", statInfo=" + this.statInfo + ",peerId="
+ this.options.getPeerId() + "]";
+ this.options.getPeerId() + ",type=" + this.options.getReplicatorType() + "]";
Copy link
Contributor

Choose a reason for hiding this comment

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

type前面少了个空格

Copy link
Contributor

Choose a reason for hiding this comment

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

我改过了

if (hasUserMeta() != other.hasUserMeta())
return false;
boolean result = true;
result = result && (hasUserMeta() == other.hasUserMeta());
Copy link
Contributor

Choose a reason for hiding this comment

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

这个地方是不是可以boolean result = hasUserMeta() == other.hasUserMeta();

Copy link
Contributor

Choose a reason for hiding this comment

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

这个类是 protobuf 自动生成,我们不做额外改动

* @param learners learners
* @since 1.3.0
*/
public Configuration(final Iterable<PeerId> conf, final Iterable<PeerId> learners) {
for (final PeerId peer : conf) {
Copy link
Contributor

Choose a reason for hiding this comment

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

这边conf需要判断是否为空吗?

Copy link
Contributor

Choose a reason for hiding this comment

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

done

@fengjiachun
Copy link
Contributor

@SteNicholas 你提的大部分意见,我昨天改过了,还得麻烦更新再看下

@fengjiachun fengjiachun merged commit 0fdb2af into master Nov 5, 2019
@fengjiachun fengjiachun deleted the feature/learner branch November 5, 2019 13:02
luozhiyun993 pushed a commit to luozhiyun993/sofa-jraft that referenced this pull request Nov 25, 2019
* 'master' of https://github.com/sofastack/sofa-jraft:
  (feat) Remove multiple of 10ms for windows platform. (sofastack#351)
  (feat) add thread pool metric report (sofastack#339)
  [ISSUE#347]upgrade the com.fasterxml.jackson.core:jackson-databind to version 2.9.10.1. (sofastack#352)
  (feat) Support readIndex from learner (sofastack#343)
  (feat) counter example (sofastack#318)
  minor fixes (sofastack#336)
  Impl learner for jraft, sofastack#8 (sofastack#312)
  (fix) Declare rpcClient to be volatile, fix sofastack#319 (sofastack#323)
  (feat) add current leader id to node describe (sofastack#322)
  (fix) fix remove metric failed on replicator destroy (sofastack#325)
  (fix) raft options copy (sofastack#321)
  (feat) contains key api (sofastack#302)
  (feat) add rocksdb table_format_config and statistics (sofastack#295)
  feat/async snapshot (sofastack#287)
  fix/state listener (sofastack#285)
@fengjiachun fengjiachun mentioned this pull request Nov 29, 2019
11 tasks
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.

(feat) Read-only member(learner)
4 participants