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