Search in sources :

Example 6 with LocalHistoryIdentifier

use of org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier in project controller by opendaylight.

the class Shard method closeTransactionChain.

private void closeTransactionChain(final CloseTransactionChain closeTransactionChain) {
    final LocalHistoryIdentifier id = closeTransactionChain.getIdentifier();
    store.closeTransactionChain(id, null);
    store.purgeTransactionChain(id, null);
}
Also used : LocalHistoryIdentifier(org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier)

Example 7 with LocalHistoryIdentifier

use of org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier in project controller by opendaylight.

the class LeaderFrontendState method handleTransactionRequest.

@Nullable
TransactionSuccess<?> handleTransactionRequest(final TransactionRequest<?> request, final RequestEnvelope envelope, final long now) throws RequestException {
    checkRequestSequence(envelope);
    try {
        final LocalHistoryIdentifier lhId = request.getTarget().getHistoryId();
        final AbstractFrontendHistory history;
        if (lhId.getHistoryId() != 0) {
            history = localHistories.get(lhId);
            if (history == null) {
                if (purgedHistories.contains(lhId.getHistoryId())) {
                    LOG.warn("{}: rejecting request {} to purged history", persistenceId, request);
                    throw new DeadHistoryException(purgedHistories.toImmutable());
                }
                LOG.warn("{}: rejecting unknown history request {}", persistenceId, request);
                throw new UnknownHistoryException(lastSeenHistory);
            }
        } else {
            history = standaloneHistory;
        }
        return history.handleTransactionRequest(request, envelope, now);
    } finally {
        expectNextRequest();
    }
}
Also used : UnknownHistoryException(org.opendaylight.controller.cluster.access.commands.UnknownHistoryException) DeadHistoryException(org.opendaylight.controller.cluster.access.commands.DeadHistoryException) LocalHistoryIdentifier(org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier) Nullable(javax.annotation.Nullable)

Example 8 with LocalHistoryIdentifier

use of org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier in project controller by opendaylight.

the class LeaderFrontendState method handleCreateHistory.

private LocalHistorySuccess handleCreateHistory(final CreateLocalHistoryRequest request, final RequestEnvelope envelope, final long now) throws RequestException {
    final LocalHistoryIdentifier historyId = request.getTarget();
    final AbstractFrontendHistory existing = localHistories.get(historyId);
    if (existing != null) {
        // History already exists: report success
        LOG.debug("{}: history {} already exists", persistenceId, historyId);
        return new LocalHistorySuccess(historyId, request.getSequence());
    }
    // end up resurrecting a purged history.
    if (purgedHistories.contains(historyId.getHistoryId())) {
        LOG.debug("{}: rejecting purged request {}", persistenceId, request);
        throw new DeadHistoryException(purgedHistories.toImmutable());
    }
    // Update last history we have seen
    if (lastSeenHistory == null || Long.compareUnsigned(lastSeenHistory, historyId.getHistoryId()) < 0) {
        lastSeenHistory = historyId.getHistoryId();
    }
    // We have to send the response only after persistence has completed
    final ShardDataTreeTransactionChain chain = tree.ensureTransactionChain(historyId, () -> {
        LOG.debug("{}: persisted history {}", persistenceId, historyId);
        envelope.sendSuccess(new LocalHistorySuccess(historyId, request.getSequence()), tree.readTime() - now);
    });
    localHistories.put(historyId, LocalFrontendHistory.create(persistenceId, tree, chain));
    LOG.debug("{}: created history {}", persistenceId, historyId);
    return null;
}
Also used : DeadHistoryException(org.opendaylight.controller.cluster.access.commands.DeadHistoryException) LocalHistoryIdentifier(org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier) LocalHistorySuccess(org.opendaylight.controller.cluster.access.commands.LocalHistorySuccess)

Example 9 with LocalHistoryIdentifier

use of org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier in project controller by opendaylight.

the class LeaderFrontendState method handleDestroyHistory.

private LocalHistorySuccess handleDestroyHistory(final DestroyLocalHistoryRequest request, final RequestEnvelope envelope, final long now) throws RequestException {
    final LocalHistoryIdentifier id = request.getTarget();
    final LocalFrontendHistory existing = localHistories.get(id);
    if (existing == null) {
        // History does not exist: report success
        LOG.debug("{}: history {} does not exist, nothing to destroy", persistenceId, id);
        return new LocalHistorySuccess(id, request.getSequence());
    }
    existing.destroy(request.getSequence(), envelope, now);
    return null;
}
Also used : LocalHistoryIdentifier(org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier) LocalHistorySuccess(org.opendaylight.controller.cluster.access.commands.LocalHistorySuccess)

Example 10 with LocalHistoryIdentifier

use of org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier in project controller by opendaylight.

the class FrontendClientMetadataBuilder method toLeaderState.

/**
 * Transform frontend metadata for a particular client into its {@link LeaderFrontendState} counterpart.
 *
 * @param shard parent shard
 * @return Leader frontend state
 */
@Nonnull
LeaderFrontendState toLeaderState(@Nonnull final Shard shard) {
    // Note: we have to make sure to *copy* all current state and not leak any views, otherwise leader/follower
    // interactions would get intertwined leading to inconsistencies.
    final Map<LocalHistoryIdentifier, LocalFrontendHistory> histories = new HashMap<>();
    for (FrontendHistoryMetadataBuilder e : currentHistories.values()) {
        if (e.getIdentifier().getHistoryId() != 0) {
            final AbstractFrontendHistory state = e.toLeaderState(shard);
            Verify.verify(state instanceof LocalFrontendHistory);
            histories.put(e.getIdentifier(), (LocalFrontendHistory) state);
        }
    }
    final AbstractFrontendHistory singleHistory;
    final FrontendHistoryMetadataBuilder singleHistoryMeta = currentHistories.get(new LocalHistoryIdentifier(identifier, 0));
    if (singleHistoryMeta == null) {
        final ShardDataTree tree = shard.getDataStore();
        singleHistory = StandaloneFrontendHistory.create(shard.persistenceId(), getIdentifier(), tree);
    } else {
        singleHistory = singleHistoryMeta.toLeaderState(shard);
    }
    return new LeaderFrontendState(shard.persistenceId(), getIdentifier(), shard.getDataStore(), purgedHistories.copy(), singleHistory, histories);
}
Also used : HashMap(java.util.HashMap) LocalHistoryIdentifier(org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier) Nonnull(javax.annotation.Nonnull)

Aggregations

LocalHistoryIdentifier (org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier)16 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)5 Test (org.junit.Test)4 LocalHistorySuccess (org.opendaylight.controller.cluster.access.commands.LocalHistorySuccess)3 Response (org.opendaylight.controller.cluster.access.concepts.Response)3 DeadHistoryException (org.opendaylight.controller.cluster.access.commands.DeadHistoryException)2 TransactionAbortSuccess (org.opendaylight.controller.cluster.access.commands.TransactionAbortSuccess)2 ClientIdentifier (org.opendaylight.controller.cluster.access.concepts.ClientIdentifier)2 FrontendIdentifier (org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier)2 SuccessEnvelope (org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope)2 ActorRef (akka.actor.ActorRef)1 HashMap (java.util.HashMap)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 GuardedBy (javax.annotation.concurrent.GuardedBy)1 Before (org.junit.Before)1 CreateLocalHistoryRequest (org.opendaylight.controller.cluster.access.commands.CreateLocalHistoryRequest)1 LocalHistoryRequest (org.opendaylight.controller.cluster.access.commands.LocalHistoryRequest)1 ModifyTransactionRequestBuilder (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder)1 TransactionRequest (org.opendaylight.controller.cluster.access.commands.TransactionRequest)1