1 package org.opendaylight.controller.cluster.datastore;
3 import akka.actor.Address;
4 import akka.actor.UntypedActor;
5 import akka.event.Logging;
6 import akka.event.LoggingAdapter;
7 import org.opendaylight.controller.cluster.datastore.messages.FindPrimary;
8 import org.opendaylight.controller.cluster.datastore.messages.PrimaryNotFound;
10 import java.util.HashMap;
11 import java.util.List;
15 * The ShardManager has the following jobs,
17 * - Create all the local shard replicas that belong on this cluster member
18 * - Find the primary replica for any given shard
19 * - Engage in shard replica elections which decide which replica should be the primary
21 * Creation of Shard replicas
22 * ==========================
23 * When the ShardManager is constructed it reads the cluster configuration to find out which shard replicas
24 * belong on this member. It finds out the name of the current cluster member from the Akka Clustering Service.
28 * The Shard Manager uses multiple cues to initiate election.
29 * - When a member of the cluster dies
30 * - When a local shard replica dies
31 * - When a local shard replica comes alive
33 public class ShardManager extends UntypedActor {
35 // Stores a mapping between a shard name and the address of the current primary
36 private final Map<String, Address> shardNameToPrimaryAddress = new HashMap<>();
38 // Stores a mapping between a member name and the address of the member
39 private final Map<String, Address> memberNameToAddress = new HashMap<>();
41 // Stores a mapping between the shard name and all the members on which a replica of that shard are available
42 private final Map<String, List<String>> shardNameToMembers = new HashMap<>();
44 LoggingAdapter log = Logging.getLogger(getContext().system(), this);
47 public void onReceive(Object message) throws Exception {
48 if(message instanceof FindPrimary ){
49 FindPrimary msg = ((FindPrimary) message);
50 getSender().tell(new PrimaryNotFound(msg.getShardName()), getSelf());