/** * This is the same or a subset of {@link #determineMergeParticipants(java.util.Map)} and contains only members * which are currently sub-partition coordinators. * @param map * @return */ public static Collection<Address> determineMergeCoords(Map<Address,View> map) { Set<Address> retval=new HashSet<>(); if(map != null) { for(View view : map.values()) { Address coord=view.getCreator(); if(coord != null) retval.add(coord); } } return retval; }
/** * Needs to return a map of all subview coordinators and their views (as a collection of members). The merge policy * is defined in https://issues.jboss.org/browse/JGRP-1910 */ protected static Map<Address,Collection<Address>> determineMergeCoords(Map<Address,View> views) { Map<Address,Collection<Address>> retval=new HashMap<>(); for(View view: views.values()) { Address coord=view.getCreator(); Collection<Address> members=retval.computeIfAbsent(coord, k -> new ArrayList<>()); for(Address mbr: view.getMembersRaw()) if(!members.contains(mbr)) members.add(mbr); } // For the merge participants which are not coordinator, we simply add them, and the associated // membership list consists only of themselves Collection<Address> merge_participants=Util.determineMergeParticipants(views); merge_participants.removeAll(retval.keySet()); merge_participants.stream().filter(merge_participant -> !retval.containsKey(merge_participant)) .forEach(merge_participant -> retval.put(merge_participant, Collections.singletonList(merge_participant))); return retval; }
/** * Determines the members which take part in a merge. The resulting list consists of all merge coordinators * plus members outside a merge partition, e.g. for views A={B,A,C}, B={B,C} and C={B,C}, the merge coordinator * is B, but the merge participants are B and A. * @param map * @return */ public static Collection<Address> determineMergeParticipants(Map<Address,View> map) { Set<Address> coords=new HashSet<>(); Set<Address> all_addrs=new HashSet<>(); if(map == null) return Collections.emptyList(); for(View view : map.values()) all_addrs.addAll(view.getMembers()); for(View view : map.values()) { Address coord=view.getCreator(); if(coord != null) coords.add(coord); } for(Address coord : coords) { View view=map.get(coord); Collection<Address> mbrs=view != null? view.getMembers() : null; if(mbrs != null) all_addrs.removeAll(mbrs); } coords.addAll(all_addrs); return coords; }
private boolean onViewChange(View view) { boolean coordinatorLeft = false; View oldView; synchronized (sharedLock) { suspected.retainAll(view.getMembers()); oldView = currentView; currentView = view; coordinatorLeft = !oldView.getMembers().isEmpty() && !view.getMembers().isEmpty() && !view.containsMember(oldView.getCreator()); } if (log.isDebugEnabled()) log.debug(localAddress + ": installing view " + view); return coordinatorLeft; }
public void writeTo(DataOutput out) throws Exception { super.writeTo(out); // write subgroups int len=subgroups != null? subgroups.length : 0; out.writeShort(len); if(len == 0) return; for(View v: subgroups) { int index=get(v.getCreator()); out.writeShort(index); // if we don't find the member, write the addres (https://issues.jboss.org/browse/JGRP-1707) if(index < 0) Util.writeAddress(v.getCreator(), out); out.writeLong(v.getViewId().getId()); int num_mbrs=v.size(); out.writeShort(num_mbrs); for(Address mbr: v) { index=get(mbr); out.writeShort(index); if(index < 0) Util.writeAddress(mbr, out); } } }
View v=it.next(); logical_time=Math.max(logical_time, v.getViewId().getId()); Address creator=v.getCreator(); if(creator != null && !merged_mbrs.contains(creator)) it.remove();
public int serializedSize() { int retval=super.serializedSize(); retval+=Global.SHORT_SIZE; // for size of subgroups vector if(subgroups == null) return retval; for(View v: subgroups) { retval+=Global.SHORT_SIZE + Global.LONG_SIZE // creator and ID (ViewId) + Global.SHORT_SIZE; // number of members in the subview Address creator=v.getCreator(); if(get(creator) < 0) retval+=Util.size(creator); retval+=v.size() * Global.SHORT_SIZE; // a short (index) for each member for(Address sub_mbr: v) { int index=get(sub_mbr); if(index < 0) retval+=Util.size(sub_mbr); } } return retval; }
protected void handleView(View new_view, View old_view, boolean coord_changed) { if(is_coord) { if(coord_changed) { if(remove_all_data_on_view_change) removeAll(cluster_name); else if(remove_old_coords_on_view_change) { Address old_coord=old_view != null? old_view.getCreator() : null; if(old_coord != null) remove(cluster_name, old_coord); } } Address[] left=View.diff(old_view, new_view)[1]; if(coord_changed || update_store_on_view_change || left.length > 0) { writeAll(left); if(remove_all_data_on_view_change || remove_old_coords_on_view_change) startInfoWriter(); } } else if(coord_changed) // I'm no longer the coordinator remove(cluster_name, local_addr); }
if(new_view.size() == 0 && gms.local_addr != null && gms.local_addr.equals(new_view.getCreator())) { if(self_leaving)
protected boolean installViewIfValidJoinRsp(final Promise<JoinRsp> join_promise, boolean block_for_rsp) { boolean success=false; JoinRsp rsp=null; try { if(join_promise.hasResult()) rsp=join_promise.getResult(1, true); else if(block_for_rsp) rsp=join_promise.getResult(gms.join_timeout, true); return success=rsp != null && isJoinResponseValid(rsp) && installView(rsp.getView(), rsp.getDigest()); } finally { if(success) gms.sendViewAck(rsp.getView().getCreator()); } }
break; case Event.GET_VIEW_FROM_COORD: Address coord=view != null? view.getCreator() : null; if(coord != null) { ViewId view_id=view != null? view.getViewId() : null;
private boolean isCoordinator(Address newAddress, View newView) { boolean coord = false; if(newAddress != null && newAddress.toString().equals(newView.getCreator().toString())) { coord = true; } return coord; }
/** * This is the same or a subset of {@link #determineMergeParticipants(java.util.Map)} and contains only members * which are currently sub-partition coordinators. * @param map * @return */ public static Collection<Address> determineMergeCoords(Map<Address,View> map) { Set<Address> retval=new HashSet<>(); if(map != null) { for(View view : map.values()) { Address coord=view.getCreator(); if(coord != null) retval.add(coord); } } return retval; }
/** * Needs to return a map of all subview coordinators and their views (as a collection of members). The merge policy * is defined in https://issues.jboss.org/browse/JGRP-1910 */ protected static Map<Address,Collection<Address>> determineMergeCoords(Map<Address,View> views) { Map<Address,Collection<Address>> retval=new HashMap<>(); for(View view: views.values()) { Address coord=view.getCreator(); Collection<Address> members=retval.computeIfAbsent(coord, k -> new ArrayList<>()); for(Address mbr: view.getMembersRaw()) if(!members.contains(mbr)) members.add(mbr); } // For the merge participants which are not coordinator, we simply add them, and the associated // membership list consists only of themselves Collection<Address> merge_participants=Util.determineMergeParticipants(views); merge_participants.removeAll(retval.keySet()); merge_participants.stream().filter(merge_participant -> !retval.containsKey(merge_participant)) .forEach(merge_participant -> retval.put(merge_participant, Collections.singletonList(merge_participant))); return retval; }
private MetaValue createViewMetaValue(View view) { Map<String, MetaValue> viewMap = new HashMap<String, MetaValue>(); viewMap.put("id", SimpleValueSupport.wrap(view.getVid().getId())); viewMap.put("creator", SimpleValueSupport.wrap(view.getCreator().toString())); Vector<Address> members = view.getMembers(); MetaValue[] memberValues = new MetaValue[members.size()]; for (int i = 0; i < memberValues.length; i++) { memberValues[i] = SimpleValueSupport.wrap(members.get(i).toString()); } viewMap.put("members", new CollectionValueSupport(MEMBERS_TYPE, memberValues)); if (memberValues.length > 0) { viewMap.put("coordinator", memberValues[0]); } MetaValue viewValue = new MapCompositeValueSupport(viewMap, VIEW_TYPE); return viewValue; }
private boolean onViewChange(View view) { boolean coordinatorLeft = false; View oldView; synchronized (sharedLock) { suspected.retainAll(view.getMembers()); oldView = currentView; currentView = view; coordinatorLeft = !oldView.getMembers().isEmpty() && !view.getMembers().isEmpty() && !view.containsMember(oldView.getCreator()); } if (log.isDebugEnabled()) log.debug(localAddress + ": installing view " + view); return coordinatorLeft; }
public void writeTo(DataOutput out) throws Exception { super.writeTo(out); // write subgroups int len=subgroups != null? subgroups.length : 0; out.writeShort(len); if(len == 0) return; for(View v: subgroups) { int index=get(v.getCreator()); out.writeShort(index); // if we don't find the member, write the addres (https://issues.jboss.org/browse/JGRP-1707) if(index < 0) Util.writeAddress(v.getCreator(), out); out.writeLong(v.getViewId().getId()); int num_mbrs=v.size(); out.writeShort(num_mbrs); for(Address mbr: v) { index=get(mbr); out.writeShort(index); if(index < 0) Util.writeAddress(mbr, out); } } }
protected void handleView(View new_view, View old_view, boolean coord_changed) { if(is_coord) { if(coord_changed) { if(remove_all_data_on_view_change) removeAll(cluster_name); else if(remove_old_coords_on_view_change) { Address old_coord=old_view != null? old_view.getCreator() : null; if(old_coord != null) remove(cluster_name, old_coord); } } Address[] left=View.diff(old_view, new_view)[1]; if(coord_changed || update_store_on_view_change || left.length > 0) { writeAll(left); if(remove_all_data_on_view_change || remove_old_coords_on_view_change) startInfoWriter(); } } else if(coord_changed) // I'm no longer the coordinator remove(cluster_name, local_addr); }
public int serializedSize() { int retval=super.serializedSize(); retval+=Global.SHORT_SIZE; // for size of subgroups vector if(subgroups == null) return retval; for(View v: subgroups) { retval+=Global.SHORT_SIZE + Global.LONG_SIZE // creator and ID (ViewId) + Global.SHORT_SIZE; // number of members in the subview Address creator=v.getCreator(); if(get(creator) < 0) retval+=Util.size(creator); retval+=v.size() * Global.SHORT_SIZE; // a short (index) for each member for(Address sub_mbr: v) { int index=get(sub_mbr); if(index < 0) retval+=Util.size(sub_mbr); } } return retval; }
protected boolean installViewIfValidJoinRsp(final Promise<JoinRsp> join_promise, boolean block_for_rsp) { boolean success=false; JoinRsp rsp=null; try { if(join_promise.hasResult()) rsp=join_promise.getResult(1, true); else if(block_for_rsp) rsp=join_promise.getResult(gms.join_timeout, true); return success=rsp != null && isJoinResponseValid(rsp) && installView(rsp.getView(), rsp.getDigest()); } finally { if(success) gms.sendViewAck(rsp.getView().getCreator()); } }