From: Tom Pantelis Date: Wed, 20 Sep 2017 18:00:31 +0000 (-0400) Subject: Fix sonar warnings in sal-distributed-datastore X-Git-Tag: release/oxygen~70 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=8232a626b43fdd2f5799da0fbcfb0f02d3c8f4fb Fix sonar warnings in sal-distributed-datastore These come from squid: - String literals should not be duplicated - Modifiers should be declared in the correct order - Lambdas and anonymous classes should not have too many lines - Nested blocks of code should not be left empty - Local variables should not shadow class fields - Exception handlers should preserve the original exception - Utility classes should not have public constructors - Overriding methods should do more than simply call the same method in the super class - Unused private fields should be removed I fixed quite a few of them. Others we'd have to suppress or modify the sonar config to be more lenient. Change-Id: I7ce7b2a05feac9844fd9c37927de82b7b8b68ee5 Signed-off-by: Tom Pantelis --- diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/AbstractDOMBroker.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/AbstractDOMBroker.java index 68191fbbc2..6e6ddf6204 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/AbstractDOMBroker.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/AbstractDOMBroker.java @@ -54,9 +54,7 @@ abstract class AbstractDOMBroker extends AbstractDOMTransactionFactory @Override public ListenerRegistration registerDataTreeChangeListener( final DOMDataTreeIdentifier treeId, final L listener) { - DOMStore store = getTxFactories().get(treeId.getDatastoreType()); - checkState(store != null, "Requested logical data store is not available."); - + DOMStore store = getDOMStore(treeId.getDatastoreType()); return ((DOMStoreTreeChangePublisher) store).registerTreeChangeListener( treeId.getRootIdentifier(), listener); } @@ -68,9 +66,7 @@ abstract class AbstractDOMBroker extends AbstractDOMTransactionFactory @Override public DOMDataTreeCommitCohortRegistration registerCommitCohort( org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier path, T cohort) { - DOMStore store = getTxFactories().get(toLegacy(path.getDatastoreType())); - checkState(store != null, "Requested logical data store is not available."); - + DOMStore store = getDOMStore(toLegacy(path.getDatastoreType())); return ((org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohortRegistry) store) .registerCommitCohort(path, cohort); } @@ -129,8 +125,7 @@ abstract class AbstractDOMBroker extends AbstractDOMTransactionFactory public ListenerRegistration registerDataChangeListener(final LogicalDatastoreType store, final YangInstanceIdentifier path, final DOMDataChangeListener listener, final DataChangeScope triggeringScope) { - DOMStore potentialStore = getTxFactories().get(store); - checkState(potentialStore != null, "Requested logical data store is not available."); + DOMStore potentialStore = getDOMStore(store); return potentialStore.registerChangeListener(path, listener, triggeringScope); } @@ -154,4 +149,10 @@ abstract class AbstractDOMBroker extends AbstractDOMTransactionFactory backingChains); return new DOMBrokerTransactionChain(chainId, backingChains, this, listener); } + + private DOMStore getDOMStore(final LogicalDatastoreType type) { + DOMStore store = getTxFactories().get(type); + checkState(store != null, "Requested logical data store is not available."); + return store; + } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/ClientBackedTransaction.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/ClientBackedTransaction.java index 5b6a451ca8..4d979cdf96 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/ClientBackedTransaction.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/ClientBackedTransaction.java @@ -45,7 +45,8 @@ abstract class ClientBackedTransaction> extend this.allocationContext = allocationContext; } - static @Nonnull > T recordTransaction( + @Nonnull + static > T recordTransaction( @Nonnull final ClientBackedTransaction referent, @Nonnull final T transaction, @Nullable final Throwable allocationContext) { FINALIZERS.add(new Finalizer(referent, transaction, allocationContext)); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/ConcurrentDOMDataBroker.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/ConcurrentDOMDataBroker.java index 71cd2dc7fe..7e92787eb3 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/ConcurrentDOMDataBroker.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/ConcurrentDOMDataBroker.java @@ -7,6 +7,10 @@ */ package org.opendaylight.controller.cluster.databroker; +import static org.opendaylight.controller.md.sal.dom.broker.impl.TransactionCommitFailedExceptionMapper.CAN_COMMIT_ERROR_MAPPER; +import static org.opendaylight.controller.md.sal.dom.broker.impl.TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER; +import static org.opendaylight.controller.md.sal.dom.broker.impl.TransactionCommitFailedExceptionMapper.PRE_COMMIT_MAPPER; + import com.google.common.annotations.Beta; import com.google.common.base.Preconditions; import com.google.common.util.concurrent.AbstractFuture; @@ -89,8 +93,7 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { doCanCommit(clientSubmitFuture, transaction, cohorts); - return MappingCheckedFuture.create(clientSubmitFuture, - TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER); + return MappingCheckedFuture.create(clientSubmitFuture, COMMIT_ERROR_MAPPER); } private void doCanCommit(final AsyncNotifyingSettableFuture clientSubmitFuture, @@ -106,25 +109,19 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { @Override public void onSuccess(Boolean result) { if (result == null || !result) { - handleException(clientSubmitFuture, transaction, cohorts, - CAN_COMMIT, TransactionCommitFailedExceptionMapper.CAN_COMMIT_ERROR_MAPPER, - new TransactionCommitFailedException( - "Can Commit failed, no detailed cause available.")); + handleException(clientSubmitFuture, transaction, cohorts, CAN_COMMIT, CAN_COMMIT_ERROR_MAPPER, + new TransactionCommitFailedException("Can Commit failed, no detailed cause available.")); + } else if (!cohortIterator.hasNext()) { + // All cohorts completed successfully - we can move on to the preCommit phase + doPreCommit(startTime, clientSubmitFuture, transaction, cohorts); } else { - if (!cohortIterator.hasNext()) { - // All cohorts completed successfully - we can move on to the preCommit phase - doPreCommit(startTime, clientSubmitFuture, transaction, cohorts); - } else { - ListenableFuture canCommitFuture = cohortIterator.next().canCommit(); - Futures.addCallback(canCommitFuture, this, MoreExecutors.directExecutor()); - } + Futures.addCallback(cohortIterator.next().canCommit(), this, MoreExecutors.directExecutor()); } } @Override public void onFailure(Throwable failure) { - handleException(clientSubmitFuture, transaction, cohorts, CAN_COMMIT, - TransactionCommitFailedExceptionMapper.CAN_COMMIT_ERROR_MAPPER, failure); + handleException(clientSubmitFuture, transaction, cohorts, CAN_COMMIT, CAN_COMMIT_ERROR_MAPPER, failure); } }; @@ -153,8 +150,7 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { @Override public void onFailure(Throwable failure) { - handleException(clientSubmitFuture, transaction, cohorts, PRE_COMMIT, - TransactionCommitFailedExceptionMapper.PRE_COMMIT_MAPPER, failure); + handleException(clientSubmitFuture, transaction, cohorts, PRE_COMMIT, PRE_COMMIT_MAPPER, failure); } }; @@ -185,8 +181,7 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { @Override public void onFailure(Throwable throwable) { - handleException(clientSubmitFuture, transaction, cohorts, COMMIT, - TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER, throwable); + handleException(clientSubmitFuture, transaction, cohorts, COMMIT, COMMIT_ERROR_MAPPER, throwable); } }; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractDataStoreClientBehavior.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractDataStoreClientBehavior.java index 007f3875cf..77db4e6c08 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractDataStoreClientBehavior.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractDataStoreClientBehavior.java @@ -21,6 +21,8 @@ import org.opendaylight.controller.cluster.access.client.BackendInfoResolver; import org.opendaylight.controller.cluster.access.client.ClientActorBehavior; import org.opendaylight.controller.cluster.access.client.ClientActorContext; import org.opendaylight.controller.cluster.access.client.ConnectedClientConnection; +import org.opendaylight.controller.cluster.access.client.ConnectionEntry; +import org.opendaylight.controller.cluster.access.client.ReconnectForwarder; import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.slf4j.Logger; @@ -139,29 +141,33 @@ abstract class AbstractDataStoreClientBehavior extends ClientActorBehavior { + return previousEntries -> finishReconnect(newConn, stamp, cohorts, previousEntries); + } + + private ReconnectForwarder finishReconnect(final ConnectedClientConnection newConn, + final long stamp, final Collection cohorts, + final Collection previousEntries) { + try { + // Step 2: Collect previous successful requests from the cohorts. We do not want to expose + // the non-throttling interface to the connection, hence we use a wrapper consumer + for (HistoryReconnectCohort c : cohorts) { + c.replayRequests(previousEntries); + } + + // Step 3: Install a forwarder, which will forward requests back to affected cohorts. Any outstanding + // requests will be immediately sent to it and requests being sent concurrently will get + // forwarded once they hit the new connection. + return BouncingReconnectForwarder.forCohorts(newConn, cohorts); + } finally { try { - // Step 2: Collect previous successful requests from the cohorts. We do not want to expose - // the non-throttling interface to the connection, hence we use a wrapper consumer + // Step 4: Complete switchover of the connection. The cohorts can resume normal operations. for (HistoryReconnectCohort c : cohorts) { - c.replayRequests(previousEntries); + c.close(); } - - // Step 3: Install a forwarder, which will forward requests back to affected cohorts. Any outstanding - // requests will be immediately sent to it and requests being sent concurrently will get - // forwarded once they hit the new connection. - return BouncingReconnectForwarder.forCohorts(newConn, cohorts); } finally { - try { - // Step 4: Complete switchover of the connection. The cohorts can resume normal operations. - for (HistoryReconnectCohort c : cohorts) { - c.close(); - } - } finally { - lock.unlockWrite(stamp); - } + lock.unlockWrite(stamp); } - }; + } } private static void startReconnect(final AbstractClientHistory history, diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransaction.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransaction.java index 51f528150d..8e094112f8 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransaction.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransaction.java @@ -413,7 +413,7 @@ abstract class AbstractProxyTransaction implements Identifiable req) { + final void recordSuccessfulRequest(@Nonnull final TransactionRequest req) { successfulRequests.add(Verify.verifyNotNull(req)); } @@ -449,7 +449,7 @@ abstract class AbstractProxyTransaction implements Identifiable) t).getCause().unwrap()); } else { - ret.voteNo(new IllegalStateException("Unhandled response " + t.getClass())); + ret.voteNo(unhandledResponseException(t)); } // This is a terminal request, hence we do not need to record it @@ -507,7 +507,7 @@ abstract class AbstractProxyTransaction implements Identifiable) t).getCause().unwrap()); } else { - ret.voteNo(new IllegalStateException("Unhandled response " + t.getClass())); + ret.voteNo(unhandledResponseException(t)); } recordSuccessfulRequest(req); @@ -569,7 +569,7 @@ abstract class AbstractProxyTransaction implements Identifiable) t).getCause().unwrap()); } else { - ret.voteNo(new IllegalStateException("Unhandled response " + t.getClass())); + ret.voteNo(unhandledResponseException(t)); } onPreCommitComplete(req); @@ -602,7 +602,7 @@ abstract class AbstractProxyTransaction implements Identifiable) t).getCause().unwrap()); } else { - ret.voteNo(new IllegalStateException("Unhandled response " + t.getClass())); + ret.voteNo(unhandledResponseException(t)); } LOG.debug("Transaction {} doCommit completed", this); @@ -687,13 +687,13 @@ abstract class AbstractProxyTransaction implements Identifiable) obj, resp -> { }, now); + successor.doReplayRequest((TransactionRequest) obj, resp -> { /*NOOP*/ }, now); } else { Verify.verify(obj instanceof IncrementSequence); final IncrementSequence increment = (IncrementSequence) obj; successor.doReplayRequest(new IncrementTransactionSequenceRequest(getIdentifier(), - increment.getSequence(), localActor(), isSnapshotOnly(), increment.getDelta()), resp -> { }, - now); + increment.getSequence(), localActor(), isSnapshotOnly(), + increment.getDelta()), resp -> { /*NOOP*/ }, now); LOG.debug("Incrementing sequence {} to successor {}", obj, successor); } } @@ -846,6 +846,10 @@ abstract class AbstractProxyTransaction implements Identifiable request, @Nullable Consumer> callback, long enqueuedTicks); + private static IllegalStateException unhandledResponseException(Response resp) { + return new IllegalStateException("Unhandled response " + resp.getClass()); + } + @Override public final String toString() { return MoreObjects.toStringHelper(this).add("identifier", getIdentifier()).add("state", state).toString(); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractShardBackendResolver.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractShardBackendResolver.java index 46e035d0ec..0ce4df0f13 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractShardBackendResolver.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractShardBackendResolver.java @@ -137,27 +137,32 @@ abstract class AbstractShardBackendResolver extends BackendInfoResolver { - if (failure != null) { - LOG.debug("Connect attempt to {} failed, will retry", shardName, failure); - future.completeExceptionally(wrap("Connection attempt failed", failure)); - return; - } - if (response instanceof RequestFailure) { - final Throwable cause = ((RequestFailure) response).getCause().unwrap(); - LOG.debug("Connect attempt to {} failed to process", shardName, cause); - final Throwable result = cause instanceof NotLeaderException - ? wrap("Leader moved during establishment", cause) : cause; - future.completeExceptionally(result); - return; - } - - LOG.debug("Resolved backend information to {}", response); - Preconditions.checkArgument(response instanceof ConnectClientSuccess, "Unhandled response %s", - response); - final ConnectClientSuccess success = (ConnectClientSuccess) response; - future.complete(new ShardBackendInfo(success.getBackend(), nextSessionId.getAndIncrement(), - success.getVersion(), shardName, UnsignedLong.fromLongBits(cookie), success.getDataTree(), - success.getMaxMessages())); + onConnectResponse(shardName, cookie, future, response, failure); }); } + + private void onConnectResponse(final String shardName, final long cookie, + final CompletableFuture future, final Object response, final Throwable failure) { + if (failure != null) { + LOG.debug("Connect attempt to {} failed, will retry", shardName, failure); + future.completeExceptionally(wrap("Connection attempt failed", failure)); + return; + } + if (response instanceof RequestFailure) { + final Throwable cause = ((RequestFailure) response).getCause().unwrap(); + LOG.debug("Connect attempt to {} failed to process", shardName, cause); + final Throwable result = cause instanceof NotLeaderException + ? wrap("Leader moved during establishment", cause) : cause; + future.completeExceptionally(result); + return; + } + + LOG.debug("Resolved backend information to {}", response); + Preconditions.checkArgument(response instanceof ConnectClientSuccess, "Unhandled response %s", + response); + final ConnectClientSuccess success = (ConnectClientSuccess) response; + future.complete(new ShardBackendInfo(success.getBackend(), nextSessionId.getAndIncrement(), + success.getVersion(), shardName, UnsignedLong.fromLongBits(cookie), success.getDataTree(), + success.getMaxMessages())); + } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionCursor.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionCursor.java index bbd8534602..41d2cb8cd1 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionCursor.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionCursor.java @@ -44,9 +44,9 @@ final class ClientTransactionCursor implements DOMDataTreeWriteCursor { @Override public void exit() { - final YangInstanceIdentifier parent = current.getParent(); - Preconditions.checkState(parent != null); - current = parent; + final YangInstanceIdentifier currentParent = current.getParent(); + Preconditions.checkState(currentParent != null); + current = currentParent; } @Override diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalProxyTransaction.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalProxyTransaction.java index f34abfff9c..b6e9bfabab 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalProxyTransaction.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalProxyTransaction.java @@ -69,7 +69,8 @@ abstract class LocalProxyTransaction extends AbstractProxyTransaction { return identifier; } - abstract @Nonnull DataTreeSnapshot readOnlyView(); + @Nonnull + abstract DataTreeSnapshot readOnlyView(); abstract void applyForwardedModifyTransactionRequest(ModifyTransactionRequest request, @Nullable Consumer> callback); @@ -103,7 +104,7 @@ abstract class LocalProxyTransaction extends AbstractProxyTransaction { } private boolean handleReadRequest(final TransactionRequest request, - final @Nullable Consumer> callback) { + @Nullable final Consumer> callback) { // Note we delay completion of read requests to limit the scope at which the client can run, as they have // listeners, which we do not want to execute while we are reconnecting. if (request instanceof ReadTransactionRequest) { @@ -133,7 +134,7 @@ abstract class LocalProxyTransaction extends AbstractProxyTransaction { @Override void handleReplayedRemoteRequest(final TransactionRequest request, - final @Nullable Consumer> callback, final long enqueuedTicks) { + @Nullable final Consumer> callback, final long enqueuedTicks) { if (request instanceof ModifyTransactionRequest) { replayModifyTransactionRequest((ModifyTransactionRequest) request, callback, enqueuedTicks); } else if (handleReadRequest(request, callback)) { @@ -206,7 +207,7 @@ abstract class LocalProxyTransaction extends AbstractProxyTransaction { } else if (request instanceof ModifyTransactionRequest) { successor.handleForwardedRequest(request, callback); } else { - throw new IllegalArgumentException("Unhandled request" + request); + throwUnhandledRequest(request); } } @@ -218,12 +219,16 @@ abstract class LocalProxyTransaction extends AbstractProxyTransaction { } else if (request instanceof TransactionPurgeRequest) { successor.enqueuePurge(callback); } else { - throw new IllegalArgumentException("Unhandled request" + request); + throwUnhandledRequest(request); } LOG.debug("Forwarded request {} to successor {}", request, successor); } + private static void throwUnhandledRequest(final TransactionRequest request) { + throw new IllegalArgumentException("Unhandled request" + request); + } + void sendAbort(final TransactionRequest request, final Consumer> callback) { sendRequest(request, callback); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalReadOnlyProxyTransaction.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalReadOnlyProxyTransaction.java index 00e294022b..ee5889da76 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalReadOnlyProxyTransaction.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalReadOnlyProxyTransaction.java @@ -55,22 +55,22 @@ final class LocalReadOnlyProxyTransaction extends LocalProxyTransaction { @Override void doDelete(final YangInstanceIdentifier path) { - throw new UnsupportedOperationException("Read-only snapshot"); + throw new UnsupportedOperationException("doDelete"); } @Override void doMerge(final YangInstanceIdentifier path, final NormalizedNode data) { - throw new UnsupportedOperationException("Read-only snapshot"); + throw new UnsupportedOperationException("doMerge"); } @Override void doWrite(final YangInstanceIdentifier path, final NormalizedNode data) { - throw new UnsupportedOperationException("Read-only snapshot"); + throw new UnsupportedOperationException("doWrite"); } @Override CommitLocalTransactionRequest commitRequest(final boolean coordinated) { - throw new UnsupportedOperationException("Read-only snapshot"); + throw new UnsupportedOperationException("commitRequest"); } @Override diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalReadWriteProxyTransaction.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalReadWriteProxyTransaction.java index 76ad672255..c4db9d8e9a 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalReadWriteProxyTransaction.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalReadWriteProxyTransaction.java @@ -228,18 +228,18 @@ final class LocalReadWriteProxyTransaction extends LocalProxyTransaction { @Override void applyForwardedModifyTransactionRequest(final ModifyTransactionRequest request, - final @Nullable Consumer> callback) { + @Nullable final Consumer> callback) { commonModifyTransactionRequest(request, callback, this::sendRequest); } @Override void replayModifyTransactionRequest(final ModifyTransactionRequest request, - final @Nullable Consumer> callback, final long enqueuedTicks) { + @Nullable final Consumer> callback, final long enqueuedTicks) { commonModifyTransactionRequest(request, callback, (req, cb) -> enqueueRequest(req, cb, enqueuedTicks)); } private void commonModifyTransactionRequest(final ModifyTransactionRequest request, - final @Nullable Consumer> callback, + @Nullable final Consumer> callback, final BiConsumer, Consumer>> sendMethod) { for (final TransactionModification mod : request.getModifications()) { if (mod instanceof TransactionWrite) { @@ -291,7 +291,7 @@ final class LocalReadWriteProxyTransaction extends LocalProxyTransaction { @Override void handleReplayedRemoteRequest(final TransactionRequest request, - final @Nullable Consumer> callback, final long enqueuedTicks) { + @Nullable final Consumer> callback, final long enqueuedTicks) { LOG.debug("Applying replayed request {}", request); if (request instanceof TransactionPreCommitRequest) { @@ -347,7 +347,8 @@ final class LocalReadWriteProxyTransaction extends LocalProxyTransaction { closedException = this::abortedException; } - private @Nonnull CursorAwareDataTreeModification getModification() { + @Nonnull + private CursorAwareDataTreeModification getModification() { if (closedException != null) { throw closedException.get(); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ProxyHistory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ProxyHistory.java index e26e00fa13..61b45ed79f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ProxyHistory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ProxyHistory.java @@ -127,10 +127,9 @@ abstract class ProxyHistory implements Identifiable { @Override void onTransactionCompleted(final AbstractProxyTransaction tx) { Verify.verify(tx instanceof LocalProxyTransaction); - if (tx instanceof LocalReadWriteProxyTransaction) { - if (LAST_SEALED_UPDATER.compareAndSet(this, (LocalReadWriteProxyTransaction) tx, null)) { - LOG.debug("Completed last sealed transaction {}", tx); - } + if (tx instanceof LocalReadWriteProxyTransaction + && LAST_SEALED_UPDATER.compareAndSet(this, (LocalReadWriteProxyTransaction) tx, null)) { + LOG.debug("Completed last sealed transaction {}", tx); } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/RemoteProxyTransaction.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/RemoteProxyTransaction.java index 5a6b539494..3120f6f4ed 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/RemoteProxyTransaction.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/RemoteProxyTransaction.java @@ -295,52 +295,7 @@ final class RemoteProxyTransaction extends AbstractProxyTransaction { void handleForwardedRequest(final TransactionRequest request, final Consumer> callback) { if (request instanceof ModifyTransactionRequest) { - final ModifyTransactionRequest req = (ModifyTransactionRequest) request; - - req.getModifications().forEach(this::appendModification); - - final java.util.Optional maybeProto = req.getPersistenceProtocol(); - if (maybeProto.isPresent()) { - // Persistence protocol implies we are sealed, propagate the marker, but hold off doing other actions - // until we know what we are going to do. - if (markSealed()) { - sealOnly(); - } - - final TransactionRequest tmp; - switch (maybeProto.get()) { - case ABORT: - tmp = abortRequest(); - sendRequest(tmp, resp -> { - completeModify(tmp, resp); - callback.accept(resp); - }); - break; - case SIMPLE: - tmp = commitRequest(false); - sendRequest(tmp, resp -> { - completeModify(tmp, resp); - callback.accept(resp); - }); - break; - case THREE_PHASE: - tmp = commitRequest(true); - sendRequest(tmp, resp -> { - recordSuccessfulRequest(tmp); - callback.accept(resp); - }); - break; - case READY: - tmp = readyRequest(); - sendRequest(tmp, resp -> { - recordSuccessfulRequest(tmp); - callback.accept(resp); - }); - break; - default: - throw new IllegalArgumentException("Unhandled protocol " + maybeProto.get()); - } - } + handleForwardedModifyTransactionRequest(callback, (ModifyTransactionRequest) request); } else if (request instanceof ReadTransactionRequest) { ensureFlushedBuider(); sendRequest(new ReadTransactionRequest(getIdentifier(), nextSequence(), localActor(), @@ -376,6 +331,54 @@ final class RemoteProxyTransaction extends AbstractProxyTransaction { } } + private void handleForwardedModifyTransactionRequest(final Consumer> callback, + final ModifyTransactionRequest req) { + req.getModifications().forEach(this::appendModification); + + final java.util.Optional maybeProto = req.getPersistenceProtocol(); + if (maybeProto.isPresent()) { + // Persistence protocol implies we are sealed, propagate the marker, but hold off doing other actions + // until we know what we are going to do. + if (markSealed()) { + sealOnly(); + } + + final TransactionRequest tmp; + switch (maybeProto.get()) { + case ABORT: + tmp = abortRequest(); + sendRequest(tmp, resp -> { + completeModify(tmp, resp); + callback.accept(resp); + }); + break; + case SIMPLE: + tmp = commitRequest(false); + sendRequest(tmp, resp -> { + completeModify(tmp, resp); + callback.accept(resp); + }); + break; + case THREE_PHASE: + tmp = commitRequest(true); + sendRequest(tmp, resp -> { + recordSuccessfulRequest(tmp); + callback.accept(resp); + }); + break; + case READY: + tmp = readyRequest(); + sendRequest(tmp, resp -> { + recordSuccessfulRequest(tmp); + callback.accept(resp); + }); + break; + default: + throw new IllegalArgumentException("Unhandled protocol " + maybeProto.get()); + } + } + } + @Override void forwardToLocal(final LocalProxyTransaction successor, final TransactionRequest request, final Consumer> callback) { @@ -421,58 +424,12 @@ final class RemoteProxyTransaction extends AbstractProxyTransaction { @Override void handleReplayedRemoteRequest(final TransactionRequest request, - final @Nullable Consumer> callback, final long enqueuedTicks) { - final Consumer> cb = callback != null ? callback : resp -> { }; + @Nullable final Consumer> callback, final long enqueuedTicks) { + final Consumer> cb = callback != null ? callback : resp -> { /* NOOP */ }; final Optional optTicks = Optional.of(Long.valueOf(enqueuedTicks)); if (request instanceof ModifyTransactionRequest) { - final ModifyTransactionRequest req = (ModifyTransactionRequest) request; - for (TransactionModification mod : req.getModifications()) { - appendModification(mod, optTicks); - } - - final java.util.Optional maybeProto = req.getPersistenceProtocol(); - if (maybeProto.isPresent()) { - // Persistence protocol implies we are sealed, propagate the marker, but hold off doing other actions - // until we know what we are going to do. - if (markSealed()) { - sealOnly(); - } - - final TransactionRequest tmp; - switch (maybeProto.get()) { - case ABORT: - tmp = abortRequest(); - enqueueRequest(tmp, resp -> { - completeModify(tmp, resp); - cb.accept(resp); - }, enqueuedTicks); - break; - case SIMPLE: - tmp = commitRequest(false); - enqueueRequest(tmp, resp -> { - completeModify(tmp, resp); - cb.accept(resp); - }, enqueuedTicks); - break; - case THREE_PHASE: - tmp = commitRequest(true); - enqueueRequest(tmp, resp -> { - recordSuccessfulRequest(tmp); - cb.accept(resp); - }, enqueuedTicks); - break; - case READY: - tmp = readyRequest(); - enqueueRequest(tmp, resp -> { - recordSuccessfulRequest(tmp); - cb.accept(resp); - }, enqueuedTicks); - break; - default: - throw new IllegalArgumentException("Unhandled protocol " + maybeProto.get()); - } - } + handleReplayedModifyTransactionRequest(enqueuedTicks, cb, (ModifyTransactionRequest) request); } else if (request instanceof ReadTransactionRequest) { ensureFlushedBuider(optTicks); enqueueRequest(new ReadTransactionRequest(getIdentifier(), nextSequence(), localActor(), @@ -514,4 +471,52 @@ final class RemoteProxyTransaction extends AbstractProxyTransaction { throw new IllegalArgumentException("Unhandled request {}" + request); } } + + private void handleReplayedModifyTransactionRequest(final long enqueuedTicks, final Consumer> cb, + final ModifyTransactionRequest req) { + req.getModifications().forEach(this::appendModification); + + final java.util.Optional maybeProto = req.getPersistenceProtocol(); + if (maybeProto.isPresent()) { + // Persistence protocol implies we are sealed, propagate the marker, but hold off doing other actions + // until we know what we are going to do. + if (markSealed()) { + sealOnly(); + } + + final TransactionRequest tmp; + switch (maybeProto.get()) { + case ABORT: + tmp = abortRequest(); + enqueueRequest(tmp, resp -> { + completeModify(tmp, resp); + cb.accept(resp); + }, enqueuedTicks); + break; + case SIMPLE: + tmp = commitRequest(false); + enqueueRequest(tmp, resp -> { + completeModify(tmp, resp); + cb.accept(resp); + }, enqueuedTicks); + break; + case THREE_PHASE: + tmp = commitRequest(true); + enqueueRequest(tmp, resp -> { + recordSuccessfulRequest(tmp); + cb.accept(resp); + }, enqueuedTicks); + break; + case READY: + tmp = readyRequest(); + enqueueRequest(tmp, resp -> { + recordSuccessfulRequest(tmp); + cb.accept(resp); + }, enqueuedTicks); + break; + default: + throw new IllegalArgumentException("Unhandled protocol " + maybeProto.get()); + } + } + } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java index c1d2db3094..89dd59a5f5 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java @@ -73,53 +73,15 @@ abstract class AbstractFrontendHistory implements Identifiable handleTransactionRequest(final TransactionRequest request, + @Nullable + final TransactionSuccess handleTransactionRequest(final TransactionRequest request, final RequestEnvelope envelope, final long now) throws RequestException { - final TransactionIdentifier id = request.getTarget(); - final UnsignedLong ul = UnsignedLong.fromLongBits(id.getTransactionId()); - if (request instanceof TransactionPurgeRequest) { - if (purgedTransactions.contains(ul)) { - // Retransmitted purge request: nothing to do - LOG.debug("{}: transaction {} already purged", persistenceId, id); - return new TransactionPurgeResponse(id, request.getSequence()); - } - - // We perform two lookups instead of a straight remove, because once the map becomes empty we switch it - // to an ImmutableMap, which does not allow remove(). - if (closedTransactions.containsKey(ul)) { - tree.purgeTransaction(id, () -> { - closedTransactions.remove(ul); - if (closedTransactions.isEmpty()) { - closedTransactions = ImmutableMap.of(); - } - - purgedTransactions.add(Range.closedOpen(ul, UnsignedLong.ONE.plus(ul))); - LOG.debug("{}: finished purging inherited transaction {}", persistenceId(), id); - envelope.sendSuccess(new TransactionPurgeResponse(id, request.getSequence()), readTime() - now); - }); - return null; - } - - final FrontendTransaction tx = transactions.get(id); - if (tx == null) { - // This should never happen because the purge callback removes the transaction and puts it into - // purged transactions in one go. If it does, we warn about the situation and - LOG.warn("{}: transaction {} not tracked in {}, but not present in active transactions", persistenceId, - id, purgedTransactions); - purgedTransactions.add(Range.closedOpen(ul, UnsignedLong.ONE.plus(ul))); - return new TransactionPurgeResponse(id, request.getSequence()); - } - - tree.purgeTransaction(id, () -> { - purgedTransactions.add(Range.closedOpen(ul, UnsignedLong.ONE.plus(ul))); - transactions.remove(id); - LOG.debug("{}: finished purging transaction {}", persistenceId(), id); - envelope.sendSuccess(new TransactionPurgeResponse(id, request.getSequence()), readTime() - now); - }); - return null; + return handleTransactionPurgeRequest(request, envelope, now); } + final TransactionIdentifier id = request.getTarget(); + final UnsignedLong ul = UnsignedLong.fromLongBits(id.getTransactionId()); if (purgedTransactions.contains(ul)) { LOG.warn("{}: Request {} is contained purged transactions {}", persistenceId, request, purgedTransactions); throw new DeadTransactionException(purgedTransactions); @@ -154,6 +116,52 @@ abstract class AbstractFrontendHistory implements Identifiable handleTransactionPurgeRequest(final TransactionRequest request, + final RequestEnvelope envelope, final long now) { + final TransactionIdentifier id = request.getTarget(); + final UnsignedLong ul = UnsignedLong.fromLongBits(id.getTransactionId()); + if (purgedTransactions.contains(ul)) { + // Retransmitted purge request: nothing to do + LOG.debug("{}: transaction {} already purged", persistenceId, id); + return new TransactionPurgeResponse(id, request.getSequence()); + } + + // We perform two lookups instead of a straight remove, because once the map becomes empty we switch it + // to an ImmutableMap, which does not allow remove(). + if (closedTransactions.containsKey(ul)) { + tree.purgeTransaction(id, () -> { + closedTransactions.remove(ul); + if (closedTransactions.isEmpty()) { + closedTransactions = ImmutableMap.of(); + } + + purgedTransactions.add(Range.closedOpen(ul, UnsignedLong.ONE.plus(ul))); + LOG.debug("{}: finished purging inherited transaction {}", persistenceId(), id); + envelope.sendSuccess(new TransactionPurgeResponse(id, request.getSequence()), readTime() - now); + }); + return null; + } + + final FrontendTransaction tx = transactions.get(id); + if (tx == null) { + // This should never happen because the purge callback removes the transaction and puts it into + // purged transactions in one go. If it does, we warn about the situation and + LOG.warn("{}: transaction {} not tracked in {}, but not present in active transactions", persistenceId, + id, purgedTransactions); + purgedTransactions.add(Range.closedOpen(ul, UnsignedLong.ONE.plus(ul))); + return new TransactionPurgeResponse(id, request.getSequence()); + } + + tree.purgeTransaction(id, () -> { + purgedTransactions.add(Range.closedOpen(ul, UnsignedLong.ONE.plus(ul))); + transactions.remove(id); + LOG.debug("{}: finished purging transaction {}", persistenceId(), id); + envelope.sendSuccess(new TransactionPurgeResponse(id, request.getSequence()), readTime() - now); + }); + + return null; + } + final void destroy(final long sequence, final RequestEnvelope envelope, final long now) { LOG.debug("{}: closing history {}", persistenceId(), getIdentifier()); tree.closeTransactionChain(getIdentifier(), @@ -178,12 +186,11 @@ abstract class AbstractFrontendHistory implements Identifiable) request).isSnapshotOnly()) { - LOG.debug("{}: allocating new open snapshot {}", persistenceId(), id); - tree.getStats().incrementReadOnlyTransactionCount(); - return createOpenSnapshot(id); - } + if (request instanceof AbstractReadTransactionRequest + && ((AbstractReadTransactionRequest) request).isSnapshotOnly()) { + LOG.debug("{}: allocating new open snapshot {}", persistenceId(), id); + tree.getStats().incrementReadOnlyTransactionCount(); + return createOpenSnapshot(id); } LOG.debug("{}: allocating new open transaction {}", persistenceId(), id); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractShardDataTreeTransaction.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractShardDataTreeTransaction.java index 1a5b968741..cde7da28f1 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractShardDataTreeTransaction.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractShardDataTreeTransaction.java @@ -14,8 +14,6 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier import org.opendaylight.controller.cluster.datastore.persisted.AbortTransactionPayload; import org.opendaylight.yangtools.concepts.Identifiable; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Abstract base for transactions running on SharrdDataTree. @@ -25,8 +23,6 @@ import org.slf4j.LoggerFactory; @NotThreadSafe abstract class AbstractShardDataTreeTransaction implements Identifiable { - private static final Logger LOG = LoggerFactory.getLogger(AbstractShardDataTreeTransaction.class); - private final ShardDataTreeTransactionParent parent; private final TransactionIdentifier id; private final T snapshot; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextConfigAdminOverlay.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextConfigAdminOverlay.java index abf07ecb40..23fcf19ec2 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextConfigAdminOverlay.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextConfigAdminOverlay.java @@ -60,7 +60,8 @@ public class DatastoreContextConfigAdminOverlay implements AutoCloseable { this.listener = listener; } - @SuppressWarnings("checkstyle:IllegalCatch") + @SuppressWarnings({"checkstyle:IllegalCatch", + "squid:S1166" /* Exception handlers should preserve the original exception */}) private void overlaySettings(ServiceReference configAdminServiceReference) { try { ConfigurationAdmin configAdmin = bundleContext.getService(configAdminServiceReference); @@ -71,10 +72,8 @@ public class DatastoreContextConfigAdminOverlay implements AutoCloseable { LOG.debug("Overlaying settings: {}", properties); - if (introspector.update(properties)) { - if (listener != null) { - listener.onDatastoreContextUpdated(introspector.newContextFactory()); - } + if (introspector.update(properties) && listener != null) { + listener.onDatastoreContextUpdated(introspector.newContextFactory()); } } else { LOG.debug("No Configuration found for {}", CONFIG_ID); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospector.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospector.java index 6685f645e8..aa54d5b9e1 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospector.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospector.java @@ -18,6 +18,7 @@ import java.beans.Introspector; import java.beans.MethodDescriptor; import java.beans.PropertyDescriptor; import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; @@ -66,16 +67,18 @@ public class DatastoreContextIntrospector { * constructor that takes a single String argument. For primitive wrappers, this constructor * converts from a String representation. */ - @SuppressWarnings("checkstyle:IllegalCatch") + // Disables "Either log or rethrow this exception" sonar warning + @SuppressWarnings("squid:S1166") private static void introspectPrimitiveTypes() { - Set> primitives = ImmutableSet.>builder().addAll( Primitives.allWrapperTypes()).add(String.class).build(); for (Class primitive: primitives) { try { processPropertyType(primitive); - } catch (Exception e) { + } catch (NoSuchMethodException e) { // Ignore primitives that can't be constructed from a String, eg Character and Void. + } catch (SecurityException | IntrospectionException e) { + LOG.error("Error introspect primitive type {}", primitive, e); } } } @@ -139,7 +142,8 @@ public class DatastoreContextIntrospector { * Finds the appropriate constructor for the specified type that we will use to construct * instances. */ - private static void processPropertyType(Class propertyType) throws Exception { + private static void processPropertyType(Class propertyType) throws NoSuchMethodException, SecurityException, + IntrospectionException { Class wrappedType = Primitives.wrap(propertyType); if (CONSTRUCTORS.containsKey(wrappedType)) { return; @@ -169,8 +173,7 @@ public class DatastoreContextIntrospector { /** * Finds the getter method on a yang-generated type for the specified property name. */ - private static void findYangTypeGetter(Class type, String propertyName) - throws Exception { + private static void findYangTypeGetter(Class type, String propertyName) throws IntrospectionException { for (PropertyDescriptor desc: Introspector.getBeanInfo(type).getPropertyDescriptors()) { if (desc.getName().equals(propertyName)) { YANG_TYPE_GETTERS.put(type, desc.getReadMethod()); @@ -178,7 +181,7 @@ public class DatastoreContextIntrospector { } } - throw new IllegalArgumentException(String.format( + throw new IntrospectionException(String.format( "Getter method for constructor property %s not found for YANG type %s", propertyName, type)); } @@ -303,7 +306,8 @@ public class DatastoreContextIntrospector { Primitives.wrap(setter.getParameterTypes()[0]), value.toString())); return true; - } catch (Exception e) { + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException + | InstantiationException e) { LOG.error("Error converting value ({}) for property {}", inValue, key, e); } @@ -321,7 +325,8 @@ public class DatastoreContextIntrospector { return StringUtils.uncapitalize(str); } - private Object convertValue(String name, Object from) throws Exception { + private Object convertValue(String name, Object from) + throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Class propertyType = DATA_STORE_PROP_TYPES.get(name); if (propertyType == null) { LOG.debug("Property not found for {}", name); @@ -345,7 +350,8 @@ public class DatastoreContextIntrospector { return converted; } - private Object constructorValueRecursively(Class toType, Object fromValue) throws Exception { + private Object constructorValueRecursively(Class toType, Object fromValue) + throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { LOG.trace("convertValueRecursively - toType: {}, fromValue {} ({})", toType.getSimpleName(), fromValue, fromValue.getClass().getSimpleName()); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DefaultShardDataChangeListenerPublisher.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DefaultShardDataChangeListenerPublisher.java index 89da5b2621..6d581f875f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DefaultShardDataChangeListenerPublisher.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DefaultShardDataChangeListenerPublisher.java @@ -86,7 +86,7 @@ final class DefaultShardDataChangeListenerPublisher implements ShardDataChangeLi final AsyncDataChangeListener> listener, final DataChangeScope scope, final DataTreeCandidate initialState, String logContext) { DefaultShardDataChangeListenerPublisher publisher = new DefaultShardDataChangeListenerPublisher(logContext); - publisher.registerDataChangeListener(path, listener, scope, Optional.absent(), noop -> { }); + publisher.registerDataChangeListener(path, listener, scope, Optional.absent(), noop -> { /* NOOP */ }); publisher.publishChanges(initialState); } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DefaultShardDataTreeChangeListenerPublisher.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DefaultShardDataTreeChangeListenerPublisher.java index 449b620170..2757c2d231 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DefaultShardDataTreeChangeListenerPublisher.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DefaultShardDataTreeChangeListenerPublisher.java @@ -88,7 +88,7 @@ final class DefaultShardDataTreeChangeListenerPublisher extends AbstractDOMStore DefaultShardDataTreeChangeListenerPublisher publisher = new DefaultShardDataTreeChangeListenerPublisher(logContext); publisher.logContext = logContext; - publisher.registerTreeChangeListener(treeId, listener, Optional.absent(), noop -> { }); + publisher.registerTreeChangeListener(treeId, listener, Optional.absent(), noop -> { /* NOOP */ }); publisher.publishChanges(state); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreFactory.java index 11bbe1b168..a4256a77c8 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreFactory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreFactory.java @@ -24,6 +24,9 @@ public class DistributedDataStoreFactory { private static final String DEFAULT_MODULE_SHARDS_PATH = "./configuration/initial/module-shards.conf"; private static final String DEFAULT_MODULES_PATH = "./configuration/initial/modules.conf"; + private DistributedDataStoreFactory() { + } + /** * Create a data store instance. * diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendReadWriteTransaction.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendReadWriteTransaction.java index 50e913025d..2b444a6b57 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendReadWriteTransaction.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendReadWriteTransaction.java @@ -247,7 +247,7 @@ final class FrontendReadWriteTransaction extends FrontendTransaction { case READY: throw new IllegalStateException("Attempted to preCommit in stage " + ready.stage); default: - throw new IllegalStateException("Unhandled commit stage " + ready.stage); + throwUnhandledCommitStage(ready); } } @@ -306,7 +306,7 @@ final class FrontendReadWriteTransaction extends FrontendTransaction { case READY: throw new IllegalStateException("Attempted to doCommit in stage " + ready.stage); default: - throw new IllegalStateException("Unhandled commit stage " + ready.stage); + throwUnhandledCommitStage(ready); } } @@ -395,7 +395,7 @@ final class FrontendReadWriteTransaction extends FrontendTransaction { case PRE_COMMIT_PENDING: throw new IllegalStateException("Attempted to canCommit in stage " + ready.stage); default: - throw new IllegalStateException("Unhandled commit stage " + ready.stage); + throwUnhandledCommitStage(ready); } } @@ -442,7 +442,7 @@ final class FrontendReadWriteTransaction extends FrontendTransaction { }); break; default: - throw new IllegalStateException("Unhandled commit stage " + ready.stage); + throwUnhandledCommitStage(ready); } } @@ -558,7 +558,8 @@ final class FrontendReadWriteTransaction extends FrontendTransaction { } } - private @Nullable TransactionSuccess handleModifyTransaction(final ModifyTransactionRequest request, + @Nullable + private TransactionSuccess handleModifyTransaction(final ModifyTransactionRequest request, final RequestEnvelope envelope, final long now) throws RequestException { // We need to examine the persistence protocol first to see if this is an idempotent request. If there is no // protocol, there is nothing for us to do. @@ -636,4 +637,8 @@ final class FrontendReadWriteTransaction extends FrontendTransaction { state); return ((Sealed) state).sealedModification; } + + private static void throwUnhandledCommitStage(final Ready ready) { + throw new IllegalStateException("Unhandled commit stage " + ready.stage); + } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/RemoteTransactionContextSupport.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/RemoteTransactionContextSupport.java index 5bafef8a85..22ba497801 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/RemoteTransactionContextSupport.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/RemoteTransactionContextSupport.java @@ -166,30 +166,29 @@ final class RemoteTransactionContextSupport { // the cached remote leader actor is no longer available. boolean retryCreateTransaction = primaryShardInfo != null && (failure instanceof NoShardLeaderException || failure instanceof AskTimeoutException); - if (retryCreateTransaction) { - // Schedule a retry unless we're out of retries. Note: totalCreateTxTimeout is volatile as it may - // be written by different threads however not concurrently, therefore decrementing it - // non-atomically here is ok. - if (totalCreateTxTimeout > 0) { - long scheduleInterval = CREATE_TX_TRY_INTERVAL_IN_MS; - if (failure instanceof AskTimeoutException) { - // Since we use the createTxMessageTimeout for the CreateTransaction request and it timed - // out, subtract it from the total timeout. Also since the createTxMessageTimeout period - // has already elapsed, we can immediately schedule the retry (10 ms is virtually immediate). - totalCreateTxTimeout -= createTxMessageTimeout.duration().toMillis(); - scheduleInterval = 10; - } - - totalCreateTxTimeout -= scheduleInterval; - - LOG.debug("Tx {}: create tx on shard {} failed with exception \"{}\" - scheduling retry in {} ms", - getIdentifier(), shardName, failure, scheduleInterval); - - getActorContext().getActorSystem().scheduler().scheduleOnce( - FiniteDuration.create(scheduleInterval, TimeUnit.MILLISECONDS), - this::tryFindPrimaryShard, getActorContext().getClientDispatcher()); - return; + + // Schedule a retry unless we're out of retries. Note: totalCreateTxTimeout is volatile as it may + // be written by different threads however not concurrently, therefore decrementing it + // non-atomically here is ok. + if (retryCreateTransaction && totalCreateTxTimeout > 0) { + long scheduleInterval = CREATE_TX_TRY_INTERVAL_IN_MS; + if (failure instanceof AskTimeoutException) { + // Since we use the createTxMessageTimeout for the CreateTransaction request and it timed + // out, subtract it from the total timeout. Also since the createTxMessageTimeout period + // has already elapsed, we can immediately schedule the retry (10 ms is virtually immediate). + totalCreateTxTimeout -= createTxMessageTimeout.duration().toMillis(); + scheduleInterval = 10; } + + totalCreateTxTimeout -= scheduleInterval; + + LOG.debug("Tx {}: create tx on shard {} failed with exception \"{}\" - scheduling retry in {} ms", + getIdentifier(), shardName, failure, scheduleInterval); + + getActorContext().getActorSystem().scheduler().scheduleOnce( + FiniteDuration.create(scheduleInterval, TimeUnit.MILLISECONDS), + this::tryFindPrimaryShard, getActorContext().getClientDispatcher()); + return; } createTransactionContext(failure, response); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java index 1789f09d2b..402bf4822b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java @@ -502,7 +502,8 @@ public class Shard extends RaftActor { throw new OutOfSequenceEnvelopeException(0); } - private static @Nonnull ABIVersion selectVersion(final ConnectClientRequest message) { + @Nonnull + private static ABIVersion selectVersion(final ConnectClientRequest message) { final Range clientRange = Range.closed(message.getMinVersion(), message.getMaxVersion()); for (ABIVersion v : SUPPORTED_ABIVERSIONS) { if (clientRange.contains(v)) { @@ -550,7 +551,8 @@ public class Shard extends RaftActor { } } - private @Nullable RequestSuccess handleRequest(final RequestEnvelope envelope, final long now) + @Nullable + private RequestSuccess handleRequest(final RequestEnvelope envelope, final long now) throws RequestException { // We are not the leader, hence we want to fail-fast. if (!isLeader() || paused || !isLeaderActive()) { @@ -683,7 +685,7 @@ public class Shard extends RaftActor { ActorSelection leader = getLeader(); if (!isLeaderActive || leader == null) { messageRetrySupport.addMessageToRetry(batched, getSender(), - "Could not commit transaction " + batched.getTransactionId()); + "Could not process BatchedModifications " + batched.getTransactionId()); } else { // If this is not the first batch and leadership changed in between batched messages, // we need to reconstruct previous BatchedModifications from the transaction @@ -736,7 +738,7 @@ public class Shard extends RaftActor { ActorSelection leader = getLeader(); if (!isLeaderActive || leader == null) { messageRetrySupport.addMessageToRetry(message, getSender(), - "Could not commit transaction " + message.getTransactionId()); + "Could not process ready local transaction " + message.getTransactionId()); } else { LOG.debug("{}: Forwarding ReadyLocalTransaction to leader {}", persistenceId(), leader); message.setRemoteVersion(getCurrentBehavior().getLeaderPayloadVersion()); @@ -755,7 +757,7 @@ public class Shard extends RaftActor { ActorSelection leader = getLeader(); if (!isLeaderActive || leader == null) { messageRetrySupport.addMessageToRetry(forwardedReady, getSender(), - "Could not commit transaction " + forwardedReady.getTransactionId()); + "Could not process forwarded ready transaction " + forwardedReady.getTransactionId()); } else { LOG.debug("{}: Forwarding ForwardedReadyTransaction to leader {}", persistenceId(), leader); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java index 37e65f6a96..e399cd49ab 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java @@ -299,7 +299,7 @@ public class ShardDataTree extends ShardDataTreeTransactionParent { * @param snapshot Snapshot that needs to be applied * @throws DataValidationFailedException when the snapshot fails to apply */ - void applyRecoverySnapshot(final @Nonnull ShardDataTreeSnapshot snapshot) throws DataValidationFailedException { + void applyRecoverySnapshot(@Nonnull final ShardDataTreeSnapshot snapshot) throws DataValidationFailedException { applySnapshot(snapshot, this::wrapWithPruning); } @@ -333,7 +333,7 @@ public class ShardDataTree extends ShardDataTreeTransactionParent { * @throws IOException when the snapshot fails to deserialize * @throws DataValidationFailedException when the snapshot fails to apply */ - void applyRecoveryPayload(final @Nonnull Payload payload) throws IOException, DataValidationFailedException { + void applyRecoveryPayload(@Nonnull final Payload payload) throws IOException, DataValidationFailedException { if (payload instanceof CommitTransactionPayload) { final Entry e = ((CommitTransactionPayload) payload).getCandidate(); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeMetadata.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeMetadata.java index 7db3a228c8..e2c1b27db1 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeMetadata.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeMetadata.java @@ -44,14 +44,16 @@ abstract class ShardDataTreeMetadata> * * @return Metadata type */ - abstract @Nonnull Class getSupportedType(); + @Nonnull + abstract Class getSupportedType(); /** * Take a snapshot of current metadata state. * * @return Metadata snapshot, or null if the metadata is empty. */ - abstract @Nullable T toSnapshot(); + @Nullable + abstract T toSnapshot(); // Lifecycle events diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransaction.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransaction.java index dfd60afa21..0e82116a0d 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransaction.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransaction.java @@ -40,7 +40,8 @@ public abstract class ShardTransaction extends AbstractUntypedActorWithMetering protected ShardTransaction(final ActorRef shardActor, final ShardStats shardStats, final TransactionIdentifier transactionId) { - super("shard-tx"); //actor name override used for metering. This does not change the "real" actor name + // actor name override used for metering. This does not change the "real" actor name + super("shard-tx"); this.shardActor = shardActor; this.shardStats = shardStats; this.transactionId = Preconditions.checkNotNull(transactionId); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/config/ConfigurationImpl.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/config/ConfigurationImpl.java index c1f687bd55..0007d0941b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/config/ConfigurationImpl.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/config/ConfigurationImpl.java @@ -142,7 +142,7 @@ public class ConfigurationImpl implements Configuration { @Override public Collection getMembersFromShardName(final String shardName) { - Preconditions.checkNotNull(shardName, "shardName should not be null"); + checkNotNullShardName(shardName); for (ModuleConfig moduleConfig: moduleConfigMap.values()) { ShardConfig shardConfig = moduleConfig.getShardConfig(shardName); @@ -160,6 +160,10 @@ public class ConfigurationImpl implements Configuration { return Collections.emptyList(); } + private static void checkNotNullShardName(final String shardName) { + Preconditions.checkNotNull(shardName, "shardName should not be null"); + } + @Override public Set getAllShardNames() { return allShardNames; @@ -234,13 +238,13 @@ public class ConfigurationImpl implements Configuration { @Override public boolean isShardConfigured(String shardName) { - Preconditions.checkNotNull(shardName, "shardName should not be null"); + checkNotNullShardName(shardName); return allShardNames.contains(shardName); } @Override public void addMemberReplicaForShard(String shardName, MemberName newMemberName) { - Preconditions.checkNotNull(shardName, "shardName should not be null"); + checkNotNullShardName(shardName); Preconditions.checkNotNull(newMemberName, "MemberName should not be null"); for (ModuleConfig moduleConfig: moduleConfigMap.values()) { @@ -256,7 +260,7 @@ public class ConfigurationImpl implements Configuration { @Override public void removeMemberReplicaForShard(String shardName, MemberName newMemberName) { - Preconditions.checkNotNull(shardName, "shardName should not be null"); + checkNotNullShardName(shardName); Preconditions.checkNotNull(newMemberName, "MemberName should not be null"); for (ModuleConfig moduleConfig: moduleConfigMap.values()) { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/config/PrefixShardConfiguration.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/config/PrefixShardConfiguration.java index 629418f99b..c387fe4ba2 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/config/PrefixShardConfiguration.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/config/PrefixShardConfiguration.java @@ -52,16 +52,17 @@ public class PrefixShardConfiguration implements Serializable { @Override public void readExternal(final ObjectInput objectInput) throws IOException, ClassNotFoundException { - final DOMDataTreeIdentifier prefix = (DOMDataTreeIdentifier) objectInput.readObject(); - final String strategyName = (String) objectInput.readObject(); + final DOMDataTreeIdentifier localPrefix = (DOMDataTreeIdentifier) objectInput.readObject(); + final String localStrategyName = (String) objectInput.readObject(); final int size = objectInput.readInt(); - final Collection shardMemberNames = new ArrayList<>(size); + final Collection localShardMemberNames = new ArrayList<>(size); for (int i = 0; i < size; i++) { - shardMemberNames.add(MemberName.readFrom(objectInput)); + localShardMemberNames.add(MemberName.readFrom(objectInput)); } - prefixShardConfiguration = new PrefixShardConfiguration(prefix, strategyName, shardMemberNames); + prefixShardConfiguration = new PrefixShardConfiguration(localPrefix, localStrategyName, + localShardMemberNames); } private Object readResolve() { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/AbstractEntityOwnerChangeListener.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/AbstractEntityOwnerChangeListener.java index 6094e2469d..7d872b4a03 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/AbstractEntityOwnerChangeListener.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/AbstractEntityOwnerChangeListener.java @@ -25,7 +25,7 @@ public abstract class AbstractEntityOwnerChangeListener implements DOMDataTreeCh .node(ENTITY_OWNER_QNAME).build(); void init(ShardDataTree shardDataTree) { - shardDataTree.registerTreeChangeListener(EOS_PATH, this, Optional.absent(), noop -> { }); + shardDataTree.registerTreeChangeListener(EOS_PATH, this, Optional.absent(), noop -> { /* NOOP */ }); } protected static String extractOwner(LeafNode ownerLeaf) { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/CandidateListChangeListener.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/CandidateListChangeListener.java index 6b6717c7da..729b7d8f82 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/CandidateListChangeListener.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/CandidateListChangeListener.java @@ -60,8 +60,8 @@ class CandidateListChangeListener implements DOMDataTreeChangeListener { void init(ShardDataTree shardDataTree) { shardDataTree.registerTreeChangeListener(YangInstanceIdentifier.builder(ENTITY_OWNERS_PATH) - .node(EntityType.QNAME).node(EntityType.QNAME).node(ENTITY_QNAME).node(ENTITY_QNAME) - .node(Candidate.QNAME).node(Candidate.QNAME).build(), this, Optional.absent(), noop -> { }); + .node(EntityType.QNAME).node(EntityType.QNAME).node(ENTITY_QNAME).node(ENTITY_QNAME) + .node(Candidate.QNAME).node(Candidate.QNAME).build(), this, Optional.absent(), noop -> { /* NOOP */ }); } @Override diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnersModel.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnersModel.java index 1b5e512c59..a392049a84 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnersModel.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnersModel.java @@ -49,6 +49,9 @@ public final class EntityOwnersModel { static final YangInstanceIdentifier ENTITY_TYPES_PATH = YangInstanceIdentifier.of(EntityOwners.QNAME).node(EntityType.QNAME); + private EntityOwnersModel() { + } + static YangInstanceIdentifier entityPath(String entityType, YangInstanceIdentifier entityId) { return YangInstanceIdentifier.builder(ENTITY_OWNERS_PATH).node(EntityType.QNAME) .nodeWithKey(EntityType.QNAME, ENTITY_TYPE_QNAME, entityType).node(ENTITY_QNAME) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/EntityOwnerSelectionStrategyConfigReader.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/EntityOwnerSelectionStrategyConfigReader.java index 29ace24754..126324fff0 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/EntityOwnerSelectionStrategyConfigReader.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/EntityOwnerSelectionStrategyConfigReader.java @@ -64,7 +64,7 @@ public final class EntityOwnerSelectionStrategyConfigReader { LOG.debug("Could not read strategy configuration file, will use default configuration"); } catch (IOException e1) { - LOG.warn("Failed to get configuration for {}, starting up empty", CONFIG_ID); + LOG.warn("Failed to get configuration for {}, starting up empty", CONFIG_ID, e1); return builder.build(); } finally { try { @@ -127,7 +127,7 @@ public final class EntityOwnerSelectionStrategyConfigReader { try { clazz = EntityOwnerSelectionStrategyConfigReader.class.getClassLoader().loadClass(strategyClassAndDelay); } catch (ClassNotFoundException e) { - throw new IllegalArgumentException("Failed to load strategy " + strategyClassAndDelay); + throw new IllegalArgumentException("Failed to load strategy " + strategyClassAndDelay, e); } Preconditions.checkArgument(EntityOwnerSelectionStrategy.class.isAssignableFrom(clazz), diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/shard/ShardMBeanFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/shard/ShardMBeanFactory.java index 08632a8535..8b46987bb3 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/shard/ShardMBeanFactory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/shard/ShardMBeanFactory.java @@ -17,6 +17,9 @@ import org.opendaylight.controller.cluster.datastore.Shard; */ public class ShardMBeanFactory { + private ShardMBeanFactory() { + } + public static ShardStats getShardStatsMBean(final String shardName, final String mxBeanType, @Nonnull final Shard shard) { String finalMXBeanType = mxBeanType != null ? mxBeanType : "DistDataStore"; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/ActorInitialized.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/ActorInitialized.java index 71d5a48291..09c5b739cf 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/ActorInitialized.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/ActorInitialized.java @@ -11,4 +11,7 @@ import java.io.Serializable; public class ActorInitialized implements Serializable { private static final long serialVersionUID = 1L; + + public ActorInitialized() { + } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataChanged.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataChanged.java index 3cc6d041d8..c753ad2764 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataChanged.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataChanged.java @@ -43,7 +43,8 @@ public class DataChanged implements Externalizable { @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - in.readShort(); // Read the version + // Read the version + in.readShort(); NormalizedNodeDataInput streamReader = NormalizedNodeInputOutput.newDataInputWithoutValidation(in); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataChangedReply.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataChangedReply.java index a5f23e5497..4f90c32635 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataChangedReply.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataChangedReply.java @@ -10,4 +10,7 @@ package org.opendaylight.controller.cluster.datastore.messages; public class DataChangedReply { public static final DataChangedReply INSTANCE = new DataChangedReply(); + + private DataChangedReply() { + } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/LocalPrimaryShardFound.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/LocalPrimaryShardFound.java index 707f50b324..0ca4f6444d 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/LocalPrimaryShardFound.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/LocalPrimaryShardFound.java @@ -27,11 +27,13 @@ public class LocalPrimaryShardFound { this.localShardDataTree = Preconditions.checkNotNull(localShardDataTree); } - public @Nonnull String getPrimaryPath() { + @Nonnull + public String getPrimaryPath() { return primaryPath; } - public @Nonnull DataTree getLocalShardDataTree() { + @Nonnull + public DataTree getLocalShardDataTree() { return localShardDataTree; } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/PrimaryShardInfo.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/PrimaryShardInfo.java index 27d247512c..f739e1e6c4 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/PrimaryShardInfo.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/PrimaryShardInfo.java @@ -39,7 +39,8 @@ public class PrimaryShardInfo { /** * Returns an ActorSelection representing the primary shard actor. */ - public @Nonnull ActorSelection getPrimaryShardActor() { + @Nonnull + public ActorSelection getPrimaryShardActor() { return primaryShardActor; } @@ -54,7 +55,8 @@ public class PrimaryShardInfo { * Returns an Optional whose value contains the primary shard's DataTree if the primary shard is local * to the caller. Otherwise the Optional value is absent. */ - public @Nonnull Optional getLocalShardDataTree() { + @Nonnull + public Optional getLocalShardDataTree() { return Optional.ofNullable(localShardDataTree); } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/ShardLeaderStateChanged.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/ShardLeaderStateChanged.java index dbd031076c..0b3b6b8918 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/ShardLeaderStateChanged.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/ShardLeaderStateChanged.java @@ -37,7 +37,8 @@ public class ShardLeaderStateChanged extends LeaderStateChanged { this.localShardDataTree = null; } - public @Nonnull Optional getLocalShardDataTree() { + @Nonnull + public Optional getLocalShardDataTree() { return Optional.ofNullable(localShardDataTree); } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/SuccessReply.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/SuccessReply.java index ace731e1de..fde42f8648 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/SuccessReply.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/SuccessReply.java @@ -18,4 +18,7 @@ public class SuccessReply implements Serializable { private static final long serialVersionUID = 1L; public static final SuccessReply INSTANCE = new SuccessReply(); + + private SuccessReply() { + } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/AbstractVersionException.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/AbstractVersionException.java index 709217d7a5..997fa45c6b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/AbstractVersionException.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/AbstractVersionException.java @@ -42,7 +42,8 @@ public abstract class AbstractVersionException extends Exception { * * @return Closest supported {@link PayloadVersion} */ - public final @Nonnull PayloadVersion getClosestVersion() { + @Nonnull + public final PayloadVersion getClosestVersion() { return closestVersion; } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/DataTreeCandidateInputOutput.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/DataTreeCandidateInputOutput.java index fb9b07a5d0..bc1fca1655 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/DataTreeCandidateInputOutput.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/DataTreeCandidateInputOutput.java @@ -168,7 +168,7 @@ public final class DataTreeCandidateInputOutput { out.writeByte(UNMODIFIED); break; default: - throw new IllegalArgumentException("Unhandled node type " + node.getModificationType()); + throwUnhandledNodeType(node); } } @@ -201,8 +201,12 @@ public final class DataTreeCandidateInputOutput { writer.writeNormalizedNode(node.getDataAfter().get()); break; default: - throw new IllegalArgumentException("Unhandled node type " + node.getModificationType()); + throwUnhandledNodeType(node); } } } + + private static void throwUnhandledNodeType(final DataTreeCandidateNode node) { + throw new IllegalArgumentException("Unhandled node type " + node.getModificationType()); + } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/DatastoreSnapshot.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/DatastoreSnapshot.java index b37fb4d001..37d4125858 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/DatastoreSnapshot.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/DatastoreSnapshot.java @@ -57,16 +57,16 @@ public class DatastoreSnapshot implements Serializable { @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - String type = (String)in.readObject(); - ShardManagerSnapshot shardManagerSnapshot = (ShardManagerSnapshot) in.readObject(); + String localType = (String)in.readObject(); + ShardManagerSnapshot localShardManagerSnapshot = (ShardManagerSnapshot) in.readObject(); int size = in.readInt(); - List shardSnapshots = new ArrayList<>(size); + List localShardSnapshots = new ArrayList<>(size); for (int i = 0; i < size; i++) { - shardSnapshots.add((ShardSnapshot) in.readObject()); + localShardSnapshots.add((ShardSnapshot) in.readObject()); } - datastoreSnapshot = new DatastoreSnapshot(type, shardManagerSnapshot, shardSnapshots); + datastoreSnapshot = new DatastoreSnapshot(localType, localShardManagerSnapshot, localShardSnapshots); } private Object readResolve() { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshot.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshot.java index fd35046f04..7a8bd4648b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshot.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshot.java @@ -13,8 +13,6 @@ import java.io.ObjectInput; import java.io.ObjectOutput; import java.util.Optional; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Abstract base class for snapshots of the ShardDataTree. @@ -23,8 +21,6 @@ import org.slf4j.LoggerFactory; */ @Beta public abstract class ShardDataTreeSnapshot { - private static final Logger LOG = LoggerFactory.getLogger(ShardDataTreeSnapshot.class); - ShardDataTreeSnapshot() { // Hidden to prevent subclassing from outside of this package } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshotMetadata.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshotMetadata.java index 0ddc785a90..3ba5a91a9c 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshotMetadata.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshotMetadata.java @@ -46,7 +46,8 @@ public abstract class ShardDataTreeSnapshotMetadata getType(); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardManagerSnapshot.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardManagerSnapshot.java index 9dc95c058a..0c1969b216 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardManagerSnapshot.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardManagerSnapshot.java @@ -63,19 +63,19 @@ public class ShardManagerSnapshot implements Serializable { @Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { int size = in.readInt(); - List shardList = new ArrayList<>(size); + List localShardList = new ArrayList<>(size); for (int i = 0; i < size; i++) { - shardList.add((String) in.readObject()); + localShardList.add((String) in.readObject()); } size = in.readInt(); - Map prefixShardConfiguration = new HashMap<>(size); + Map localPrefixShardConfiguration = new HashMap<>(size); for (int i = 0; i < size; i++) { - prefixShardConfiguration.put((DOMDataTreeIdentifier) in.readObject(), + localPrefixShardConfiguration.put((DOMDataTreeIdentifier) in.readObject(), (PrefixShardConfiguration) in.readObject()); } - snapshot = new ShardManagerSnapshot(shardList, prefixShardConfiguration); + snapshot = new ShardManagerSnapshot(localShardList, localPrefixShardConfiguration); } private Object readResolve() { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManager.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManager.java index 992786ad4b..e3d3a60409 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManager.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManager.java @@ -336,7 +336,7 @@ class ShardManager extends AbstractUntypedPersistentActorWithMetering { private void onInitConfigListener() { LOG.debug("{}: Initializing config listener on {}", persistenceId(), cluster.getCurrentMemberName()); - final org.opendaylight.mdsal.common.api.LogicalDatastoreType type = + final org.opendaylight.mdsal.common.api.LogicalDatastoreType datastoreType = org.opendaylight.mdsal.common.api.LogicalDatastoreType .valueOf(datastoreContextFactory.getBaseDatastoreContext().getLogicalStoreType().name()); @@ -345,7 +345,7 @@ class ShardManager extends AbstractUntypedPersistentActorWithMetering { } configUpdateHandler = new PrefixedShardConfigUpdateHandler(self(), cluster.getCurrentMemberName()); - configUpdateHandler.initListener(dataStore, type); + configUpdateHandler.initListener(dataStore, datastoreType); } private void onShutDown() { @@ -849,7 +849,8 @@ class ShardManager extends AbstractUntypedPersistentActorWithMetering { final ActorRef sender = getSender(); if (sender == null) { - return; //why is a non-actor sending this message? Just ignore. + // why is a non-actor sending this message? Just ignore. + return; } String actorName = sender.path().name(); @@ -1252,7 +1253,8 @@ class ShardManager extends AbstractUntypedPersistentActorWithMetering { } } - restoreFromSnapshot = null; // null out to GC + // null out to GC + restoreFromSnapshot = null; for (String shardName : memberShardNames) { ShardIdentifier shardId = getShardIdentifier(memberName, shardName); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManagerSnapshot.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManagerSnapshot.java index 9899aeb1fc..5322420670 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManagerSnapshot.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManagerSnapshot.java @@ -39,7 +39,7 @@ public final class ShardManagerSnapshot implements Serializable { * org.opendaylight.controller.cluster.datastore.ShardManagerSnapshot is removed. */ @Deprecated - public static ShardManagerSnapshot forShardList(final @Nonnull List shardList) { + public static ShardManagerSnapshot forShardList(@Nonnull final List shardList) { return new ShardManagerSnapshot(shardList); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ClusterUtils.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ClusterUtils.java index 06bb712fd8..a877430034 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ClusterUtils.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ClusterUtils.java @@ -43,6 +43,9 @@ public class ClusterUtils { public static final YangInstanceIdentifier SHARD_LIST_PATH = PREFIX_SHARDS_PATH.node(SHARD_LIST_QNAME).toOptimized(); + private ClusterUtils() { + } + public static ShardIdentifier getShardIdentifier(final MemberName memberName, final DOMDataTreeIdentifier prefix) { final String type; switch (prefix.getDatastoreType()) { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/CompositeOnComplete.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/CompositeOnComplete.java index 0ae3fefa97..6e7d2bfd4b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/CompositeOnComplete.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/CompositeOnComplete.java @@ -29,7 +29,7 @@ public abstract class CompositeOnComplete extends OnComplete { onCompleteTasks.add(task); } - @SuppressWarnings("checkstyle:IllegalCatch") + @SuppressWarnings({ "checkstyle:IllegalCatch", "squid:S1181" /* Throwable and Error should not be caught */ }) protected void notifyOnCompleteTasks(Throwable failure, T result) { for (OnComplete task: onCompleteTasks) { try { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/PrimaryShardInfoFutureCache.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/PrimaryShardInfoFutureCache.java index 70d9b94a00..3d4476a972 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/PrimaryShardInfoFutureCache.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/PrimaryShardInfoFutureCache.java @@ -23,7 +23,8 @@ import scala.concurrent.Future; public class PrimaryShardInfoFutureCache { private final Cache> primaryShardInfoCache = CacheBuilder.newBuilder().build(); - public @Nullable Future getIfPresent(@Nonnull String shardName) { + @Nullable + public Future getIfPresent(@Nonnull String shardName) { return primaryShardInfoCache.getIfPresent(shardName); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DOMDataTreeShardCreationFailedException.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DOMDataTreeShardCreationFailedException.java index f6628ad9de..eda11532ce 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DOMDataTreeShardCreationFailedException.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DOMDataTreeShardCreationFailedException.java @@ -18,11 +18,11 @@ import javax.annotation.Nonnull; public class DOMDataTreeShardCreationFailedException extends Exception { private static final long serialVersionUID = 1L; - public DOMDataTreeShardCreationFailedException(final @Nonnull String message) { + public DOMDataTreeShardCreationFailedException(@Nonnull final String message) { super(message); } - public DOMDataTreeShardCreationFailedException(final @Nonnull String message, final @Nonnull Throwable cause) { + public DOMDataTreeShardCreationFailedException(@Nonnull final String message, @Nonnull final Throwable cause) { super(message, cause); } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardChangePublisher.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardChangePublisher.java index 0eef92ad14..57e75136c7 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardChangePublisher.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardChangePublisher.java @@ -57,9 +57,6 @@ public class DistributedShardChangePublisher private final AbstractDataStore distributedDataStore; private final YangInstanceIdentifier shardPath; - // This will be useful for signaling back pressure - private final DataStoreClient client; - private final Map childShards; @GuardedBy("this") @@ -69,7 +66,6 @@ public class DistributedShardChangePublisher final AbstractDataStore distributedDataStore, final DOMDataTreeIdentifier prefix, final Map childShards) { - this.client = client; this.distributedDataStore = distributedDataStore; // TODO keeping the whole dataTree thats contained in subshards doesn't seem like a good idea // maybe the whole listener logic would be better in the backend shards where we have direct access to the @@ -306,7 +302,7 @@ public class DistributedShardChangePublisher // data tree yet. Postpone processing of these changes till we // receive changes from current shard. LOG.debug("Validation for modification built from subshard {} changes {} failed, current data tree {}.", - pathFromRoot, changes, dataTree); + pathFromRoot, changes, dataTree, e); stashedDataTreeCandidates.addAll(newCandidates); } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardProxyProducer.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardProxyProducer.java index 3c8db5f23c..b78836bfa6 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardProxyProducer.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardProxyProducer.java @@ -11,25 +11,17 @@ package org.opendaylight.controller.cluster.sharding; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import java.util.Collection; -import java.util.concurrent.atomic.AtomicLong; import javax.annotation.Nonnull; import org.opendaylight.controller.cluster.databroker.actors.dds.ClientLocalHistory; import org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient; import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; import org.opendaylight.mdsal.dom.spi.shard.DOMDataTreeShardProducer; import org.opendaylight.mdsal.dom.spi.shard.DOMDataTreeShardWriteTransaction; -import org.opendaylight.mdsal.dom.store.inmemory.InMemoryDOMDataTreeShard; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Proxy producer implementation that creates transactions that forward all calls to {@link DataStoreClient}. */ class ShardProxyProducer implements DOMDataTreeShardProducer { - - private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMDataTreeShard.class); - private static final AtomicLong COUNTER = new AtomicLong(); - private final DOMDataTreeIdentifier shardRoot; private final Collection prefixes; private final ClientLocalHistory history; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardProxyTransaction.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardProxyTransaction.java index 52630eb4ba..a614f92596 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardProxyTransaction.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardProxyTransaction.java @@ -124,7 +124,7 @@ class ShardProxyTransaction implements DOMDataTreeShardWriteTransaction { public ListenableFuture submit() { LOG.debug("Submitting transaction for shard {}", shardRoot); - Preconditions.checkState(!cohorts.isEmpty(), "Transaction not readied yet"); + checkTransactionReadied(); final AsyncFunction validateFunction = input -> prepare(); final AsyncFunction prepareFunction = input -> commit(); @@ -136,11 +136,15 @@ class ShardProxyTransaction implements DOMDataTreeShardWriteTransaction { return Futures.transformAsync(prepareFuture, prepareFunction, MoreExecutors.directExecutor()); } + private void checkTransactionReadied() { + Preconditions.checkState(!cohorts.isEmpty(), "Transaction not readied yet"); + } + @Override public ListenableFuture validate() { LOG.debug("Validating transaction for shard {}", shardRoot); - Preconditions.checkState(!cohorts.isEmpty(), "Transaction not readied yet"); + checkTransactionReadied(); final List> futures = cohorts.stream().map(DOMStoreThreePhaseCommitCohort::canCommit).collect(Collectors.toList()); final SettableFuture ret = SettableFuture.create(); @@ -164,7 +168,7 @@ class ShardProxyTransaction implements DOMDataTreeShardWriteTransaction { public ListenableFuture prepare() { LOG.debug("Preparing transaction for shard {}", shardRoot); - Preconditions.checkState(!cohorts.isEmpty(), "Transaction not readied yet"); + checkTransactionReadied(); final List> futures = cohorts.stream().map(DOMStoreThreePhaseCommitCohort::preCommit).collect(Collectors.toList()); final SettableFuture ret = SettableFuture.create(); @@ -188,7 +192,7 @@ class ShardProxyTransaction implements DOMDataTreeShardWriteTransaction { public ListenableFuture commit() { LOG.debug("Committing transaction for shard {}", shardRoot); - Preconditions.checkState(!cohorts.isEmpty(), "Transaction not readied yet"); + checkTransactionReadied(); final List> futures = cohorts.stream().map(DOMStoreThreePhaseCommitCohort::commit).collect(Collectors.toList()); final SettableFuture ret = SettableFuture.create(); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardedDataTreeActor.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardedDataTreeActor.java index 0f55831e36..3efbbabeb8 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardedDataTreeActor.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardedDataTreeActor.java @@ -17,7 +17,6 @@ import akka.actor.PoisonPill; import akka.actor.Props; import akka.actor.Status; import akka.actor.Status.Success; -import akka.cluster.Cluster; import akka.cluster.ClusterEvent; import akka.cluster.ClusterEvent.MemberExited; import akka.cluster.ClusterEvent.MemberRemoved; @@ -98,11 +97,6 @@ public class ShardedDataTreeActor extends AbstractUntypedPersistentActor { private final int lookupTaskMaxRetries; private final Map idToProducer = new HashMap<>(); - private final Map idToShardRegistration = new HashMap<>(); - - private final Cluster cluster; - - private final Map currentConfiguration = new HashMap<>(); ShardedDataTreeActor(final ShardedDataTreeActorCreator builder) { LOG.debug("Creating ShardedDataTreeActor on {}", builder.getClusterWrapper().getCurrentMemberName()); @@ -118,7 +112,6 @@ public class ShardedDataTreeActor extends AbstractUntypedPersistentActor { DistributedShardedDOMDataTree.ACTOR_ID, clusterWrapper.getCurrentMemberName()); clusterWrapper.subscribeToMemberEvents(self()); - cluster = Cluster.get(actorSystem); } @Override