protected void write(List<PingData> list, String clustername) { File dir=new File(root_dir, clustername); if(!dir.exists()) dir.mkdir(); String filename=addressToFilename(local_addr); File destination=new File(dir, filename); try { write(list, new FileOutputStream(destination)); } catch(Exception ioe) { log.error(Util.getMessage("AttemptToWriteDataFailedAt") + clustername + " : " + destination.getName(), ioe); deleteFile(destination); } }
PhysicalAddress physical_addr=(PhysicalAddress)down(new Event(Event.GET_PHYSICAL_ADDRESS,local_addr)); PingData coord_data=new PingData(local_addr, true, NameCache.get(local_addr), physical_addr).coord(is_coord); write(Collections.singletonList(coord_data), cluster_name); return;
protected void writeAll(Address[] excluded_mbrs) { Map<Address,PhysicalAddress> cache_contents= (Map<Address,PhysicalAddress>)down_prot.down(new Event(Event.GET_LOGICAL_PHYSICAL_MAPPINGS, false)); if(excluded_mbrs != null) for(Address excluded_mbr : excluded_mbrs) cache_contents.remove(excluded_mbr); List<PingData> list=new ArrayList<>(cache_contents.size()); for(Map.Entry<Address,PhysicalAddress> entry: cache_contents.entrySet()) { Address addr=entry.getKey(); if(update_store_on_view_change && (view != null && !view.containsMember(addr))) continue; PhysicalAddress phys_addr=entry.getValue(); PingData data=new PingData(addr, true, NameCache.get(addr), phys_addr).coord(addr.equals(local_addr)); list.add(data); } write(list, cluster_name); if(log.isTraceEnabled()) log.trace("%s: wrote to backend store: %s", local_addr, list.stream().map(PingData::getAddress).collect(Collectors.toList())); }
protected void write(List<PingData> list, String clustername) { File dir=new File(root_dir, clustername); if(!dir.exists()) dir.mkdir(); String filename=addressToFilename(local_addr); File destination=new File(dir, filename); try { write(list, new FileOutputStream(destination)); } catch(Exception ioe) { log.error(Util.getMessage("AttemptToWriteDataFailedAt") + clustername + " : " + destination.getName(), ioe); deleteFile(destination); } }
protected void writeAll(Address[] excluded_mbrs) { Map<Address,PhysicalAddress> cache_contents= (Map<Address,PhysicalAddress>)down_prot.down(new Event(Event.GET_LOGICAL_PHYSICAL_MAPPINGS, false)); if(excluded_mbrs != null) for(Address excluded_mbr : excluded_mbrs) cache_contents.remove(excluded_mbr); List<PingData> list=new ArrayList<>(cache_contents.size()); for(Map.Entry<Address,PhysicalAddress> entry: cache_contents.entrySet()) { Address addr=entry.getKey(); if(update_store_on_view_change && (view != null && !view.containsMember(addr))) continue; PhysicalAddress phys_addr=entry.getValue(); PingData data=new PingData(addr, true, NameCache.get(addr), phys_addr).coord(addr.equals(local_addr)); list.add(data); } write(list, cluster_name); if(log.isTraceEnabled()) log.trace("wrote to backend store: %s", list.stream().map(PingData::getAddress).collect(Collectors.toList())); }
public void findMembers(final List<Address> members, final boolean initial_discovery, Responses responses) { try { readAll(members, cluster_name, responses); if(responses.isEmpty()) { PhysicalAddress physical_addr=(PhysicalAddress)down(new Event(Event.GET_PHYSICAL_ADDRESS,local_addr)); PingData coord_data=new PingData(local_addr, true, NameCache.get(local_addr), physical_addr).coord(is_coord); write(Collections.singletonList(coord_data), cluster_name); return; } PhysicalAddress phys_addr=(PhysicalAddress)down_prot.down(new Event(Event.GET_PHYSICAL_ADDRESS, local_addr)); PingData data=responses.findResponseFrom(local_addr); // the logical addr *and* IP address:port have to match if(data != null && data.getPhysicalAddr().equals(phys_addr)) { if(data.isCoord() && initial_discovery) responses.clear(); else ; // use case #1 if we have predefined files: most members join but are not coord } else { sendDiscoveryResponse(local_addr, phys_addr, NameCache.get(local_addr), null, false); } } finally { responses.done(); } }