~pbeaman/akiban-persistit/3.3.1-SNAPSHOT

« back to all changes in this revision

Viewing changes to src/main/java/com/persistit/Persistit.java

merge nwilliams: Fix closing of transactions from threads that have been abandoned.

https://code.launchpad.net/~nwilliams/akiban-persistit/handle-abandoned-txn-status/+merge/149643

Show diffs side-by-side

added added

removed removed

Lines of Context:
1496
1496
        return _bufferPoolTable;
1497
1497
    }
1498
1498
 
 
1499
    /**
 
1500
     * Remove any sessions that have expired and close transactions associated
 
1501
     * with them. Also flush statistics for all known volumes.
 
1502
     */
1499
1503
    void cleanup() {
1500
 
        final Set<SessionId> sessionIds;
1501
 
        synchronized (_transactionSessionMap) {
1502
 
            sessionIds = new HashSet<SessionId>(_transactionSessionMap.keySet());
1503
 
        }
1504
 
        for (final SessionId sessionId : sessionIds) {
1505
 
            if (!sessionId.isAlive()) {
1506
 
                Transaction transaction = null;
1507
 
                synchronized (_transactionSessionMap) {
1508
 
                    transaction = _transactionSessionMap.remove(sessionId);
1509
 
                }
1510
 
                if (transaction != null) {
1511
 
                    try {
1512
 
                        transaction.close();
1513
 
                    } catch (final PersistitException e) {
1514
 
                        _logBase.exception.log(e);
1515
 
                    }
1516
 
                }
1517
 
            }
1518
 
        }
 
1504
        closeZombieTransactions(false);
1519
1505
        final List<Volume> volumes;
1520
1506
        synchronized (this) {
1521
1507
            volumes = new ArrayList<Volume>(_volumes);
1676
1662
            waitForIOTaskStop(task);
1677
1663
 
1678
1664
            interruptActiveThreads(SHORT_DELAY);
1679
 
            closeZombieTransactions();
 
1665
            closeZombieTransactions(true);
1680
1666
 
1681
1667
            for (final Volume volume : volumes) {
1682
1668
                volume.close();
1695
1681
        releaseAllResources();
1696
1682
    }
1697
1683
 
1698
 
    private void closeZombieTransactions() {
 
1684
    private void closeZombieTransactions(boolean removeAllSessions) {
1699
1685
        final Set<SessionId> sessionIds;
1700
1686
        synchronized (_transactionSessionMap) {
1701
1687
            sessionIds = new HashSet<SessionId>(_transactionSessionMap.keySet());
1702
1688
        }
1703
1689
        for (final SessionId sessionId : sessionIds) {
1704
 
            Transaction transaction = null;
1705
 
            synchronized (_transactionSessionMap) {
1706
 
                transaction = _transactionSessionMap.remove(sessionId);
1707
 
            }
1708
 
            if (!sessionId.isAlive()) {
 
1690
            if (!sessionId.isAlive() || removeAllSessions) {
 
1691
                Transaction transaction = null;
 
1692
                synchronized (_transactionSessionMap) {
 
1693
                    transaction = _transactionSessionMap.remove(sessionId);
 
1694
                }
1709
1695
                if (transaction != null) {
1710
1696
                    try {
1711
1697
                        transaction.close();