Search in sources :

Example 1 with NoopPayload

use of org.opendaylight.controller.cluster.raft.persisted.NoopPayload in project controller by opendaylight.

the class RaftActor method handleApplyState.

private void handleApplyState(final ApplyState applyState) {
    long startTime = System.nanoTime();
    Payload payload = applyState.getReplicatedLogEntry().getData();
    if (LOG.isDebugEnabled()) {
        LOG.debug("{}: Applying state for log index {} data {}", persistenceId(), applyState.getReplicatedLogEntry().getIndex(), payload);
    }
    if (!(payload instanceof NoopPayload) && !(payload instanceof ServerConfigurationPayload)) {
        applyState(applyState.getClientActor(), applyState.getIdentifier(), payload);
    }
    long elapsedTime = System.nanoTime() - startTime;
    if (elapsedTime >= APPLY_STATE_DELAY_THRESHOLD_IN_NANOS) {
        LOG.debug("ApplyState took more time than expected. Elapsed Time = {} ms ApplyState = {}", TimeUnit.NANOSECONDS.toMillis(elapsedTime), applyState);
    }
    // Send the ApplyState message back to self to handle further processing asynchronously.
    self().tell(applyState, self());
}
Also used : ServerConfigurationPayload(org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload) NoopPayload(org.opendaylight.controller.cluster.raft.persisted.NoopPayload) ServerConfigurationPayload(org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload) NoopPayload(org.opendaylight.controller.cluster.raft.persisted.NoopPayload) Payload(org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload)

Example 2 with NoopPayload

use of org.opendaylight.controller.cluster.raft.persisted.NoopPayload in project controller by opendaylight.

the class RaftActor method handleCommand.

/**
 * Handles a message.
 *
 * @deprecated This method is not final for testing purposes. DO NOT OVERRIDE IT, override
 * {@link #handleNonRaftCommand(Object)} instead.
 */
@Deprecated
@Override
protected // FIXME: make this method final once our unit tests do not need to override it
void handleCommand(final Object message) {
    if (serverConfigurationSupport.handleMessage(message, getSender())) {
        return;
    }
    if (snapshotSupport.handleSnapshotMessage(message, getSender())) {
        return;
    }
    if (message instanceof ApplyState) {
        ApplyState applyState = (ApplyState) message;
        if (!hasFollowers()) {
            // for single node, the capture should happen after the apply state
            // as we delete messages from the persistent journal which have made it to the snapshot
            // capturing the snapshot before applying makes the persistent journal and snapshot out of sync
            // and recovery shows data missing
            context.getReplicatedLog().captureSnapshotIfReady(applyState.getReplicatedLogEntry());
            context.getSnapshotManager().trimLog(context.getLastApplied());
        }
        possiblyHandleBehaviorMessage(message);
    } else if (message instanceof ApplyJournalEntries) {
        ApplyJournalEntries applyEntries = (ApplyJournalEntries) message;
        LOG.debug("{}: Persisting ApplyJournalEntries with index={}", persistenceId(), applyEntries.getToIndex());
        persistence().persistAsync(applyEntries, NoopProcedure.instance());
    } else if (message instanceof FindLeader) {
        getSender().tell(new FindLeaderReply(getLeaderAddress()), getSelf());
    } else if (message instanceof GetOnDemandRaftState) {
        onGetOnDemandRaftStats();
    } else if (message instanceof InitiateCaptureSnapshot) {
        captureSnapshot();
    } else if (message instanceof SwitchBehavior) {
        switchBehavior((SwitchBehavior) message);
    } else if (message instanceof LeaderTransitioning) {
        onLeaderTransitioning((LeaderTransitioning) message);
    } else if (message instanceof Shutdown) {
        onShutDown();
    } else if (message instanceof Runnable) {
        ((Runnable) message).run();
    } else if (message instanceof NoopPayload) {
        persistData(null, null, (NoopPayload) message, false);
    } else if (message instanceof RequestLeadership) {
        onRequestLeadership((RequestLeadership) message);
    } else if (!possiblyHandleBehaviorMessage(message)) {
        handleNonRaftCommand(message);
    }
}
Also used : InitiateCaptureSnapshot(org.opendaylight.controller.cluster.raft.base.messages.InitiateCaptureSnapshot) FindLeaderReply(org.opendaylight.controller.cluster.raft.client.messages.FindLeaderReply) Shutdown(org.opendaylight.controller.cluster.raft.client.messages.Shutdown) RequestLeadership(org.opendaylight.controller.cluster.raft.messages.RequestLeadership) FindLeader(org.opendaylight.controller.cluster.raft.client.messages.FindLeader) NoopPayload(org.opendaylight.controller.cluster.raft.persisted.NoopPayload) ApplyJournalEntries(org.opendaylight.controller.cluster.raft.persisted.ApplyJournalEntries) GetOnDemandRaftState(org.opendaylight.controller.cluster.raft.client.messages.GetOnDemandRaftState) LeaderTransitioning(org.opendaylight.controller.cluster.raft.base.messages.LeaderTransitioning) SwitchBehavior(org.opendaylight.controller.cluster.raft.base.messages.SwitchBehavior) ApplyState(org.opendaylight.controller.cluster.raft.base.messages.ApplyState)

Aggregations

NoopPayload (org.opendaylight.controller.cluster.raft.persisted.NoopPayload)2 ApplyState (org.opendaylight.controller.cluster.raft.base.messages.ApplyState)1 InitiateCaptureSnapshot (org.opendaylight.controller.cluster.raft.base.messages.InitiateCaptureSnapshot)1 LeaderTransitioning (org.opendaylight.controller.cluster.raft.base.messages.LeaderTransitioning)1 SwitchBehavior (org.opendaylight.controller.cluster.raft.base.messages.SwitchBehavior)1 FindLeader (org.opendaylight.controller.cluster.raft.client.messages.FindLeader)1 FindLeaderReply (org.opendaylight.controller.cluster.raft.client.messages.FindLeaderReply)1 GetOnDemandRaftState (org.opendaylight.controller.cluster.raft.client.messages.GetOnDemandRaftState)1 Shutdown (org.opendaylight.controller.cluster.raft.client.messages.Shutdown)1 RequestLeadership (org.opendaylight.controller.cluster.raft.messages.RequestLeadership)1 ApplyJournalEntries (org.opendaylight.controller.cluster.raft.persisted.ApplyJournalEntries)1 ServerConfigurationPayload (org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload)1 Payload (org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload)1