use of com.ms.silverking.cloud.dht.daemon.Waiter in project SilverKing by Morgan-Stanley.
the class NamespaceStore method put.
public void put(List<StorageValueAndParameters> values, byte[] userData, KeyedOpResultListener resultListener) {
Set<Waiter> triggeredWaitFors;
NamespaceVersionMode nsVersionMode;
boolean locked;
triggeredWaitFors = null;
nsVersionMode = nsOptions.getVersionMode();
// LWTThreadUtil.setBlocked();
writeLock.lock();
try {
// System.out.printf("NamespaceStore.put() group size: %d\n", values.size());
for (StorageValueAndParameters value : values) {
OpResult storageResult;
if (putTrigger != null) {
storageResult = putTrigger.put(this, value.getKey(), value.getValue(), new SSStorageParametersImpl(value, value.getValue().remaining()), userData, nsVersionMode);
} else {
storageResult = _put(value.getKey(), value.getValue(), value, userData, nsVersionMode);
}
// if (storageResult != OpResult.SUCCEEDED) Log.warningf("fail _put %s %s %d", KeyUtil.keyToString(value.getKey()), storageResult, value.getVersion()); // for debugging
resultListener.sendResult(value.getKey(), storageResult);
if (storageResult == OpResult.SUCCEEDED) {
Set<Waiter> _triggeredWaitFors;
_triggeredWaitFors = checkPendingWaitFors(value.getKey());
if (_triggeredWaitFors != null) {
if (triggeredWaitFors == null) {
triggeredWaitFors = new HashSet<>();
}
triggeredWaitFors.addAll(_triggeredWaitFors);
}
}
}
} finally {
writeLock.unlock();
// LWTThreadUtil.setNonBlocked();
}
if (triggeredWaitFors != null) {
handleTriggeredWaitFors(triggeredWaitFors);
}
}
use of com.ms.silverking.cloud.dht.daemon.Waiter in project SilverKing by Morgan-Stanley.
the class NamespaceStore method checkPendingWaitFors.
// write lock must be held
private Set<Waiter> checkPendingWaitFors(DHTKey key) {
if (debugWaitFor) {
System.out.println("checkPendingWaitFors");
System.out.printf("pendingWaitFors.size() %d\n", pendingWaitFors.size());
}
if (pendingWaitFors.size() > 0) {
Set<Waiter> triggeredWaiters;
Collection<PendingWaitFor> pendingWaitForCollection;
triggeredWaiters = null;
pendingWaitForCollection = pendingWaitFors.get(key);
if (pendingWaitForCollection != null) {
for (PendingWaitFor pendingWaitFor : pendingWaitForCollection) {
ByteBuffer result;
if (debugWaitFor) {
System.out.printf("pendingWaitFor %s options %s\n", pendingWaitFor, pendingWaitFor.getOptions());
}
result = _retrieve(key, pendingWaitFor.getOptions());
if (result != null) {
Waiter waiter;
// we have a result, now we need to send it back...
waiter = activeRetrievals.get(pendingWaitFor.getOpUUID());
if (waiter != null) {
if (triggeredWaiters == null) {
triggeredWaiters = new HashSet<>();
}
triggeredWaiters.add(waiter);
// waiter gets its own
if (debugWaitFor) {
System.out.printf("Triggering waiter for %s\n", pendingWaitFor.getOpUUID());
}
waiter.waitForTriggered(key, result.duplicate());
// Give the waiter the result of the waitfor.
// In addition, we pass back the triggered wait fors so that
// the waiter can send messages back when
// they have all been gathered.
} else {
if (debugWaitFor) {
System.out.printf("No waiter found for %s\n", pendingWaitFor.getOpUUID());
}
}
pendingWaitForCollection.remove(pendingWaitFor);
} else {
if (debugWaitFor) {
System.out.printf("No result found for %s\n", KeyUtil.keyToString(key));
}
}
}
} else {
if (debugWaitFor) {
System.out.println("pendingWaitForCollection not found");
}
}
return triggeredWaiters;
} else {
return null;
}
}
use of com.ms.silverking.cloud.dht.daemon.Waiter in project SilverKing by Morgan-Stanley.
the class NamespaceStore method putUpdate_.
public OpResult putUpdate_(DHTKey key, long version, byte storageState) {
OpResult result;
Set<Waiter> triggeredWaitFors;
if (debug) {
System.out.println("Single key putUpdate()");
}
triggeredWaitFors = null;
writeLock.lock();
try {
result = _putUpdate(key, version, storageState);
// if (result != OpResult.SUCCEEDED) Log.warningf("fail putUpdate %s %s %d", KeyUtil.keyToString(key), result, version); // for debugging
if (result == OpResult.SUCCEEDED && StorageProtocolUtil.storageStateValidForRead(nsOptions.getConsistencyProtocol(), storageState)) {
triggeredWaitFors = checkPendingWaitFors(key);
}
} finally {
writeLock.unlock();
}
if (triggeredWaitFors != null) {
handleTriggeredWaitFors(triggeredWaitFors);
}
return result;
}
use of com.ms.silverking.cloud.dht.daemon.Waiter 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;
}
Aggregations