public void removeExpiredTxns(long currentMillis) {
        writeLock();
        try {
            StringBuilder expiredTxnMsgs = new StringBuilder(1024);
            String prefix = "";
            int numJobsToRemove = getTransactionNum() - Config.label_keep_max_num;
            while (!finalStatusTransactionStateDeque.isEmpty()) {
                TransactionState transactionState = finalStatusTransactionStateDeque.getFirst();
                if (transactionState.isExpired(currentMillis) || numJobsToRemove > 0) {
                    finalStatusTransactionStateDeque.pop();
                    clearTransactionState(transactionState);
                    --numJobsToRemove;
                    expiredTxnMsgs.append(prefix);
                    prefix = ", ";
                    expiredTxnMsgs.append(transactionState.getTransactionId());
                    if (expiredTxnMsgs.length() > 4096) {
                        LOG.info("transaction list [{}] are expired, remove them from transaction manager",
                                expiredTxnMsgs);
                        expiredTxnMsgs = new StringBuilder(1024);
                    }
                } else {
                    break;
                }
            }
            if (expiredTxnMsgs.length() > 0) {
                LOG.info("transaction list [{}] are expired, remove them from transaction manager",
                        expiredTxnMsgs);
            }
        } finally {
            writeUnlock();
        }
    }
@Test
    public void testRemoveExpiredTxns() throws AnalysisException {
        DatabaseTransactionMgr masterDbTransMgr =
                masterTransMgr.getDatabaseTransactionMgr(GlobalStateMgrTestUtil.testDbId1);
        Config.label_keep_max_second = -1;
        long currentMillis = System.currentTimeMillis();
        masterDbTransMgr.removeExpiredTxns(currentMillis);
        assertEquals(0, masterDbTransMgr.getFinishedTxnNums());
        assertEquals(7, masterDbTransMgr.getTransactionNum());
        assertNull(masterDbTransMgr.unprotectedGetTxnIdsByLabel(GlobalStateMgrTestUtil.testTxnLable1));
    }