Search in sources :

Example 1 with DHTKey

use of com.ms.silverking.cloud.dht.common.DHTKey in project SilverKing by Morgan-Stanley.

the class AsyncPutOperationImpl method debugTimeout.

protected void debugTimeout() {
    /**/
    for (OperationUUID opUUID : opUUIDs) {
        ConcurrentMap<DHTKey, WeakReference<ActiveKeyedOperationResultListener<OpResult>>> keyMap;
        System.out.println("opUUID:\t" + opUUID);
        // keyMap = activePutListeners.get(opUUID);
        keyMap = activePutListeners.getKeyMap(opUUID);
        for (DHTKey key : keyMap.keySet()) {
            if (keyMap.get(key).get() == this) {
                OpResult result;
                result = opResults.get(key);
                if (result == null || !result.isComplete()) {
                    System.out.printf("IncompleteA: %s\t%s\n", opUUID, key);
                }
            } else {
                System.out.println(key + " -> " + keyMap.get(key));
            }
        }
    }
    /**/
    for (DHTKey key : dhtKeys) {
        OpResult result;
        result = opResults.get(key);
        if (result == null || !result.isComplete()) {
            System.out.printf("IncompleteB: %s\t%d\n", key, creationCalls);
        }
    }
}
Also used : WeakReference(java.lang.ref.WeakReference) OpResult(com.ms.silverking.cloud.dht.common.OpResult) DHTKey(com.ms.silverking.cloud.dht.common.DHTKey)

Example 2 with DHTKey

use of com.ms.silverking.cloud.dht.common.DHTKey in project SilverKing by Morgan-Stanley.

the class AsyncPutOperationImpl method createMessagesForIncomplete.

private ProtoPutMessageGroup<V> createMessagesForIncomplete(ProtoPutMessageGroup<V> protoPutMG, List<MessageGroup> messageGroups, PutMessageEstimate estimate) {
    int oldSegmentsCreated;
    // }
    assert estimate.getNumKeys() != 0;
    oldSegmentsCreated = segmentsCreated;
    creationCalls++;
    resolveVersion();
    if (debug) {
        System.out.printf("createMessagesForIncomplete() %d\n", getKeys().size());
    }
    for (K key : getKeys()) {
        if (debug) {
            Log.warning(String.format("getSent() %s opResults.get(keyToDHTKey.get(key)) %s\n", getSent(), opResults.get(keyToDHTKey.get(key))));
        }
        if (!getSent() || OpResult.isIncompleteOrNull(opResults.get(keyToDHTKey.get(key)))) {
            DHTKey dhtKey;
            V value;
            ValueAdditionResult additionResult;
            boolean listenerInserted;
            dhtKey = keyToDHTKey.get(key);
            value = putOperation.getValue(key);
            listenerInserted = activePutListeners.addListener(protoPutMG.getUUID(), dhtKey, this);
            if (listenerInserted) {
                if (debug) {
                    Log.warning(String.format("add1\t" + dhtKey + "\t" + resolvedVersion + "\t" + protoPutMG.getVersion() + "\tuuid " + protoPutMG.getUUID()));
                }
                additionResult = protoPutMG.addValue(dhtKey, value);
                if (additionResult == ValueAdditionResult.MessageGroupFull) {
                    // If we couldn't add this key/value to the current ProtoPutMessageGroup, then we must
                    // create a new message group. Save the current group to the list of groups before that.
                    // First update the message estimate to remove keys/bytes already added.
                    estimate.addKeys(-protoPutMG.currentBufferKeys());
                    estimate.addBytes(-protoPutMG.currentValueBytes());
                    assert estimate.getNumKeys() != 0;
                    protoPutMG.addToMessageGroupList(messageGroups);
                    protoPutMG = createProtoPutMG(estimate);
                    listenerInserted = activePutListeners.addListener(protoPutMG.getUUID(), dhtKey, this);
                    if (!listenerInserted) {
                        throw new RuntimeException("Can't insert listener to new protoPutMG");
                    }
                    // hold a reference to the uuid to prevent GC
                    opUUIDs.add((OperationUUID) protoPutMG.getUUID());
                    additionResult = protoPutMG.addValue(dhtKey, value);
                    if (additionResult != ValueAdditionResult.Added) {
                        throw new RuntimeException("Can't add to new protoPutMG");
                    }
                } else if (additionResult == ValueAdditionResult.ValueNeedsSegmentation) {
                    segment(key, messageGroups);
                    continue;
                // FIXME - call continue? how to handle the opUUIDs.add() below?
                }
            } else {
                // The existing protoPutMG already had an entry for the given key.
                // Create a new protoPutMG so that we can add this key.
                estimate.addKeys(-protoPutMG.currentBufferKeys());
                estimate.addBytes(-protoPutMG.currentValueBytes());
                assert estimate.getNumKeys() != 0;
                protoPutMG.addToMessageGroupList(messageGroups);
                protoPutMG = createProtoPutMG(estimate, DHTClient.getValueCreator().getBytes());
                // hold a reference to the uuid to prevent GC
                opUUIDs.add((OperationUUID) protoPutMG.getUUID());
                listenerInserted = activePutListeners.addListener(protoPutMG.getUUID(), dhtKey, this);
                if (!listenerInserted) {
                    throw new RuntimeException("Can't insert listener to new protoPutMG");
                }
                if (debug) {
                    System.out.println("add2\t" + dhtKey + "\t" + resolvedVersion + "\t" + protoPutMG.getVersion());
                }
                additionResult = protoPutMG.addValue(dhtKey, value);
                if (additionResult != ValueAdditionResult.Added) {
                    throw new RuntimeException("Can't add to new protoPutMG");
                }
            }
            // hold a reference to the uuid to prevent GC
            opUUIDs.add((OperationUUID) protoPutMG.getUUID());
        // protoPutMG.addResultListener(dhtKey, this);
        }
    }
    /*
        if (protoPutMG.isNonEmpty()) {
            MessageGroup    messageGroup;
            
            messageGroup = new MessageGroup(MessageType.PUT, context.contextAsLong(), protoPutMG.getBufferList());
            messageGroups.add(messageGroup);
            messageGroup.displayForDebug();
        }
        */
    setSent();
    return protoPutMG;
}
Also used : DHTKey(com.ms.silverking.cloud.dht.common.DHTKey) ValueAdditionResult(com.ms.silverking.cloud.dht.net.ProtoPutMessageGroup.ValueAdditionResult)

Example 3 with DHTKey

use of com.ms.silverking.cloud.dht.common.DHTKey in project SilverKing by Morgan-Stanley.

the class AsyncRetrievalOperationImpl method getLatestValues.

@Override
public Map<K, V> getLatestValues() throws RetrievalException {
    Map<K, V> valueMap;
    valueMap = new HashMap<>(retrievalOperation.size() - latestStoredReturned.size());
    for (Map.Entry<K, RetrievalResultBase<V>> resultEntry : results.entrySet()) {
        K key;
        DHTKey dhtKey;
        key = resultEntry.getKey();
        dhtKey = keyToDHTKey.get(key);
        if (!latestStoredReturned.contains(dhtKey)) {
            RetrievalResultBase<V> value;
            latestStoredReturned.add(dhtKey);
            value = resultEntry.getValue();
            if (value.getOpResult() == OpResult.SUCCEEDED) {
                valueMap.put(resultEntry.getKey(), value.getValue());
            }
        }
    }
    return valueMap;
}
Also used : DHTKey(com.ms.silverking.cloud.dht.common.DHTKey) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentSingleMap(com.ms.silverking.collection.ConcurrentSingleMap)

Example 4 with DHTKey

use of com.ms.silverking.cloud.dht.common.DHTKey in project SilverKing by Morgan-Stanley.

the class AsyncRetrievalOperationImpl method retrieveSegments.

private void retrieveSegments(DHTKey relayKey, DHTKey[] segmentKeys, MetaData metaData) {
    List<MessageGroup> messageGroups;
    SegmentedRetrievalValue<K, V> segmentedRetrievalValue;
    if (segmentedRetrievalValues == null) {
        segmentedRetrievalValues = new ArrayList<>(segmentKeys.length);
    }
    segmentedRetrievalValue = new SegmentedRetrievalValue<>(segmentKeys, relayKey, this, nspoImpl.getValueDeserializer(), metaData);
    messageGroups = new ArrayList<>();
    for (DHTKey segmentKey : segmentKeys) {
        ProtoRetrievalMessageGroup protoRetrievalMG;
        boolean listenerInserted;
        List<WeakReference<ActiveKeyedOperationResultListener<MessageGroupRetrievalResponseEntry>>> listeners;
        protoRetrievalMG = createProtoRetrievalMG(new KeyedMessageEstimate(1), false);
        listenerInserted = activeRetrievalListeners.addListener(protoRetrievalMG.getUUID(), segmentKey, segmentedRetrievalValue);
        if (!listenerInserted) {
            throw new RuntimeException("Duplicate listener insertion");
        }
        protoRetrievalMG.addKey(segmentKey);
        protoRetrievalMG.addToMessageGroupList(messageGroups);
        // hold a reference to the uuid to prevent GC
        opUUIDs.add((OperationUUID) protoRetrievalMG.getUUID());
        segmentedRetrievalValues.add(segmentedRetrievalValue);
    }
    for (MessageGroup messageGroup : messageGroups) {
        retrievalSender.send(messageGroup);
    }
}
Also used : MessageGroup(com.ms.silverking.cloud.dht.net.MessageGroup) ProtoRetrievalMessageGroup(com.ms.silverking.cloud.dht.net.ProtoRetrievalMessageGroup) ProtoMessageGroup(com.ms.silverking.cloud.dht.net.ProtoMessageGroup) DHTKey(com.ms.silverking.cloud.dht.common.DHTKey) ProtoRetrievalMessageGroup(com.ms.silverking.cloud.dht.net.ProtoRetrievalMessageGroup) MessageGroupRetrievalResponseEntry(com.ms.silverking.cloud.dht.net.MessageGroupRetrievalResponseEntry) WeakReference(java.lang.ref.WeakReference)

Example 5 with DHTKey

use of com.ms.silverking.cloud.dht.common.DHTKey in project SilverKing by Morgan-Stanley.

the class AsyncRetrievalOperationImpl method createProtoRetrievalMG.

private ProtoRetrievalMessageGroup createProtoRetrievalMG(MessageEstimate estimate, boolean verifyIntegrity) {
    OperationUUID opUUID;
    ConcurrentMap<DHTKey, List<ActiveKeyedOperationResultListener<MessageGroupRetrievalResponseEntry>>> newMap;
    KeyedMessageEstimate keyedMessageEstimate;
    int relDeadline;
    keyedMessageEstimate = (KeyedMessageEstimate) estimate;
    opUUID = activeRetrievalListeners.newOpUUID();
    relDeadline = operation.getTimeoutController().getMaxRelativeTimeoutMillis(this);
    if (debugShortTimeout) {
        if (relDeadline < shortTimeoutLimit) {
            Log.warning("short relDeadline: " + relDeadline);
            // Log.warning(timeoutParameters.computeTimeout(keyedMessageEstimate.getNumKeys()));
            Log.warning(timeoutState.getCurRelTimeoutMillis());
        // throw new RuntimeException();
        }
    }
    return new ProtoRetrievalMessageGroup(opUUID, context.contextAsLong(), new InternalRetrievalOptions(retrievalOperation.retrievalOptions(), verifyIntegrity), originator, keyedMessageEstimate.getNumKeys(), relDeadline, retrievalOperation.retrievalOptions().getForwardingMode());
}
Also used : DHTKey(com.ms.silverking.cloud.dht.common.DHTKey) ProtoRetrievalMessageGroup(com.ms.silverking.cloud.dht.net.ProtoRetrievalMessageGroup) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) MessageGroupRetrievalResponseEntry(com.ms.silverking.cloud.dht.net.MessageGroupRetrievalResponseEntry) InternalRetrievalOptions(com.ms.silverking.cloud.dht.common.InternalRetrievalOptions) VersionConstraint(com.ms.silverking.cloud.dht.VersionConstraint)

Aggregations

DHTKey (com.ms.silverking.cloud.dht.common.DHTKey)47 VersionConstraint (com.ms.silverking.cloud.dht.VersionConstraint)10 OpResult (com.ms.silverking.cloud.dht.common.OpResult)7 ByteBuffer (java.nio.ByteBuffer)7 KeyAndVersionChecksum (com.ms.silverking.cloud.dht.daemon.storage.KeyAndVersionChecksum)5 SimpleKey (com.ms.silverking.cloud.dht.common.SimpleKey)4 MessageGroupKeyOrdinalEntry (com.ms.silverking.cloud.dht.net.MessageGroupKeyOrdinalEntry)4 MessageGroupRetrievalResponseEntry (com.ms.silverking.cloud.dht.net.MessageGroupRetrievalResponseEntry)4 IOException (java.io.IOException)4 WeakReference (java.lang.ref.WeakReference)4 InternalRetrievalOptions (com.ms.silverking.cloud.dht.common.InternalRetrievalOptions)3 ConvergencePoint (com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint)3 ProtoRetrievalMessageGroup (com.ms.silverking.cloud.dht.net.ProtoRetrievalMessageGroup)3 Triple (com.ms.silverking.collection.Triple)3 File (java.io.File)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 RetrievalOptions (com.ms.silverking.cloud.dht.RetrievalOptions)2 DHTKeyIntEntry (com.ms.silverking.cloud.dht.collection.DHTKeyIntEntry)2