use of com.ms.silverking.cloud.dht.net.ProtoPutMessageGroup.ValueAdditionResult 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;
}
Aggregations