protected StoreTransaction unwrapTx(StoreTransaction t) { assert null != t; assert t instanceof ExpectedValueCheckingTransaction; return ((ExpectedValueCheckingTransaction) t).getInconsistentTx(); }
public Builder lockWait(Duration d) { this.lockWait = d; return self(); }
private static StoreTransaction getConsistentTx(StoreTransaction t) { assert null != t; assert t instanceof ExpectedValueCheckingTransaction; return ((ExpectedValueCheckingTransaction) t).getConsistentTx(); } }
@Override public Locker apply(String lockerName) { KeyColumnValueStore lockerStore; try { lockerStore = storeManager.openDatabase(lockerName); } catch (BackendException e) { throw new TitanConfigurationException("Could not retrieve store named " + lockerName + " for locker configuration", e); } return new ConsistentKeyLocker.Builder(lockerStore, storeManager).fromConfig(configuration).build(); } };
/** * If {@code !}{@link #isMutationStarted()}, check all locks and expected * values, then mark the transaction as started. * <p> * If {@link #isMutationStarted()}, this does nothing. * * @throws com.thinkaurelius.titan.diskstorage.BackendException * * @return true if this transaction holds at least one lock, false if the * transaction holds no locks */ boolean prepareForMutations() throws BackendException { if (!isMutationStarted()) { checkAllLocks(); checkAllExpectedValues(); mutationStarted(); } return !expectedValuesByStore.isEmpty(); }
public ConsistentKeyLocker build() { preBuild(); final LockCleanerService cleaner; switch (cleanerConfig) { case STANDARD: Preconditions.checkArgument(null == customCleanerService); cleaner = new StandardLockCleanerService(store, serializer, times); break; case CUSTOM: Preconditions.checkArgument(null != customCleanerService); cleaner = customCleanerService; break; default: cleaner = null; } return new ConsistentKeyLocker(store, manager, rid, times, serializer, llm, lockWait, lockRetryCount, lockExpire, lockState, cleaner); }
/** * {@inheritDoc} * <p/> * This implementation supports locking when {@code lockStore} is non-null. */ @Override public void mutate(StaticBuffer key, List<Entry> additions, List<StaticBuffer> deletions, StoreTransaction txh) throws BackendException { ExpectedValueCheckingTransaction etx = (ExpectedValueCheckingTransaction)txh; boolean hasAtLeastOneLock = etx.prepareForMutations(); if (hasAtLeastOneLock) { // Force all mutations on this transaction to use strong consistency store.mutate(key, additions, deletions, getConsistentTx(txh)); } else { store.mutate(key, additions, deletions, unwrapTx(txh)); } }
/** * Check all locks attempted by earlier * {@link KeyColumnValueStore#acquireLock(StaticBuffer, StaticBuffer, StaticBuffer, StoreTransaction)} * calls using this transaction. * * @throws com.thinkaurelius.titan.diskstorage.BackendException */ void checkAllLocks() throws BackendException { StoreTransaction lt = getConsistentTx(); for (ExpectedValueCheckingStore store : expectedValuesByStore.keySet()) { Locker locker = store.getLocker(); // Ignore locks on stores without a locker if (null == locker) continue; locker.checkLocks(lt); } }
private WriteResult tryDeleteLockOnce(StaticBuffer key, StaticBuffer col, StoreTransaction txh) { Throwable t = null; final Timer delTimer = times.getTimer().start(); try { StoreTransaction newTx = overrideTimestamp(txh, delTimer.getStartTime()); store.mutate(key, ImmutableList.<Entry>of(), Arrays.asList(col), newTx); } catch (BackendException e) { t = e; } delTimer.stop(); return new WriteResult(delTimer.elapsed(), delTimer.getStartTime(), null, t); }
@Override public void commit() throws BackendException { inconsistentTx.commit(); deleteAllLocks(); strongConsistentTx.commit(); }
public StandardLockCleanerService(KeyColumnValueStore store, ConsistentKeyLockerSerializer serializer, TimestampProvider times) { this (store, serializer, getDefaultExecutor(), COOLDOWN_TIME, times); }
@Override public void run() { try { runWithExceptions(); } catch (BackendException e) { log.warn("Expired lock cleaner failed", e); } }
private void deleteAllLocks() throws BackendException { for (ExpectedValueCheckingStore s : expectedValuesByStore.keySet()) { s.deleteLocks(this); } } }
/** * Check that all expected values saved from earlier * {@link KeyColumnValueStore#acquireLock(StaticBuffer, StaticBuffer, StaticBuffer, StoreTransaction)} * calls using this transaction. * * @throws com.thinkaurelius.titan.diskstorage.BackendException */ void checkAllExpectedValues() throws BackendException { for (final ExpectedValueCheckingStore store : expectedValuesByStore.keySet()) { final Map<KeyColumn, StaticBuffer> m = expectedValuesByStore.get(store); for (final KeyColumn kc : m.keySet()) { checkSingleExpectedValue(kc, m.get(kc), store); } } }
@Override public TimestampRid apply(Entry e) { return serializer.fromLockColumn(e.getColumnAs(StaticBuffer.STATIC_FACTORY), times); } });
void deleteLocks(ExpectedValueCheckingTransaction tx) throws BackendException { locker.deleteLocks(tx.getConsistentTx()); }
public Builder standardCleaner() { this.cleanerConfig = CleanerConfig.STANDARD; this.customCleanerService = null; return self(); }
@Override public void rollback() throws BackendException { deleteAllLocks(); inconsistentTx.rollback(); strongConsistentTx.rollback(); }
public Builder lockRetryCount(int count) { this.lockRetryCount = count; return self(); }
public Builder customCleaner(LockCleanerService s) { this.cleanerConfig = CleanerConfig.CUSTOM; this.customCleanerService = s; Preconditions.checkNotNull(this.customCleanerService); return self(); }