Search in sources :

Example 1 with ShardSnapshotState

use of org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState in project controller by opendaylight.

the class ShardRecoveryCoordinatorTest method createSnapshot.

private static ShardSnapshotState createSnapshot() {
    final DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SchemaContextHelper.select(SchemaContextHelper.CARS_YANG, SchemaContextHelper.PEOPLE_YANG));
    DataTreeSnapshot snapshot = dataTree.takeSnapshot();
    DataTreeModification modification = snapshot.newModification();
    modification.merge(CarsModel.BASE_PATH, CarsModel.create());
    modification.merge(PeopleModel.BASE_PATH, PeopleModel.create());
    modification.ready();
    dataTree.commit(dataTree.prepare(modification));
    return new ShardSnapshotState(new MetadataShardDataTreeSnapshot(dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY).get()));
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) ShardSnapshotState(org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)

Example 2 with ShardSnapshotState

use of org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState in project controller by opendaylight.

the class AbstractShardTest method setupInMemorySnapshotStore.

DataTree setupInMemorySnapshotStore() throws DataValidationFailedException {
    final DataTree testStore = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);
    writeToStore(testStore, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
    final NormalizedNode<?, ?> root = readStore(testStore, YangInstanceIdentifier.EMPTY);
    InMemorySnapshotStore.addSnapshot(shardID.toString(), Snapshot.create(new ShardSnapshotState(new MetadataShardDataTreeSnapshot(root)), Collections.<ReplicatedLogEntry>emptyList(), 0, 1, -1, -1, 1, null, null));
    return testStore;
}
Also used : ReplicatedLogEntry(org.opendaylight.controller.cluster.raft.ReplicatedLogEntry) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) ShardSnapshotState(org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)

Example 3 with ShardSnapshotState

use of org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState in project controller by opendaylight.

the class ShardRecoveryCoordinator method applyRecoverySnapshot.

/**
 * Applies a recovered snapshot to the data store.
 *
 * @param snapshotState the serialized snapshot
 */
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public void applyRecoverySnapshot(final Snapshot.State snapshotState) {
    if (!(snapshotState instanceof ShardSnapshotState)) {
        log.debug("{}: applyRecoverySnapshot ignoring snapshot: {}", snapshotState);
    }
    log.debug("{}: Applying recovered snapshot", shardName);
    ShardDataTreeSnapshot shardSnapshot = ((ShardSnapshotState) snapshotState).getSnapshot();
    try {
        store.applyRecoverySnapshot(shardSnapshot);
    } catch (Exception e) {
        final File f = writeRoot("snapshot", shardSnapshot.getRootNode().orElse(null));
        throw new IllegalStateException(String.format("%s: Failed to apply recovery snapshot %s. Node data was written to file %s", shardName, shardSnapshot, f), e);
    }
}
Also used : ShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshot) ShardSnapshotState(org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState) File(java.io.File)

Example 4 with ShardSnapshotState

use of org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState in project controller by opendaylight.

the class ShardSnapshotCohort method applySnapshot.

@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public void applySnapshot(final Snapshot.State snapshotState) {
    if (!(snapshotState instanceof ShardSnapshotState)) {
        log.debug("{}: applySnapshot ignoring snapshot: {}", snapshotState);
    }
    final ShardDataTreeSnapshot snapshot = ((ShardSnapshotState) snapshotState).getSnapshot();
    // Since this will be done only on Recovery or when this actor is a Follower
    // we can safely commit everything in here. We not need to worry about event notifications
    // as they would have already been disabled on the follower
    log.info("{}: Applying snapshot", logId);
    try {
        store.applySnapshot(snapshot);
    } catch (Exception e) {
        log.error("{}: Failed to apply snapshot {}", logId, snapshot, e);
        return;
    }
    log.info("{}: Done applying snapshot", logId);
}
Also used : ShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshot) ShardSnapshotState(org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState) IOException(java.io.IOException)

Example 5 with ShardSnapshotState

use of org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState in project controller by opendaylight.

the class ShardSnapshotActor method onSerializeSnapshot.

private void onSerializeSnapshot(final SerializeSnapshot request) {
    Optional<OutputStream> installSnapshotStream = request.getInstallSnapshotStream();
    if (installSnapshotStream.isPresent()) {
        try (ObjectOutputStream out = new ObjectOutputStream(installSnapshotStream.get())) {
            request.getSnapshot().serialize(out);
        } catch (IOException e) {
            // TODO - we should communicate the failure in the CaptureSnapshotReply.
            LOG.error("Error serializing snapshot", e);
        }
    }
    request.getReplyTo().tell(new CaptureSnapshotReply(new ShardSnapshotState(request.getSnapshot()), installSnapshotStream), ActorRef.noSender());
}
Also used : CaptureSnapshotReply(org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshotReply) ShardSnapshotState(org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState) OutputStream(java.io.OutputStream) ObjectOutputStream(java.io.ObjectOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

Aggregations

ShardSnapshotState (org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState)10 MetadataShardDataTreeSnapshot (org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot)7 DataTree (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)6 InMemoryDataTreeFactory (org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)6 Snapshot (org.opendaylight.controller.cluster.raft.persisted.Snapshot)4 Test (org.junit.Test)3 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 AddressFromURIString (akka.actor.AddressFromURIString)2 IOException (java.io.IOException)2 ShardDataTreeSnapshot (org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshot)2 ReplicatedLogEntry (org.opendaylight.controller.cluster.raft.ReplicatedLogEntry)2 ApplySnapshot (org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot)2 SaveSnapshotSuccess (akka.persistence.SaveSnapshotSuccess)1 Stopwatch (com.google.common.base.Stopwatch)1 File (java.io.File)1 ObjectOutputStream (java.io.ObjectOutputStream)1 OutputStream (java.io.OutputStream)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1