Search in sources :

Example 21 with OpResult

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();
    }
}
Also used : OpResult(com.ms.silverking.cloud.dht.common.OpResult)

Example 22 with OpResult

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();
                }
            }
        }
    }
}
Also used : OpResult(com.ms.silverking.cloud.dht.common.OpResult)

Example 23 with OpResult

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);
}
Also used : OpResult(com.ms.silverking.cloud.dht.common.OpResult) DHTKey(com.ms.silverking.cloud.dht.common.DHTKey)

Example 24 with OpResult

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;
}
Also used : OpResult(com.ms.silverking.cloud.dht.common.OpResult)

Example 25 with OpResult

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);
            }
        }
    }
}
Also used : OpResult(com.ms.silverking.cloud.dht.common.OpResult)

Aggregations

OpResult (com.ms.silverking.cloud.dht.common.OpResult)32 DHTKey (com.ms.silverking.cloud.dht.common.DHTKey)7 IOException (java.io.IOException)5 ProtoOpResponseMessageGroup (com.ms.silverking.cloud.dht.net.ProtoOpResponseMessageGroup)4 Waiter (com.ms.silverking.cloud.dht.daemon.Waiter)3 ConvergencePoint (com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint)3 MessageGroupKeyOrdinalEntry (com.ms.silverking.cloud.dht.net.MessageGroupKeyOrdinalEntry)3 VersionConstraint (com.ms.silverking.cloud.dht.VersionConstraint)2 MessageGroupRetrievalResponseEntry (com.ms.silverking.cloud.dht.net.MessageGroupRetrievalResponseEntry)2 IPAndPort (com.ms.silverking.net.IPAndPort)2 WeakReference (java.lang.ref.WeakReference)2 ImmutableList (com.google.common.collect.ImmutableList)1 NamespaceVersionMode (com.ms.silverking.cloud.dht.NamespaceVersionMode)1 NonExistenceResponse (com.ms.silverking.cloud.dht.NonExistenceResponse)1 RetrievalOptions (com.ms.silverking.cloud.dht.RetrievalOptions)1 WaitOptions (com.ms.silverking.cloud.dht.WaitOptions)1 CorruptValueException (com.ms.silverking.cloud.dht.common.CorruptValueException)1 InternalRetrievalOptions (com.ms.silverking.cloud.dht.common.InternalRetrievalOptions)1 RawRetrievalResult (com.ms.silverking.cloud.dht.common.RawRetrievalResult)1 SimpleKey (com.ms.silverking.cloud.dht.common.SimpleKey)1