Search in sources :

Example 16 with OpResult

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

the class AsyncPutOperationImpl method getOperationState.

@Override
public OperationState getOperationState(K key) {
    OpResult result;
    result = opResults.get(keyToDHTKey.get(key));
    return result == null ? OperationState.INCOMPLETE : result.toOperationState();
}
Also used : OpResult(com.ms.silverking.cloud.dht.common.OpResult)

Example 17 with OpResult

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

the class AsyncRetrievalOperationImpl method resultReceived.

@Override
public void resultReceived(DHTKey dhtKey, MessageGroupRetrievalResponseEntry entry) {
    RawRetrievalResult rawResult;
    OpResult opResult;
    boolean setComplete;
    int oldSegmentsCreated;
    boolean segmented;
    // NEED TO MODIFY THIS METHOD TO ACCEPT SEGMENTED COMPLETIONS
    // THINK ABOUT STRUCTURE OF CODE
    oldSegmentsCreated = segmentsCreated;
    // System.out.printf("resultReceived key: %s\nentry: %s\n%s\nvalue: %s\n%s\n",
    // dhtKey, entry, entry.getOpResult(), StringUtil.byteBufferToHexString(entry.getValue()),
    // StringUtil.byteBufferToString(entry.getValue()));
    // System.out.printf("resultReceived key: %s\nentry: %s\n%s\nvalue buf: %s\n",
    // dhtKey, entry, entry.getOpResult(), entry.getValue());
    /*
        if (mvLock != null) {
            mvLock.lock();
        }
        try {
        */
    segmented = false;
    // FUTURE - avoid the multi-step construction
    rawResult = new RawRetrievalResult(retrievalOperation.retrievalOptions().getRetrievalType());
    opResult = entry.getOpResult();
    Log.fine("opResult: ", opResult);
    if (opResult == OpResult.SUCCEEDED) {
        try {
            if (testReceiveCorruption) {
                MetaDataUtil.testCorruption(entry.getValue(), receiveCorruptionProbability, MetaDataUtil.getDataOffset(entry.getValue(), 0));
            }
            // segmented = MetaDataUtil.isSegmented(entry.getValue().array(), entry.getValue().position());
            segmented = MetaDataUtil.isSegmented(entry.getValue());
            rawResult.setStoredValue(entry.getValue(), !segmented && retrievalOperation.retrievalOptions().getVerifyChecksums(), !retrievalOperation.retrievalOptions().getReturnInvalidations(), nspoImpl.getNSPOptions().getEncrypterDecrypter());
        } catch (CorruptValueException cve) {
            Log.infoAsync(String.format("Corrupt\t%s", dhtKey));
            handleCorruptValue(dhtKey);
            return;
        }
    } else {
        rawResult.setOpResult(opResult);
    }
    if (opResult == OpResult.SUCCEEDED && segmented) {
        ByteBuffer buf;
        if (debugSegmentation) {
            System.out.printf("SEGMENTED RESULT\n");
        }
        buf = rawResult.getValue();
        if (retrievalOperation.retrievalOptions().getRetrievalType().hasValue()) {
            DHTKey[] segmentKeys;
            int numSegments;
            if (debugSegmentation) {
                System.out.printf("SEGMENTED\t%s\t%s\t%d\t%d\n", StringUtil.byteArrayToHexString(SegmentationUtil.getCreatorBytes(buf)), buf, SegmentationUtil.getStoredLength(buf), SegmentationUtil.getUncompressedLength(buf));
            }
            if (true) {
                int storedLength;
                // not using below since the internal checksum should handle this
                // if (SegmentationUtil.checksumSegmentMetaDataBuffer(buf, nspoImpl.getNSPOptions().getChecksumType())) {
                setComplete = false;
                storedLength = SegmentationUtil.getStoredLength(buf);
                if (storedLength < 0) {
                    System.out.println(StringUtil.byteBufferToHexString(buf));
                    System.out.println(SegmentationUtil.getMetaData(rawResult, buf));
                    System.exit(-1);
                    numSegments = 1;
                } else {
                    numSegments = SegmentationUtil.getNumSegments(storedLength, SegmentationUtil.maxValueSegmentSize);
                }
                segmentsCreated += numSegments;
                if (debugSegmentation) {
                    System.out.printf("NUM SEGMENTS\t%d\n", numSegments);
                }
                segmentKeys = keyCreator.createSubKeys(dhtKey, numSegments);
                retrieveSegments(dhtKey, segmentKeys, SegmentationUtil.getMetaData(rawResult, buf));
            } else {
                setComplete = true;
                rawResult.setOpResult(OpResult.CORRUPT, true);
                opResult = OpResult.CORRUPT;
            }
        } else {
            if (debugSegmentation) {
                System.out.printf("SEGMENTED. MetaData retrieval\n");
            }
            setComplete = true;
        }
    } else {
        if (debugSegmentation) {
            System.out.printf("opResult %s\n", opResult);
        }
        setComplete = true;
    }
    if (setComplete) {
        RetrievalResultBase<V> prev;
        RetrievalResult<V> newResult;
        if (Log.levelMet(Level.FINE)) {
            Log.fine("setComplete: ", setComplete);
            Log.fine("dhtKey ", dhtKey);
        }
        newResult = new RetrievalResult<>(rawResult, nspoImpl.getValueDeserializer());
        prev = results.putIfAbsent(dhtKeyToKey.get(dhtKey), newResult);
        if (prev == null) {
            if (resultsReceived.incrementAndGet() >= size) {
                checkForCompletion();
            // FUTURE - this doesn't work for multi valued since we don't know how many we are getting...
            // For now, we ignore this since we aren't supporting multi-value yet
            }
        } else {
        /*
                RetrievalResultBase<V>  p;
                boolean					unique;
            	
                // FUTURE - handle mutual exclusion
                unique = true;
                p = prev;
                while (p.getNext() != null) {
                	p = p.getNext();
                	if (p.getCreationTime().equals(newResult.getCreationTime())) {
                		unique = false;
                		break;
                	}
                }
            	if (unique) {
            		p.setNext(newResult);
            	} else {
            		// Ignoring duplicate result
            	}
            	*/
        }
    }
    /*
        if (segmentsCreated != oldSegmentsCreated) {
            recomputeTimeoutState();
        }
        // FUTURE THINK ABOUT WHETHER WE NEED THIS
        */
    checkForUpdates();
}
Also used : OpResult(com.ms.silverking.cloud.dht.common.OpResult) DHTKey(com.ms.silverking.cloud.dht.common.DHTKey) RawRetrievalResult(com.ms.silverking.cloud.dht.common.RawRetrievalResult) ByteBuffer(java.nio.ByteBuffer) VersionConstraint(com.ms.silverking.cloud.dht.VersionConstraint) CorruptValueException(com.ms.silverking.cloud.dht.common.CorruptValueException)

Example 18 with OpResult

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

the class AsyncRetrievalOperationImpl method isFailure.

@Override
protected boolean isFailure(OpResult result) {
    switch(result) {
        case MULTIPLE:
            // multiple will only be called when checking completion of the entire operation
            // others will be called key-by-key also
            // filter no such value errors to allow for users to override
            // all other failures result in a failure
            NonExistenceResponse nonExistenceResponse;
            nonExistenceResponse = getNonExistenceResponse();
            for (OpResult _result : allResults) {
                if (_result.hasFailed(nonExistenceResponse)) {
                    return true;
                }
            }
            return false;
        case TIMEOUT:
            RetrievalOptions retrievalOptions;
            retrievalOptions = retrievalOperation.retrievalOptions();
            if (retrievalOptions.getWaitMode() == WaitMode.WAIT_FOR && ((WaitOptions) retrievalOptions).getTimeoutResponse() == TimeoutResponse.IGNORE) {
                return false;
            } else {
                return result.hasFailed();
            }
        default:
            return result.hasFailed(getNonExistenceResponse());
    }
}
Also used : RetrievalOptions(com.ms.silverking.cloud.dht.RetrievalOptions) InternalRetrievalOptions(com.ms.silverking.cloud.dht.common.InternalRetrievalOptions) OpResult(com.ms.silverking.cloud.dht.common.OpResult) WaitOptions(com.ms.silverking.cloud.dht.WaitOptions) NonExistenceResponse(com.ms.silverking.cloud.dht.NonExistenceResponse)

Example 19 with OpResult

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

the class ActivePutListeners method receivedPutResponse.

public <K, V> void receivedPutResponse(MessageGroup message) {
    if (enableMultipleOpsPerMessage) {
        long version;
        ConcurrentMap<DHTKey, WeakReference<ActiveKeyedOperationResultListener<OpResult>>> listenerMap;
        version = message.getBuffers()[0].getLong(0);
        // Log.warning("receivedPutResponse version ", version);
        listenerMap = activePutListeners.get(message.getUUID());
        if (listenerMap != null) {
            for (MessageGroupKeyOrdinalEntry entry : message.getKeyOrdinalIterator()) {
                WeakReference<ActiveKeyedOperationResultListener<OpResult>> listenerRef;
                ActiveKeyedOperationResultListener<OpResult> listener;
                if (debug) {
                    System.out.println(new SimpleKey(entry.getKey()));
                }
                listenerRef = listenerMap.get(entry.getKey());
                listener = listenerRef.get();
                if (listener != null) {
                    listener.resultReceived(entry.getKey(), EnumValues.opResult[entry.getOrdinal()]);
                } else {
                    Log.info("receivedPutResponse. null listener ref for: ", message.getUUID() + "\t" + entry.getKey());
                }
            }
        } else {
            // If we're receiving the error, then it's possible that we lost the
            // reference that was stored in the weak map.
            Log.warning("receivedPutResponse. No listenerMap for: ", message.getUUID());
        }
    } else {
        ActiveKeyedOperationResultListener<OpResult> listener;
        listener = activeOpListeners.get(message.getUUID());
        if (listener == null) {
            Log.info("receivedRetrievalResponse. No listener for uuid: ", message.getUUID());
        } else {
            for (MessageGroupKeyOrdinalEntry entry : message.getKeyOrdinalIterator()) {
                listener.resultReceived(entry.getKey(), EnumValues.opResult[entry.getOrdinal()]);
            }
        }
    }
}
Also used : MessageGroupKeyOrdinalEntry(com.ms.silverking.cloud.dht.net.MessageGroupKeyOrdinalEntry) WeakReference(java.lang.ref.WeakReference) OpResult(com.ms.silverking.cloud.dht.common.OpResult) DHTKey(com.ms.silverking.cloud.dht.common.DHTKey) SimpleKey(com.ms.silverking.cloud.dht.common.SimpleKey)

Example 20 with OpResult

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

the class AsyncKeyedOperationImpl method old_checkForCompletion.

protected void old_checkForCompletion() {
    // This method should only be called once in most cases,
    // so a lock here is OK. If it winds up being called multiple
    // times, then this approach is not appropriate.
    completionCheckLock.lock();
    try {
        // synchronized (this) {
        if (keyedNamespaceOperation.size() == 0) {
            setResult(OpResult.SUCCEEDED);
            return;
        } else {
            OpResult candidateResult;
            candidateResult = null;
            for (K key : keyedNamespaceOperation.getKeys()) {
                OpResult keyResult;
                keyResult = getOpResult(key);
                if (!keyResult.isComplete()) {
                    // early exit if any result is not complete
                    return;
                }
                if (candidateResult == null) {
                    candidateResult = keyResult;
                } else {
                    if (candidateResult != keyResult) {
                        candidateResult = OpResult.MULTIPLE;
                    }
                }
                if (isFailure(keyResult)) {
                    getFailureCauses().put(key, keyResult.toFailureCause());
                }
            }
            // we only arrive here if all results are complete
            setResult(candidateResult);
        }
    } finally {
        completionCheckLock.unlock();
    }
}
Also used : OpResult(com.ms.silverking.cloud.dht.common.OpResult)

Aggregations

OpResult (com.ms.silverking.cloud.dht.common.OpResult)32 DHTKey (com.ms.silverking.cloud.dht.common.DHTKey)7 IOException (java.io.IOException)5 ProtoOpResponseMessageGroup (com.ms.silverking.cloud.dht.net.ProtoOpResponseMessageGroup)4 Waiter (com.ms.silverking.cloud.dht.daemon.Waiter)3 ConvergencePoint (com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint)3 MessageGroupKeyOrdinalEntry (com.ms.silverking.cloud.dht.net.MessageGroupKeyOrdinalEntry)3 VersionConstraint (com.ms.silverking.cloud.dht.VersionConstraint)2 MessageGroupRetrievalResponseEntry (com.ms.silverking.cloud.dht.net.MessageGroupRetrievalResponseEntry)2 IPAndPort (com.ms.silverking.net.IPAndPort)2 WeakReference (java.lang.ref.WeakReference)2 ImmutableList (com.google.common.collect.ImmutableList)1 NamespaceVersionMode (com.ms.silverking.cloud.dht.NamespaceVersionMode)1 NonExistenceResponse (com.ms.silverking.cloud.dht.NonExistenceResponse)1 RetrievalOptions (com.ms.silverking.cloud.dht.RetrievalOptions)1 WaitOptions (com.ms.silverking.cloud.dht.WaitOptions)1 CorruptValueException (com.ms.silverking.cloud.dht.common.CorruptValueException)1 InternalRetrievalOptions (com.ms.silverking.cloud.dht.common.InternalRetrievalOptions)1 RawRetrievalResult (com.ms.silverking.cloud.dht.common.RawRetrievalResult)1 SimpleKey (com.ms.silverking.cloud.dht.common.SimpleKey)1