@Override public void run(ImmutableMap<Integer, Long> cache) { // Every MPI change means a new single MPI. Just do the right thing here int pid = MpInitiator.MP_INIT_PID; // Can be zero-length at startup if (cache.size() > 0) { sendLeaderChangeNotify(cache.get(pid), pid); } }
@Override public void run(ImmutableMap<Integer, Long> cache) { // We know there's a 1:1 mapping between partitions and HSIds in this map. // let's flip it Map<Long, Integer> hsIdToPart = new HashMap<Long, Integer>(); for (Entry<Integer, Long> e : cache.entrySet()) { hsIdToPart.put(e.getValue(), e.getKey()); } Set<Long> newMasters = new HashSet<Long>(); newMasters.addAll(cache.values()); // we want to see items which are present in the new map but not in the old, // these are newly promoted SPIs newMasters.removeAll(m_currentSPMasters); // send the messages indicating promotion from here for each new master for (long newMaster : newMasters) { sendLeaderChangeNotify(newMaster, hsIdToPart.get(newMaster)); } m_currentSPMasters.clear(); m_currentSPMasters.addAll(cache.values()); }