use of com.ms.silverking.cloud.dht.common.RawRetrievalResult 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;
}
}
use of com.ms.silverking.cloud.dht.common.RawRetrievalResult in project SilverKing by Morgan-Stanley.
the class FileSegmentUtil method displayValue.
private void displayValue(ByteBuffer value) {
RawRetrievalResult rawResult;
ByteBuffer aValue;
aValue = BufferUtil.convertToArrayBacked(value);
// System.out.printf("value: %s\n", StringUtil.byteBufferToHexString(value));
rawResult = new RawRetrievalResult(RetrievalType.VALUE_AND_META_DATA);
rawResult.setStoredValue_direct(aValue);
System.out.printf("ss: %x\n", CCSSUtil.getStorageState(rawResult.getCCSS()));
System.out.printf("%s\n", MetaDataTextUtil.toMetaDataString(rawResult.getMetaData(), true));
}
use of com.ms.silverking.cloud.dht.common.RawRetrievalResult 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();
}
use of com.ms.silverking.cloud.dht.common.RawRetrievalResult in project SilverKing by Morgan-Stanley.
the class AsyncRetrievalOperationImpl method reassembledResultReceived.
public void reassembledResultReceived(DHTKey dhtKey, SegmentedRetrievalResult<V> segmentedRetrievalResult) {
RawRetrievalResult rawResult;
if (false) {
System.out.printf("reassembledResultReceived %s %s\n", dhtKey, segmentedRetrievalResult);
}
results.putIfAbsent(dhtKeyToKey.get(dhtKey), segmentedRetrievalResult);
if (resultsReceived.incrementAndGet() >= size) {
// System.out.println("checkForCompletion");
checkForCompletion();
} else {
// System.out.printf("%d < %d\n", resultsReceived.incrementAndGet(), size);
}
}
use of com.ms.silverking.cloud.dht.common.RawRetrievalResult in project SilverKing by Morgan-Stanley.
the class SegmentedRetrievalValue method translateRawResult.
// deprecated
private ByteBuffer translateRawResult(ByteBuffer rawValue) {
RawRetrievalResult rawResult;
rawResult = new RawRetrievalResult(RetrievalType.VALUE);
rawResult.setStoredValue_direct(rawValue);
return rawResult.getValue();
}
Aggregations