use of com.ms.silverking.cloud.dht.net.MessageGroupKeyOrdinalEntry in project SilverKing by Morgan-Stanley.
the class SingleWriterConsistentWrite method quorumTransition.
private void quorumTransition(DHTKey key, Collection<IPAndPort> replicas, TwoPhaseStorageState nextState, OpResult update, PutVirtualCommunicator pvComm) {
if (debug) {
System.out.printf("quorumTransition %s %s %s\n", KeyUtil.keyToString(key), nextState, update);
}
for (IPAndPort replica : replicas) {
MessageGroupKeyOrdinalEntry entry;
if (debug) {
System.out.printf("quorumTransition replica %s %s\n", KeyUtil.keyToString(key), replica);
}
entry = new MessageGroupKeyOrdinalEntry(key, (byte) nextState.ordinal());
// FUTURE - Consider faster implementation for local case. For now, we handle
// local with remote.
// if (pvComm.isLocalReplica(replica)) {
// update(key, replica, (byte)nextState.ordinal(), update, pvComm);
// } else {
pvComm.forwardUpdateEntry(replica, entry);
// }
}
if (debug) {
System.out.printf("out quorumTransition %s %s %s\n", KeyUtil.keyToString(key), nextState, update);
}
}
use of com.ms.silverking.cloud.dht.net.MessageGroupKeyOrdinalEntry in project SilverKing by Morgan-Stanley.
the class ActiveProxyPut method localOp_putupdate.
protected void localOp_putupdate(List<? extends DHTKey> _entries, PutCommunicator pComm) {
List<OpResult> results;
int _entriesSize;
results = getStorage().putUpdate(getContext(), _entries, getVersion());
_entriesSize = _entries.size();
if (results.size() != _entriesSize) {
throw new RuntimeException("panic");
}
for (int i = 0; i < _entriesSize; i++) {
DHTKey _entry;
MessageGroupKeyOrdinalEntry mgkoEntry;
OpResult result;
_entry = _entries.get(i);
if (debug) {
System.out.printf("localOp_putupdate: %s\n", _entry);
}
mgkoEntry = (MessageGroupKeyOrdinalEntry) _entry;
result = results.get(i);
storageOperation.localUpdate(_entry, mgkoEntry.getOrdinal(), result, pComm);
}
}
use of com.ms.silverking.cloud.dht.net.MessageGroupKeyOrdinalEntry in project SilverKing by Morgan-Stanley.
the class ActivePutListeners method receivedPutResponse.
public <K, V> void receivedPutResponse(MessageGroup message) {
if (enableMultipleOpsPerMessage) {
long version;
ConcurrentMap<DHTKey, WeakReference<ActiveKeyedOperationResultListener<OpResult>>> listenerMap;
version = message.getBuffers()[0].getLong(0);
// Log.warning("receivedPutResponse version ", version);
listenerMap = activePutListeners.get(message.getUUID());
if (listenerMap != null) {
for (MessageGroupKeyOrdinalEntry entry : message.getKeyOrdinalIterator()) {
WeakReference<ActiveKeyedOperationResultListener<OpResult>> listenerRef;
ActiveKeyedOperationResultListener<OpResult> listener;
if (debug) {
System.out.println(new SimpleKey(entry.getKey()));
}
listenerRef = listenerMap.get(entry.getKey());
listener = listenerRef.get();
if (listener != null) {
listener.resultReceived(entry.getKey(), EnumValues.opResult[entry.getOrdinal()]);
} else {
Log.info("receivedPutResponse. null listener ref for: ", message.getUUID() + "\t" + entry.getKey());
}
}
} else {
// If we're receiving the error, then it's possible that we lost the
// reference that was stored in the weak map.
Log.warning("receivedPutResponse. No listenerMap for: ", message.getUUID());
}
} else {
ActiveKeyedOperationResultListener<OpResult> listener;
listener = activeOpListeners.get(message.getUUID());
if (listener == null) {
Log.info("receivedRetrievalResponse. No listener for uuid: ", message.getUUID());
} else {
for (MessageGroupKeyOrdinalEntry entry : message.getKeyOrdinalIterator()) {
listener.resultReceived(entry.getKey(), EnumValues.opResult[entry.getOrdinal()]);
}
}
}
}
use of com.ms.silverking.cloud.dht.net.MessageGroupKeyOrdinalEntry in project SilverKing by Morgan-Stanley.
the class NamespaceStore method putUpdate.
public List<OpResult> putUpdate(List<? extends DHTKey> updates, long version) {
List<OpResult> results;
Set<Waiter> triggeredWaitFors;
triggeredWaitFors = null;
results = new ArrayList<>(updates.size());
writeLock.lock();
try {
for (DHTKey update : updates) {
MessageGroupKeyOrdinalEntry entry;
OpResult result;
entry = (MessageGroupKeyOrdinalEntry) update;
result = _putUpdate(entry, version, entry.getOrdinal());
results.add(result);
if (result == OpResult.SUCCEEDED && StorageProtocolUtil.storageStateValidForRead(nsOptions.getConsistencyProtocol(), entry.getOrdinal())) {
Set<Waiter> _triggeredWaitFors;
_triggeredWaitFors = checkPendingWaitFors(update);
if (_triggeredWaitFors != null) {
if (triggeredWaitFors == null) {
triggeredWaitFors = new HashSet<>();
}
triggeredWaitFors.addAll(_triggeredWaitFors);
}
}
}
} finally {
writeLock.unlock();
}
if (triggeredWaitFors != null) {
handleTriggeredWaitFors(triggeredWaitFors);
}
return results;
}
use of com.ms.silverking.cloud.dht.net.MessageGroupKeyOrdinalEntry in project SilverKing by Morgan-Stanley.
the class ActiveProxyPut method localOp.
protected void localOp(List<? extends DHTKey> _entries, OpCommunicator<MessageGroupKeyEntry, PutResult> comm) {
boolean useUpdate;
PutCommunicator pComm;
pComm = (PutCommunicator) comm;
useUpdate = _entries.size() > 0 && (_entries.get(0) instanceof MessageGroupKeyOrdinalEntry);
if (!useUpdate) {
List<StorageValueAndParameters> values;
long creationTime;
creationTime = SystemTimeUtil.systemTimeSource.absTimeNanos();
values = new ArrayList<>(_entries.size());
for (DHTKey _entry : _entries) {
values.add(new StorageValueAndParameters((MessageGroupPutEntry) _entry, (PutOperationContainer) this, creationTime));
if (debug) {
System.out.printf("localOp: %s\n", _entry);
}
// Log.fine(entry);
}
getStorage().put(getContext(), values, getUserData(), pComm);
if (forwardingMode.forwards()) {
for (DHTKey _entry : _entries) {
storageOperation.localUpdate(_entry, StorageProtocolUtil.initialStorageStateOrdinal, OpResult.SUCCEEDED, pComm);
}
}
} else {
localOp_putupdate(_entries, pComm);
}
}
Aggregations