Package com.persistit

Examples of com.persistit.TransactionStatus


        long commitTimestamp = tsv;
        /*
         * There were members on at least one of the lists so we need to try to
         * find the corresponding TransactionStatus identified by tsv.
         */
        TransactionStatus status = getStatus(tsv);
        /*
         * The result can be null in the event the TransactionStatus was freed.
         * It could only have been freed if its transaction committed at a tc
         * that is now primordial. Therefore if status is null we can return tsv
         * as the imputed tc value.
         */
        if (status != null) {
            /*
             * Found the TransactionStatus identified by tsv, but by the time we
             * we read its tc, that TransactionStatus may already be committed
             * to a new transaction with a different ts. Therefore we briefly to
             * lock it to get an accurate reading.
             *
             * If the TransactionStatus was concurrently freed and reallocated
             * to a different transaction, then it must have committed before
             * the floor timestamp.
             */
            long tc = status.getTc();
            while (status.getTs() == tsv) {
                if (tc >= ts) {
                    return UNCOMMITTED;
                }
                if (tc >= 0) {
                    return tc;
                }
                if (tc == ABORTED) {
                    return tc;
                }
                /*
                 * Waiting for status to resolve. To do this, lock, unlock and
                 * then retry.
                 */
                if (status.wwLock(SHORT_TIMEOUT)) {
                    tc = status.getTc();
                    status.wwUnlock();
                }
            }
        }
        return commitTimestamp;
    }
View Full Code Here


    }

    private TransactionStatus registerTransaction(final boolean forCheckpoint) throws TimeoutException,
            InterruptedException {
        Debug.suspend();
        final TransactionStatus status;
        final TransactionIndexBucket bucket;
        synchronized (this) {
            final long ts;
            if (forCheckpoint) {
                ts = _timestampAllocator.allocateCheckpointTimestamp();
            } else {
                ts = _timestampAllocator.updateTimestamp();
            }
            int index = hashIndex(ts);
            bucket = _hashTable[index];
            bucket.lock();
            try {
                status = bucket.allocateTransactionStatus();
                status.initialize(ts);
                bucket.addCurrent(status);
            } finally {
                bucket.unlock();
            }
        }

        try {
            /*
             * The TransactionStatus is locked for the entire duration of the
             * running transaction. The following call should always succeed
             * immediately; a TimeoutException here signifies a software failure
             * or a thread terminated by {@link Thread#stop()} somewhere else.
             */
            if (!status.wwLock(VERY_LONG_TIMEOUT)) {
                throw new IllegalStateException("wwLock was unavailable on newly allocated TransactionStatus");
            }
            /*
             * General hygiene - call reduce if the current count is bigger than
             * the threshold - but this is merely an optimization and the test
             * does not need to be synchronized.
             */
            if (bucket.getCurrentCount() > _longRunningThreshold) {
                bucket.lock();
                try {
                    bucket.reduce();
                } finally {
                    bucket.unlock();
                }
            }
        } catch (InterruptedException ie) {
            status.abort();
            status.complete(0);
            throw ie;
        }
        return status;
    }
View Full Code Here

            /*
             * Same transaction
             */
            return 0;
        }
        final TransactionStatus target = getStatus(tsv);
        if (target == null) {
            /*
             * Target is gone
             */
            return 0;
        }
        if (target.getTs() != tsv) {
            /*
             * By the time the selected TransactionStatus has been found, it may
             * already be allocated to another transaction. If that's true the
             * the original transaction must have committed. The following code
             * checks the identity of the transaction on each iteration after
             * short lock attempts.
             */
            return 0;
        }

        if (target.getTc() > 0 && target.getTc() < source.getTs() || target.getTc() == ABORTED) {
            /*
             * Target is committed or aborted
             */
            return 0;
        }

        final long start = System.currentTimeMillis();
        /*
         * Blocks until the target transaction finishes, either by committing or
         * aborting.
         */
        do {
            try {
                /*
                 * Link to target transaction, then test for deadlock. Abort
                 * immediately
                 */
                source.setDepends(target);
                if (isDeadlocked(source)) {
                    _deadlockCounter.incrementAndGet();
                    return UNCOMMITTED;
                }
                if (target.wwLock(Math.min(timeout, SHORT_TIMEOUT))) {
                    try {
                        if (target.getTs() != tsv) {
                            return 0;
                        }
                        final long tc = target.getTc();
                        if (tc == ABORTED) {
                            return 0;
                        }
                        /*
                         * The following is true because the target's wwLock was
                         * acquired, which means it has either aborted or
                         * committed.
                         */
                        if (tc < 0 || tc == UNCOMMITTED) {
                            throw new IllegalStateException("Commit incomplete");
                        }
                        /*
                         * true if and only if this is a concurrent transaction
                         */
                        if (tc > source.getTs()) {
                            return tc;
                        } else {
                            return 0;
                        }

                    } finally {
                        target.wwUnlock();
                    }
                } else {
                    if (timeout == 0) {
                        return TIMED_OUT;
                    }
View Full Code Here

        } while (timeout > 0 && System.currentTimeMillis() - start < timeout);
        return TIMED_OUT;
    }

    boolean isDeadlocked(final TransactionStatus source) {
        TransactionStatus s = source;
        for (int count = 0; count < CYCLE_LIMIT; count++) {
            s = s.getDepends();
            if (s == null || s.getTc() == ABORTED) {
                return false;
            } else if (s == source) {
                return true;
            }
        }
View Full Code Here

     *             if the supplied <code>versionHandle</code> does not identify
     *             an aborted transaction.
     */
    long decrementMvvCount(final long versionHandle) {
        final long tsv = vh2ts(versionHandle);
        final TransactionStatus status = getStatus(tsv);
        if (status == null || status.getTs() != tsv || status.getTc() != ABORTED) {
            throw new IllegalArgumentException("No such aborted transaction " + versionHandle);
        }
        return status.decrementMvvCount();
    }
View Full Code Here

     *
     * @param timestamp
     * @throws InterruptedException
     */
    void injectAbortedTransaction(final long ts) throws InterruptedException {
        final TransactionStatus status;
        final TransactionIndexBucket bucket;
        synchronized (this) {
            int index = hashIndex(ts);
            bucket = _hashTable[index];
            bucket.lock();
            try {
                status = bucket.allocateTransactionStatus();
                status.initializeAsAborted(ts);
                bucket.addAborted(status);
            } finally {
                bucket.unlock();
            }
        }
View Full Code Here

TOP

Related Classes of com.persistit.TransactionStatus

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.