@Override public BaseTransactionConfig getConfiguration() { return inconsistentTx.getConfiguration(); }
@Override public BaseTransactionConfig getConfiguration() { return tx.getConfiguration(); }
public MaskedTimestamp(StoreTransaction txh) { this(txh.getConfiguration().getCommitTime()); }
private Lock getLock(StoreTransaction txh) { Boolean txOn = txh.getConfiguration().getCustomOption(STORAGE_TRANSACTIONAL); if (null != txOn && txOn) { ReentrantLock result = lock; if (result == null) { synchronized (this) { result = lock; if (result == null) { lock = result = new ReentrantLock(); } } } return result; } else return NoLock.INSTANCE; }
private void recordSliceMetrics(StoreTransaction txh, List<Entry> row) { if (!txh.getConfiguration().hasGroupName()) return; String p = txh.getConfiguration().getGroupName(); final MetricManager mgr = MetricManager.INSTANCE; mgr.getCounter(p, metricsStoreName, M_GET_SLICE, M_ENTRIES_COUNT).inc(row.size()); mgr.getHistogram(p, metricsStoreName, M_GET_SLICE, M_ENTRIES_HISTO).update(row.size()); }
protected void incActionBy(int by, CacheMetricsAction action, StoreTransaction txh) { assert by>=1; if (metricsName!=null && txh.getConfiguration().hasGroupName()) { MetricManager.INSTANCE.getCounter(txh.getConfiguration().getGroupName(), metricsName, action.getName()).inc(by); } }
@Override public KeyIterator getKeys(final SliceQuery query, final StoreTransaction txh) throws BackendException { return runWithMetrics(txh, metricsStoreName, M_GET_KEYS, () -> { final KeyIterator ki = backend.getKeys(query, txh); if (txh.getConfiguration().hasGroupName()) { return MetricInstrumentedIterator.of(ki, txh.getConfiguration().getGroupName(), metricsStoreName, M_GET_KEYS, M_ITERATOR); } else { return ki; } }); }
@Override public KeyIterator getKeys(final KeyRangeQuery query, final StoreTransaction txh) throws BackendException { return runWithMetrics(txh, metricsStoreName, M_GET_KEYS, () -> { final KeyIterator ki = backend.getKeys(query, txh); if (txh.getConfiguration().hasGroupName()) { return MetricInstrumentedIterator.of(ki, txh.getConfiguration().getGroupName(), metricsStoreName, M_GET_KEYS, M_ITERATOR); } else { return ki; } }); }
@Override public void deleteLocks(StoreTransaction tx) throws TemporaryLockingException, PermanentLockingException { if (null != tx.getConfiguration().getGroupName()) { MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_DELETE, M_CALLS).inc(); } Map<KeyColumn, S> m = lockState.getLocksForTx(tx); final Iterator<Map.Entry<KeyColumn, S>> iterator = m.entrySet().iterator(); while (iterator.hasNext()) { final Map.Entry<KeyColumn, S> entry = iterator.next(); final KeyColumn kc = entry.getKey(); final S ls = entry.getValue(); try { deleteSingleLock(kc, ls, tx); } catch (AssertionError ae) { throw ae; // Concession to ease testing with mocks & behavior verification } catch (Throwable t) { log.error("Exception while deleting lock on " + kc, t); if (null != tx.getConfiguration().getGroupName()) { MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_DELETE, M_CALLS).inc(); } } // Regardless of whether we successfully deleted the lock from storage, take it out of the local mediator llm.unlock(kc, tx); iterator.remove(); } }
static <T> T runWithMetrics(StoreTransaction txh, String storeName, String name, StorageCallable<T> impl) throws BackendException { if (!txh.getConfiguration().hasGroupName()) { return impl.call(); } String prefix = txh.getConfiguration().getGroupName(); Preconditions.checkNotNull(name); Preconditions.checkNotNull(impl); final MetricManager mgr = MetricManager.INSTANCE; mgr.getCounter(prefix, storeName, name, M_CALLS).inc(); final Timer.Context tc = mgr.getTimer(prefix, storeName, name, M_TIME).time(); try { return impl.call(); } catch (BackendException | RuntimeException e) { mgr.getCounter(prefix, storeName, name, M_EXCEPTIONS).inc(); throw e; } finally { tc.stop(); } }
@Override public void mutateMany(Map<String, Map<StaticBuffer, KCVMutation>> mutations, StoreTransaction txh) throws BackendException { if (!txh.getConfiguration().hasGroupName()) { backend.mutateMany(mutations,txh); } String prefix = txh.getConfiguration().getGroupName(); final MetricManager mgr = MetricManager.INSTANCE; mgr.getCounter(prefix, managerMetricsName, M_MUTATE, M_CALLS).inc(); final Timer.Context tc = mgr.getTimer(prefix, managerMetricsName, M_MUTATE, M_TIME).time(); try { backend.mutateMany(mutations,txh); } catch (BackendException | RuntimeException e) { mgr.getCounter(prefix, managerMetricsName, M_MUTATE, M_EXCEPTIONS).inc(); throw e; } finally { tc.stop(); } }
@Override public void checkLocks(StoreTransaction tx) throws TemporaryLockingException, PermanentLockingException { if (null != tx.getConfiguration().getGroupName()) { MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_CHECK, M_CALLS).inc(); throw new PermanentLockingException(t); } finally { if (!ok && null != tx.getConfiguration().getGroupName()) { MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_CHECK, M_CALLS).inc();
public static<R> R execute(Transactional<R> exe, TransactionalProvider provider, TimestampProvider times) throws BackendException { StoreTransaction txh = null; try { txh = provider.openTx(); if (!txh.getConfiguration().hasCommitTime()) txh.getConfiguration().setCommitTime(times.getTime()); return exe.call(txh); } catch (BackendException e) { if (txh!=null) txh.rollback(); txh=null; throw e; } finally { if (txh!=null) txh.commit(); } }
private StoreTransaction overrideTimestamp(final StoreTransaction tx, final Instant commitTime) throws BackendException { StandardBaseTransactionConfig newCfg = new StandardBaseTransactionConfig.Builder(tx.getConfiguration()) .commitTime(commitTime).build(); return manager.beginTransaction(newCfg); }
@Override public void writeLock(KeyColumn lockID, StoreTransaction tx) throws TemporaryLockingException, PermanentLockingException { if (null != tx.getConfiguration().getGroupName()) { MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_WRITE, M_CALLS).inc(); if (null != tx.getConfiguration().getGroupName()) { MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_WRITE, M_EXCEPTIONS).inc();