Search in sources :

Example 6 with RingRegion

use of com.ms.silverking.cloud.ring.RingRegion in project SilverKing by Morgan-Stanley.

the class RegionTreePruner method pruneLeafNode.

private static ChecksumNode pruneLeafNode(LeafChecksumNode node, RingRegion pruneRegion) {
    IntersectionResult iResult;
    RingRegion oRegion;
    // long[]				_kvc;
    List<KeyAndVersionChecksum> kvcList;
    List<KeyAndVersionChecksum> prunedKVCList;
    if (!node.getRegion().overlaps(pruneRegion)) {
        throw new RuntimeException("panic");
    }
    iResult = RingRegion.intersect(node.getRegion(), pruneRegion);
    if (iResult.getIntersectionType() == IntersectionType.wrappedPartial) {
        // FUTURE - handle this
        throw new RuntimeException("wrappedPartial pruning not yet handled");
    }
    oRegion = iResult.getOverlapping().get(0);
    // _kvc = node.getKeyAndVersionChecksumsAsArray();
    // FUTURE - improve the efficiency of this approach
    // This is n log n, and each step is heavy
    // Should be able to do at least log n with very light steps
    kvcList = node.getKeyAndVersionChecksums();
    prunedKVCList = new ArrayList<>(kvcList.size());
    for (KeyAndVersionChecksum kvc : kvcList) {
        if (pruneRegion.contains(KeyUtil.keyToCoordinate(kvc.getKey()))) {
            prunedKVCList.add(kvc);
        }
    }
    return new LeafChecksumNode(oRegion, prunedKVCList);
}
Also used : KeyAndVersionChecksum(com.ms.silverking.cloud.dht.daemon.storage.KeyAndVersionChecksum) RingRegion(com.ms.silverking.cloud.ring.RingRegion) IntersectionResult(com.ms.silverking.cloud.ring.IntersectionResult)

Example 7 with RingRegion

use of com.ms.silverking.cloud.ring.RingRegion in project SilverKing by Morgan-Stanley.

the class RegionTreeBuilder method main.

public static void main(String[] args) {
    if (args.length != 4) {
        System.out.println("numKeys keysPerNode regionStart regionEnd");
    } else {
        RegionTreeBuilder rtb;
        int numKeys;
        int keysPerNode;
        long regionStart;
        long regionEnd;
        RingRegion region;
        numKeys = Integer.parseInt(args[0]);
        keysPerNode = Integer.parseInt(args[1]);
        regionStart = Long.parseLong(args[2]);
        regionEnd = Long.parseLong(args[3]);
        region = new RingRegion(regionStart, regionEnd);
        rtb = new RegionTreeBuilder(region, keysPerNode, numKeys);
        for (int i = 0; i < numKeys; i++) {
            rtb.addChecksum(new KeyAndVersionChecksum(KeyUtil.randomRegionKey(region), i));
        }
        System.out.println(rtb);
    }
}
Also used : KeyAndVersionChecksum(com.ms.silverking.cloud.dht.daemon.storage.KeyAndVersionChecksum) RingRegion(com.ms.silverking.cloud.ring.RingRegion)

Example 8 with RingRegion

use of com.ms.silverking.cloud.ring.RingRegion in project SilverKing by Morgan-Stanley.

the class RegionTreeBuilder method createInternalNodes.

private static ChecksumNode createInternalNodes(LeafChecksumNode[] leaves, int height, int entriesPerNode, int estimatedKeys) {
    ChecksumNode[][] nodes;
    nodes = new ChecksumNode[height][];
    /*
         * 0          => root
         * height - 1 => leaves
         * 
         * e.g. with 128 keys, 8 per node we have
         * row  numMembers  children or content per member
         * 0:   1           2
         * 1:   2           8
         * 2:   16          8 (content in this case)
         * 
         */
    int nextRowChildren;
    nextRowChildren = estimatedKeys;
    for (int i = height - 1; i >= 0; i--) {
        // System.out.printf("\n%d **********************************\n", i);
        if (i < height - 1) {
            int rowSize;
            int childrenPerNode;
            assert nextRowChildren > 0;
            rowSize = (nextRowChildren - 1) / entriesPerNode + 1;
            nodes[i] = new NonLeafChecksumNode[rowSize];
            // childrenPerNode = Math.round(nextRowChildren / rowSize);
            childrenPerNode = entriesPerNode;
            for (int j = 0; j < nodes[i].length; j++) {
                RingRegion region;
                List<ChecksumNode> children;
                int i0;
                int i1;
                i0 = j * childrenPerNode;
                i1 = Math.min(i0 + childrenPerNode, nextRowChildren);
                children = ImmutableList.copyOf(Arrays.copyOfRange(nodes[i + 1], i0, i1));
                region = new RingRegion(children.get(0).getRegion().getStart(), children.get(children.size() - 1).getRegion().getEnd());
                nodes[i][j] = new NonLeafChecksumNode(region, children);
                if (debug) {
                    System.out.printf("%d %d\t%d %d\t%s\n", i, j, i0, i1, nodes[i][j].getRegion());
                }
            }
            nextRowChildren = rowSize;
        } else {
            nodes[i] = leaves;
            nextRowChildren = leaves.length;
        }
        if (debug) {
            System.out.println();
        }
    }
    if (nodes[0].length != 1) {
        throw new RuntimeException("panic");
    }
    return nodes[0][0];
}
Also used : RingRegion(com.ms.silverking.cloud.ring.RingRegion)

Example 9 with RingRegion

use of com.ms.silverking.cloud.ring.RingRegion 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)

Example 10 with RingRegion

use of com.ms.silverking.cloud.ring.RingRegion in project SilverKing by Morgan-Stanley.

the class RingTree method cleanupList.

private List<RingEntry> cleanupList(RingRegion ringspace, List<RingEntry> dirty) {
    if (Math.abs(RingRegion.getTotalSize(RingEntry.getRegions(dirty)) - ringspace.getSize()) > allowedError) {
        System.err.println("ringspace");
        System.err.println(ringspace);
        System.err.println("RingEntry.toString(dirty)");
        System.err.println(RingEntry.toString(dirty));
        System.err.printf("RingRegion.getTotalSize(RingEntry.getRegions(dirty)) %d\n", RingRegion.getTotalSize(RingEntry.getRegions(dirty)));
        System.err.printf("ringspace.getSize() %d\n", ringspace.getSize());
        throw new RuntimeException("Size error exceeds allowed limit");
    } else {
        List<RingEntry> clean;
        clean = new ArrayList<>(dirty.size());
        if (dirty.size() == 0) {
        // no action required
        } else if (dirty.size() == 1) {
            clean.add(dirty.get(0).replaceRegion(ringspace));
        } else {
            for (int i = 0; i < dirty.size() - 1; i++) {
                RingRegion r1;
                RingRegion r2;
                long error;
                int j;
                j = (i + 1) % dirty.size();
                r1 = dirty.get(i).getRegion();
                r2 = dirty.get(j).getRegion();
                error = Math.abs(LongRingspace.nextPoint(r1.getEnd()) - r2.getStart());
                if (error != 0) {
                    if (error > allowedContiquityError) {
                        System.err.println(r1);
                        System.err.println(r2);
                        throw new RuntimeException("Contiguity error exceeds allowed limit");
                    } else {
                        clean.add(dirty.get(i).replaceRegion(new RingRegion(r1.getStart(), LongRingspace.prevPoint(r2.getStart()))));
                    /*
                            if (r1.getSize() >= r2.getSize()) {
                                clean.add(dirty.get(i).replaceRegion(new RingRegion(r1.getStart(), LongRingspace.prevPoint(r2.getStart()))));
                            } else {
                                //clean.add(dirty.get(j).replaceRegion(new RingRegion(LongRingspace.nextPoint(r1.getEnd()), r2.getEnd())));
                            }
                            */
                    }
                } else {
                    clean.add(dirty.get(i));
                }
            }
            clean.add(dirty.get(dirty.size() - 1));
        }
        return RingEntry.simplify(clean);
    }
}
Also used : RingRegion(com.ms.silverking.cloud.ring.RingRegion)

Aggregations

RingRegion (com.ms.silverking.cloud.ring.RingRegion)22 IntersectionResult (com.ms.silverking.cloud.ring.IntersectionResult)5 IPAndPort (com.ms.silverking.net.IPAndPort)4 KeyAndVersionChecksum (com.ms.silverking.cloud.dht.daemon.storage.KeyAndVersionChecksum)3 ConvergencePoint (com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint)3 RingEntry (com.ms.silverking.cloud.toporing.RingEntry)2 AbstractChecksumNode (com.ms.silverking.cloud.dht.daemon.storage.convergence.AbstractChecksumNode)1 ChecksumNode (com.ms.silverking.cloud.dht.daemon.storage.convergence.ChecksumNode)1 LeafChecksumNode (com.ms.silverking.cloud.dht.daemon.storage.convergence.LeafChecksumNode)1 NonLeafChecksumNode (com.ms.silverking.cloud.dht.daemon.storage.convergence.NonLeafChecksumNode)1 RingID (com.ms.silverking.cloud.dht.daemon.storage.convergence.RingID)1 RingIDAndVersionPair (com.ms.silverking.cloud.dht.daemon.storage.convergence.RingIDAndVersionPair)1 SKGridConfiguration (com.ms.silverking.cloud.dht.gridconfig.SKGridConfiguration)1 MessageGroup (com.ms.silverking.cloud.dht.net.MessageGroup)1 ProtoChecksumTreeMessageGroup (com.ms.silverking.cloud.dht.net.ProtoChecksumTreeMessageGroup)1 ProtoChecksumTreeRequestMessageGroup (com.ms.silverking.cloud.dht.net.ProtoChecksumTreeRequestMessageGroup)1 UUIDBase (com.ms.silverking.id.UUIDBase)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1