Search in sources :

Example 1 with MessageGroupKeyOrdinalEntry

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

Example 2 with MessageGroupKeyOrdinalEntry

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);
    }
}
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)

Example 3 with MessageGroupKeyOrdinalEntry

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()]);
            }
        }
    }
}
Also used : MessageGroupKeyOrdinalEntry(com.ms.silverking.cloud.dht.net.MessageGroupKeyOrdinalEntry) WeakReference(java.lang.ref.WeakReference) OpResult(com.ms.silverking.cloud.dht.common.OpResult) DHTKey(com.ms.silverking.cloud.dht.common.DHTKey) SimpleKey(com.ms.silverking.cloud.dht.common.SimpleKey)

Example 4 with MessageGroupKeyOrdinalEntry

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;
}
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)

Example 5 with MessageGroupKeyOrdinalEntry

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);
    }
}
Also used : MessageGroupKeyOrdinalEntry(com.ms.silverking.cloud.dht.net.MessageGroupKeyOrdinalEntry) PutCommunicator(com.ms.silverking.cloud.dht.daemon.storage.protocol.PutCommunicator) DHTKey(com.ms.silverking.cloud.dht.common.DHTKey) PutOperationContainer(com.ms.silverking.cloud.dht.daemon.storage.protocol.PutOperationContainer) StorageValueAndParameters(com.ms.silverking.cloud.dht.daemon.storage.StorageValueAndParameters) MessageGroupPutEntry(com.ms.silverking.cloud.dht.net.MessageGroupPutEntry)

Aggregations

MessageGroupKeyOrdinalEntry (com.ms.silverking.cloud.dht.net.MessageGroupKeyOrdinalEntry)6 DHTKey (com.ms.silverking.cloud.dht.common.DHTKey)4 OpResult (com.ms.silverking.cloud.dht.common.OpResult)3 PutCommunicator (com.ms.silverking.cloud.dht.daemon.storage.protocol.PutCommunicator)2 IPAndPort (com.ms.silverking.net.IPAndPort)2 SimpleKey (com.ms.silverking.cloud.dht.common.SimpleKey)1 Waiter (com.ms.silverking.cloud.dht.daemon.Waiter)1 StorageValueAndParameters (com.ms.silverking.cloud.dht.daemon.storage.StorageValueAndParameters)1 PutOperationContainer (com.ms.silverking.cloud.dht.daemon.storage.protocol.PutOperationContainer)1 MessageGroupPutEntry (com.ms.silverking.cloud.dht.net.MessageGroupPutEntry)1 WeakReference (java.lang.ref.WeakReference)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1