use of com.ms.silverking.cloud.dht.client.RetrievalException in project SilverKing by Morgan-Stanley.
the class HelloCallbackDHT2 method asyncOperationUpdated.
@Override
public void asyncOperationUpdated(AsyncOperation asyncOperation) {
OperationState opState;
opState = asyncOperation.getState();
if (opState == OperationState.FAILED) {
System.out.printf("Operation failed: %s\n", asyncOperation.getClass());
} else if (opState == OperationState.INCOMPLETE || opState == OperationState.SUCCEEDED) {
if (asyncOperation instanceof AsyncValueRetrieval) {
AsyncValueRetrieval asyncValueRetrieval;
Map<String, String> values;
asyncValueRetrieval = (AsyncValueRetrieval) asyncOperation;
try {
values = asyncValueRetrieval.getLatestValues();
for (Map.Entry<String, String> entry : values.entrySet()) {
System.out.printf("Complete: %s\t=>\t%s\n", entry.getKey(), entry.getValue());
}
} catch (RetrievalException e) {
e.printStackTrace();
}
// System.out.printf("Incomplete keys: %d\n", asyncValueRetrieval.getIncompleteKeys().size());
} else {
System.out.printf("Operation incomplete: %s\n", asyncOperation.getClass());
}
if (opState == OperationState.SUCCEEDED) {
s.release();
}
} else {
s.release();
}
// System.out.printf("%s %s %s\n", Thread.currentThread().getName(), asyncOperation.getClass(), opState);
}
use of com.ms.silverking.cloud.dht.client.RetrievalException in project SilverKing by Morgan-Stanley.
the class SilverKingClient method retrieveAllValuesForKey.
private Map<String, ? extends StoredValue<byte[]>> retrieveAllValuesForKey(String key) throws RetrievalException {
RetrievalOptions retrievalOptions;
Map<String, StoredValue<byte[]>> keyValues;
keyValues = new HashMap<>();
retrievalOptions = syncNSP.getOptions().getDefaultGetOptions().retrievalType(RetrievalType.META_DATA).nonExistenceResponse(NonExistenceResponse.NULL_VALUE).versionConstraint(VersionConstraint.greatest).returnInvalidations(true);
try {
do {
StoredValue<byte[]> storedValue;
// System.out.printf("%s\t%s\n", key, retrievalOptions);
storedValue = syncNSP.retrieve(key, retrievalOptions);
if (storedValue != null) {
String keyAndVersion;
keyAndVersion = String.format("%s %d %d %s", key, storedValue.getVersion(), storedValue.getCreationTime().inNanos(), storedValue.getCreationTime().toDateString());
keyValues.put(keyAndVersion, storedValue);
// System.out.printf("%d\t%d\n", storedValue.getMetaData().getVersion(), storedValue.getMetaData().getCreationTime().inNanos());
// retrievalOptions = retrievalOptions.versionConstraint(retrievalOptions.getVersionConstraint().maxCreationTime(storedValue.getCreationTime().inNanos() - 1));
retrievalOptions = retrievalOptions.versionConstraint(retrievalOptions.getVersionConstraint().maxBelowOrEqual(storedValue.getVersion() - 1));
// ThreadUtil.sleep(1000);
} else {
break;
}
} while (true);
} catch (RetrievalException re) {
displayRetrievalExceptionDetails(re);
throw re;
}
return keyValues;
}
use of com.ms.silverking.cloud.dht.client.RetrievalException in project SilverKing by Morgan-Stanley.
the class SilverKingClient method retrieve.
private Map<String, ? extends StoredValue<byte[]>> retrieve(String[] args, RetrievalOptions retrievalOptions) throws OperationException, IOException {
try {
Map<String, ? extends StoredValue<byte[]>> storedValues;
Set<String> keys;
if (syncNSP == null) {
out.printf("No namespace set\n");
return ImmutableMap.of();
}
keys = retrievalKeySet(args);
opMessage("Retrieving");
storedValues = null;
sw.reset();
for (int i = 0; i < 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;
} catch (RetrievalException re) {
displayRetrievalExceptionDetails(re);
throw re;
}
}
use of com.ms.silverking.cloud.dht.client.RetrievalException 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;
}
}
use of com.ms.silverking.cloud.dht.client.RetrievalException in project SilverKing by Morgan-Stanley.
the class NamespaceOptionsClient method storeNamespaceProperties.
public void storeNamespaceProperties(long namespace, NamespaceProperties nsProperties) throws NamespaceCreationException {
boolean retry;
retry = false;
do {
NamespaceProperties existingProperties;
try {
existingProperties = getNamespaceProperties(namespace, seTimeoutController.getMaxRelativeTimeoutMillis(null));
} catch (TimeoutException te) {
Log.warning("Failed to store namespace due to timeout " + String.format("%x", namespace));
throw new NamespaceCreationException(Long.toHexString(namespace), te);
} catch (RetrievalException re) {
Log.warning(re.getDetailedFailureMessage());
throw new NamespaceCreationException("RetrievalException during first property check", re);
}
if (existingProperties != null) {
if (!existingProperties.equals(nsProperties)) {
Log.warning("existingProperties", existingProperties);
Log.warning("nsProperties", nsProperties);
throw new NamespaceCreationException("Namespace already created with incompatible properties");
} else {
// Already created with the same options. No further action required.
}
} else {
try {
if (debug) {
System.out.printf("storeNamespaceProperties(%x, %s)\n", namespace, nsProperties);
}
syncNSP.put(getOptionsKey(namespace), nsProperties.toString());
if (debug) {
System.out.println("Done storeNamespaceOptions");
}
} catch (PutException pe) {
// For other errors, we try this also on the
try {
boolean optionsMatch;
try {
optionsMatch = verifyNamespaceProperties(namespace, nsProperties);
if (!optionsMatch) {
throw new NamespaceCreationException("Namespace already created with incompatible properties");
}
} catch (NamespaceNotCreatedException nnce) {
// Should not be possible any more, but leave old retry in for now.
retry = true;
} catch (RuntimeException re) {
Log.logErrorWarning(re);
Log.warning(pe.getDetailedFailureMessage());
Log.logErrorWarning(pe, "Couldn't store options due to exception");
}
} catch (RetrievalException re) {
Log.warning("storeNamespaceProperties failing");
Log.warning("PutException");
pe.printStackTrace();
Log.warning("RetrievalException");
re.printStackTrace();
throw new NamespaceCreationException(re);
}
}
}
} while (retry);
}
Aggregations