+
+ final ActorRef shardActor = shardInformation.getActor();
+ if (shardActor != null) {
+ long timeoutInMS = Math.max(shardInformation.getDatastoreContext().getShardRaftConfig()
+ .getElectionTimeOutInterval().$times(3).toMillis(), 10000);
+
+ LOG.debug("{} : Sending Shutdown to Shard actor {} with {} ms timeout", persistenceId(), shardActor,
+ timeoutInMS);
+
+ final Future<Boolean> stopFuture = Patterns.gracefulStop(shardActor,
+ FiniteDuration.apply(timeoutInMS, TimeUnit.MILLISECONDS), Shutdown.INSTANCE);
+
+ final CompositeOnComplete<Boolean> onComplete = new CompositeOnComplete<>() {
+ @Override
+ public void onComplete(final Throwable failure, final Boolean result) {
+ if (failure == null) {
+ LOG.debug("{} : Successfully shut down Shard actor {}", persistenceId(), shardActor);
+ } else {
+ LOG.warn("{}: Failed to shut down Shard actor {}", persistenceId(), shardActor, failure);
+ }
+
+ self().tell((RunnableMessage) () -> {
+ // At any rate, invalidate primaryShardInfo cache
+ primaryShardInfoCache.remove(shardName);
+
+ shardActorsStopping.remove(shardName);
+ notifyOnCompleteTasks(failure, result);
+ }, ActorRef.noSender());
+ }
+ };
+
+ shardActorsStopping.put(shardName, onComplete);
+ stopFuture.onComplete(onComplete, new Dispatchers(context().system().dispatchers())
+ .getDispatcher(Dispatchers.DispatcherType.Client));
+ }
+
+ LOG.debug("{} : Local Shard replica for shard {} has been removed", persistenceId(), shardName);