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);
}
}
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
}
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;
}
}
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();
}
}
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
}
}
Aggregations