Search in sources :

Example 6 with RetrievalOptions

use of com.ms.silverking.cloud.dht.RetrievalOptions in project SilverKing by Morgan-Stanley.

the class ClientTool method _doRetrieve.

private Object _doRetrieve(ClientOptions options, SynchronousNamespacePerspective<String, byte[]> syncNSP, Stopwatch sw, RetrievalType retrievalType, WaitMode waitMode) throws OperationException, IOException {
    try {
        SynchronousNamespacePerspective<String, byte[]> ns;
        RetrievalOptions retrievalOptions;
        StoredValue<byte[]> storedValue;
        VersionConstraint vc;
        if (options.maxVersion > 0) {
            // if (options.minVersion >= 0 && options.maxVersion > 0) {
            vc = new VersionConstraint(Long.MIN_VALUE, options.maxVersion, VersionConstraint.Mode.GREATEST);
        // vc = new VersionConstraint(options.minVersion, options.maxVersion, Mode.NEWEST);
        } else {
            vc = VersionConstraint.defaultConstraint;
        }
        retrievalOptions = OptionsHelper.newRetrievalOptions(retrievalType, waitMode, vc);
        Log.warning(retrievalOptions);
        Log.warning("Getting value");
        storedValue = null;
        if (options.action == Action.MultiGet) {
            Set<String> keys;
            Map<String, ? extends StoredValue<byte[]>> storedValues;
            keys = ImmutableSet.copyOf(options.key.split(multiKeyDelimiter));
            storedValues = null;
            sw.reset();
            for (int i = 0; i < options.reps; i++) {
                // System.out.printf("Calling retrieve %d\n", i);
                storedValues = syncNSP.retrieve(keys, retrievalOptions);
            // System.out.printf("Done retrieve %d\n", i);
            }
            sw.stop();
            return storedValues;
        } else {
            sw.reset();
            for (int i = 0; i < options.reps; i++) {
                // System.out.printf("Calling retrieve %d\n", i);
                storedValue = syncNSP.retrieve(options.key, retrievalOptions);
            // System.out.printf("Done retrieve %d\n", i);
            }
            sw.stop();
            return storedValue;
        }
    } catch (RetrievalException re) {
        displayRetrievalExceptionDetails(re);
        throw re;
    }
}
Also used : VersionConstraint(com.ms.silverking.cloud.dht.VersionConstraint) RetrievalOptions(com.ms.silverking.cloud.dht.RetrievalOptions) RetrievalException(com.ms.silverking.cloud.dht.client.RetrievalException) VersionConstraint(com.ms.silverking.cloud.dht.VersionConstraint)

Example 7 with RetrievalOptions

use of com.ms.silverking.cloud.dht.RetrievalOptions in project SilverKing by Morgan-Stanley.

the class AsyncRetrievalOperationImpl method isFailure.

@Override
protected boolean isFailure(OpResult result) {
    switch(result) {
        case MULTIPLE:
            // multiple will only be called when checking completion of the entire operation
            // others will be called key-by-key also
            // filter no such value errors to allow for users to override
            // all other failures result in a failure
            NonExistenceResponse nonExistenceResponse;
            nonExistenceResponse = getNonExistenceResponse();
            for (OpResult _result : allResults) {
                if (_result.hasFailed(nonExistenceResponse)) {
                    return true;
                }
            }
            return false;
        case TIMEOUT:
            RetrievalOptions retrievalOptions;
            retrievalOptions = retrievalOperation.retrievalOptions();
            if (retrievalOptions.getWaitMode() == WaitMode.WAIT_FOR && ((WaitOptions) retrievalOptions).getTimeoutResponse() == TimeoutResponse.IGNORE) {
                return false;
            } else {
                return result.hasFailed();
            }
        default:
            return result.hasFailed(getNonExistenceResponse());
    }
}
Also used : RetrievalOptions(com.ms.silverking.cloud.dht.RetrievalOptions) InternalRetrievalOptions(com.ms.silverking.cloud.dht.common.InternalRetrievalOptions) OpResult(com.ms.silverking.cloud.dht.common.OpResult) WaitOptions(com.ms.silverking.cloud.dht.WaitOptions) NonExistenceResponse(com.ms.silverking.cloud.dht.NonExistenceResponse)

Example 8 with RetrievalOptions

use of com.ms.silverking.cloud.dht.RetrievalOptions in project SilverKing by Morgan-Stanley.

the class DebugKey method replicaContainsKey.

private boolean replicaContainsKey(IPAndPort replica, String key) throws ClientException {
    DHTSession dhtSession;
    SynchronousNamespacePerspective<String, byte[]> nsp;
    RetrievalOptions ro;
    StoredValue<byte[]> storedValue;
    dhtSession = dhtClient.openSession(new SessionOptions(gc, replica.getIPAsString()));
    nsp = dhtSession.openSyncNamespacePerspective(namespace, String.class, byte[].class);
    ro = nsp.getNamespace().getOptions().getDefaultGetOptions();
    ro = ro.retrievalType(RetrievalType.META_DATA);
    ro = ro.forwardingMode(ForwardingMode.DO_NOT_FORWARD);
    ro = ro.nonExistenceResponse(NonExistenceResponse.NULL_VALUE);
    storedValue = nsp.retrieve(key, ro);
    nsp.close();
    dhtSession.close();
    if (storedValue == null) {
        return false;
    } else {
        // out.println(storedValue.getMetaData());
        return true;
    }
}
Also used : RetrievalOptions(com.ms.silverking.cloud.dht.RetrievalOptions) SessionOptions(com.ms.silverking.cloud.dht.SessionOptions) DHTSession(com.ms.silverking.cloud.dht.client.DHTSession)

Example 9 with RetrievalOptions

use of com.ms.silverking.cloud.dht.RetrievalOptions in project SilverKing by Morgan-Stanley.

the class ConvergenceController2 method incomingChecksumTree.

// FUTURE - ENSURE THAT NO CONVERGENCE CODE USES THE RECEIVE THREADS TO DO WORK
// USE A WORKER
private void incomingChecksumTree(UUIDBase incomingUUID, ConvergencePoint cp, ChecksumNode remoteTree, MessageGroupConnection connection) {
    ChecksumNode localTree;
    MatchResult matchResult;
    Set<DHTKey> keysToFetch;
    List<DHTKey> keysToFetchList;
    outstandingChecksumTreeRequests.remove(incomingUUID);
    checkQueuedChecksumTreeRequests();
    if (remoteTree == null) {
        checkForCompletion();
        return;
    }
    localTree = checksumTreeServer.getRegionChecksumTree_Local(cp, remoteTree.getRegion(), new LongInterval(Long.MIN_VALUE, cp.getDataVersion()));
    if (verbose) {
        Log.warningAsyncf("incomingChecksumTree %s", incomingUUID);
    }
    if (debug) {
        Log.warningAsyncf("incomingChecksumTree %x\t%s\t%s\t%s", ns, cp, remoteTree.getRegion(), incomingUUID);
        Log.warningAsyncf(remoteTree + "\n\nlocalTree\n" + localTree);
    }
    if (localTree == null) {
        checkForCompletion();
        return;
    }
    try {
        matchResult = TreeMatcher.match(localTree, remoteTree);
    } catch (RuntimeException re) {
        System.err.println(localTree);
        System.err.println();
        System.err.println(connection);
        System.err.println(remoteTree);
        throw re;
    }
    if (debug) {
        Log.warningAsyncf("%s", matchResult);
    }
    keysToFetch = new HashSet<>();
    for (KeyAndVersionChecksum kvc : matchResult.getDestNotInSource()) {
        if (debug) {
            System.out.printf("Adding destNotInSource %s\n", kvc.getKey());
        }
        keysToFetch.add(kvc.getKey());
    }
    for (KeyAndVersionChecksum kvc : matchResult.getChecksumMismatch()) {
        if (debug) {
            System.out.printf("Adding checksumMismatch %s\n", kvc.getKey());
        }
        keysToFetch.add(kvc.getKey());
    }
    /*
        Queue<DHTKey>   keysToFetchQueue;
        
        keysToFetchQueue = keysToFetchMap.get(cp);
        if (keysToFetchQueue == null) {
            Queue<DHTKey>   prev;
            
            keysToFetchQueue = new ConcurrentLinkedQueue<>();
            prev = keysToFetchMap.putIfAbsent(cp, keysToFetchQueue);
            if (prev != null) {
                keysToFetchQueue = prev;
            }
        }
        keysToFetchQueue.addAll(keysToFetch);
        */
    keysToFetchList = new LinkedList<>(keysToFetch);
    while (keysToFetchList.size() > 0) {
        Set<DHTKey> batchKeys;
        int batchSize;
        RetrievalOptions retrievalOptions;
        UUIDBase uuid;
        // MessageGroup        mg;
        SyncRetrievalRequest srr;
        // batchKeys = new HashSet<>(retrievalBatchSize);
        batchKeys = new ConcurrentSkipListSet<DHTKey>();
        batchSize = 0;
        while (keysToFetchList.size() > 0 && batchSize < retrievalBatchSize) {
            batchKeys.add(keysToFetchList.remove(0));
            ++batchSize;
        }
        // FUTURE - could consider sending SourceNotInDest
        retrievalOptions = OptionsHelper.newRetrievalOptions(RetrievalType.VALUE_AND_META_DATA, WaitMode.GET, checksumVersionConstraint(cp.getDataVersion()));
        // new VersionConstraint(Long.MIN_VALUE + 1, version, Mode.NEWEST));
        uuid = UUIDBase.random();
        srr = new SyncRetrievalRequest(uuid, batchKeys, cp.getDataVersion(), connection);
        outstandingSyncRetrievalRequests.put(uuid, srr);
        convergenceControllers.put(uuid, this);
        sendSyncRetrievalRequest(srr);
    // mg = new ProtoRetrievalMessageGroup(uuid, ns, new InternalRetrievalOptions(retrievalOptions),
    // mgBase.getMyID(), batchKeys, convergenceRelativeDeadlineMillis).toMessageGroup();
    // outgoingMessages.add(new OutgoingMessage(mg, new IPAndPort(connection.getRemoteSocketAddress())));
    /*
            try {
                connection.sendAsynchronous(mg, mg.getDeadlineAbsMillis(absMillisTimeSource));
            } catch (IOException ioe) {
                Log.logErrorWarning(ioe);
            }
            */
    // if (keysToFetchList.size() > 0) {
    // ThreadUtil.sleep(5);
    // }
    }
    checkMGQueue();
    if (debug) {
        Log.warningAsyncf("no more keysToFetch");
    }
    checkForCompletion();
}
Also used : DHTKey(com.ms.silverking.cloud.dht.common.DHTKey) UUIDBase(com.ms.silverking.id.UUIDBase) VersionConstraint(com.ms.silverking.cloud.dht.VersionConstraint) KeyAndVersionChecksum(com.ms.silverking.cloud.dht.daemon.storage.KeyAndVersionChecksum) InternalRetrievalOptions(com.ms.silverking.cloud.dht.common.InternalRetrievalOptions) RetrievalOptions(com.ms.silverking.cloud.dht.RetrievalOptions) LongInterval(com.ms.silverking.numeric.LongInterval)

Example 10 with RetrievalOptions

use of com.ms.silverking.cloud.dht.RetrievalOptions in project SilverKing by Morgan-Stanley.

the class ConvergenceController2 method sendSyncRetrievalRequest.

private void sendSyncRetrievalRequest(SyncRetrievalRequest srr) {
    MessageGroup mg;
    RetrievalOptions retrievalOptions;
    retrievalOptions = OptionsHelper.newRetrievalOptions(RetrievalType.VALUE_AND_META_DATA, WaitMode.GET, checksumVersionConstraint(srr.dataVersion));
    mg = new ProtoRetrievalMessageGroup(srr.uuid, ns, new InternalRetrievalOptions(retrievalOptions), mgBase.getMyID(), srr.outstandingKeys, convergenceRelativeDeadlineMillis).toMessageGroup();
    outgoingMessages.add(new OutgoingMessage(mg, new IPAndPort(srr.connection.getRemoteSocketAddress())));
}
Also used : IPAndPort(com.ms.silverking.net.IPAndPort) InternalRetrievalOptions(com.ms.silverking.cloud.dht.common.InternalRetrievalOptions) RetrievalOptions(com.ms.silverking.cloud.dht.RetrievalOptions) ProtoChecksumTreeRequestMessageGroup(com.ms.silverking.cloud.dht.net.ProtoChecksumTreeRequestMessageGroup) MessageGroup(com.ms.silverking.cloud.dht.net.MessageGroup) ProtoRetrievalMessageGroup(com.ms.silverking.cloud.dht.net.ProtoRetrievalMessageGroup) ProtoRetrievalMessageGroup(com.ms.silverking.cloud.dht.net.ProtoRetrievalMessageGroup) InternalRetrievalOptions(com.ms.silverking.cloud.dht.common.InternalRetrievalOptions)

Aggregations

RetrievalOptions (com.ms.silverking.cloud.dht.RetrievalOptions)11 InternalRetrievalOptions (com.ms.silverking.cloud.dht.common.InternalRetrievalOptions)6 VersionConstraint (com.ms.silverking.cloud.dht.VersionConstraint)4 RetrievalException (com.ms.silverking.cloud.dht.client.RetrievalException)2 DHTKey (com.ms.silverking.cloud.dht.common.DHTKey)2 KeyAndVersionChecksum (com.ms.silverking.cloud.dht.daemon.storage.KeyAndVersionChecksum)2 MessageGroup (com.ms.silverking.cloud.dht.net.MessageGroup)2 ProtoChecksumTreeRequestMessageGroup (com.ms.silverking.cloud.dht.net.ProtoChecksumTreeRequestMessageGroup)2 ProtoRetrievalMessageGroup (com.ms.silverking.cloud.dht.net.ProtoRetrievalMessageGroup)2 SSRetrievalOptions (com.ms.silverking.cloud.dht.serverside.SSRetrievalOptions)2 UUIDBase (com.ms.silverking.id.UUIDBase)2 LongInterval (com.ms.silverking.numeric.LongInterval)2 NonExistenceResponse (com.ms.silverking.cloud.dht.NonExistenceResponse)1 SessionOptions (com.ms.silverking.cloud.dht.SessionOptions)1 WaitOptions (com.ms.silverking.cloud.dht.WaitOptions)1 DHTSession (com.ms.silverking.cloud.dht.client.DHTSession)1 StoredValue (com.ms.silverking.cloud.dht.client.StoredValue)1 OpResult (com.ms.silverking.cloud.dht.common.OpResult)1 ConvergencePoint (com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint)1 IPAndPort (com.ms.silverking.net.IPAndPort)1