Search in sources :

Example 1 with SessionOptions

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

the class ClientTool method doAction.

public void doAction(ClientOptions options) throws Exception {
    DHTSession session;
    Action action;
    SynchronousNamespacePerspective<String, byte[]> syncNSP;
    Stopwatch sw;
    int outerReps;
    NamespacePerspectiveOptions<String, byte[]> nspOptions;
    // FUTURE - IMPLEMENT VALIDATION FLAG
    // DHTClient.setValidateChecksums(!options.noValidation);
    // note - server may be null
    session = dhtClient.openSession(new SessionOptions(SKGridConfiguration.parseFile(options.gridConfig), options.server));
    if (session == null) {
        throw new RuntimeException("null session");
    }
    if (options.action != Action.CreateNamespace) {
        Namespace ns;
        ns = session.getNamespace(options.namespace);
        nspOptions = ns.getDefaultNSPOptions(String.class, byte[].class);
        if (options.checksumType != null) {
            nspOptions = nspOptions.defaultPutOptions(session.getDefaultPutOptions().checksumType(options.checksumType));
        }
        syncNSP = ns.openSyncPerspective(nspOptions);
    } else {
        syncNSP = null;
    }
    // syncNSP = session.openSyncNamespacePerspective(options.namespace, nspOptions);
    if (options.warmup) {
        outerReps = 2;
    } else {
        outerReps = 1;
    }
    for (int i = 0; i < outerReps; i++) {
        sw = new SimpleStopwatch();
        try {
            action = options.action;
            switch(action) {
                case Put:
                    doPut(options, session, syncNSP, sw);
                    break;
                case MultiPut:
                    doMultiPut(options, session, syncNSP, sw);
                    break;
                case MultiGet:
                    doMultiGet(options, syncNSP, sw);
                    break;
                case Get:
                    doGet(options, syncNSP, sw);
                    break;
                case GetMeta:
                    doGetMeta(options, syncNSP, sw);
                    break;
                case GetValueAndMeta:
                    doGetValueAndMeta(options, syncNSP, sw);
                    break;
                case WaitFor:
                    doWaitFor(options, syncNSP, sw);
                    break;
                case Snapshot:
                    doSnapshot(options, syncNSP, sw);
                    break;
                case SyncRequest:
                    doSyncRequest(options, syncNSP, sw);
                    break;
                case CreateNamespace:
                    doCreateNamespace(options, session, sw);
                    break;
                case GetNamespaceOptions:
                    doGetNamespaceOptions(options, session, sw);
                    break;
                default:
                    throw new RuntimeException("panic");
            }
        } finally {
            session.close();
        }
        // sw.stop();
        Log.warning("Elapsed:\t" + sw.getElapsedSeconds());
        if (options.warmup || i < outerReps - 1) {
            ThreadUtil.sleep(warmupDelayMillis);
        }
    }
}
Also used : SessionOptions(com.ms.silverking.cloud.dht.SessionOptions) Stopwatch(com.ms.silverking.time.Stopwatch) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) DHTSession(com.ms.silverking.cloud.dht.client.DHTSession) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) VersionConstraint(com.ms.silverking.cloud.dht.VersionConstraint) Namespace(com.ms.silverking.cloud.dht.client.Namespace)

Example 2 with SessionOptions

use of com.ms.silverking.cloud.dht.SessionOptions 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)

Aggregations

SessionOptions (com.ms.silverking.cloud.dht.SessionOptions)2 DHTSession (com.ms.silverking.cloud.dht.client.DHTSession)2 RetrievalOptions (com.ms.silverking.cloud.dht.RetrievalOptions)1 VersionConstraint (com.ms.silverking.cloud.dht.VersionConstraint)1 Namespace (com.ms.silverking.cloud.dht.client.Namespace)1 SimpleStopwatch (com.ms.silverking.time.SimpleStopwatch)1 Stopwatch (com.ms.silverking.time.Stopwatch)1