X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FShard.java;h=d476b332b30dd35a73e9fe648b718149653cd8fe;hp=a7b89e18003844e96ed3e097381786dda4714b99;hb=a3459dc797e4e0722b945b80bc8ef3123762fc8d;hpb=3115b8171461584e85f58d87a9f179013cfbb262 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 a7b89e1800..d476b332b3 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 @@ -7,7 +7,10 @@ */ package org.opendaylight.controller.cluster.datastore; +import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Verify.verify; +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; import akka.actor.ActorRef; import akka.actor.ActorSelection; @@ -19,11 +22,11 @@ import akka.actor.Status.Failure; import akka.serialization.JavaSerializer; import akka.serialization.Serialization; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; import com.google.common.base.Ticker; import com.google.common.base.Verify; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Range; import java.io.IOException; import java.util.Arrays; @@ -75,6 +78,8 @@ import org.opendaylight.controller.cluster.datastore.messages.CommitTransaction; import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction; import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply; import org.opendaylight.controller.cluster.datastore.messages.ForwardedReadyTransaction; +import org.opendaylight.controller.cluster.datastore.messages.GetKnownClients; +import org.opendaylight.controller.cluster.datastore.messages.GetKnownClientsReply; import org.opendaylight.controller.cluster.datastore.messages.GetShardDataTree; import org.opendaylight.controller.cluster.datastore.messages.MakeLeaderLocal; import org.opendaylight.controller.cluster.datastore.messages.OnDemandShardState; @@ -107,8 +112,8 @@ import org.opendaylight.yangtools.concepts.Identifier; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider; import scala.concurrent.duration.FiniteDuration; /** @@ -147,6 +152,9 @@ public class Shard extends RaftActor { private static final Collection SUPPORTED_ABIVERSIONS; + // Make sure to keep this in sync with the journal configuration in factory-akka.conf + public static final String NON_PERSISTENT_JOURNAL_ID = "akka.persistence.non-persistent.journal"; + static { final ABIVersion[] values = ABIVersion.values(); final ABIVersion[] real = Arrays.copyOfRange(values, 1, values.length - 1); @@ -219,10 +227,12 @@ public class Shard extends RaftActor { new ShardDataTreeChangeListenerPublisherActorProxy(getContext(), name + "-DTCL-publisher", name); if (builder.getDataTree() != null) { store = new ShardDataTree(this, builder.getSchemaContext(), builder.getDataTree(), - treeChangeListenerPublisher, name, frontendMetadata); + treeChangeListenerPublisher, name, + frontendMetadata); } else { store = new ShardDataTree(this, builder.getSchemaContext(), builder.getTreeType(), - builder.getDatastoreContext().getStoreRoot(), treeChangeListenerPublisher, name, frontendMetadata); + builder.getDatastoreContext().getStoreRoot(), treeChangeListenerPublisher, name, + frontendMetadata); } shardMBean = ShardMBeanFactory.getShardStatsMBean(name, datastoreContext.getDataStoreMXBeanType(), this); @@ -247,7 +257,7 @@ public class Shard extends RaftActor { self(), getContext(), shardMBean, builder.getId().getShardName()); snapshotCohort = ShardSnapshotCohort.create(getContext(), builder.getId().getMemberName(), store, LOG, - this.name); + this.name, datastoreContext); messageRetrySupport = new ShardTransactionMessageRetrySupport(this); @@ -278,7 +288,7 @@ public class Shard extends RaftActor { } @Override - public void postStop() { + public void postStop() throws Exception { LOG.info("Stopping Shard {}", persistenceId()); super.postStop(); @@ -370,6 +380,8 @@ public class Shard extends RaftActor { onMakeLeaderLocal(); } else if (RESUME_NEXT_PENDING_TRANSACTION.equals(message)) { store.resumeNextPendingTransaction(); + } else if (GetKnownClients.INSTANCE.equals(message)) { + handleGetKnownClients(); } else if (!responseMessageSlicer.handleMessage(message)) { super.handleNonRaftCommand(message); } @@ -596,6 +608,18 @@ public class Shard extends RaftActor { } } + private void handleGetKnownClients() { + final ImmutableSet clients; + if (isLeader()) { + clients = knownFrontends.values().stream() + .map(LeaderFrontendState::getIdentifier) + .collect(ImmutableSet.toImmutableSet()); + } else { + clients = frontendMetadata.getClients(); + } + sender().tell(new GetKnownClientsReply(clients), self()); + } + private boolean hasLeader() { return getLeaderId() != null; } @@ -625,7 +649,7 @@ public class Shard extends RaftActor { } protected void onDatastoreContext(final DatastoreContext context) { - datastoreContext = context; + datastoreContext = verifyNotNull(context); setTransactionCommitTimeout(); @@ -880,11 +904,11 @@ public class Shard extends RaftActor { } private void updateSchemaContext(final UpdateSchemaContext message) { - updateSchemaContext(message.getSchemaContext()); + updateSchemaContext(message.getEffectiveModelContext()); } @VisibleForTesting - void updateSchemaContext(final SchemaContext schemaContext) { + void updateSchemaContext(final @NonNull EffectiveModelContext schemaContext) { store.updateSchemaContext(schemaContext); } @@ -1062,6 +1086,16 @@ public class Shard extends RaftActor { return this.name; } + @Override + public String journalPluginId() { + // This method may be invoked from super constructor (wonderful), hence we also need to handle the case of + // the field being uninitialized because our constructor is not finished. + if (datastoreContext != null && !datastoreContext.isPersistent()) { + return NON_PERSISTENT_JOURNAL_ID; + } + return super.journalPluginId(); + } + @VisibleForTesting ShardCommitCoordinator getCommitCoordinator() { return commitCoordinator; @@ -1090,7 +1124,7 @@ public class Shard extends RaftActor { private ShardIdentifier id; private Map peerAddresses = Collections.emptyMap(); private DatastoreContext datastoreContext; - private SchemaContextProvider schemaContextProvider; + private EffectiveModelContextProvider schemaContextProvider; private DatastoreSnapshot.ShardSnapshot restoreFromSnapshot; private DataTree dataTree; @@ -1101,7 +1135,7 @@ public class Shard extends RaftActor { } protected void checkSealed() { - Preconditions.checkState(!sealed, "Builder isalready sealed - further modifications are not allowed"); + checkState(!sealed, "Builder isalready sealed - further modifications are not allowed"); } @SuppressWarnings("unchecked") @@ -1127,9 +1161,9 @@ public class Shard extends RaftActor { return self(); } - public T schemaContextProvider(final SchemaContextProvider newSchemaContextProvider) { + public T schemaContextProvider(final EffectiveModelContextProvider newSchemaContextProvider) { checkSealed(); - this.schemaContextProvider = Preconditions.checkNotNull(newSchemaContextProvider); + this.schemaContextProvider = requireNonNull(newSchemaContextProvider); return self(); } @@ -1157,8 +1191,8 @@ public class Shard extends RaftActor { return datastoreContext; } - public SchemaContext getSchemaContext() { - return Verify.verifyNotNull(schemaContextProvider.getSchemaContext()); + public EffectiveModelContext getSchemaContext() { + return Verify.verifyNotNull(schemaContextProvider.getEffectiveModelContext()); } public DatastoreSnapshot.ShardSnapshot getRestoreFromSnapshot() { @@ -1182,10 +1216,10 @@ public class Shard extends RaftActor { } protected void verify() { - Preconditions.checkNotNull(id, "id should not be null"); - Preconditions.checkNotNull(peerAddresses, "peerAddresses should not be null"); - Preconditions.checkNotNull(datastoreContext, "dataStoreContext should not be null"); - Preconditions.checkNotNull(schemaContextProvider, "schemaContextProvider should not be null"); + requireNonNull(id, "id should not be null"); + requireNonNull(peerAddresses, "peerAddresses should not be null"); + requireNonNull(datastoreContext, "dataStoreContext should not be null"); + requireNonNull(schemaContextProvider, "schemaContextProvider should not be null"); } public Props props() { @@ -1200,7 +1234,7 @@ public class Shard extends RaftActor { this(Shard.class); } - Builder(Class shardClass) { + Builder(final Class shardClass) { super(shardClass); } }