本文整理汇总了Java中org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot类的典型用法代码示例。如果您正苦于以下问题:Java ApplySnapshot类的具体用法?Java ApplySnapshot怎么用?Java ApplySnapshot使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ApplySnapshot类属于org.opendaylight.controller.cluster.raft.base.messages包,在下文中一共展示了ApplySnapshot类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleSnapshotMessage
import org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot; //导入依赖的package包/类
boolean handleSnapshotMessage(Object message, ActorRef sender) {
if (message instanceof ApplySnapshot) {
onApplySnapshot((ApplySnapshot) message);
} else if (message instanceof SaveSnapshotSuccess) {
onSaveSnapshotSuccess((SaveSnapshotSuccess) message);
} else if (message instanceof SaveSnapshotFailure) {
onSaveSnapshotFailure((SaveSnapshotFailure) message);
} else if (message instanceof CaptureSnapshotReply) {
onCaptureSnapshotReply((CaptureSnapshotReply) message);
} else if (COMMIT_SNAPSHOT.equals(message)) {
context.getSnapshotManager().commit(-1, -1);
} else if (message instanceof GetSnapshot) {
onGetSnapshot(sender);
} else {
return false;
}
return true;
}
示例2: possiblyRestoreFromSnapshot
import org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot; //导入依赖的package包/类
@SuppressWarnings("checkstyle:IllegalCatch")
private void possiblyRestoreFromSnapshot() {
Snapshot restoreFromSnapshot = cohort.getRestoreFromSnapshot();
if (restoreFromSnapshot == null) {
return;
}
if (anyDataRecovered) {
log.warn("{}: The provided restore snapshot was not applied because the persistence store is not empty",
context.getId());
return;
}
log.debug("{}: Restore snapshot: {}", context.getId(), restoreFromSnapshot);
context.getSnapshotManager().apply(new ApplySnapshot(restoreFromSnapshot));
}
示例3: testOnApplySnapshot
import org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot; //导入依赖的package包/类
@Test
public void testOnApplySnapshot() {
long lastAppliedDuringSnapshotCapture = 1;
long lastIndexDuringSnapshotCapture = 2;
byte[] snapshotBytes = {1,2,3,4,5};
Snapshot snapshot = Snapshot.create(ByteState.of(snapshotBytes), Collections.<ReplicatedLogEntry>emptyList(),
lastIndexDuringSnapshotCapture, 1, lastAppliedDuringSnapshotCapture, 1, -1, null, null);
ApplySnapshot applySnapshot = new ApplySnapshot(snapshot);
sendMessageToSupport(applySnapshot);
verify(mockSnapshotManager).apply(applySnapshot);
}
示例4: onApplySnapshot
import org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot; //导入依赖的package包/类
private void onApplySnapshot(ApplySnapshot message) {
log.info("{}: Applying snapshot on follower: {}", context.getId(), message.getSnapshot());
context.getSnapshotManager().apply(message);
}
示例5: apply
import org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot; //导入依赖的package包/类
@Override
public void apply(ApplySnapshot snapshot) {
currentState.apply(snapshot);
}
示例6: handleInstallSnapshot
import org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot; //导入依赖的package包/类
private void handleInstallSnapshot(final ActorRef sender, final InstallSnapshot installSnapshot) {
log.debug("{}: handleInstallSnapshot: {}", logName(), installSnapshot);
leaderId = installSnapshot.getLeaderId();
if (snapshotTracker == null) {
snapshotTracker = new SnapshotTracker(log, installSnapshot.getTotalChunks(), installSnapshot.getLeaderId(),
context);
}
updateInitialSyncStatus(installSnapshot.getLastIncludedIndex(), installSnapshot.getLeaderId());
try {
final InstallSnapshotReply reply = new InstallSnapshotReply(
currentTerm(), context.getId(), installSnapshot.getChunkIndex(), true);
if (snapshotTracker.addChunk(installSnapshot.getChunkIndex(), installSnapshot.getData(),
installSnapshot.getLastChunkHashCode())) {
log.info("{}: Snapshot installed from leader: {}", logName(), installSnapshot.getLeaderId());
Snapshot snapshot = Snapshot.create(
context.getSnapshotManager().convertSnapshot(snapshotTracker.getSnapshotBytes()),
new ArrayList<>(),
installSnapshot.getLastIncludedIndex(),
installSnapshot.getLastIncludedTerm(),
installSnapshot.getLastIncludedIndex(),
installSnapshot.getLastIncludedTerm(),
context.getTermInformation().getCurrentTerm(),
context.getTermInformation().getVotedFor(),
installSnapshot.getServerConfig().orNull());
ApplySnapshot.Callback applySnapshotCallback = new ApplySnapshot.Callback() {
@Override
public void onSuccess() {
log.debug("{}: handleInstallSnapshot returning: {}", logName(), reply);
sender.tell(reply, actor());
}
@Override
public void onFailure() {
sender.tell(new InstallSnapshotReply(currentTerm(), context.getId(), -1, false), actor());
}
};
actor().tell(new ApplySnapshot(snapshot, applySnapshotCallback), actor());
closeSnapshotTracker();
} else {
log.debug("{}: handleInstallSnapshot returning: {}", logName(), reply);
sender.tell(reply, actor());
}
} catch (IOException e) {
log.debug("{}: Exception in InstallSnapshot of follower", logName(), e);
sender.tell(new InstallSnapshotReply(currentTerm(), context.getId(),
-1, false), actor());
closeSnapshotTracker();
}
}
示例7: testFollowerRecoveryAfterInstallSnapshot
import org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot; //导入依赖的package包/类
@Test
public void testFollowerRecoveryAfterInstallSnapshot() throws Exception {
send2InitialPayloads();
leader = leaderActor.underlyingActor().getCurrentBehavior();
follower2Actor = newTestRaftActor(follower2Id, ImmutableMap.of(leaderId, testActorPath(leaderId)),
newFollowerConfigParams());
follower2CollectorActor = follower2Actor.underlyingActor().collectorActor();
leaderActor.tell(new SetPeerAddress(follower2Id, follower2Actor.path().toString()), ActorRef.noSender());
final MockPayload payload2 = sendPayloadData(leaderActor, "two");
// Verify the leader applies the 3rd payload state.
MessageCollectorActor.expectMatching(leaderCollectorActor, ApplyJournalEntries.class, 1);
MessageCollectorActor.expectMatching(follower2CollectorActor, ApplyJournalEntries.class, 1);
assertEquals("Leader commit index", 2, leaderContext.getCommitIndex());
assertEquals("Leader last applied", 2, leaderContext.getLastApplied());
assertEquals("Leader snapshot index", 1, leaderContext.getReplicatedLog().getSnapshotIndex());
assertEquals("Leader replicatedToAllIndex", 1, leader.getReplicatedToAllIndex());
killActor(follower2Actor);
InMemoryJournal.clear();
follower2Actor = newTestRaftActor(follower2Id, ImmutableMap.of(leaderId, testActorPath(leaderId)),
newFollowerConfigParams());
TestRaftActor follower2Underlying = follower2Actor.underlyingActor();
follower2CollectorActor = follower2Underlying.collectorActor();
follower2Context = follower2Underlying.getRaftActorContext();
leaderActor.tell(new SetPeerAddress(follower2Id, follower2Actor.path().toString()), ActorRef.noSender());
// The leader should install a snapshot so wait for the follower to receive ApplySnapshot.
MessageCollectorActor.expectFirstMatching(follower2CollectorActor, ApplySnapshot.class);
// Wait for the follower to persist the snapshot.
MessageCollectorActor.expectFirstMatching(follower2CollectorActor, SaveSnapshotSuccess.class);
final List<MockPayload> expFollowerState = Arrays.asList(payload0, payload1, payload2);
assertEquals("Follower commit index", 2, follower2Context.getCommitIndex());
assertEquals("Follower last applied", 2, follower2Context.getLastApplied());
assertEquals("Follower snapshot index", 2, follower2Context.getReplicatedLog().getSnapshotIndex());
assertEquals("Follower state", expFollowerState, follower2Underlying.getState());
killActor(follower2Actor);
follower2Actor = newTestRaftActor(follower2Id, ImmutableMap.of(leaderId, testActorPath(leaderId)),
newFollowerConfigParams());
follower2Underlying = follower2Actor.underlyingActor();
follower2Underlying.waitForRecoveryComplete();
follower2Context = follower2Underlying.getRaftActorContext();
assertEquals("Follower commit index", 2, follower2Context.getCommitIndex());
assertEquals("Follower last applied", 2, follower2Context.getLastApplied());
assertEquals("Follower snapshot index", 2, follower2Context.getReplicatedLog().getSnapshotIndex());
assertEquals("Follower state", expFollowerState, follower2Underlying.getState());
}
示例8: testRaftActorForwardsToRaftActorSnapshotMessageSupport
import org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot; //导入依赖的package包/类
@Test
public void testRaftActorForwardsToRaftActorSnapshotMessageSupport() {
String persistenceId = factory.generateActorId("leader-");
DefaultConfigParamsImpl config = new DefaultConfigParamsImpl();
config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));
RaftActorSnapshotMessageSupport mockSupport = mock(RaftActorSnapshotMessageSupport.class);
TestActorRef<MockRaftActor> mockActorRef = factory.createTestActor(MockRaftActor.builder().id(persistenceId)
.config(config).snapshotMessageSupport(mockSupport).props());
MockRaftActor mockRaftActor = mockActorRef.underlyingActor();
// Wait for akka's recovery to complete so it doesn't interfere.
mockRaftActor.waitForRecoveryComplete();
ApplySnapshot applySnapshot = new ApplySnapshot(mock(Snapshot.class));
doReturn(true).when(mockSupport).handleSnapshotMessage(same(applySnapshot), any(ActorRef.class));
mockRaftActor.handleCommand(applySnapshot);
CaptureSnapshotReply captureSnapshotReply = new CaptureSnapshotReply(ByteState.empty(),
java.util.Optional.empty());
doReturn(true).when(mockSupport).handleSnapshotMessage(same(captureSnapshotReply), any(ActorRef.class));
mockRaftActor.handleCommand(captureSnapshotReply);
SaveSnapshotSuccess saveSnapshotSuccess = new SaveSnapshotSuccess(new SnapshotMetadata("", 0L, 0L));
doReturn(true).when(mockSupport).handleSnapshotMessage(same(saveSnapshotSuccess), any(ActorRef.class));
mockRaftActor.handleCommand(saveSnapshotSuccess);
SaveSnapshotFailure saveSnapshotFailure = new SaveSnapshotFailure(new SnapshotMetadata("", 0L, 0L),
new Throwable());
doReturn(true).when(mockSupport).handleSnapshotMessage(same(saveSnapshotFailure), any(ActorRef.class));
mockRaftActor.handleCommand(saveSnapshotFailure);
doReturn(true).when(mockSupport).handleSnapshotMessage(same(RaftActorSnapshotMessageSupport.COMMIT_SNAPSHOT),
any(ActorRef.class));
mockRaftActor.handleCommand(RaftActorSnapshotMessageSupport.COMMIT_SNAPSHOT);
doReturn(true).when(mockSupport).handleSnapshotMessage(same(GetSnapshot.INSTANCE), any(ActorRef.class));
mockRaftActor.handleCommand(GetSnapshot.INSTANCE);
verify(mockSupport).handleSnapshotMessage(same(applySnapshot), any(ActorRef.class));
verify(mockSupport).handleSnapshotMessage(same(captureSnapshotReply), any(ActorRef.class));
verify(mockSupport).handleSnapshotMessage(same(saveSnapshotSuccess), any(ActorRef.class));
verify(mockSupport).handleSnapshotMessage(same(saveSnapshotFailure), any(ActorRef.class));
verify(mockSupport).handleSnapshotMessage(same(RaftActorSnapshotMessageSupport.COMMIT_SNAPSHOT),
any(ActorRef.class));
verify(mockSupport).handleSnapshotMessage(same(GetSnapshot.INSTANCE), any(ActorRef.class));
}
示例9: testAddServerWithNoExistingFollower
import org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot; //导入依赖的package包/类
@Test
public void testAddServerWithNoExistingFollower() throws Exception {
LOG.info("testAddServerWithNoExistingFollower starting");
setupNewFollower();
RaftActorContext initialActorContext = new MockRaftActorContext();
initialActorContext.setCommitIndex(1);
initialActorContext.setLastApplied(1);
initialActorContext.setReplicatedLog(new MockRaftActorContext.MockReplicatedLogBuilder().createEntries(
0, 2, 1).build());
TestActorRef<MockLeaderRaftActor> leaderActor = actorFactory.createTestActor(
MockLeaderRaftActor.props(ImmutableMap.<String, String>of(),
initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()),
actorFactory.generateActorId(LEADER_ID));
MockLeaderRaftActor leaderRaftActor = leaderActor.underlyingActor();
final RaftActorContext leaderActorContext = leaderRaftActor.getRaftActorContext();
final ActorRef leaderCollectorActor = newLeaderCollectorActor(leaderRaftActor);
leaderActor.tell(new AddServer(NEW_SERVER_ID, newFollowerRaftActor.path().toString(), true), testKit.getRef());
// Leader should install snapshot - capture and verify ApplySnapshot contents
ApplySnapshot applySnapshot = expectFirstMatching(newFollowerCollectorActor, ApplySnapshot.class);
List<Object> snapshotState = MockRaftActor.fromState(applySnapshot.getSnapshot().getState());
assertEquals("Snapshot state", snapshotState, leaderRaftActor.getState());
AddServerReply addServerReply = testKit.expectMsgClass(JavaTestKit.duration("5 seconds"), AddServerReply.class);
assertEquals("getStatus", ServerChangeStatus.OK, addServerReply.getStatus());
assertEquals("getLeaderHint", LEADER_ID, addServerReply.getLeaderHint().get());
// Verify ServerConfigurationPayload entry in leader's log
expectFirstMatching(leaderCollectorActor, ApplyState.class);
assertEquals("Leader journal last index", 2, leaderActorContext.getReplicatedLog().lastIndex());
assertEquals("Leader commit index", 2, leaderActorContext.getCommitIndex());
assertEquals("Leader last applied index", 2, leaderActorContext.getLastApplied());
verifyServerConfigurationPayloadEntry(leaderActorContext.getReplicatedLog(), votingServer(LEADER_ID),
votingServer(NEW_SERVER_ID));
// Verify ServerConfigurationPayload entry in the new follower
expectFirstMatching(newFollowerCollectorActor, ApplyState.class);
assertEquals("New follower journal last index", 2, newFollowerActorContext.getReplicatedLog().lastIndex());
verifyServerConfigurationPayloadEntry(newFollowerActorContext.getReplicatedLog(), votingServer(LEADER_ID),
votingServer(NEW_SERVER_ID));
// Verify new server config was applied in the new follower
assertEquals("New follower peers", Sets.newHashSet(LEADER_ID), newFollowerActorContext.getPeerIds());
LOG.info("testAddServerWithNoExistingFollower ending");
}
示例10: testAddServerWithPriorSnapshotInProgress
import org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot; //导入依赖的package包/类
@Test
public void testAddServerWithPriorSnapshotInProgress() throws Exception {
LOG.info("testAddServerWithPriorSnapshotInProgress starting");
setupNewFollower();
RaftActorContext initialActorContext = new MockRaftActorContext();
TestActorRef<MockLeaderRaftActor> leaderActor = actorFactory.createTestActor(
MockLeaderRaftActor.props(ImmutableMap.<String, String>of(),
initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()),
actorFactory.generateActorId(LEADER_ID));
MockLeaderRaftActor leaderRaftActor = leaderActor.underlyingActor();
final RaftActorContext leaderActorContext = leaderRaftActor.getRaftActorContext();
ActorRef leaderCollectorActor = newLeaderCollectorActor(leaderRaftActor);
// Drop commit message for now to delay snapshot completion
leaderRaftActor.setDropMessageOfType(String.class);
leaderActor.tell(new InitiateCaptureSnapshot(), leaderActor);
Object commitMsg = expectFirstMatching(leaderCollectorActor, COMMIT_MESSAGE_CLASS);
leaderActor.tell(new AddServer(NEW_SERVER_ID, newFollowerRaftActor.path().toString(), true), testKit.getRef());
leaderRaftActor.setDropMessageOfType(null);
leaderActor.tell(commitMsg, leaderActor);
AddServerReply addServerReply = testKit.expectMsgClass(JavaTestKit.duration("5 seconds"), AddServerReply.class);
assertEquals("getStatus", ServerChangeStatus.OK, addServerReply.getStatus());
assertEquals("getLeaderHint", LEADER_ID, addServerReply.getLeaderHint().get());
expectFirstMatching(newFollowerCollectorActor, ApplySnapshot.class);
// Verify ServerConfigurationPayload entry in leader's log
expectFirstMatching(leaderCollectorActor, ApplyState.class);
assertEquals("Leader journal last index", 0, leaderActorContext.getReplicatedLog().lastIndex());
assertEquals("Leader commit index", 0, leaderActorContext.getCommitIndex());
assertEquals("Leader last applied index", 0, leaderActorContext.getLastApplied());
verifyServerConfigurationPayloadEntry(leaderActorContext.getReplicatedLog(), votingServer(LEADER_ID),
votingServer(NEW_SERVER_ID));
LOG.info("testAddServerWithPriorSnapshotInProgress ending");
}
示例11: testApplySnapshot
import org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot; //导入依赖的package包/类
@Test
public void testApplySnapshot() throws Exception {
final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps()
.withDispatcher(Dispatchers.DefaultDispatcherId()), "testApplySnapshot");
ShardTestKit.waitUntilLeader(shard);
final DataTree store = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
store.setSchemaContext(SCHEMA_CONTEXT);
final ContainerNode container = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
.withChild(ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).addChild(
ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1)).build()).build();
writeToStore(store, TestModel.TEST_PATH, container);
final YangInstanceIdentifier root = YangInstanceIdentifier.EMPTY;
final NormalizedNode<?,?> expected = readStore(store, root);
final Snapshot snapshot = Snapshot.create(
new ShardSnapshotState(new MetadataShardDataTreeSnapshot(expected)),
Collections.<ReplicatedLogEntry>emptyList(), 1, 2, 3, 4, -1, null, null);
shard.tell(new ApplySnapshot(snapshot), ActorRef.noSender());
final Stopwatch sw = Stopwatch.createStarted();
while (sw.elapsed(TimeUnit.SECONDS) <= 5) {
Uninterruptibles.sleepUninterruptibly(75, TimeUnit.MILLISECONDS);
try {
assertEquals("Root node", expected, readStore(shard, root));
return;
} catch (final AssertionError e) {
// try again
}
}
fail("Snapshot was not applied");
}
示例12: apply
import org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot; //导入依赖的package包/类
/**
* Applies a snapshot on a follower that was installed by the leader.
*
* @param snapshot the Snapshot to apply.
*/
void apply(ApplySnapshot snapshot);