public static ValidTxnList createValidTxnListForCleaner(GetOpenTxnsResponse txns, long minOpenTxnGLB) { long highWaterMark = minOpenTxnGLB - 1; long[] abortedTxns = new long[txns.getOpen_txnsSize()]; BitSet abortedBits = BitSet.valueOf(txns.getAbortedBits()); int i = 0; for(long txnId : txns.getOpen_txns()) { if(txnId > highWaterMark) { break; } if(abortedBits.get(i)) { abortedTxns[i] = txnId; } else { assert false : JavaUtils.txnIdToString(txnId) + " is open and <= hwm:" + highWaterMark; } ++i; } abortedTxns = Arrays.copyOf(abortedTxns, i); BitSet bitSet = new BitSet(abortedTxns.length); bitSet.set(0, abortedTxns.length); //add ValidCleanerTxnList? - could be problematic for all the places that read it from // string as they'd have to know which object to instantiate return new ValidReadTxnList(abortedTxns, bitSet, highWaterMark, Long.MAX_VALUE); } /**
assertEquals(3, txnList.getOpen_txnsSize()); txnHandler.cleanEmptyAbortedTxns(); txnList = txnHandler.getOpenTxns(); assertEquals(2, txnList.getOpen_txnsSize()); txnHandler.cleanEmptyAbortedTxns(); txnList = txnHandler.getOpenTxns(); assertEquals(3, txnList.getOpen_txnsSize());
@Test public void cleanEmptyAbortedTxns() throws Exception { // Test that we are cleaning aborted transactions with no components left in txn_components. // Put one aborted transaction with an entry in txn_components to make sure we don't // accidently clean it too. Table t = newTable("default", "ceat", false); long txnid = openTxn(); LockComponent comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.TABLE, "default"); comp.setTablename("ceat"); comp.setOperationType(DataOperationType.UPDATE); List<LockComponent> components = new ArrayList<LockComponent>(1); components.add(comp); LockRequest req = new LockRequest(components, "me", "localhost"); req.setTxnid(txnid); LockResponse res = txnHandler.lock(req); txnHandler.abortTxn(new AbortTxnRequest(txnid)); conf.setIntVar(HiveConf.ConfVars.HIVE_TXN_MAX_OPEN_BATCH, TxnStore.TIMED_OUT_TXN_ABORT_BATCH_SIZE + 50); OpenTxnsResponse resp = txnHandler.openTxns(new OpenTxnRequest( TxnStore.TIMED_OUT_TXN_ABORT_BATCH_SIZE + 50, "user", "hostname")); txnHandler.abortTxns(new AbortTxnsRequest(resp.getTxn_ids())); GetOpenTxnsResponse openTxns = txnHandler.getOpenTxns(); Assert.assertEquals(TxnStore.TIMED_OUT_TXN_ABORT_BATCH_SIZE + 50 + 1, openTxns.getOpen_txnsSize()); startInitiator(); openTxns = txnHandler.getOpenTxns(); Assert.assertEquals(1, openTxns.getOpen_txnsSize()); }
TxnStore.FAILED_RESPONSE, resp.getCompacts().get(0).getState()); GetOpenTxnsResponse openResp = txnHandler.getOpenTxns(); Assert.assertEquals(openResp.toString(), 1, openResp.getOpen_txnsSize()); Assert.assertEquals(openResp.toString(), 1, openResp.getOpen_txnsSize()); Assert.assertEquals(openResp.toString(), 0, openResp.getOpen_txnsSize());