Skip to content

RATIS-1498. Take snapshot on specific ratis server#586

Merged
szetszwo merged 2 commits intoapache:masterfrom
codings-dan:specific
Jan 23, 2022
Merged

RATIS-1498. Take snapshot on specific ratis server#586
szetszwo merged 2 commits intoapache:masterfrom
codings-dan:specific

Conversation

@codings-dan
Copy link
Contributor

What changes were proposed in this pull request?

subtask of Support snapshot command: Take snapshot on specific ratis server

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/RATIS-1498

How was this patch tested?

UT

@codings-dan
Copy link
Contributor Author

@szetszwo I changed the API related to take shanpshot, PTAL, thx! The result of the CI test has nothing to do with this code change.

Error:  Tests run: 3, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 3.116 s <<< FAILURE! - in org.apache.ratis.grpc.TestRaftStateMachineExceptionWithGrpc
Error:  testRetryOnExceptionDuringReplication(org.apache.ratis.grpc.TestRaftStateMachineExceptionWithGrpc)  Time elapsed: 0.59 s  <<< ERROR!
java.lang.NullPointerException
	at java.util.Objects.requireNonNull(Objects.java:203)
	at org.apache.ratis.server.impl.RaftStateMachineExceptionTests.runTestRetryOnExceptionDuringReplication(RaftStateMachineExceptionTests.java:172)
	at org.apache.ratis.server.impl.MiniRaftCluster$Factory$Get.runWithNewCluster(MiniRaftCluster.java:125)
	at org.apache.ratis.server.impl.MiniRaftCluster$Factory$Get.runWithNewCluster(MiniRaftCluster.java:113)
	at org.apache.ratis.server.impl.RaftStateMachineExceptionTests.testRetryOnExceptionDuringReplication(RaftStateMachineExceptionTests.java:147)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:298)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:292)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.lang.Thread.run(Thread.java:748)

Copy link
Contributor

@szetszwo szetszwo left a comment

Choose a reason for hiding this comment

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

@codings-dan , thanks for working on this. We should support the case server == null. See the comment inlined.


/** Get the {@link SnapshotManagementApi}. */
SnapshotManagementApi getSnapshotManagementApi();
/** Get the {@link SnapshotManagementApi} for the given server. */
Copy link
Contributor

Choose a reason for hiding this comment

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

We should support null as below:

  /**
   * If server != null, return the {@link SnapshotManagementApi} for the given server.
   * Otherwise, return the {@link SnapshotManagementApi} for the group.
   */

Comment on lines +41 to +44
final RaftClientReply reply = client.io().sendRequestWithRetry(
() -> SnapshotManagementRequest.newCreate(client.getId(), server,
client.getGroupId(), callId, timeoutMs));
return reply;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should support the case the server == null. When server == null, use client.getLeaderId() as before.

    return client.io().sendRequestWithRetry(() -> SnapshotManagementRequest.newCreate(client.getId(),
        Optional.ofNullable(server).orElseGet(client::getLeaderId), client.getGroupId(), callId, timeoutMs));

if (cl.hasOption(PEER_ID_OPTION_NAME)) {
peerId = RaftPeerId.getRaftPeerId(cl.getOptionValue(PEER_ID_OPTION_NAME));
} else {
peerId = raftClient.getLeaderId();
Copy link
Contributor

Choose a reason for hiding this comment

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

Just set peerId = null. The leader could change so that we should getLeaderId right before sending the rpc.

Copy link
Contributor

@szetszwo szetszwo left a comment

Choose a reason for hiding this comment

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

+1 the change looks good.

@szetszwo szetszwo merged commit 8dc6493 into apache:master Jan 23, 2022
@codings-dan codings-dan deleted the specific branch February 17, 2022 06:34
symious pushed a commit to symious/ratis that referenced this pull request Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants