Search in sources :

Example 1 with ProtoChecksumTreeMessageGroup

use of com.ms.silverking.cloud.dht.net.ProtoChecksumTreeMessageGroup in project SilverKing by Morgan-Stanley.

the class ChecksumTreeServer method getChecksumTree.

// ////////////////////////////////////////////////////////////////////
// Handle incoming request for a convergence tree
public void getChecksumTree(UUIDBase uuid, ConvergencePoint targetCP, ConvergencePoint sourceCP, MessageGroupConnection connection, byte[] originator, RingRegion region) {
    ChecksumNode root;
    ProtoChecksumTreeMessageGroup pmg;
    int bufferSize;
    ConvergencePoint mixedCP;
    if (verbose || debug) {
        System.out.printf("getChecksumTree %x\t%s\t%s\t%s\t%s\n", ns, targetCP, sourceCP, region, uuid);
    }
    // FUTURE - support both min and max version
    // We create a mixedCP because we need to retrieve target data from the source regions, but
    // we need to use the target data version
    mixedCP = sourceCP.dataVersion(targetCP.getDataVersion());
    root = getRegionChecksumTree_Local(mixedCP, region, new LongInterval(Long.MIN_VALUE, mixedCP.getDataVersion()));
    if (root == null) {
        if (verbose || debug) {
            System.out.printf("null root for %x\t%s\t%s\n", ns, mixedCP, region);
        }
    }
    if (debug) {
        System.out.println("computed:");
        System.out.println(root);
    }
    bufferSize = estimateBufferSize(root);
    pmg = null;
    do {
        try {
            pmg = new ProtoChecksumTreeMessageGroup(uuid, ns, targetCP, originator, root, bufferSize);
        // pmg = new ProtoChecksumTreeMessageGroup(uuid, ns, mixedCP, originator, root, bufferSize);
        } catch (BufferOverflowException bfe) {
            pmg = null;
            if (bufferSize == Integer.MAX_VALUE) {
                throw new RuntimeException("Buffer limit reached");
            } else {
                if (debug) {
                    System.out.printf("raising checksum tree buffer limit %s\n", uuid);
                }
                bufferSize = bufferSize << 1;
                if (bufferSize < 0) {
                    bufferSize = Integer.MAX_VALUE;
                }
            }
        }
    } while (pmg == null);
    try {
        MessageGroup mg;
        mg = pmg.toMessageGroup();
        if (verbose || debug) {
            System.out.printf("Sending checksum tree %s to %s\n", uuid, connection.getRemoteIPAndPort());
        }
        if (debug) {
            System.out.printf("Sending checksum tree at %d %d\n", absMillisTimeSource.absTimeMillis(), mg.getDeadlineAbsMillis(absMillisTimeSource));
        }
        connection.sendAsynchronous(mg, mg.getDeadlineAbsMillis(absMillisTimeSource));
    } catch (IOException ioe) {
        Log.logErrorWarning(ioe);
    }
}
Also used : ProtoChecksumTreeMessageGroup(com.ms.silverking.cloud.dht.net.ProtoChecksumTreeMessageGroup) ProtoChecksumTreeMessageGroup(com.ms.silverking.cloud.dht.net.ProtoChecksumTreeMessageGroup) MessageGroup(com.ms.silverking.cloud.dht.net.MessageGroup) LongInterval(com.ms.silverking.numeric.LongInterval) BufferOverflowException(java.nio.BufferOverflowException) IOException(java.io.IOException)

Aggregations

MessageGroup (com.ms.silverking.cloud.dht.net.MessageGroup)1 ProtoChecksumTreeMessageGroup (com.ms.silverking.cloud.dht.net.ProtoChecksumTreeMessageGroup)1 LongInterval (com.ms.silverking.numeric.LongInterval)1 IOException (java.io.IOException)1 BufferOverflowException (java.nio.BufferOverflowException)1