use of com.ms.silverking.cloud.dht.common.OpResult in project SilverKing by Morgan-Stanley.
the class SegmentedRetrievalValue method checkForCompletion.
@Override
protected void checkForCompletion() {
MessageGroupRetrievalResponseEntry response;
OpResult result;
result = OpResult.SUCCEEDED;
for (DHTKey key : keys) {
if (getResult(key) != OpResult.SUCCEEDED) {
result = getResult(key);
// System.out.println("Incomplete: "+ key);
}
}
if (result == OpResult.SUCCEEDED) {
// System.out.println("SegmentedRetrievalValue complete");
parent.reassembledResultReceived(relayKey, new SegmentedRetrievalResult<>(metaData, deserializer, getBuffers(), result));
} else {
// System.out.println("SegmentedRetrievalValue incomplete");
// parent.resultReceived(relayKey, MessageGroupRetrievalResponseEntry);
}
}
use of com.ms.silverking.cloud.dht.common.OpResult in project SilverKing by Morgan-Stanley.
the class StorageModule method handleReap.
public void handleReap(MessageGroup message, MessageGroupConnection connection) {
OpResult result;
ProtoOpResponseMessageGroup response;
asyncInvocation("reap");
result = OpResult.SUCCEEDED;
response = new ProtoOpResponseMessageGroup(message.getUUID(), 0, result, myOriginatorID.getBytes(), message.getDeadlineRelativeMillis());
try {
connection.sendAsynchronous(response.toMessageGroup(), SystemTimeUtil.systemTimeSource.absTimeMillis() + message.getDeadlineRelativeMillis());
} catch (IOException ioe) {
Log.logErrorWarning(ioe);
}
}
use of com.ms.silverking.cloud.dht.common.OpResult in project SilverKing by Morgan-Stanley.
the class SingleWriterConsistentWrite method update.
/**
* Called after a replica state updates
*/
@Override
public void update(DHTKey key, IPAndPort replica, byte storageState, OpResult update, PutVirtualCommunicator pvComm) {
assert replica != null;
if (update == OpResult.SUCCEEDED || update == OpResult.INVALID_VERSION || update == OpResult.MUTATION || update == OpResult.NO_SUCH_NAMESPACE) {
SingleWriterConsistentStorageEntryState entryState;
if (debug) {
System.out.printf("key %s replica %s\tupdate %s\n", KeyUtil.keyToString(key), replica, update);
}
// FUTURE - could refactor code to only perform this lookup once if needed
entryState = getEntryState(key);
synchronized (entryState) {
if (entryState.getCurOpResult() == OpResult.INCOMPLETE) {
TwoPhaseStorageState prevState;
StateTransitionResult transitionResult;
TwoPhaseStorageState nextState;
OpResult opResult;
prevState = TwoPhaseStorageState.values[storageState];
if (update.toOperationState() != OperationState.FAILED) {
nextState = TwoPhaseStorageState.nextState(prevState);
transitionResult = entryState.transitionFromState(replica, prevState);
opResult = nextState.toOpResult();
} else {
entryState.fail(replica, prevState);
transitionResult = StateTransitionResult.COMPLETION;
nextState = TwoPhaseStorageState.FAILED;
opResult = update;
}
if (debug) {
System.out.printf("key %s prevState %s nextState %s transitionResult %s\n", KeyUtil.keyToString(key), prevState, nextState, transitionResult);
}
switch(transitionResult) {
case REPLICA_TRANSITION:
break;
case QUORUM_TRANSITION:
quorumTransition(key, entryState.primaryReplicas(), nextState, update, pvComm);
quorumTransition(key, entryState.secondaryReplicas(), nextState, update, pvComm);
if (!nextState.isComplete()) {
break;
} else {
// fall through if complete
}
case COMPLETION:
int _completeEntries;
pvComm.sendResult(key, opResult);
_completeEntries = completeEntries.incrementAndGet();
if (debug) {
System.out.printf("COMPLETION %s %d %d\n", KeyUtil.keyToString(key), _completeEntries, numEntries);
}
if (_completeEntries >= numEntries) {
setOpResult(OpResult.SUCCEEDED);
}
if (debug) {
System.out.printf("opResult %s\n", getOpResult());
}
break;
case NO_TRANSITION:
// must be old update
break;
default:
throw new RuntimeException("panic");
}
} else {
if (Log.levelMet(Level.FINE)) {
Log.fine("Update for non-incomplete: ", key + " " + replica + " " + update);
}
}
}
} else {
// FUTURE - Consider additional error handling
Log.warning("Unexpected update: ", key + " " + replica + " " + update);
}
}
use of com.ms.silverking.cloud.dht.common.OpResult in project SilverKing by Morgan-Stanley.
the class NamespaceStore method __putUpdate.
private OpResult __putUpdate(DHTKey key, long version, byte storageState) {
OpResult result;
int segmentNumber;
if (debugVersion) {
System.out.println("putUpdate:\t" + key);
System.out.println("version:\t" + version);
}
segmentNumber = getSegmentNumber(key, VersionConstraint.exactMatch(version));
assert segmentNumber >= 0 || segmentNumber == IntCuckooConstants.noSuchValue;
if (segmentNumber == IntCuckooConstants.noSuchValue) {
if (debug) {
System.out.println("_putUpdate returning INVALID_VERSION");
}
Log.warningf("Couldn't find %s %d in _putUpdate()", KeyUtil.keyToString(key), version);
return OpResult.ERROR;
// return OpResult.INVALID_VERSION;
} else {
if (headSegment.getSegmentNumber() == segmentNumber) {
if (debugSegments) {
Log.warning("PutUpdate, head segment");
}
result = headSegment.putUpdate(key, version, storageState);
if (debugSegments) {
Log.warning("Done PutUpdate, head segment " + result + " " + storageState);
}
} else {
try {
WritableSegmentBase segment;
/*
FileSegment.SyncMode syncMode;
syncMode = FileSegment.SyncMode.NoSync;
switch (nsOptions.getStorageType()) {
case RAM:
segment = ramSegments.get(segmentNumber);
break;
case FILE_SYNC:
syncMode = FileSegment.SyncMode.Sync;
// fall through
case FILE:
// FUTURE - consider getting this from file segment cache
segment = FileSegment.openForDataUpdate(nsDir, segmentNumber,
nsOptions.getSegmentSize(), syncMode, nsOptions);
break;
default: throw new RuntimeException("Panic");
}
*/
segment = getFileSegment(segmentNumber, SegmentPrereadMode.NoPreread);
try {
if (debugSegments) {
Log.warning("Read from file segment");
}
result = segment.putUpdate(key, version, storageState);
if (debugSegments) {
Log.warning("Done read from file segment");
Log.warning("result: " + result);
}
} finally {
switch(nsOptions.getStorageType()) {
case RAM:
break;
case FILE:
// ((FileSegment)segment).close();
((FileSegment) segment).removeReference();
break;
default:
throw new RuntimeException("Panic");
}
}
} catch (IOException ioe) {
Log.logErrorWarning(ioe);
return OpResult.ERROR;
}
}
return result;
}
}
use of com.ms.silverking.cloud.dht.common.OpResult in project SilverKing by Morgan-Stanley.
the class NamespaceStore method put.
public void put(List<StorageValueAndParameters> values, byte[] userData, KeyedOpResultListener resultListener) {
Set<Waiter> triggeredWaitFors;
NamespaceVersionMode nsVersionMode;
boolean locked;
triggeredWaitFors = null;
nsVersionMode = nsOptions.getVersionMode();
// LWTThreadUtil.setBlocked();
writeLock.lock();
try {
// System.out.printf("NamespaceStore.put() group size: %d\n", values.size());
for (StorageValueAndParameters value : values) {
OpResult storageResult;
if (putTrigger != null) {
storageResult = putTrigger.put(this, value.getKey(), value.getValue(), new SSStorageParametersImpl(value, value.getValue().remaining()), userData, nsVersionMode);
} else {
storageResult = _put(value.getKey(), value.getValue(), value, userData, nsVersionMode);
}
// if (storageResult != OpResult.SUCCEEDED) Log.warningf("fail _put %s %s %d", KeyUtil.keyToString(value.getKey()), storageResult, value.getVersion()); // for debugging
resultListener.sendResult(value.getKey(), storageResult);
if (storageResult == OpResult.SUCCEEDED) {
Set<Waiter> _triggeredWaitFors;
_triggeredWaitFors = checkPendingWaitFors(value.getKey());
if (_triggeredWaitFors != null) {
if (triggeredWaitFors == null) {
triggeredWaitFors = new HashSet<>();
}
triggeredWaitFors.addAll(_triggeredWaitFors);
}
}
}
} finally {
writeLock.unlock();
// LWTThreadUtil.setNonBlocked();
}
if (triggeredWaitFors != null) {
handleTriggeredWaitFors(triggeredWaitFors);
}
}
Aggregations