public InternalDistributedMember getCoordinator() { synchronized (members) { for (InternalDistributedMember addr : members) { if (addr.getNetMember().preferredForCoordinator()) { return addr; } } if (members.size() > 0) { return members.get(0); } } return null; }
void checkAddressesForUUIDs(InternalDistributedMember[] addresses) { for (int i=0; i<addresses.length; i++) { InternalDistributedMember m = addresses[i]; if(m != null) { GMSMember id = (GMSMember)m.getNetMember(); if (!id.hasUUID()) { latestViewLock.readLock().lock(); try { addresses[i] = latestView.getCanonicalID(addresses[i]); } finally { latestViewLock.readLock().unlock(); } } } } }
/** * @param daddress the address of the distributed system */ public void setLocalAddress(InternalDistributedMember daddress) { Address jgroupsAddress = ((JGroupMember)daddress.getNetMember()).getAddress(); setLocalAddress(jgroupsAddress); }
/** check to see if the given address is next in line to be coordinator */ public boolean shouldBeCoordinator(InternalDistributedMember who) { Iterator<InternalDistributedMember> it = this.members.iterator(); InternalDistributedMember firstNonPreferred = null; while (it.hasNext()) { InternalDistributedMember mbr = it.next(); if (mbr.getNetMember().preferredForCoordinator()) { return mbr.equals(who); } else if (firstNonPreferred == null) { firstNonPreferred = mbr; } } return (firstNonPreferred == null || firstNonPreferred.equals(who)); }
public void waitForChannelState(DistributedMember otherMember, HashMap channelState) throws InterruptedException { if (Thread.interrupted()) throw new InterruptedException(); DirectChannel dc = directChannel; Long mcastState = (Long)channelState.remove("JGroups.MCast"); Stub stub; synchronized (latestViewLock) { stub = memberToStubMap.get(otherMember); } if (dc != null && stub != null) { dc.waitForChannelState(stub, channelState); } if (mcastState != null) { InternalDistributedMember idm = (InternalDistributedMember)otherMember; JGroupMember jgm = (JGroupMember)idm.getNetMember(); Address other = jgm.getAddress(); channel.waitForMulticastState(other, mcastState.longValue()); } }
/** * Returns the coordinator of this view, rejecting any in the * given collection of IDs */ public InternalDistributedMember getCoordinator(Collection<InternalDistributedMember> rejections) { if (rejections == null) { return getCoordinator(); } synchronized (members) { for (InternalDistributedMember addr : members) { if (addr.getNetMember().preferredForCoordinator() && !rejections.contains(addr)) { return addr; } } for (InternalDistributedMember addr: members) { if (!rejections.contains(addr)) { return addr; } } } return null; }
private int getWeight(Collection<InternalDistributedMember> idms, InternalDistributedMember leader) { int weight = 0; for (InternalDistributedMember mbr : idms) { int thisWeight = mbr.getNetMember().getMemberWeight(); if (mbr.getVmKind() == 10 /* NORMAL_DM_KIND */) { thisWeight += 10; if (leader != null && mbr.equals(leader)) { thisWeight += 5; } } else if (mbr.getNetMember().preferredForCoordinator()) { thisWeight += 3; } weight += thisWeight; } return weight; }
public InternalDistributedMember withOrdinal(short ordinalToUse ) { InternalDistributedMember copy = new InternalDistributedMember(); copy.vmKind = this.vmKind; copy.ipAddr = this.getNetMember(); copy.hostName = this.hostName; copy.isPartial = this.isPartial; copy.dcPort = this.dcPort; copy.vmPid = this.vmPid; copy.groups = this.groups; copy.name = this.name; copy.uniqueTag = this.uniqueTag; copy.vmViewId = this.vmViewId; copy.durableClientAttributes = this.durableClientAttributes; copy.version = ordinalToUse; copy.versionObj = Version.fromOrdinalOrCurrent(copy.version); copy.cachedToString = null; copy.essentialData = null; return copy; }
public boolean verifyMember(DistributedMember mbr, String reason) { if (mbr != null && memberExists((InternalDistributedMember)mbr)) { Address jgmbr = ((JGroupMember)((InternalDistributedMember)mbr) .getNetMember()).getAddress(); return this.fdSockProtocol.checkSuspect(jgmbr, reason); } return false; }
public void suspectMember(Stub mbr, String reason) { InternalDistributedMember idm = getMemberForStub(mbr, false); if (idm != null) { Address jgmbr = ((JGroupMember)idm.getNetMember()).getAddress(); this.fdSockProtocol.suspect(jgmbr, false, reason); } }
public void toData(DataOutput out) throws IOException { toDataPre_GFE_9_0_0_0(out); if (this.version >= Version.GFE_90.ordinal()) { getNetMember().writeAdditionalData(out); } }
public void suspectMember(DistributedMember mbr, String reason) { if (mbr != null) { Address jgmbr = ((JGroupMember)((InternalDistributedMember)mbr) .getNetMember()).getAddress(); this.fdSockProtocol.suspect(jgmbr, false, reason); } else { if (this.logger.fineEnabled()) { this.logger.fine("attempt to suspect member with null ID detected. This usually means that the target has left membership during startup."); } } }
public void initialize() { receivedAcks = new ConcurrentHashSet<InternalDistributedMember>(); pingPonger = new GMSPingPonger(); // UUID logicalAddress = (UUID) channel.getAddress(); // IpAddress ipaddr = (IpAddress) channel.down(new Event(Event.GET_PHYSICAL_ADDRESS)); // // myAddress = new JGAddress(logicalAddress, ipaddr); myAddress = (JGAddress)channel.down(new Event(Event.GET_LOCAL_ADDRESS)); addressConversionMap = new ConcurrentHashMap<SocketAddress, InternalDistributedMember>(this.lastView.size()); List<InternalDistributedMember> members = this.lastView.getMembers(); for (InternalDistributedMember addr : members) { SocketAddress sockaddr = new InetSocketAddress(addr.getNetMember().getInetAddress(), addr.getPort()); addressConversionMap.put(sockaddr, addr); } isDebugEnabled = logger.isDebugEnabled(); resume(); }
public JGAddress(InternalDistributedMember idm) { super(); GMSMember mbr = (GMSMember)idm.getNetMember(); this.mostSigBits = mbr.getUuidMSBs(); this.leastSigBits = mbr.getUuidLSBs(); this.ip_addr = idm.getInetAddress(); this.port = idm.getPort(); this.vmViewId = idm.getVmViewId(); }
/** * returns the member ID for the given GMSMember object */ private InternalDistributedMember getMemberFromView(GMSMember jgId, short version) { NetView v = services.getJoinLeave().getView(); if (v != null) { for (InternalDistributedMember m: v.getMembers()) { if (((GMSMember)m.getNetMember()).equals(jgId)) { return m; } } } return new InternalDistributedMember(jgId); }
/** * returns the weight of the members in this membership view */ public int memberWeight() { int result = 0; InternalDistributedMember lead = getLeadMember(); for (InternalDistributedMember mbr : this.members) { result += mbr.getNetMember().getMemberWeight(); switch (mbr.getVmKind()) { case DistributionManager.NORMAL_DM_TYPE: result += 10; if (lead != null && mbr.equals(lead)) { result += 5; } break; case DistributionManager.LOCATOR_DM_TYPE: result += 3; break; case DistributionManager.ADMIN_ONLY_DM_TYPE: break; default: throw new IllegalStateException("Unknown member type: " + mbr.getVmKind()); } } return result; }
/** * returns the weight of crashed members in this membership view * with respect to the given previous view */ public int getCrashedMemberWeight(NetView oldView) { int result = 0; InternalDistributedMember lead = oldView.getLeadMember(); for (InternalDistributedMember mbr : this.crashedMembers) { if (!oldView.contains(mbr)) { continue; } result += mbr.getNetMember().getMemberWeight(); switch (mbr.getVmKind()) { case DistributionManager.NORMAL_DM_TYPE: result += 10; if (lead != null && mbr.equals(lead)) { result += 5; } break; case DistributionManager.LOCATOR_DM_TYPE: result += 3; break; case DistributionManager.ADMIN_ONLY_DM_TYPE: break; default: throw new IllegalStateException("Unknown member type: " + mbr.getVmKind()); } } return result; }
/** * Some settings are gleaned from locator responses and set into the local * configuration */ private void inheritSettingsFromLocator(InetSocketAddress addr, FindCoordinatorResponse response) { boolean enabled = response.isNetworkPartitionDetectionEnabled(); if (!enabled && services.getConfig().isNetworkPartitionDetectionEnabled()) { throw new GemFireConfigException("locator at "+addr +" does not have network-partition-detection enabled but my configuration has it enabled"); } GMSMember mbr = (GMSMember) this.localAddress.getNetMember(); mbr.setSplitBrainEnabled(enabled); services.getConfig().setNetworkPartitionDetectionEnabled(enabled); services.getConfig().getDistributionConfig().setEnableNetworkPartitionDetection(enabled); if (response.isUsePreferredCoordinators()) { this.quorumRequired = true; logger.debug("The locator indicates that all locators should be preferred as coordinators"); if (services.getLocator() != null || Locator.hasLocator() || !services.getConfig().getDistributionConfig().getStartLocator().isEmpty() || localAddress.getVmKind() == DistributionManager.LOCATOR_DM_TYPE) { ((GMSMember) localAddress.getNetMember()).setPreferredForCoordinator(true); } } else { ((GMSMember) localAddress.getNetMember()).setPreferredForCoordinator(true); } }
public void messageReceived(DistributionMessage msg) { // bug 36851 - notify failure detection that we've had contact from a member IpAddress addr = ((JGroupMember)msg.getSender().getNetMember()).getAddress(); if (fdProtocol != null) { fdProtocol.messageReceivedFrom(addr); } if (verifySuspectProtocol != null) { if (addr.getBirthViewId() < 0) { if (logger.fineEnabled()) { // if there is no view ID then this is not a valid address logger.fine("Membership: invalid address found in sender of " + msg); } } else { verifySuspectProtocol.unsuspect(addr); } } handleOrDeferMessage(msg); }
@Override public void run2() { InternalDistributedSystem system = (InternalDistributedSystem) InternalDistributedSystem.getAnyInstance(); JGroupMembershipManager jgmm = MembershipManagerHelper.getMembershipManager(system); JChannel jchannel = MembershipManagerHelper.getJChannel(system); NetMember locMem = system.getDistributedMember().getNetMember(); // Check if protocol statck has GemfireTimeSync protocol in it in // correct position. if (jchannel != null && jchannel.isConnected()) { ProtocolStack pstack = jchannel.getProtocolStack(); GemFireTimeSync gts = (GemFireTimeSync) pstack.findProtocol("GemFireTimeSync"); NetView nw = jgmm.getView(); IpAddress memAdd = null; for (Object member : nw) { InternalDistributedMember iMem = (InternalDistributedMember) member; NetMember netMem = iMem.getNetMember(); if (!netMem.equals(locMem)) { memAdd = ((JGroupMember)netMem).getAddress(); } } Message offsetMessage = new Message(); offsetMessage.setDest(memAdd); offsetMessage.isHighPriority = true; offsetMessage.putHeader("GemFireTimeSync", new GFTimeSyncHeader(0, /* GFTimeSyncHeader.OP_TIME_OFFSET */(byte) 2, (joinTimeOffset - 19))); gts.passDown(new Event(Event.MSG, offsetMessage)); getLogWriter().info("Sent a GemfireTimeSync message to apply lower offset: " + (joinTimeOffset - 19) + "ms"); } } });