Skip to content

Commit

Permalink
fix/format (#18)
Browse files Browse the repository at this point in the history
* (fix) comma

* (fix) code format

* (fix) formatter source version to 1.7
  • Loading branch information
fengjiachun committed Mar 8, 2019
1 parent b34565d commit 5a90ee5
Show file tree
Hide file tree
Showing 64 changed files with 649 additions and 654 deletions.
6 changes: 3 additions & 3 deletions .middleware-common/AlipayFormatter120.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/>
<setting id="org.eclipse.jdt.core.compiler.source" value="1.5"/>
<setting id="org.eclipse.jdt.core.compiler.source" value="1.7"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="false"/>
Expand Down Expand Up @@ -164,7 +164,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="20"/>
<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.5"/>
<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.7"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/>
Expand Down Expand Up @@ -237,7 +237,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="18"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.5"/>
<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.7"/>
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member" value="insert"/>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ SOFAJRAFT 是一个基于 [RAFT](https://raft.github.io/) 一致性算法的生
SOFAJRAFT 是从百度的 [braft](https://github.com/brpc/braft) 移植而来,做了一些优化和改进,感谢百度 braft 团队开源了优秀的 C++ RAFT 实现

## 开源许可
SOFAJRAFT 基于 [Apache License 2.0](https://github.com/alipay/sofa-jraft/blob/master/LICENSE) 协议,SOFAJRAFT 依赖了一些三方组件,它们的开源协议也为 Apache License 2.0,
SOFAJRAFT 基于 [Apache License 2.0](https://github.com/alipay/sofa-jraft/blob/master/LICENSE) 协议,SOFAJRAFT 依赖了一些三方组件,它们的开源协议也为 Apache License 2.0
另外 SOFAJRAFT 也直接引用了一些开源的代码(可能有一些小小的改动)包括:
- [JCTools](https://github.com/JCTools/JCTools) 中的 NonBlockingHashMap/NonBlockingHashMapLong
- [Netty](https://github.com/netty/netty) 中的 HashedWheelTimer,另外还参考了 Netty 的 Pipeline 设计
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public static Executor createExecutor(final String prefix, int number) {
if (number <= 0) {
return null;
}
return ThreadPoolUtil.newThreadPool(prefix, true, number, number, 60L,
new SynchronousQueue<>(), createThreadFactory(prefix));
return ThreadPoolUtil.newThreadPool(prefix, true, number, number, 60L, new SynchronousQueue<>(),
createThreadFactory(prefix));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@ public Configuration getConfiguration(final String groupId) {
* @param timeoutMs timeout millis
* @return operation status
*/
public Status refreshLeader(final CliClientService cliClientService, final String groupId,
final int timeoutMs) throws InterruptedException, TimeoutException {
public Status refreshLeader(final CliClientService cliClientService, final String groupId, final int timeoutMs)
throws InterruptedException,
TimeoutException {
Requires.requireTrue(!StringUtils.isBlank(groupId), "Blank group id");
Requires.requireTrue(timeoutMs > 0, "Invalid timeout: " + timeoutMs);

Expand Down Expand Up @@ -309,8 +310,8 @@ public Status refreshConfiguration(final CliClientService cliClientService, fina
rb.setGroupId(groupId);
rb.setLeaderId(leaderId.toString());
try {
final Message result = cliClientService.getPeers(leaderId.getEndpoint(), rb.build(), null)
.get(timeoutMs, TimeUnit.MILLISECONDS);
final Message result = cliClientService.getPeers(leaderId.getEndpoint(), rb.build(), null).get(timeoutMs,
TimeUnit.MILLISECONDS);
if (result instanceof CliRequests.GetPeersResponse) {
final CliRequests.GetPeersResponse resp = (CliRequests.GetPeersResponse) result;
final Configuration newConf = new Configuration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public ConfigurationEntry getLastConfiguration() {
public ConfigurationEntry get(long lastIncludedIndex) {
if (this.configurations.isEmpty()) {
Requires.requireTrue(lastIncludedIndex >= this.snapshot.getId().getIndex(),
"lastIncludedIndex %d is less than snapshot index %d", lastIncludedIndex,
this.snapshot.getId().getIndex());
"lastIncludedIndex %d is less than snapshot index %d", lastIncludedIndex, this.snapshot.getId()
.getIndex());
return snapshot;
}
ListIterator<ConfigurationEntry> it = this.configurations.listIterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class BallotBox implements Lifecycle<BallotBoxOptions> {
private FSMCaller waiter;
private ClosureQueue closureQueue;
private final StampedLock stampedLock = new StampedLock();
private long lastCommittedIndex = 0;
private long lastCommittedIndex = 0;
private long pendingIndex;
private final ArrayDequeue<Ballot> pendingMetaQueue = new ArrayDequeue<>();

Expand Down Expand Up @@ -227,8 +227,8 @@ public boolean setLastCommittedIndex(long lastCommittedIndex) {
try {
if (pendingIndex != 0 || !pendingMetaQueue.isEmpty()) {
Requires.requireTrue(lastCommittedIndex < this.pendingIndex,
"Node changes to leader, pendingIndex=%d, param lastCommittedIndex=%d",
pendingIndex,lastCommittedIndex);
"Node changes to leader, pendingIndex=%d, param lastCommittedIndex=%d", pendingIndex,
lastCommittedIndex);
return false;
}
if (lastCommittedIndex < this.lastCommittedIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ public List<PeerId> getPeers(String groupId, Configuration conf) {
rb.setGroupId(groupId);
rb.setLeaderId(leaderId.toString());
try {
final Message result = cliClientService.getPeers(leaderId.getEndpoint(), rb.build(), null)
.get(cliOptions.getTimeoutMs() <= 0 ? this.cliOptions.getRpcDefaultTimeout()
: cliOptions.getTimeoutMs(), TimeUnit.MILLISECONDS);
final Message result = cliClientService.getPeers(leaderId.getEndpoint(), rb.build(), null).get(
cliOptions.getTimeoutMs() <= 0 ? this.cliOptions.getRpcDefaultTimeout() : cliOptions.getTimeoutMs(),
TimeUnit.MILLISECONDS);
if (result instanceof GetPeersResponse) {
final GetPeersResponse resp = (GetPeersResponse) result;
final List<PeerId> peerIdList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ public boolean init(FSMCallerOptions opts) {
this.lastAppliedIndex.set(opts.getBootstrapId().getIndex());
this.notifyLastAppliedIndexUpdated(lastAppliedIndex.get());
this.lastAppliedTerm = opts.getBootstrapId().getTerm();
this.disruptor = new Disruptor<>(new ApplyTaskFactory(), opts.getDisruptorBufferSize(),
new NamedThreadFactory("Jraft-FSMCaller-disruptor-", true));
this.disruptor = new Disruptor<>(new ApplyTaskFactory(), opts.getDisruptorBufferSize(), new NamedThreadFactory(
"Jraft-FSMCaller-disruptor-", true));
this.disruptor.handleEventsWith(new ApplyTaskHandler());
this.disruptor.setDefaultExceptionHandler(new LogExceptionHandler<Object>(this.getClass().getSimpleName()));
this.disruptor.start();
Expand Down Expand Up @@ -468,7 +468,7 @@ private void doCommitted(long committedIndex) {
if (iterImpl.entry().getType() != EnumOutter.EntryType.ENTRY_TYPE_DATA) {
if (iterImpl.entry().getType() == EnumOutter.EntryType.ENTRY_TYPE_CONFIGURATION) {
if (iterImpl.entry().getOldPeers() != null && !iterImpl.entry().getOldPeers().isEmpty()) {
//Joint stage is not supposed to be noticeable by end users.
// Joint stage is not supposed to be noticeable by end users.
fsm.onConfigurationCommitted(new Configuration(iterImpl.entry().getPeers()));
}
}
Expand Down Expand Up @@ -506,7 +506,7 @@ private void onTaskCommitted(final List<Closure> closures) {
final int closureListSize = closures.size();
for (int i = 0; i < closureListSize; i++) {
final Closure done = closures.get(i);
if (done != null && done instanceof TaskClosure) {
if (done instanceof TaskClosure) {
((TaskClosure) done).onCommitted();
}
}
Expand All @@ -532,13 +532,13 @@ private void doApplyTasks(IteratorImpl iterImpl) {
private void doSnapshotSave(SaveSnapshotClosure done) {
Requires.requireNonNull(done, "SaveSnapshotClosure is null");
final long lastAppliedIndex = this.lastAppliedIndex.get();
final RaftOutter.SnapshotMeta.Builder metaBuilder = RaftOutter.SnapshotMeta.newBuilder().setLastIncludedIndex(lastAppliedIndex)
.setLastIncludedTerm(this.lastAppliedTerm);
final RaftOutter.SnapshotMeta.Builder metaBuilder = RaftOutter.SnapshotMeta.newBuilder()
.setLastIncludedIndex(lastAppliedIndex).setLastIncludedTerm(this.lastAppliedTerm);
final ConfigurationEntry confEntry = logManager.getConfiguration(lastAppliedIndex);
if (confEntry == null || confEntry.isEmpty()) {
LOG.error("Empty conf entry for lastAppliedIndex={}", lastAppliedIndex);
Utils.runClosureInThread(done,
new Status(RaftError.EINVAL, "Empty conf entry for lastAppliedIndex=%s", lastAppliedIndex));
Utils.runClosureInThread(done, new Status(RaftError.EINVAL, "Empty conf entry for lastAppliedIndex=%s",
lastAppliedIndex));
return;
}
for (final PeerId peer : confEntry.getConf()) {
Expand Down Expand Up @@ -609,23 +609,24 @@ private void doSnapshotLoad(LoadSnapshotClosure done) {
done.run(new Status(RaftError.EINVAL, "SnapshotReader load meta failed"));
if (reader.getRaftError() == RaftError.EIO) {
final RaftException err = new RaftException(EnumOutter.ErrorType.ERROR_TYPE_SNAPSHOT, RaftError.EIO,
"Fail to load snapshot meta");
"Fail to load snapshot meta");
setError(err);
}
return;
}
final LogId lastAppliedId = new LogId(lastAppliedIndex.get(), lastAppliedTerm);
final LogId snapshotId = new LogId(meta.getLastIncludedIndex(), meta.getLastIncludedTerm());
if (lastAppliedId.compareTo(snapshotId) > 0) {
done.run(new Status(RaftError.ESTALE,
done.run(new Status(
RaftError.ESTALE,
"Loading a stale snapshot last_applied_index=%d last_applied_term=%d snapshot_index=%d snapshot_term=%d",
lastAppliedId.getIndex(), lastAppliedId.getTerm(), snapshotId.getIndex(), snapshotId.getTerm()));
return;
}
if (!this.fsm.onSnapshotLoad(reader)) {
done.run(new Status(-1, "StateMachine onSnapshotLoad failed"));
final RaftException e = new RaftException(EnumOutter.ErrorType.ERROR_TYPE_STATE_MACHINE, RaftError.ESTATEMACHINE,
"StateMachine onSnapshotLoad failed");
final RaftException e = new RaftException(EnumOutter.ErrorType.ERROR_TYPE_STATE_MACHINE,
RaftError.ESTATEMACHINE, "StateMachine onSnapshotLoad failed");
setError(e);
return;
}
Expand Down
Loading

0 comments on commit 5a90ee5

Please sign in to comment.