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%2FDistributedDataStore.java;h=8051f7d49bab43e48ad1a82215d35b49a55281e5;hp=a136cc6f75392e9d95426fe786d10e9381a1a6cd;hb=db0dbb7e7976efc860012dfdba61d5416d45900c;hpb=e40d6fff44efc7eac7f5e00cb9db4f08f33a8df0 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStore.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStore.java index a136cc6f75..8051f7d49b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStore.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStore.java @@ -8,9 +8,11 @@ package org.opendaylight.controller.cluster.datastore; +import akka.actor.ActorRef; import akka.actor.ActorSystem; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; +import com.google.common.util.concurrent.Uninterruptibles; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import org.opendaylight.controller.cluster.datastore.identifiers.ShardManagerIdentifier; @@ -77,10 +79,8 @@ public class DistributedDataStore implements DOMStore, SchemaContextListener, String shardDispatcher = new Dispatchers(actorSystem.dispatchers()).getDispatcherPath(Dispatchers.DispatcherType.Shard); - actorContext = new ActorContext(actorSystem, actorSystem.actorOf( - ShardManager.props(cluster, configuration, datastoreContext, waitTillReadyCountDownLatch) - .withDispatcher(shardDispatcher).withMailbox(ActorContext.MAILBOX), shardManagerId ), - cluster, configuration, datastoreContext); + actorContext = new ActorContext(actorSystem, createShardManager(actorSystem, cluster, configuration, + datastoreContext, shardDispatcher, shardManagerId ), cluster, configuration, datastoreContext); this.waitTillReadyTimeInMillis = actorContext.getDatastoreContext().getShardLeaderElectionTimeout().duration().toMillis() * READY_WAIT_FACTOR; @@ -186,11 +186,12 @@ public class DistributedDataStore implements DOMStore, SchemaContextListener, try { closeable.close(); } catch (Exception e) { - LOG.debug("Error closing insance", e); + LOG.debug("Error closing instance", e); } } actorContext.shutdown(); + DistributedDataStoreFactory.destroyInstance(this); } @VisibleForTesting @@ -212,6 +213,25 @@ public class DistributedDataStore implements DOMStore, SchemaContextListener, } } + private ActorRef createShardManager(ActorSystem actorSystem, ClusterWrapper cluster, Configuration configuration, + DatastoreContext datastoreContext, String shardDispatcher, String shardManagerId){ + Exception lastException = null; + + for(int i=0;i<100;i++) { + try { + return actorSystem.actorOf( + ShardManager.props(cluster, configuration, datastoreContext, waitTillReadyCountDownLatch) + .withDispatcher(shardDispatcher).withMailbox(ActorContext.MAILBOX), shardManagerId); + } catch (Exception e){ + lastException = e; + Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); + LOG.debug(String.format("Could not create actor %s because of %s - waiting for sometime before retrying (retry count = %d)", shardManagerId, e.getMessage(), i)); + } + } + + throw new IllegalStateException("Failed to create Shard Manager", lastException); + } + @VisibleForTesting public CountDownLatch getWaitTillReadyCountDownLatch() { return waitTillReadyCountDownLatch;