Search in sources :

Example 16 with Token

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);
}
Also used : RangeToken(com.cinchapi.concourse.server.concurrent.RangeToken) RangeToken(com.cinchapi.concourse.server.concurrent.RangeToken) Token(com.cinchapi.concourse.server.concurrent.Token)

Example 17 with Token

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);
}
Also used : RangeToken(com.cinchapi.concourse.server.concurrent.RangeToken) Token(com.cinchapi.concourse.server.concurrent.Token)

Example 18 with 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);
    }
}
Also used : Token(com.cinchapi.concourse.server.concurrent.Token)

Aggregations

Token (com.cinchapi.concourse.server.concurrent.Token)18 RangeToken (com.cinchapi.concourse.server.concurrent.RangeToken)17 PriorityReadWriteLock (com.cinchapi.concourse.server.concurrent.PriorityReadWriteLock)3 Lock (java.util.concurrent.locks.Lock)3 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)3 DoNotInvoke (com.cinchapi.concourse.annotate.DoNotInvoke)1 LockType (com.cinchapi.concourse.server.concurrent.LockType)1 Text (com.cinchapi.concourse.server.model.Text)1 Value (com.cinchapi.concourse.server.model.Value)1 TObject (com.cinchapi.concourse.thrift.TObject)1 Range (com.google.common.collect.Range)1 RangeSet (com.google.common.collect.RangeSet)1 TreeRangeSet (com.google.common.collect.TreeRangeSet)1