Search in sources :

Example 1 with ChecksumNode

use of com.ms.silverking.cloud.dht.daemon.storage.convergence.ChecksumNode in project SilverKing by Morgan-Stanley.

the class DHTRingMaster method displayChecksumTree.

public void displayChecksumTree(MessageGroup message, MessageGroupConnection connection) {
    ChecksumNode remoteTree;
    ConvergencePoint cp;
    cp = ProtoChecksumTreeMessageGroup.getConvergencePoint(message);
    remoteTree = ProtoChecksumTreeMessageGroup.deserialize(message);
    System.out.printf("incomingChecksumTree: %s\t%s\t%s\n", message.getUUID(), cp, connection);
    System.out.println(remoteTree);
}
Also used : ConvergencePoint(com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint) ChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.ChecksumNode)

Example 2 with ChecksumNode

use of com.ms.silverking.cloud.dht.daemon.storage.convergence.ChecksumNode in project SilverKing by Morgan-Stanley.

the class StorageModule method incomingChecksumTree.

// used only for testing
/*
    public void requestChecksumTree(long version) {
        for (NamespaceStore nsStore : namespaces.values()) {
            System.out.printf("requestChecksumTree: %x\n", nsStore.getNamespace());
            nsStore.requestChecksumTree(version, OwnerQueryMode.Secondary);
        }
    }
    */
public void incomingChecksumTree(MessageGroup message, MessageGroupConnection connection) {
    NamespaceStore nsStore;
    ChecksumNode remoteTree;
    ConvergencePoint cp;
    nsStore = getNamespaceStore(message.getContext(), NSCreationMode.CreateIfAbsent);
    cp = ProtoChecksumTreeMessageGroup.getConvergencePoint(message);
    remoteTree = ProtoChecksumTreeMessageGroup.deserialize(message);
    nsStore.incomingChecksumTree(message.getUUID(), remoteTree, cp, connection);
}
Also used : ConvergencePoint(com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint) ChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.ChecksumNode)

Example 3 with ChecksumNode

use of com.ms.silverking.cloud.dht.daemon.storage.convergence.ChecksumNode in project SilverKing by Morgan-Stanley.

the class TreeTest method test.

public void test() {
    ChecksumNode tree1;
    ChecksumNode tree2;
    ChecksumNode tree2b;
    ChecksumNode tree3;
    ChecksumNode tree4;
    ChecksumNode tree5;
    tree1 = RegionTreeBuilder.build(region, entriesPerNode, numKeys, kvcList);
    System.out.println(tree1);
    tree2 = tree1.duplicate();
    System.out.println("\n *** Should be equal ***");
    System.out.println(TreeMatcher.match(tree2, tree1));
    tree2b = RegionTreeBuilder.build(region, entriesPerNode, numKeys / 2, kvcList);
    System.out.println(tree2b);
    System.out.println("\n *** Should be equal (different key estimates) ***");
    System.out.println(TreeMatcher.match(tree2b, tree1));
    List<KeyAndVersionChecksum> _kvcList;
    List<KeyAndVersionChecksum> _kvcList4;
    KeyAndVersionChecksum kvc1;
    KeyAndVersionChecksum kvc2;
    long checksum2;
    // remove one key so that we have destNotInSource and sourceNotInDest tests
    _kvcList = new ArrayList<>(kvcList);
    _kvcList.remove(0);
    tree3 = RegionTreeBuilder.build(region, entriesPerNode, numKeys, _kvcList);
    // now create a mismatch
    _kvcList4 = new ArrayList<>(kvcList);
    kvc1 = _kvcList4.remove(0);
    checksum2 = kvc1.getVersionChecksum() + 1;
    kvc2 = new KeyAndVersionChecksum(kvc1.getKey(), checksum2);
    _kvcList4.add(0, kvc2);
    tree4 = RegionTreeBuilder.build(region, entriesPerNode, numKeys, _kvcList4);
    _kvcList4.remove(1);
    tree5 = RegionTreeBuilder.build(region, entriesPerNode, numKeys, _kvcList4);
    System.out.println("\n *** Should have destNotInSource ***");
    System.out.println(TreeMatcher.match(tree3, tree1));
    System.out.println("\n *** Should have sourceNotInDest ***");
    System.out.println(TreeMatcher.match(tree1, tree3));
    System.out.println("\n *** Should have mismatch ***");
    System.out.println(TreeMatcher.match(tree4, tree1));
    System.out.println("\n *** Should be a mix ***");
    System.out.println(TreeMatcher.match(tree5, tree3));
    System.out.flush();
    serializationTest(tree1);
}
Also used : KeyAndVersionChecksum(com.ms.silverking.cloud.dht.daemon.storage.KeyAndVersionChecksum) ChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.ChecksumNode)

Example 4 with ChecksumNode

use of com.ms.silverking.cloud.dht.daemon.storage.convergence.ChecksumNode in project SilverKing by Morgan-Stanley.

the class ProtoChecksumTreeMessageGroup method serialize.

public static void serialize(ByteBuffer buffer, ChecksumNode node) {
    if (node == null) {
        // only supported for root of tree
        writeNullRoot(buffer);
    } else {
        if (node instanceof NonLeafChecksumNode) {
            List<? extends ChecksumNode> children;
            writeNodeHeader(buffer, NodeType.NON_LEAF, node);
            children = node.getChildren();
            for (ChecksumNode child : children) {
                serialize(buffer, child);
            }
        } else if (node instanceof LeafChecksumNode) {
            writeNodeHeader(buffer, NodeType.LEAF, node);
            writeKeyAndVersionChecksums(buffer, (LeafChecksumNode) node);
        } else {
            throw new RuntimeException("panic");
        }
    }
}
Also used : NonLeafChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.NonLeafChecksumNode) LeafChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.LeafChecksumNode) NonLeafChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.NonLeafChecksumNode) AbstractChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.AbstractChecksumNode) ChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.ChecksumNode) LeafChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.LeafChecksumNode) NonLeafChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.NonLeafChecksumNode)

Example 5 with ChecksumNode

use of com.ms.silverking.cloud.dht.daemon.storage.convergence.ChecksumNode in project SilverKing by Morgan-Stanley.

the class ProtoChecksumTreeMessageGroup method deserialize.

public static ChecksumNode deserialize(ByteBuffer buffer) {
    NodeType type;
    RingRegion region;
    int numChildren;
    AbstractChecksumNode root;
    type = NodeType.values()[buffer.get()];
    if (type != NodeType.NULL) {
        region = deserializeRegion(buffer);
        numChildren = buffer.getInt();
    } else {
        region = null;
        numChildren = 0;
    }
    switch(type) {
        case NON_LEAF:
            List<ChecksumNode> children;
            children = new ArrayList<>(numChildren);
            for (int i = 0; i < numChildren; i++) {
                children.add(deserialize(buffer));
            }
            root = new NonLeafChecksumNode(region, children);
            break;
        case LEAF:
            List<KeyAndVersionChecksum> keyAndVersionChecksums;
            keyAndVersionChecksums = deserializeKeyAndVersionChecksums(buffer);
            root = new LeafChecksumNode(region, keyAndVersionChecksums);
            break;
        case NULL:
            root = null;
            break;
        default:
            throw new RuntimeException("panic");
    }
    if (root != null) {
        root.freezeIfNotFrozen();
    }
    return root;
}
Also used : KeyAndVersionChecksum(com.ms.silverking.cloud.dht.daemon.storage.KeyAndVersionChecksum) NonLeafChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.NonLeafChecksumNode) RingRegion(com.ms.silverking.cloud.ring.RingRegion) LeafChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.LeafChecksumNode) NonLeafChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.NonLeafChecksumNode) AbstractChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.AbstractChecksumNode) ChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.ChecksumNode) LeafChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.LeafChecksumNode) NonLeafChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.NonLeafChecksumNode) AbstractChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.AbstractChecksumNode) ConvergencePoint(com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint)

Aggregations

ChecksumNode (com.ms.silverking.cloud.dht.daemon.storage.convergence.ChecksumNode)8 ConvergencePoint (com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint)4 KeyAndVersionChecksum (com.ms.silverking.cloud.dht.daemon.storage.KeyAndVersionChecksum)2 AbstractChecksumNode (com.ms.silverking.cloud.dht.daemon.storage.convergence.AbstractChecksumNode)2 LeafChecksumNode (com.ms.silverking.cloud.dht.daemon.storage.convergence.LeafChecksumNode)2 NonLeafChecksumNode (com.ms.silverking.cloud.dht.daemon.storage.convergence.NonLeafChecksumNode)2 RingRegion (com.ms.silverking.cloud.ring.RingRegion)1 ByteBuffer (java.nio.ByteBuffer)1