Search in sources :

Example 1 with LocalHistorySuccess

use of org.opendaylight.controller.cluster.access.commands.LocalHistorySuccess in project controller by opendaylight.

the class LeaderFrontendState method handlePurgeHistory.

private LocalHistorySuccess handlePurgeHistory(final PurgeLocalHistoryRequest request, final RequestEnvelope envelope, final long now) throws RequestException {
    final LocalHistoryIdentifier id = request.getTarget();
    final LocalFrontendHistory existing = localHistories.remove(id);
    if (existing == null) {
        LOG.debug("{}: history {} has already been purged", persistenceId, id);
        return new LocalHistorySuccess(id, request.getSequence());
    }
    LOG.debug("{}: purging history {}", persistenceId, id);
    purgedHistories.add(id.getHistoryId());
    existing.purge(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 2 with LocalHistorySuccess

use of org.opendaylight.controller.cluster.access.commands.LocalHistorySuccess 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 3 with LocalHistorySuccess

use of org.opendaylight.controller.cluster.access.commands.LocalHistorySuccess 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)

Aggregations

LocalHistorySuccess (org.opendaylight.controller.cluster.access.commands.LocalHistorySuccess)3 LocalHistoryIdentifier (org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier)3 DeadHistoryException (org.opendaylight.controller.cluster.access.commands.DeadHistoryException)1