private void resetTxnMode() { LockMode original = mOriginalMode; if (original != null) { mOriginalMode = null; mCursor.link().lockMode(original); } } }
/** * @param cursor unpositioned cursor; must be linked to a non-null transaction */ CursorUpgradableUpdater(Cursor cursor) throws IOException { super(cursor); Transaction txn = cursor.link(); mOriginalMode = txn.lockMode(); txn.lockMode(LockMode.UPGRADABLE_READ); cursor.first(); cursor.register(); }
txn = newTransaction(null); try { txn.lockMode(LockMode.REPEATABLE_READ); doTouch(txn, key); } finally { } else if (txn.lockMode() == LockMode.READ_COMMITTED) { LockResult result; final LockMode original = txn.lockMode(); try { txn.lockMode(LockMode.REPEATABLE_READ); result = doTouch(txn, key); if (result.isAcquired()) { txn.lockMode(original);
txn = mView.newTransaction(null); try { txn.lockMode(LockMode.REPEATABLE_READ); action.perform(txn); } finally { } else if (txn.lockMode() == LockMode.READ_COMMITTED) { LockResult result; final LockMode original = txn.lockMode(); try { txn.lockMode(LockMode.REPEATABLE_READ); result = action.perform(txn); if (result.isAcquired()) { txn.lockMode(original);
@Override public byte[] load(Transaction txn, byte[] key) throws IOException { if (mCombiner.combineLocks()) combine: { if (txn == null) { txn = newTransaction(null); txn.lockMode(LockMode.REPEATABLE_READ); } else if (txn.lockMode() == LockMode.READ_COMMITTED) { txn.enter(); } else { break combine; } try { return doLoad(txn, key); } finally { txn.exit(); } } return doLoad(txn, key); }
@Override public boolean remove(final Transaction txn, final byte[] tkey, final byte[] tvalue) throws IOException { final byte[] key = inverseTransformKey(tkey); if (key == null) { return tvalue == null; } final byte[] value = mTransformer.inverseTransformValue(tvalue, key, tkey); if (txn == null || txn.lockMode() == LockMode.UNSAFE) { return mSource.remove(txn, key, value); } return condUpdate(txn, key, value, null); }
@Override public boolean replace(final Transaction txn, final byte[] tkey, final byte[] tvalue) throws IOException { final byte[] key = inverseTransformKey(tkey); if (key == null) { return false; } final byte[] value = mTransformer.inverseTransformValue(tvalue, key, tkey); if (txn == null || txn.lockMode() == LockMode.UNSAFE) { return mSource.replace(txn, key, value); } return condStore(txn, key, value, null); }
@Override public boolean replace(final Transaction txn, final byte[] tkey, final byte[] tvalue) throws IOException { final byte[] key = inverseTransformKey(tkey); if (key == null) { return false; } final byte[] value = mTransformer.inverseTransformValue(tvalue, key, tkey); if (txn == null || txn.lockMode() == LockMode.UNSAFE) { return mSource.replace(txn, key, value); } return condStore(txn, key, value, null); }
@Override public boolean remove(final Transaction txn, final byte[] tkey, final byte[] tvalue) throws IOException { final byte[] key = inverseTransformKey(tkey); if (key == null) { return tvalue == null; } final byte[] value = mTransformer.inverseTransformValue(tvalue, key, tkey); if (txn == null || txn.lockMode() == LockMode.UNSAFE) { return mSource.remove(txn, key, value); } return condUpdate(txn, key, value, null); }
@Override public boolean insert(final Transaction txn, final byte[] tkey, final byte[] tvalue) throws IOException { final byte[] key = inverseTransformKey(tkey); if (key == null) { if (tvalue == null) { return true; } throw fail(); } final byte[] value = mTransformer.inverseTransformValue(tvalue, key, tkey); if (txn == null || txn.lockMode() == LockMode.UNSAFE) { return mSource.insert(txn, key, value); } return condStore(txn, key, value, Cursor.NOT_LOADED); }
@Override public boolean insert(final Transaction txn, final byte[] tkey, final byte[] tvalue) throws IOException { final byte[] key = inverseTransformKey(tkey); if (key == null) { if (tvalue == null) { return true; } throw fail(); } final byte[] value = mTransformer.inverseTransformValue(tvalue, key, tkey); if (txn == null || txn.lockMode() == LockMode.UNSAFE) { return mSource.insert(txn, key, value); } return condStore(txn, key, value, Cursor.NOT_LOADED); }
@Override public void store(byte[] value) throws IOException { byte[] key = mKey; ViewUtils.positionCheck(key); Transaction txn = mTxn; if (txn == null) { txn = mView.newTransaction(null); try { store(txn, key, value); txn.commit(); } finally { txn.reset(); } } else if (txn.lockMode() != LockMode.UNSAFE) { txn.enter(); try { txn.lockMode(LockMode.UPGRADABLE_READ); store(txn, key, value); txn.commit(); } finally { txn.exit(); } } else { store(txn, key, value); } }
@Override public boolean update(final Transaction txn, final byte[] tkey, final byte[] oldTValue, final byte[] newTValue) throws IOException { final byte[] key = inverseTransformKey(tkey); if (key == null) { if (oldTValue == null) { if (newTValue == null) { return true; } throw fail(); } return false; } final byte[] oldValue = mTransformer.inverseTransformValue(oldTValue, key, tkey); final byte[] newValue = mTransformer.inverseTransformValue(newTValue, key, tkey); if (txn == null || txn.lockMode() == LockMode.UNSAFE) { return mSource.update(txn, key, oldValue, newValue); } return condUpdate(txn, key, oldValue, newValue); }
@Override public boolean update(final Transaction txn, final byte[] tkey, final byte[] oldTValue, final byte[] newTValue) throws IOException { final byte[] key = inverseTransformKey(tkey); if (key == null) { if (oldTValue == null) { if (newTValue == null) { return true; } throw fail(); } return false; } final byte[] oldValue = mTransformer.inverseTransformValue(oldTValue, key, tkey); final byte[] newValue = mTransformer.inverseTransformValue(newTValue, key, tkey); if (txn == null || txn.lockMode() == LockMode.UNSAFE) { return mSource.update(txn, key, oldValue, newValue); } return condUpdate(txn, key, oldValue, newValue); }
@Override public byte[] load(final Transaction txn, final byte[] tkey) throws IOException { final byte[] key = inverseTransformKey(tkey); if (key == null) { return null; } if (txn == null || !txn.lockMode().isRepeatable()) { return mTransformer.transformValue(mSource.load(txn, key), key, tkey); } txn.enter(); try { byte[] value = mSource.load(txn, key); if (value == null || (value = mTransformer.transformValue(value, key, tkey)) != null) { // Keep the lock if value doesn't exist or if allowed by transformer. txn.commit(); } return value; } finally { txn.exit(); } }
@Override public byte[] load(final Transaction txn, final byte[] tkey) throws IOException { final byte[] key = inverseTransformKey(tkey); if (key == null) { return null; } if (txn == null || !txn.lockMode().isRepeatable()) { return mTransformer.transformValue(mSource.load(txn, key), key, tkey); } txn.enter(); try { byte[] value = mSource.load(txn, key); if (value == null || (value = mTransformer.transformValue(value, key, tkey)) != null) { // Keep the lock if value doesn't exist or if allowed by transformer. txn.commit(); } return value; } finally { txn.exit(); } }
public TuplStoreTransaction beginTransaction(BaseTransactionConfig config) throws BackendException { final Configuration effectiveCfg = new MergedConfiguration( config.getCustomOptions() /*overrides, defined in individual titan transaction configs*/, getStorageConfig() /*defaults, in superclass AbstractStoreManager, passed into ctor*/); //configure the durability mode if(batchLoading && effectiveCfg.has(TUPL_DURABILITY_MODE)) { throw new PermanentBackendException(CANNOT_OVERRIDE_DURABILITY_MODE_WHEN_BATCH_LOADING); } final DurabilityMode effectiveDurabilityMode = batchLoading ? DurabilityMode.NO_REDO : DurabilityMode.valueOf(effectiveCfg.get(TUPL_DURABILITY_MODE)); //configure the lock mode if((!transactional || batchLoading) && effectiveCfg.has(TUPL_LOCK_MODE)) { throw new PermanentBackendException(CANT_OVERRIDE_LOCK_MODE_WITHOUT_TX_OR_WHEN_BATCH_LOADING); } final LockMode effectiveLockMode = (transactional && !batchLoading) ? LockMode.valueOf(effectiveCfg.get(TUPL_LOCK_MODE)) : LockMode.UNSAFE; final Transaction txn = database.newTransaction(effectiveDurabilityMode); txn.lockMode(effectiveLockMode); return new TuplStoreTransaction(config, txn, database); }
if (txn == null || !txn.lockMode().isRepeatable()) { return mTransformer.transformValue(mSource.load(txn, key), key, tkey) != null;
if (txn == null || !txn.lockMode().isRepeatable()) { return mTransformer.transformValue(mSource.load(txn, key), key, tkey);