private void checkPresentAndCheckCount(TransactionOutcome outcome, long count) { MetricName metricName = actual.getMetricName(outcome, ImmutableMap.of()); checkPresentAndCheckCount(metricName, count); }
private void handleTransactionConflict(TableReference tableRef) { transactionOutcomeMetrics.markReadWriteConflict(tableRef); throw TransactionSerializableConflictException.create(tableRef, getTimestamp(), System.currentTimeMillis() - timeCreated); } }
@Test public void canMarkMultipleSuccessfulCommits() { transactionOutcomeMetrics.markSuccessfulCommit(); transactionOutcomeMetrics.markSuccessfulCommit(); transactionOutcomeMetrics.markSuccessfulCommit(); transactionOutcomeMetrics.markSuccessfulCommit(); assertThat(transactionOutcomeMetrics).hasSuccessfulCommits(4); }
public void markLocksExpired() { getMeter(TransactionOutcome.LOCKS_EXPIRED).mark(); }
@Test public void tableReferencesIncludedAsTagIfSafe() { transactionOutcomeMetrics.markReadWriteConflict(SAFE_REFERENCE_1); transactionOutcomeMetrics.markReadWriteConflict(SAFE_REFERENCE_1); transactionOutcomeMetrics.markWriteWriteConflict(SAFE_REFERENCE_1); assertThat(transactionOutcomeMetrics) .hasNamedReadWriteConflicts(SAFE_REFERENCE_1, 2) .hasNamedWriteWriteConflicts(SAFE_REFERENCE_1, 1); }
transactionOutcomeMetrics.markSuccessfulCommit(); } else { state.set(State.FAILED); transactionOutcomeMetrics.markFailedCommit();
protected void throwIfWriteAlreadyCommitted(TableReference tableRef, Map<Cell, byte[]> writes, ConflictHandler conflictHandler, LockToken commitLocksToken, TransactionService transactionService) throws TransactionConflictException { if (writes.isEmpty() || !conflictHandler.checkWriteWriteConflicts()) { return; } Set<CellConflict> spanningWrites = Sets.newHashSet(); Set<CellConflict> dominatingWrites = Sets.newHashSet(); Map<Cell, Long> keysToLoad = Maps.asMap(writes.keySet(), Functions.constant(Long.MAX_VALUE)); while (!keysToLoad.isEmpty()) { keysToLoad = detectWriteAlreadyCommittedInternal( tableRef, keysToLoad, spanningWrites, dominatingWrites, transactionService); } if (conflictHandler == ConflictHandler.RETRY_ON_VALUE_CHANGED) { throwIfValueChangedConflict(tableRef, writes, spanningWrites, dominatingWrites, commitLocksToken); } else { if (!spanningWrites.isEmpty() || !dominatingWrites.isEmpty()) { transactionOutcomeMetrics.markWriteWriteConflict(tableRef); throw TransactionConflictException.create(tableRef, getStartTimestamp(), spanningWrites, dominatingWrites, System.currentTimeMillis() - timeCreated); } } }
private void throwIfImmutableTsOrCommitLocksExpired(@Nullable LockToken commitLocksToken) { Set<LockToken> expiredLocks = refreshCommitAndImmutableTsLocks(commitLocksToken); if (!expiredLocks.isEmpty()) { final String baseMsg = "Required locks are no longer valid. "; String expiredLocksErrorString = getExpiredLocksErrorString(commitLocksToken, expiredLocks); TransactionLockTimeoutException ex = new TransactionLockTimeoutException(baseMsg + expiredLocksErrorString); log.error(baseMsg + "{}", expiredLocksErrorString, ex); transactionOutcomeMetrics.markLocksExpired(); throw ex; } }
public void markWriteWriteConflict(TableReference tableReference) { getMeterForTable(TransactionOutcome.WRITE_WRITE_CONFLICT, tableReference).mark(); }
public static TransactionOutcomeMetrics create(MetricsManager metricsManager) { return new TransactionOutcomeMetrics(metricsManager, LoggingArgs::isSafe); }
@Override public void abort() { if (state.get() == State.ABORTED) { return; } while (true) { ensureUncommitted(); if (state.compareAndSet(State.UNCOMMITTED, State.ABORTED)) { if (hasWrites()) { throwIfPreCommitRequirementsNotMet(null, getStartTimestamp()); } transactionOutcomeMetrics.markAbort(); return; } } }
public void markRollbackOtherTransaction() { getMeter(TransactionOutcome.ROLLBACK_OTHER).mark(); }
@Test public void conflictsInUnsafeTablesAreNotIncludedAsTags() { transactionOutcomeMetrics.markWriteWriteConflict(UNSAFE_REFERENCE_1); transactionOutcomeMetrics.markReadWriteConflict(UNSAFE_REFERENCE_2); assertThat(transactionOutcomeMetrics) .hasNoKnowledgeOf(UNSAFE_REFERENCE_1) .hasNoKnowledgeOf(UNSAFE_REFERENCE_2); }
transactionOutcomeMetrics.markSuccessfulCommit(); } else { state.set(State.FAILED); transactionOutcomeMetrics.markFailedCommit();
Predicates.in(conflictingCells), CellConflict.getCellFunction()); transactionOutcomeMetrics.markWriteWriteConflict(table); throw TransactionConflictException.create(table, getStartTimestamp(),
transactionOutcomeMetrics.markLocksExpired(); throw new TransactionLockTimeoutException("Our commit was already rolled back at commit time" + " because our locks timed out. startTs: " + getStartTimestamp() + ". "
public void markReadWriteConflict(TableReference tableReference) { getMeterForTable(TransactionOutcome.READ_WRITE_CONFLICT, tableReference).mark(); }
public static TransactionOutcomeMetrics create(MetricsManager metricsManager) { return new TransactionOutcomeMetrics(metricsManager, LoggingArgs::isSafe); }
@Override public void abort() { if (state.get() == State.ABORTED) { return; } while (true) { ensureUncommitted(); if (state.compareAndSet(State.UNCOMMITTED, State.ABORTED)) { if (hasWrites()) { throwIfPreCommitRequirementsNotMet(null, getStartTimestamp()); } transactionOutcomeMetrics.markAbort(); return; } } }
public TransactionOutcomeMetricsAssert hasNoKnowledgeOf(TableReference tableReference) { assertMetricNotExists(actual.getMetricName( TransactionOutcome.READ_WRITE_CONFLICT, getTableReferenceTags(tableReference))); assertMetricNotExists(actual.getMetricName( TransactionOutcome.WRITE_WRITE_CONFLICT, getTableReferenceTags(tableReference))); return this; }