Search in sources :

Example 1 with SafeAndUnsafeTableReferences

use of com.palantir.atlasdb.logging.LoggingArgs.SafeAndUnsafeTableReferences in project atlasdb by palantir.

the class SnapshotTransaction method commitWrites.

private void commitWrites(TransactionService transactionService) {
    if (!hasWrites()) {
        if (hasReads()) {
            // verify any pre-commit conditions on the transaction
            preCommitCondition.throwIfConditionInvalid(getStartTimestamp());
            // to ensure that sweep hasn't thoroughly deleted cells we tried to read
            if (validationNecessaryForInvolvedTables()) {
                throwIfImmutableTsOrCommitLocksExpired(null);
            }
            return;
        }
        return;
    }
    Timer.Context acquireLocksTimer = getTimer("commitAcquireLocks").time();
    LockToken commitLocksToken = acquireLocksForCommit();
    long millisForLocks = TimeUnit.NANOSECONDS.toMillis(acquireLocksTimer.stop());
    try {
        Timer.Context conflictsTimer = getTimer("commitCheckingForConflicts").time();
        throwIfConflictOnCommit(commitLocksToken, transactionService);
        long millisCheckingForConflicts = TimeUnit.NANOSECONDS.toMillis(conflictsTimer.stop());
        Timer.Context writesTimer = getTimer("commitWrite").time();
        keyValueService.multiPut(writesByTable, getStartTimestamp());
        long millisForWrites = TimeUnit.NANOSECONDS.toMillis(writesTimer.stop());
        // Now that all writes are done, get the commit timestamp
        // We must do this before we check that our locks are still valid to ensure that
        // other transactions that will hold these locks are sure to have start
        // timestamps after our commit timestamp.
        long commitTimestamp = timelockService.getFreshTimestamp();
        commitTsForScrubbing = commitTimestamp;
        // punch on commit so that if hard delete is the only thing happening on a system,
        // we won't block forever waiting for the unreadable timestamp to advance past the
        // scrub timestamp (same as the hard delete transaction's start timestamp)
        Timer.Context punchTimer = getTimer("millisForPunch").time();
        cleaner.punch(commitTimestamp);
        long millisForPunch = TimeUnit.NANOSECONDS.toMillis(punchTimer.stop());
        throwIfReadWriteConflictForSerializable(commitTimestamp);
        // Verify that our locks and pre-commit conditions are still valid before we actually commit;
        // this throwIfPreCommitRequirementsNotMet is required by the transaction protocol for correctness
        throwIfPreCommitRequirementsNotMet(commitLocksToken, commitTimestamp);
        Timer.Context commitTsTimer = getTimer("commitPutCommitTs").time();
        putCommitTimestamp(commitTimestamp, commitLocksToken, transactionService);
        long millisForCommitTs = TimeUnit.NANOSECONDS.toMillis(commitTsTimer.stop());
        long millisSinceCreation = System.currentTimeMillis() - timeCreated;
        getTimer("commitTotalTimeSinceTxCreation").update(millisSinceCreation, TimeUnit.MILLISECONDS);
        getHistogram(AtlasDbMetricNames.SNAPSHOT_TRANSACTION_BYTES_WRITTEN).update(byteCount.get());
        if (perfLogger.isDebugEnabled()) {
            SafeAndUnsafeTableReferences tableRefs = LoggingArgs.tableRefs(writesByTable.keySet());
            perfLogger.debug("Committed {} bytes with locks, start ts {}, commit ts {}, " + "acquiring locks took {} ms, checking for conflicts took {} ms, " + "writing took {} ms, punch took {} ms, putCommitTs took {} ms, " + "total time since tx creation {} ms, tables: {}.", SafeArg.of("numBytes", byteCount.get()), SafeArg.of("startTs", getStartTimestamp()), SafeArg.of("commitTs", commitTimestamp), SafeArg.of("millisForLocks", millisForLocks), SafeArg.of("millisCheckForConflicts", millisCheckingForConflicts), SafeArg.of("millisForWrites", millisForWrites), SafeArg.of("millisForPunch", millisForPunch), SafeArg.of("millisForCommitTs", millisForCommitTs), SafeArg.of("millisSinceCreation", millisSinceCreation), tableRefs.safeTableRefs(), tableRefs.unsafeTableRefs());
        }
        sweepQueue.enqueue(writesByTable, getStartTimestamp());
    } finally {
        timelockService.unlock(ImmutableSet.of(commitLocksToken));
    }
}
Also used : Timer(com.codahale.metrics.Timer) LockToken(com.palantir.lock.v2.LockToken) SafeAndUnsafeTableReferences(com.palantir.atlasdb.logging.LoggingArgs.SafeAndUnsafeTableReferences)

Aggregations

Timer (com.codahale.metrics.Timer)1 SafeAndUnsafeTableReferences (com.palantir.atlasdb.logging.LoggingArgs.SafeAndUnsafeTableReferences)1 LockToken (com.palantir.lock.v2.LockToken)1