Search in sources :

Example 1 with Waiter

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

Example 2 with Waiter

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;
    }
}
Also used : Waiter(com.ms.silverking.cloud.dht.daemon.Waiter) ByteBuffer(java.nio.ByteBuffer)

Example 3 with Waiter

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

Example 4 with Waiter

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

Aggregations

Waiter (com.ms.silverking.cloud.dht.daemon.Waiter)4 OpResult (com.ms.silverking.cloud.dht.common.OpResult)3 NamespaceVersionMode (com.ms.silverking.cloud.dht.NamespaceVersionMode)1 DHTKey (com.ms.silverking.cloud.dht.common.DHTKey)1 MessageGroupKeyOrdinalEntry (com.ms.silverking.cloud.dht.net.MessageGroupKeyOrdinalEntry)1 ByteBuffer (java.nio.ByteBuffer)1