use of com.cinchapi.concourse.server.concurrent.Token in project concourse by cinchapi.
the class AtomicOperation method remove.
@Override
protected final boolean remove(Write write, Sync sync, Verify verify) throws AtomicStateException {
checkState();
String key = write.getKey().toString();
long record = write.getRecord().longValue();
Token token = Token.wrap(key, record);
RangeToken rangeToken = RangeToken.forWriting(write.getKey(), write.getValue());
Token wide = wideReads.get(record);
if (wide != null) {
wide.upgrade();
writes2Lock.add(wide);
} else {
source.addVersionChangeListener(token, this);
writes2Lock.add(token);
// CON-669: Prevent a
writes2Lock.add(Token.shareable(record));
// conflicting wide read,
// but don't listen for
// wide version change
}
writes2Lock.add(rangeToken);
return super.remove(write, sync, verify);
}
use of com.cinchapi.concourse.server.concurrent.Token in project concourse by cinchapi.
the class AtomicOperation method touch.
/**
* Register interest in {@code record} so that this AtomicOperation can
* listen for changes and grab a read lock at commit time.
*
* @param record
*/
public void touch(long record) {
checkState();
Token token = Token.wrap(record);
source.addVersionChangeListener(token, this);
reads2Lock.add(token);
wideReads.put(record, token);
}
use of com.cinchapi.concourse.server.concurrent.Token in project concourse by cinchapi.
the class Transaction method onVersionChange.
@Override
public void onVersionChange(Token token) {
// We override this method to handle the case where an atomic operation
// started from this transaction must fail because of a version change,
// but that failure should not cause the transaction itself to fail
// (i.e. calling verifyAndSwap from a transaction and a version change
// causes that particular operation to fail prior to commit. The logic
// in this method will simply cause the invocation of verifyAndSwap to
// return false while this transaction would stay alive.
boolean callSuper = true;
for (AtomicOperation operation : managedVersionChangeListeners.keySet()) {
for (Token tok : managedVersionChangeListeners.get(operation)) {
if (tok.equals(token)) {
operation.onVersionChange(tok);
managedVersionChangeListeners.remove(operation, tok);
callSuper = false;
break;
}
}
}
if (callSuper) {
super.onVersionChange(token);
}
}
Aggregations