Search in sources :

Example 1 with RetrievalResult

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

the class ActiveProxyRetrieval method sendSecondaryReplicasUpdate.

private void sendSecondaryReplicasUpdate(SecondaryReplicasUpdate secondaryReplicasUpdate) {
    RetrievalResult result;
    result = secondaryReplicasUpdate.getResult();
    for (IPAndPort replica : secondaryReplicasUpdate.getReplicas()) {
        ProtoMessageGroup pmg;
        if (debug) {
            Log.warning("ActiveProxyRetrieval sending secondary replicas update to ", replica);
        }
        // pmg = createPutForSecondaryReplicas(result);
        pmg = createValueMessageForSecondaryReplicas(result);
        messageModule.getMessageGroupBase().send(pmg.toMessageGroup(), replica);
    }
}
Also used : IPAndPort(com.ms.silverking.net.IPAndPort) RetrievalResult(com.ms.silverking.cloud.dht.daemon.storage.protocol.RetrievalResult) ProtoMessageGroup(com.ms.silverking.cloud.dht.net.ProtoMessageGroup)

Example 2 with RetrievalResult

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

the class ActiveProxyRetrieval method waitForTriggered.

public void waitForTriggered(DHTKey key, ByteBuffer result) {
    RetrievalResult retrievalResult;
    if (result.position() > 0) {
        System.err.println(result);
        Thread.dumpStack();
        System.exit(-1);
    }
    // debugString.append(result.toString() +"\n");
    if (debugWaitFor) {
        System.out.println("waitForTriggered " + key);
    }
    retrievalResult = new RetrievalResult(key, OpResult.SUCCEEDED, result);
    retrievalOperation.update((DHTKey) key, localIPAndPort(), retrievalResult, rComm);
// Complete operations are removed in bulk by MessageModule.Cleaner
}
Also used : RetrievalResult(com.ms.silverking.cloud.dht.daemon.storage.protocol.RetrievalResult)

Example 3 with RetrievalResult

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

the class ActiveProxyRetrieval method createResultGroups.

private List<List<RetrievalResult>> createResultGroups(List<RetrievalResult> results) {
    if (results.size() == 1) {
        return ImmutableList.of(results);
    } else {
        List<List<RetrievalResult>> resultGroups;
        List<RetrievalResult> curGroup;
        int curGroupSize;
        resultGroups = new ArrayList<>(Math.min(results.size(), resultListInitialSize));
        curGroup = new ArrayList<>(Math.min(results.size(), resultListInitialSize));
        resultGroups.add(curGroup);
        curGroupSize = 0;
        for (int i = 0; i < results.size(); i++) {
            RetrievalResult result;
            result = results.get(i);
            if (curGroupSize != 0) {
                if (curGroupSize + result.getResultLength() > ProtoValueMessageGroup.maxValueBytesPerMessage) {
                    curGroup = new ArrayList<>(Math.min(results.size() - i, resultListInitialSize));
                    resultGroups.add(curGroup);
                    curGroupSize = 0;
                }
            }
            curGroup.add(result);
            curGroupSize += result.getResultLength();
        }
        return resultGroups;
    }
}
Also used : ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) RetrievalResult(com.ms.silverking.cloud.dht.daemon.storage.protocol.RetrievalResult)

Example 4 with RetrievalResult

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

the class ActiveProxyRetrieval method sendResults.

/**
 * Send responses for all locally completed operations
 * @param retrievalOperation
 */
protected void sendResults(List<RetrievalResult> results) {
    if (debug) {
        System.out.printf("ActiveProxyRetrieval.sendresults() %d\n", results.size());
    }
    /*
        debugString.append("***\n");
        for (RetrievalResult result : results) {
            debugString.append(result.getValue() +"\n");
        }
        debugString.append("+++\n");
        */
    try {
        if (results.size() > 0) {
            ProtoValueMessageGroup pmg;
            byte[] _originator;
            List<List<RetrievalResult>> resultGroups;
            _originator = ConvergenceController2.isChecksumVersionConstraint(retrievalOptions.getVersionConstraint()) ? originator : messageModule.getMessageGroupBase().getMyID();
            resultGroups = createResultGroups(results);
            for (List<RetrievalResult> resultGroup : resultGroups) {
                MessageGroup messageGroup;
                int groupLength;
                groupLength = RetrievalResult.totalResultLength(resultGroup);
                pmg = new ProtoValueMessageGroup(uuid, namespace, results.size(), groupLength, _originator, messageModule.getAbsMillisTimeSource().relMillisRemaining(absDeadlineMillis));
                for (RetrievalResult result : resultGroup) {
                    DHTKey key;
                    ByteBuffer value;
                    if (debug) {
                        System.out.println(result);
                    }
                    key = result.getKey();
                    if (retrievalOptions.getWaitMode() != WaitMode.WAIT_FOR || result.getValue() == null) {
                        value = result.getValue();
                    } else {
                        value = result.getValue().duplicate();
                    }
                    if (value == null) {
                        pmg.addErrorCode(key, result.getResult());
                    } else {
                        pmg.addValue(key, value, result.getResultLength(), true);
                    }
                }
                messageGroup = pmg.toMessageGroup();
                connection.sendAsynchronous(messageGroup, messageGroup.getDeadlineAbsMillis(messageModule.getAbsMillisTimeSource()));
            }
        }
    /*
        } catch (RuntimeException re) {
            // for debugging only
            re.printStackTrace();
            System.out.println("results.size() "+ results.size());
            for (RetrievalResult result : results) {
                System.out.println(result);
            }
            //rComm.displayDebug();
            System.exit(-1);
            */
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}
Also used : ProtoKeyedMessageGroup(com.ms.silverking.cloud.dht.net.ProtoKeyedMessageGroup) MessageGroup(com.ms.silverking.cloud.dht.net.MessageGroup) ProtoValueMessageGroup(com.ms.silverking.cloud.dht.net.ProtoValueMessageGroup) ProtoRetrievalMessageGroup(com.ms.silverking.cloud.dht.net.ProtoRetrievalMessageGroup) ProtoMessageGroup(com.ms.silverking.cloud.dht.net.ProtoMessageGroup) DHTKey(com.ms.silverking.cloud.dht.common.DHTKey) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) RetrievalResult(com.ms.silverking.cloud.dht.daemon.storage.protocol.RetrievalResult) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) ProtoValueMessageGroup(com.ms.silverking.cloud.dht.net.ProtoValueMessageGroup)

Example 5 with RetrievalResult

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

the class ActiveProxyRetrieval method localOp.

@Override
protected void localOp(List<? extends DHTKey> destEntries, OpCommunicator<DHTKey, RetrievalResult> comm) {
    List<ByteBuffer> results;
    results = getStorage().retrieve(getContext(), // entry can act as a key
    destEntries, getRetrievalOptions(), uuid);
    for (int i = 0; i < destEntries.size(); i++) {
        RetrievalResult retrievalResult;
        ByteBuffer result;
        DHTKey entry;
        entry = destEntries.get(i);
        result = results.get(i);
        if (debug) {
            Log.warning("localRetrieval: ", entry);
            System.out.printf("result %s %s\n", result, StringUtil.byteBufferToHexString(result));
        }
        // FUTURE - THIS NEEDS TO GO THROUGH THE PROTOCOL
        // INSTEAD OF PROTOCOL SEMANTICS BEING HANDLED HERE
        Log.fine(entry);
        if (result != null && result != ValueUtil.corruptValue) {
            retrievalResult = new RetrievalResult(entry, OpResult.SUCCEEDED, result);
        } else {
            if (result != ValueUtil.corruptValue) {
                if (retrievalOptions.getWaitMode() != WaitMode.WAIT_FOR || messageModule.getReplicaList(getContext(), entry, OwnerQueryMode.Secondary, RingOwnerQueryOpType.Read).contains(localIPAndPort())) {
                    retrievalResult = new RetrievalResult(entry, OpResult.NO_SUCH_VALUE, null);
                } else {
                    retrievalResult = null;
                }
            } else {
                if (debug) {
                    System.out.println("Returning corrupt result");
                }
                retrievalResult = new RetrievalResult(entry, OpResult.CORRUPT, null);
            }
        }
        if (retrievalResult != null) {
            // retrievalOperation.update((DHTKey)entry, localIPAndPort(), retrievalResult, rComm);
            rComm.sendResult(retrievalResult);
        }
    // Complete operations are removed in bulk by MessageModule.Cleaner
    }
}
Also used : DHTKey(com.ms.silverking.cloud.dht.common.DHTKey) RetrievalResult(com.ms.silverking.cloud.dht.daemon.storage.protocol.RetrievalResult) ByteBuffer(java.nio.ByteBuffer)

Aggregations

RetrievalResult (com.ms.silverking.cloud.dht.daemon.storage.protocol.RetrievalResult)6 ImmutableList (com.google.common.collect.ImmutableList)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 DHTKey (com.ms.silverking.cloud.dht.common.DHTKey)2 ProtoMessageGroup (com.ms.silverking.cloud.dht.net.ProtoMessageGroup)2 IPAndPort (com.ms.silverking.net.IPAndPort)2 ByteBuffer (java.nio.ByteBuffer)2 OpResult (com.ms.silverking.cloud.dht.common.OpResult)1 RetrievalCommunicator (com.ms.silverking.cloud.dht.daemon.storage.protocol.RetrievalCommunicator)1 MessageGroup (com.ms.silverking.cloud.dht.net.MessageGroup)1 MessageGroupRetrievalResponseEntry (com.ms.silverking.cloud.dht.net.MessageGroupRetrievalResponseEntry)1 ProtoKeyedMessageGroup (com.ms.silverking.cloud.dht.net.ProtoKeyedMessageGroup)1 ProtoRetrievalMessageGroup (com.ms.silverking.cloud.dht.net.ProtoRetrievalMessageGroup)1 ProtoValueMessageGroup (com.ms.silverking.cloud.dht.net.ProtoValueMessageGroup)1 IOException (java.io.IOException)1