-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
@fengjiachun @SteNicholas This PR is ready to be reviewed. |
@fengjiachun @SteNicholas @masaimu 这个 PR 有空帮忙 review 下。 |
jraft-core/src/main/java/com/alipay/sofa/jraft/core/CliServiceImpl.java
Outdated
Show resolved
Hide resolved
jraft-core/src/main/java/com/alipay/sofa/jraft/core/NodeImpl.java
Outdated
Show resolved
Hide resolved
jraft-core/src/main/java/com/alipay/sofa/jraft/core/NodeImpl.java
Outdated
Show resolved
Hide resolved
jraft-core/src/main/java/com/alipay/sofa/jraft/core/ReplicatorGroupImpl.java
Outdated
Show resolved
Hide resolved
jraft-core/src/main/java/com/alipay/sofa/jraft/entity/codec/v1/V1Encoder.java
Show resolved
Hide resolved
jraft-core/src/main/java/com/alipay/sofa/jraft/option/ReplicatorOptions.java
Outdated
Show resolved
Hide resolved
@fengjiachun fixed all, please review it again. |
jraft-core/src/main/java/com/alipay/sofa/jraft/conf/Configuration.java
Outdated
Show resolved
Hide resolved
jraft-core/src/main/java/com/alipay/sofa/jraft/conf/Configuration.java
Outdated
Show resolved
Hide resolved
import com.google.protobuf.Message; | ||
|
||
/** | ||
* RemoveLearners request processor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reset learners request processor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释有误:Reset learners request processor.
d139e0f
to
dd92e39
Compare
dd92e39
to
b1cc39a
Compare
* @since 1.3.0 | ||
* @return the learners set | ||
*/ | ||
LinkedHashSet<PeerId> listLearners(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
* (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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上~
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这边可以直接return intersection.isEmpty()是不是更好点?
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这边需要打印下异常日志吗?
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
缺少final关键字~
There was a problem hiding this comment.
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() + "]"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type前面少了个空格
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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();
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这边conf需要判断是否为空吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@SteNicholas 你提的大部分意见,我昨天改过了,还得麻烦更新再看下 |
* '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)
Motivation:
Impl read-only member(learner) for jraft, #8
Modification:
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.