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