Package org.apache.cassandra.utils

Examples of org.apache.cassandra.utils.MerkleTree$TreeRange


        oout.writeObject(mt);
        oout.close();

        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
        ObjectInputStream oin = new ObjectInputStream(bin);
        MerkleTree restored = (MerkleTree)oin.readObject();
   
        // restore partitioner after serialization
        restored.partitioner(partitioner);

        assertHashEquals(initialhash, restored.hash(full));
    }
View Full Code Here


    public void testDifference()
    {
        Range full = new Range(tok(0), tok(0));
        int maxsize = 16;
        mt.maxsize(maxsize);
        MerkleTree mt2 = new MerkleTree(partitioner, RECOMMENDED_DEPTH, maxsize);
        mt.init();
        mt2.init();

        TreeRange leftmost = null;
        TreeRange middle = null;
        TreeRange rightmost = null;

        // compact the leftmost, and split the rightmost
        Iterator<TreeRange> ranges = mt.invalids(full);
        leftmost = ranges.next();
        rightmost = null;
        while (ranges.hasNext())
            rightmost = ranges.next();
        mt.compact(leftmost.right);
        leftmost = mt.get(leftmost.right); // leftmost is now a larger range
        mt.split(rightmost.right);
       
        // set the hash for the left neighbor of rightmost
        middle = mt.get(rightmost.left);
        middle.hash("arbitrary!".getBytes());
        byte depth = middle.depth;

        // add dummy hashes to the rest of both trees
        for (TreeRange range : mt.invalids(full))
            range.addAll(new HIterator(range.right));
        for (TreeRange range : mt2.invalids(full))
            range.addAll(new HIterator(range.right));
       
        // trees should disagree for leftmost, (middle.left, rightmost.right]
        List<TreeRange> diffs = MerkleTree.difference(mt, mt2);
        assertEquals(diffs + " contains wrong number of differences:", 2, diffs.size());
View Full Code Here

    {
        this(desc,
             initiator,
             // TODO: memory usage (maxsize) should either be tunable per
             // CF, globally, or as shared for all CFs in a cluster
             new MerkleTree(DatabaseDescriptor.getPartitioner(), desc.range, MerkleTree.RECOMMENDED_DEPTH, (int)Math.pow(2, 15)),
             gcBefore);
    }
View Full Code Here

        // generate a tree
        Validator validator = new Validator(request);
        validator.prepare(store);
        validator.completeTree();
        MerkleTree ltree = validator.tree;

        // and a clone
        validator = new Validator(request);
        validator.prepare(store);
        validator.completeTree();
        MerkleTree rtree = validator.tree;

        // change a range in one of the trees
        Token ltoken = StorageService.getPartitioner().midpoint(local_range.left, local_range.right);
        ltree.invalidate(ltoken);
        MerkleTree.TreeRange changed = ltree.get(ltoken);
View Full Code Here

    private void testTreeResponseWrite() throws IOException
    {
        AntiEntropyService.Validator v0 = new AntiEntropyService.Validator(Statics.req);
        IPartitioner part = new RandomPartitioner();
        MerkleTree mt = new MerkleTree(part, FULL_RANGE, MerkleTree.RECOMMENDED_DEPTH, Integer.MAX_VALUE);
        List<Token> tokens = new ArrayList<Token>();
        for (int i = 0; i < 10; i++)
        {
            Token t = part.getRandomToken();
            tokens.add(t);
            mt.split(t);
        }
        AntiEntropyService.Validator v1 = new AntiEntropyService.Validator(Statics.req, mt);
        DataOutputStream out = getOutput("service.TreeResponse.bin");
        AntiEntropyService.TreeResponseVerbHandler.SERIALIZER.serialize(v0, out, getVersion());
        AntiEntropyService.TreeResponseVerbHandler.SERIALIZER.serialize(v1, out, getVersion());
View Full Code Here

            }
        });
        Range<Token> range = new Range<>(partirioner.getMinimumToken(), partirioner.getRandomToken());
        RepairJobDesc desc = new RepairJobDesc(UUID.randomUUID(), "Keyspace1", "Standard1", range);

        MerkleTree tree1 = createInitialTree(desc);
        MerkleTree tree2 = createInitialTree(desc);

        // difference the trees
        // note: we reuse the same endpoint which is bogus in theory but fine here
        TreeResponse r1 = new TreeResponse(ep1, tree1);
        TreeResponse r2 = new TreeResponse(ep2, tree2);
View Full Code Here

    public void testDifference() throws Throwable
    {
        Range<Token> range = new Range<>(partirioner.getMinimumToken(), partirioner.getRandomToken());
        RepairJobDesc desc = new RepairJobDesc(UUID.randomUUID(), "Keyspace1", "Standard1", range);

        MerkleTree tree1 = createInitialTree(desc);
        MerkleTree tree2 = createInitialTree(desc);

        // change a range in one of the trees
        Token token = partirioner.midpoint(range.left, range.right);
        tree1.invalidate(token);
        MerkleTree.TreeRange changed = tree1.get(token);
View Full Code Here

        assertEquals("Wrong differing ranges", interesting, new HashSet<>(diff.differences));
    }

    private MerkleTree createInitialTree(RepairJobDesc desc)
    {
        MerkleTree tree = new MerkleTree(partirioner, desc.range, MerkleTree.RECOMMENDED_DEPTH, (int)Math.pow(2, 15));
        tree.init();
        for (MerkleTree.TreeRange r : tree.invalids())
        {
            r.ensureHashInitialised();
        }
        return tree;
    }
View Full Code Here

        // generate a tree
        Validator validator = new Validator(request);
        validator.prepare(store);
        validator.completeTree();
        MerkleTree ltree = validator.tree;

        // and a clone
        validator = new Validator(request);
        validator.prepare(store);
        validator.completeTree();
        MerkleTree rtree = validator.tree;

        // change a range in one of the trees
        Token ltoken = StorageService.getPartitioner().midpoint(local_range.left, local_range.right);
        ltree.invalidate(ltoken);
        MerkleTree.TreeRange changed = ltree.get(ltoken);
View Full Code Here

        // empty validation
        AntiEntropyService.Validator v0 = new AntiEntropyService.Validator(Statics.req);

        // validation with a tree
        IPartitioner p = new RandomPartitioner();
        MerkleTree mt = new MerkleTree(p, FULL_RANGE, MerkleTree.RECOMMENDED_DEPTH, Integer.MAX_VALUE);
        for (int i = 0; i < 10; i++)
            mt.split(p.getRandomToken());
        AntiEntropyService.Validator v1 = new AntiEntropyService.Validator(Statics.req, mt);

        DataOutputStream out = getOutput("service.TreeResponse.bin");
        AntiEntropyService.Validator.serializer.serialize(v0, out, getVersion());
        AntiEntropyService.Validator.serializer.serialize(v1, out, getVersion());
View Full Code Here

TOP

Related Classes of org.apache.cassandra.utils.MerkleTree$TreeRange

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.