Search in sources :

Example 1 with CorruptValueException

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

the class StorageValueAndParameters method createSVP.

public static StorageValueAndParameters createSVP(MessageGroupRetrievalResponseEntry entry) {
    try {
        RawRetrievalResult rawRetrievalResult;
        if (entry.getValue() == null) {
            Log.warning("createSVP Couldn't find value for: ", entry);
            return null;
        } else {
            if (debug) {
                System.out.printf("Found %s\n", entry);
            }
        }
        rawRetrievalResult = new RawRetrievalResult(RetrievalType.VALUE_AND_META_DATA);
        rawRetrievalResult.setStoredValue(entry.getValue(), true, false, null);
        StorageValueAndParameters valueAndParameters;
        ByteBuffer rawValueBuffer;
        ByteBuffer valueBuffer;
        // valueBuffer = (ByteBuffer)entry.getValue().duplicate().limit(rawRetrievalResult.getStoredLength());
        rawValueBuffer = entry.getValue();
        if (debug) {
            System.out.printf("key %s buf %s storedLength %d uncompressedLength %d compressedLength %d\n", entry, rawValueBuffer, rawRetrievalResult.getStoredLength(), rawRetrievalResult.getUncompressedLength(), MetaDataUtil.getCompressedLength(rawValueBuffer, 0));
            System.out.printf("rawValueBuffer %s\n", StringUtil.byteBufferToHexString(rawValueBuffer));
        }
        valueBuffer = (ByteBuffer) rawValueBuffer.duplicate().position(rawValueBuffer.position() + MetaDataUtil.getDataOffset(rawValueBuffer, 0));
        // FUTURE - consider making the nsstore allow a put that just accepts the buffer as is
        // to improve performance
        valueAndParameters = new StorageValueAndParameters(entry, valueBuffer, rawRetrievalResult.getVersion(), rawRetrievalResult.getUncompressedLength(), MetaDataUtil.getCompressedLength(rawValueBuffer, 0), rawRetrievalResult.getCCSS(), rawRetrievalResult.getChecksum(), rawRetrievalResult.getCreator().getBytes(), rawRetrievalResult.getCreationTimeRaw());
        return valueAndParameters;
    } catch (CorruptValueException cve) {
        Log.warning("Corrupt value in convergence: ", entry);
        return null;
    }
}
Also used : RawRetrievalResult(com.ms.silverking.cloud.dht.common.RawRetrievalResult) ByteBuffer(java.nio.ByteBuffer) CorruptValueException(com.ms.silverking.cloud.dht.common.CorruptValueException)

Example 2 with CorruptValueException

use of com.ms.silverking.cloud.dht.common.CorruptValueException 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 3 with CorruptValueException

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

the class ConvergenceController2 method incomingSyncRetrievalResponse.

// Currently unused
private void incomingSyncRetrievalResponse(MessageGroupRetrievalResponseEntry entry) {
    try {
        RawRetrievalResult rawRetrievalResult;
        if (entry.getValue() == null) {
            Log.warning("Couldn't find value for: ", entry);
            return;
        } else {
            if (debug) {
                System.out.printf("Found %s\n", entry);
            }
        }
        rawRetrievalResult = new RawRetrievalResult(RetrievalType.VALUE_AND_META_DATA);
        rawRetrievalResult.setStoredValue(entry.getValue(), true, false, null);
        StorageValueAndParameters valueAndParameters;
        ByteBuffer rawValueBuffer;
        ByteBuffer valueBuffer;
        // valueBuffer = (ByteBuffer)entry.getValue().duplicate().limit(rawRetrievalResult.getStoredLength());
        rawValueBuffer = entry.getValue();
        if (debug && true) {
            System.out.printf("key %s buf %s storedLength %d uncompressedLength %d compressedLength %d\n", entry, rawValueBuffer, rawRetrievalResult.getStoredLength(), rawRetrievalResult.getUncompressedLength(), MetaDataUtil.getCompressedLength(rawValueBuffer, 0));
            System.out.printf("rawValueBuffer %s\n", StringUtil.byteBufferToHexString(rawValueBuffer));
        }
        valueBuffer = (ByteBuffer) rawValueBuffer.duplicate().position(rawValueBuffer.position() + MetaDataUtil.getDataOffset(rawValueBuffer, 0));
        // FUTURE - consider making the nsstore allow a put that just accepts the buffer as is
        // to improve performance
        valueAndParameters = new StorageValueAndParameters(entry, valueBuffer, rawRetrievalResult.getVersion(), rawRetrievalResult.getUncompressedLength(), MetaDataUtil.getCompressedLength(rawValueBuffer, 0), rawRetrievalResult.getCCSS(), rawRetrievalResult.getChecksum(), rawRetrievalResult.getCreator().getBytes(), rawRetrievalResult.getCreationTimeRaw());
        nsStore.put(ImmutableList.of(valueAndParameters), emptyUserData, this);
    // FUTURE - preserve user data
    } catch (CorruptValueException cve) {
        Log.logErrorWarning(cve);
    // FUTURE - let this replica know that it's bad
    }
}
Also used : RawRetrievalResult(com.ms.silverking.cloud.dht.common.RawRetrievalResult) StorageValueAndParameters(com.ms.silverking.cloud.dht.daemon.storage.StorageValueAndParameters) ByteBuffer(java.nio.ByteBuffer) CorruptValueException(com.ms.silverking.cloud.dht.common.CorruptValueException)

Aggregations

CorruptValueException (com.ms.silverking.cloud.dht.common.CorruptValueException)3 RawRetrievalResult (com.ms.silverking.cloud.dht.common.RawRetrievalResult)3 ByteBuffer (java.nio.ByteBuffer)3 VersionConstraint (com.ms.silverking.cloud.dht.VersionConstraint)1 DHTKey (com.ms.silverking.cloud.dht.common.DHTKey)1 OpResult (com.ms.silverking.cloud.dht.common.OpResult)1 StorageValueAndParameters (com.ms.silverking.cloud.dht.daemon.storage.StorageValueAndParameters)1