Search in sources :

Example 1 with PersistentDataProvider

use of org.opendaylight.controller.cluster.PersistentDataProvider in project controller by opendaylight.

the class RaftActor method setPersistence.

protected void setPersistence(final boolean persistent) {
    DataPersistenceProvider currentPersistence = persistence();
    if (persistent && (currentPersistence == null || !currentPersistence.isRecoveryApplicable())) {
        setPersistence(new PersistentDataProvider(this));
        if (getCurrentBehavior() != null) {
            LOG.info("{}: Persistence has been enabled - capturing snapshot", persistenceId());
            captureSnapshot();
        }
    } else if (!persistent && (currentPersistence == null || currentPersistence.isRecoveryApplicable())) {
        setPersistence(new NonPersistentDataProvider(this) {

            /*
                 * The way snapshotting works is,
                 * <ol>
                 * <li> RaftActor calls createSnapshot on the Shard
                 * <li> Shard sends a CaptureSnapshotReply and RaftActor then calls saveSnapshot
                 * <li> When saveSnapshot is invoked on the akka-persistence API it uses the SnapshotStore to save
                 * the snapshot. The SnapshotStore sends SaveSnapshotSuccess or SaveSnapshotFailure. When the
                 * RaftActor gets SaveSnapshot success it commits the snapshot to the in-memory journal. This
                 * commitSnapshot is mimicking what is done in SaveSnapshotSuccess.
                 * </ol>
                 */
            @Override
            public void saveSnapshot(final Object object) {
                // Make saving Snapshot successful
                // Committing the snapshot here would end up calling commit in the creating state which would
                // be a state violation. That's why now we send a message to commit the snapshot.
                self().tell(RaftActorSnapshotMessageSupport.COMMIT_SNAPSHOT, self());
            }
        });
    }
}
Also used : PersistentDataProvider(org.opendaylight.controller.cluster.PersistentDataProvider) DelegatingPersistentDataProvider(org.opendaylight.controller.cluster.DelegatingPersistentDataProvider) NonPersistentDataProvider(org.opendaylight.controller.cluster.NonPersistentDataProvider) DataPersistenceProvider(org.opendaylight.controller.cluster.DataPersistenceProvider) NonPersistentDataProvider(org.opendaylight.controller.cluster.NonPersistentDataProvider)

Aggregations

DataPersistenceProvider (org.opendaylight.controller.cluster.DataPersistenceProvider)1 DelegatingPersistentDataProvider (org.opendaylight.controller.cluster.DelegatingPersistentDataProvider)1 NonPersistentDataProvider (org.opendaylight.controller.cluster.NonPersistentDataProvider)1 PersistentDataProvider (org.opendaylight.controller.cluster.PersistentDataProvider)1