X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FLeaderFrontendState.java;h=916cb75f5acd9d6c75c3372671cfad28ab5d1865;hb=HEAD;hp=ba64bad55d36d627717fc6550f8f7772d719bd72;hpb=e9efe27538adb5ae575f77fda90f147d46341801;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LeaderFrontendState.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LeaderFrontendState.java index ba64bad55d..916cb75f5a 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LeaderFrontendState.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LeaderFrontendState.java @@ -12,8 +12,8 @@ import static java.util.Objects.requireNonNull; import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects.ToStringHelper; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; +import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.controller.cluster.access.commands.CreateLocalHistoryRequest; import org.opendaylight.controller.cluster.access.commands.DeadHistoryException; @@ -39,10 +39,8 @@ import org.slf4j.LoggerFactory; /** * Frontend state as observed by the shard leader. This class is responsible for tracking generations and sequencing * in the frontend/backend conversation. This class is NOT thread-safe. - * - * @author Robert Varga */ -abstract class LeaderFrontendState implements Identifiable { +abstract sealed class LeaderFrontendState implements Identifiable { static final class Disabled extends LeaderFrontendState { Disabled(final String persistenceId, final ClientIdentifier clientId, final ShardDataTree tree) { super(persistenceId, clientId, tree); @@ -94,12 +92,12 @@ abstract class LeaderFrontendState implements Identifiable { checkRequestSequence(envelope); try { - if (request instanceof CreateLocalHistoryRequest) { - return handleCreateHistory((CreateLocalHistoryRequest) request, envelope, now); - } else if (request instanceof DestroyLocalHistoryRequest) { - return handleDestroyHistory((DestroyLocalHistoryRequest) request, envelope, now); - } else if (request instanceof PurgeLocalHistoryRequest) { - return handlePurgeHistory((PurgeLocalHistoryRequest)request, envelope, now); + if (request instanceof CreateLocalHistoryRequest req) { + return handleCreateHistory(req, envelope, now); + } else if (request instanceof DestroyLocalHistoryRequest req) { + return handleDestroyHistory(req, envelope, now); + } else if (request instanceof PurgeLocalHistoryRequest req) { + return handlePurgeHistory(req, envelope, now); } else { LOG.warn("{}: rejecting unsupported request {}", persistenceId(), request); throw new UnsupportedRequestException(request); @@ -115,7 +113,7 @@ abstract class LeaderFrontendState implements Identifiable { checkRequestSequence(envelope); try { - final LocalHistoryIdentifier lhId = request.getTarget().getHistoryId(); + final var lhId = request.getTarget().getHistoryId(); final AbstractFrontendHistory history; if (lhId.getHistoryId() != 0) { @@ -162,8 +160,8 @@ abstract class LeaderFrontendState implements Identifiable { 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); + final var historyId = request.getTarget(); + final var existing = localHistories.get(historyId); if (existing != null) { // History already exists: report success LOG.debug("{}: history {} already exists", persistenceId(), historyId); @@ -183,7 +181,7 @@ abstract class LeaderFrontendState implements Identifiable { } // We have to send the response only after persistence has completed - final ShardDataTreeTransactionChain chain = tree().ensureTransactionChain(historyId, () -> { + final var chain = tree().ensureTransactionChain(historyId, () -> { LOG.debug("{}: persisted history {}", persistenceId(), historyId); envelope.sendSuccess(new LocalHistorySuccess(historyId, request.getSequence()), tree().readTime() - now); @@ -196,8 +194,8 @@ abstract class LeaderFrontendState implements Identifiable { private LocalHistorySuccess handleDestroyHistory(final DestroyLocalHistoryRequest request, final RequestEnvelope envelope, final long now) { - final LocalHistoryIdentifier id = request.getTarget(); - final LocalFrontendHistory existing = localHistories.get(id); + final var id = request.getTarget(); + final var existing = localHistories.get(id); if (existing == null) { // History does not exist: report success LOG.debug("{}: history {} does not exist, nothing to destroy", persistenceId(), id); @@ -210,8 +208,8 @@ abstract class LeaderFrontendState implements Identifiable { private LocalHistorySuccess handlePurgeHistory(final PurgeLocalHistoryRequest request, final RequestEnvelope envelope, final long now) { - final LocalHistoryIdentifier id = request.getTarget(); - final LocalFrontendHistory existing = localHistories.remove(id); + final var id = request.getTarget(); + final var existing = localHistories.remove(id); if (existing == null) { LOG.debug("{}: history {} has already been purged", persistenceId(), id); return new LocalHistorySuccess(id, request.getSequence()); @@ -236,9 +234,9 @@ abstract class LeaderFrontendState implements Identifiable { private static final Logger LOG = LoggerFactory.getLogger(LeaderFrontendState.class); - private final ShardDataTree tree; - private final ClientIdentifier clientId; - private final String persistenceId; + private final @NonNull ClientIdentifier clientId; + private final @NonNull String persistenceId; + private final @NonNull ShardDataTree tree; private long lastConnectTicks; private long lastSeenTicks; @@ -296,16 +294,16 @@ abstract class LeaderFrontendState implements Identifiable { void retire() { // Hunt down any transactions associated with this frontend - final Iterator it = tree.cohortIterator(); + final var it = tree.cohortIterator(); while (it.hasNext()) { - final SimpleShardDataTreeCohort cohort = it.next(); - if (clientId.equals(cohort.getIdentifier().getHistoryId().getClientId())) { + final var cohort = it.next(); + final var transactionId = cohort.transactionId(); + if (clientId.equals(transactionId.getHistoryId().getClientId())) { if (cohort.getState() != State.COMMIT_PENDING) { - LOG.debug("{}: Retiring transaction {}", persistenceId, cohort.getIdentifier()); + LOG.debug("{}: Retiring transaction {}", persistenceId, transactionId); it.remove(); } else { - LOG.debug("{}: Transaction {} already committing, not retiring it", persistenceId, - cohort.getIdentifier()); + LOG.debug("{}: Transaction {} already committing, not retiring it", persistenceId, transactionId); } } }