How many entries does the currentShardAllocations Map
(actorRefIndexedSeqMap in your code) have when allocateShard is invoked for
shard "1" and shard "2"?

It might be that not all shard regions have registered themselves to the
coordinator yet, i.e. you have only one entry in currentShardAllocations.

Normally those would have been rebalanced later, but you disable that part.

Regards,
Patrik


On Mon, Jun 9, 2014 at 7:55 AM, Luis Medina <[email protected]> wrote:

> I'm trying to make a ShardAllocationStrategy that allocates new shards to
> ShardRegion's such that the difference between the most and the least
> number of allocated shards is 1 and so that it doesn't do any re-balancing.
> This is what I came up with:
>
> public class NonRebalancingLeastShardAllocationStrategy implements
> ShardCoordinator.ShardAllocationStrategy {
>     @Override
>     public ActorRef allocateShard(ActorRef actorRef, String s,
> Map<ActorRef, IndexedSeq<String>> actorRefIndexedSeqMap) {
>         return new ShardCoordinator.LeastShardAllocationStrategy(1,
> 10).allocateShard(actorRef, s, actorRefIndexedSeqMap);
>     }
>
>     @Override
>     public Set<String> rebalance(scala.collection.immutable.Map<ActorRef,
> scala.collection.immutable.IndexedSeq<String>> actorRefIndexedSeqMap,
> Set<String> stringSet) {
>         return new HashSet<>();
>     }
> }
>
> For the non-rebalancing part, returning an empty HashSet works fine. It's
> the allocateShard method that is giving me issues. For example, when I to
> instantiate just 2 instances of an entry in my cluster such that each
> instance ends up on a different node, I pass the following 2 messages to my
> shard region:
>
> ActorRef region = ClusterSharding.get(system).shardRegion("Region");
> region.tell(new ShardMessage(new Object(), "1", "1"), null);
> region.tell(new ShardMessage(new Object(), "2", "2"), null);
>
> In this case my MessageExtractor will use the last 2 arguments of a 
> ShardMessage
> as the entryId and shardId respectively. In the example above, if my
> cluster has 2 nodes, one shard of my entry should get created in one of the
> nodes and the second shard should get created in the other node. However,
> I've found that there are cases where when I start up my cluster (I have
> set the min-nr-of-members = 2 in my configuration), both of the shards
> will end up on the same node.
>
> This leads to me wonder if there would be any cases where such a
> ShardAllocationStrategy as the one I defined above would cause the
> cluster to not evenly distribute shards. From my testing this seems to
> happen at random. Does setting the allocateShard to use the
> LeastShardAllocationStrategy's allocateShard method with the parameters I
> defined above guaranteed to always distribute my shards evenly? Does it
> work on a sort of "best effort" where shard distribution is not always
> guaranteed to happen evenly? Am I maybe starting up the 2 nodes in my
> cluster too fast (I figure this one is probably a long shot)?
>
> --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ:
> http://doc.akka.io/docs/akka/current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Patrik Nordwall
Typesafe <http://typesafe.com/> -  Reactive apps on the JVM
Twitter: @patriknw

<http://www.scaladays.org/>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to