use of com.ms.silverking.cloud.dht.common.OpResult in project SilverKing by Morgan-Stanley.
the class AsyncKeyedOperationImpl method checkForCompletion.
protected void checkForCompletion() {
// This method should only be called once in most cases,
// so a lock here is OK. If it winds up being called multiple
// times, then this approach is not appropriate.
completionCheckLock.lock();
try {
// synchronized (this) {
if (keyedNamespaceOperation.size() == 0) {
setResult(OpResult.SUCCEEDED);
return;
} else {
EnumSet<OpResult> candidateResults;
candidateResults = null;
for (K key : keyedNamespaceOperation.getKeys()) {
OpResult keyResult;
keyResult = getOpResult(key);
if (!keyResult.isComplete()) {
// early exit if any result is not complete
return;
}
if (candidateResults == null) {
candidateResults = EnumSet.of(keyResult);
} else {
candidateResults.add(keyResult);
}
if (isFailure(keyResult)) {
getFailureCauses().put(key, keyResult.toFailureCause(getNonExistenceResponse()));
}
}
// we only arrive here if all results are complete
if (candidateResults != null && candidateResults.size() > 0) {
setResult(candidateResults);
}
}
} finally {
completionCheckLock.unlock();
}
}
use of com.ms.silverking.cloud.dht.common.OpResult in project SilverKing by Morgan-Stanley.
the class KeyedOpGroup method update.
void update(DHTKey key, OpResult result) {
OpResult oldResult;
oldResult = results.put(key, result);
if (oldResult == null) {
throw new RuntimeException("Unexpected key for update");
} else {
if (oldResult.supercedes(result)) {
// Note - this accounting is a little loose since
// while a complete result has been removed,
// it's possible for multiple final results to come in here,
// so the minIncomplete counter may be too low.
// In such a case, we wind up with an arbitrary one
// of the multiple complete results.
results.put(key, oldResult);
} else {
if (result.isComplete()) {
if (minIncomplete.decrementAndGet() <= 0) {
checkForCompletion();
}
}
}
}
}
use of com.ms.silverking.cloud.dht.common.OpResult in project SilverKing by Morgan-Stanley.
the class SegmentedPutValue method checkForCompletion.
@Override
protected void checkForCompletion() {
OpResult result;
result = OpResult.SUCCEEDED;
for (DHTKey key : keys) {
if (getResult(key) != OpResult.SUCCEEDED) {
result = getResult(key);
}
}
if (getResult(relayKey) != OpResult.SUCCEEDED) {
result = getResult(relayKey);
}
parent.resultReceived(relayKey, result);
}
use of com.ms.silverking.cloud.dht.common.OpResult in project SilverKing by Morgan-Stanley.
the class StorageEntrySingleState method getCurOpResult.
@Override
OpResult getCurOpResult() {
OpResult result;
result = OpResult.INCOMPLETE;
for (int i = 0; i < replicas.size(); i++) {
OpResult replicaResult;
replicaResult = replicaResults[i];
if (replicaResult.isComplete()) {
if (replicaResult.hasFailed()) {
if (result == OpResult.INCOMPLETE) {
result = replicaResult;
} else {
if (result != replicaResult) {
result = OpResult.MULTIPLE;
}
}
} else {
result = OpResult.SUCCEEDED;
}
}
}
return result;
}
use of com.ms.silverking.cloud.dht.common.OpResult in project SilverKing by Morgan-Stanley.
the class LooseConsistencyWrite method update.
@Override
public void update(DHTKey key, IPAndPort replica, byte storageState, OpResult update, PutVirtualCommunicator pvComm) {
// FIXME - reduce or eliminate locking here
synchronized (this) {
StorageEntrySingleState entryState;
if (debug) {
System.out.printf("replica %s\tupdate %s\n", replica, update);
}
entryState = getEntryState(key);
if (debug) {
System.out.printf("curOpResult %s\n", entryState.getCurOpResult());
}
if (entryState.getCurOpResult() == OpResult.INCOMPLETE) {
entryState.setReplicaResult(replica, update);
if (update.isComplete()) {
OpResult looseResult;
looseResult = entryState.getCurOpResult();
if (debug) {
System.out.printf("looseResult %s\n", looseResult);
}
if (looseResult.isComplete()) {
int _completeEntries;
pvComm.sendResult(key, looseResult);
_completeEntries = completeEntries.incrementAndGet();
if (_completeEntries >= numEntries) {
setOpResult(OpResult.SUCCEEDED);
}
}
if (debug) {
System.out.printf("completeEntries %d numEntries %d\n", completeEntries.get(), numEntries);
}
} else {
Log.warning("Unexpected incomplete update: ", update);
}
} else {
if (Log.levelMet(Level.FINE)) {
Log.fine("Update for non-incomplete: ", key + " " + replica + " " + update);
}
}
}
}
Aggregations