Search in sources :

Example 1 with DHTSession

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

the class ClientSpecifiedVersionUnrestrictedRevisionsTest method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws ClientException, IOException {
    DHTSession session = createSession();
    Namespace ns = createNamespace(session, namespaceName, CLIENT_SPECIFIED, UNRESTRICTED_REVISIONS);
    syncNsp = ns.openSyncPerspective(String.class, String.class);
}
Also used : DHTSession(com.ms.silverking.cloud.dht.client.DHTSession) Namespace(com.ms.silverking.cloud.dht.client.Namespace) BeforeClass(org.junit.BeforeClass)

Example 2 with DHTSession

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

the class AsyncInvalidationExample method runExample.

public static String runExample(SKGridConfiguration gridConfig) {
    try {
        AsynchronousNamespacePerspective<String, String> asyncNSP;
        AsyncInvalidation<String> asyncInvalidation;
        AsyncPut<String> asyncPut;
        AsyncSingleValueRetrieval<String, String> asyncGet;
        DHTSession session;
        Namespace ns;
        session = new DHTClient().openSession(gridConfig);
        ns = session.createNamespace("MyNamespace" + System.currentTimeMillis(), session.getDefaultNamespaceOptions().versionMode(NamespaceVersionMode.SYSTEM_TIME_NANOS));
        System.out.printf("Using namespace %s\n", ns.getName());
        asyncNSP = ns.openAsyncPerspective(String.class, String.class);
        asyncPut = asyncNSP.put(key, value);
        asyncPut.waitForCompletion();
        asyncPut = asyncNSP.put(key, value);
        asyncPut.waitForCompletion();
        asyncGet = asyncNSP.get(key);
        asyncGet.waitForCompletion();
        System.out.printf("Before invalidation %s\n", asyncGet.getValue());
        asyncInvalidation = asyncNSP.invalidate(key);
        asyncInvalidation.waitForCompletion();
        asyncGet = asyncNSP.get(key);
        asyncGet.waitForCompletion();
        System.out.printf("After invalidation %s\n", asyncGet.getValue());
        return asyncGet.getValue();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : DHTSession(com.ms.silverking.cloud.dht.client.DHTSession) Namespace(com.ms.silverking.cloud.dht.client.Namespace) DHTClient(com.ms.silverking.cloud.dht.client.DHTClient) IOException(java.io.IOException)

Example 3 with DHTSession

use of com.ms.silverking.cloud.dht.client.DHTSession 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 4 with DHTSession

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

the class SilverkingFieldSpecificDB method init.

public void init() throws DBException {
    try {
        DHTSession session;
        // NamespacePerspectiveOptions<String,ByteIterator> nspOptions;
        ImmutableSet.Builder<String> builder;
        // session = dhtClient.openSession(new ClientDHTConfiguration("instance name", "ip:port"));
        // FUTURE - fix if this test is needed
        System.err.println("Update SilverkingFieldSpecificDB before use");
        session = null;
        if (session == null) {
            throw new RuntimeException("null session");
        }
        /*
            nspOptions = new NamespacePerspectiveOptions<>(String.class, ByteIterator.class);
            nspOptions = nspOptions.defaultPutOptions(nspOptions.getDefaultPutOptions().compression(Compression.NONE).checksumType(ChecksumType.NONE));
            System.out.println(nspOptions);
            */
        // syncNSP = session.openSyncNamespacePerspective(SilverkingDBConstants.namespace, SilverkingDBConstants.nspOptions);
        builder = new ImmutableSet.Builder<>();
        for (int i = 0; i < numFields; i++) {
            builder.add(fieldPrefix + i);
        }
        allFields = builder.build();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) DHTSession(com.ms.silverking.cloud.dht.client.DHTSession) DBException(com.yahoo.ycsb.DBException) PutException(com.ms.silverking.cloud.dht.client.PutException) RetrievalException(com.ms.silverking.cloud.dht.client.RetrievalException)

Example 5 with DHTSession

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

the class DevTest method test.

public void test(int numKeys, int reps, String namespace, Compression compression, ChecksumType checksumType, EnumSet<Test> tests) throws Exception {
    DHTClient client;
    ClientDHTConfiguration dhtConfig;
    DHTSession session;
    AsynchronousNamespacePerspective<String, String> asyncNSP;
    AsyncRetrieval<String, String> asyncRetrieval;
    AsyncPut<String> asyncPut;
    Stopwatch sw;
    PutOptions putOptions;
    asyncPut = null;
    client = new DHTClient();
    dhtConfig = new ClientDHTConfiguration(dhtName, new ZooKeeperConfig(zkLocs));
    session = client.openSession(dhtConfig);
    putOptions = session.getDefaultNamespaceOptions().getDefaultPutOptions().compression(compression).checksumType(checksumType);
    asyncNSP = session.openAsyncNamespacePerspective(namespace, String.class, String.class);
    sw = new SimpleStopwatch();
    if (tests.contains(Test.Put)) {
        System.out.println("\n\n\t\tPUT");
        for (int i = 0; i < reps; i++) {
            // asyncPut = asyncNSP.put("Hello"+ i, "world!");
            asyncPut = asyncNSP.put(createMap(i, numKeys), putOptions);
            asyncPut.waitForCompletion();
        }
        sw.stop();
        displayTimes(sw, reps, numKeys, valueSize);
    }
    if (tests.contains(Test.Get)) {
        System.out.println("\n\n\t\tGET");
        GetOptions getOptions;
        sw.reset();
        getOptions = OptionsHelper.newGetOptions(RetrievalType.VALUE_AND_META_DATA, session.getDefaultNamespaceOptions().getDefaultGetOptions().getVersionConstraint());
        for (int i = 0; i < reps; i++) {
            Set<String> keys;
            Map<String, ? extends StoredValue<String>> values;
            keys = createSet(i, numKeys);
            asyncRetrieval = asyncNSP.get(keys, getOptions);
            asyncRetrieval.waitForCompletion();
            if (displayValues) {
                System.out.printf("keys: %s\n", CollectionUtil.toString(keys));
                values = asyncRetrieval.getStoredValues();
                System.out.printf("values: %s\n", CollectionUtil.toString(values.entrySet()));
                for (Entry<String, ? extends StoredValue<String>> entry : values.entrySet()) {
                    System.out.println(entry.getKey() + " -> " + entry.getValue().getValue() + "\t" + entry.getValue().getMetaData().toString(true));
                }
            }
        }
        sw.stop();
        displayTimes(sw, reps, numKeys, valueSize);
    }
}
Also used : ZooKeeperConfig(com.ms.silverking.cloud.zookeeper.ZooKeeperConfig) ClientDHTConfiguration(com.ms.silverking.cloud.dht.client.ClientDHTConfiguration) 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) GetOptions(com.ms.silverking.cloud.dht.GetOptions) PutOptions(com.ms.silverking.cloud.dht.PutOptions) DHTClient(com.ms.silverking.cloud.dht.client.DHTClient)

Aggregations

DHTSession (com.ms.silverking.cloud.dht.client.DHTSession)9 Namespace (com.ms.silverking.cloud.dht.client.Namespace)6 BeforeClass (org.junit.BeforeClass)4 SessionOptions (com.ms.silverking.cloud.dht.SessionOptions)2 DHTClient (com.ms.silverking.cloud.dht.client.DHTClient)2 SimpleStopwatch (com.ms.silverking.time.SimpleStopwatch)2 Stopwatch (com.ms.silverking.time.Stopwatch)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 GetOptions (com.ms.silverking.cloud.dht.GetOptions)1 PutOptions (com.ms.silverking.cloud.dht.PutOptions)1 RetrievalOptions (com.ms.silverking.cloud.dht.RetrievalOptions)1 VersionConstraint (com.ms.silverking.cloud.dht.VersionConstraint)1 ClientDHTConfiguration (com.ms.silverking.cloud.dht.client.ClientDHTConfiguration)1 PutException (com.ms.silverking.cloud.dht.client.PutException)1 RetrievalException (com.ms.silverking.cloud.dht.client.RetrievalException)1 ZooKeeperConfig (com.ms.silverking.cloud.zookeeper.ZooKeeperConfig)1 DBException (com.yahoo.ycsb.DBException)1 IOException (java.io.IOException)1