/** Compares our trees, and triggers repairs for any ranges that mismatch. */ public void run() { InetAddress local = FBUtilities.getLocalAddress(); // restore partitioners (in case we were serialized) if (ltree.partitioner() == null) ltree.partitioner(StorageService.getPartitioner()); if (rtree.partitioner() == null) rtree.partitioner(StorageService.getPartitioner()); // compare trees, and collect differences differences.addAll(MerkleTree.difference(ltree, rtree)); // choose a repair method based on the significance of the difference String format = "Endpoints " + local + " and " + remote + " %s for " + cfname + " on " + range; if (differences.isEmpty()) { logger.info(String.format(format, "are consistent")); completed(remote, cfname); return; } // non-0 difference: perform streaming repair logger.info(String.format(format, "have " + differences.size() + " range(s) out of sync")); try { performStreamingRepair(); } catch (IOException e) { throw new RuntimeException(e); } }
/** Send merkle tree request to every involved neighbor. */ public void sendTreeRequests() { requestedEndpoints.addAll(endpoints); requestedEndpoints.add(FBUtilities.getLocalAddress()); // send requests to all nodes for (InetAddress endpoint : requestedEndpoints) AntiEntropyService.instance.request(getName(), endpoint, range, tablename, cfname); }
/** * Submit differencers for running. All tree *must* have been received before this is called. */ public void submitDifferencers() { assert requestedEndpoints.size() == 0; // Right now, we only difference local host against each other. CASSANDRA-2610 will fix // that. // In the meantime ugly special casing will work good enough. MerkleTree localTree = trees.get(FBUtilities.getLocalAddress()); assert localTree != null; for (Map.Entry<InetAddress, MerkleTree> entry : trees.entrySet()) { if (entry.getKey().equals(FBUtilities.getLocalAddress())) continue; Differencer differencer = new Differencer(cfname, entry.getKey(), entry.getValue(), localTree); syncJobs.add(entry.getKey()); logger.debug("Queueing comparison " + differencer); StageManager.getStage(Stage.ANTI_ENTROPY).execute(differencer); } trees.clear(); // allows gc to do its thing }
static Message makeVerb(TreeRequest request, int version) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); SERIALIZER.serialize(request, dos, version); return new Message( FBUtilities.getLocalAddress(), StorageService.Verb.TREE_REQUEST, bos.toByteArray(), version); } catch (IOException e) { throw new RuntimeException(e); } }
/** Return all of the neighbors with whom we share data. */ static Set<InetAddress> getNeighbors(String table, Range range) { StorageService ss = StorageService.instance; Map<Range, List<InetAddress>> replicaSets = ss.getRangeToAddressMap(table); if (!replicaSets.containsKey(range)) return Collections.emptySet(); Set<InetAddress> neighbors = new HashSet<InetAddress>(replicaSets.get(range)); neighbors.remove(FBUtilities.getLocalAddress()); // Excluding all node with version <= 0.7 since they don't know how to // create a correct merkle tree (they build it over the full range) Iterator<InetAddress> iter = neighbors.iterator(); while (iter.hasNext()) { InetAddress endpoint = iter.next(); if (Gossiper.instance.getVersion(endpoint) <= MessagingService.VERSION_07) { logger.info( "Excluding " + endpoint + " from repair because it is on version 0.7 or sooner. You should consider updating this node before running repair again."); iter.remove(); } } return neighbors; }
/** * Called after the validation lifecycle to respond with the now valid tree. Runs in * Stage.ANTIENTROPY. * * @return A meaningless object. */ public void run() { // respond to the request that triggered this validation AntiEntropyService.instance.respond(this, FBUtilities.getLocalAddress()); }