@Override public OpenTxnsResponse open_txns(OpenTxnRequest rqst) throws TException { OpenTxnsResponse response = getTxnHandler().openTxns(rqst); List<Long> txnIds = response.getTxn_ids(); if (txnIds != null && listeners != null && !listeners.isEmpty()) { MetaStoreListenerNotifier.notifyEvent(listeners, EventType.OPEN_TXN, new OpenTxnEvent(txnIds, this)); } return response; }
private long openTxn() throws MetaException { List<Long> txns = txnHandler.openTxns(new OpenTxnRequest(1, "me", "localhost")).getTxn_ids(); return txns.get(0); }
private long openTxn() throws MetaException { List<Long> txns = txnHandler.openTxns(new OpenTxnRequest(1, "me", "localhost")).getTxn_ids(); return txns.get(0); }
private long openTxn() throws MetaException { List<Long> txns = txnHandler.openTxns(new OpenTxnRequest(1, "me", "localhost")).getTxn_ids(); return txns.get(0); }
protected long openTxn() throws MetaException { List<Long> txns = txnHandler.openTxns(new OpenTxnRequest(1, System.getProperty("user.name"), Worker.hostname())).getTxn_ids(); return txns.get(0); }
private List<Long> replOpenTxnForTest(long startId, int numTxn, String replPolicy) throws Exception { conf.setIntVar(HiveConf.ConfVars.HIVE_TXN_MAX_OPEN_BATCH, numTxn); long lastId = startId + numTxn - 1; OpenTxnRequest rqst = new OpenTxnRequest(numTxn, "me", "localhost"); rqst.setReplPolicy(replPolicy); rqst.setReplSrcTxnIds(LongStream.rangeClosed(startId, lastId) .boxed().collect(Collectors.toList())); OpenTxnsResponse openedTxns = txnHandler.openTxns(rqst); List<Long> txnList = openedTxns.getTxn_ids(); assertEquals(txnList.size(), numTxn); int numTxnPresentNow = TxnDbUtil.countQueryAgent(conf, "select count(*) from TXNS where TXN_ID >= " + txnList.get(0) + " and TXN_ID <= " + txnList.get(numTxn - 1)); assertEquals(numTxn, numTxnPresentNow); checkReplTxnForTest(startId, lastId, replPolicy, txnList); return txnList; }
@Test public void testValidTxnsNoneOpen() throws Exception { txnHandler.openTxns(new OpenTxnRequest(2, "me", "localhost")); txnHandler.commitTxn(new CommitTxnRequest(1)); txnHandler.commitTxn(new CommitTxnRequest(2)); GetOpenTxnsInfoResponse txnsInfo = txnHandler.getOpenTxnsInfo(); assertEquals(2L, txnsInfo.getTxn_high_water_mark()); assertEquals(0, txnsInfo.getOpen_txns().size()); GetOpenTxnsResponse txns = txnHandler.getOpenTxns(); assertEquals(2L, txns.getTxn_high_water_mark()); assertEquals(0, txns.getOpen_txns().size()); }
@Test public void testValidTxnsSomeOpen() throws Exception { txnHandler.openTxns(new OpenTxnRequest(3, "me", "localhost")); txnHandler.abortTxn(new AbortTxnRequest(1)); txnHandler.commitTxn(new CommitTxnRequest(2)); GetOpenTxnsInfoResponse txnsInfo = txnHandler.getOpenTxnsInfo(); assertEquals(3L, txnsInfo.getTxn_high_water_mark()); assertEquals(2, txnsInfo.getOpen_txns().size()); assertEquals(1L, txnsInfo.getOpen_txns().get(0).getId()); assertEquals(TxnState.ABORTED, txnsInfo.getOpen_txns().get(0).getState()); assertEquals(3L, txnsInfo.getOpen_txns().get(1).getId()); assertEquals(TxnState.OPEN, txnsInfo.getOpen_txns().get(1).getState()); GetOpenTxnsResponse txns = txnHandler.getOpenTxns(); assertEquals(3L, txns.getTxn_high_water_mark()); assertEquals(2, txns.getOpen_txns().size()); boolean[] saw = new boolean[4]; for (int i = 0; i < saw.length; i++) saw[i] = false; for (Long tid : txns.getOpen_txns()) { saw[tid.intValue()] = true; } assertTrue(saw[1]); assertFalse(saw[2]); assertTrue(saw[3]); }
@Test public void testRecoverManyTimeouts() throws Exception { long timeout = txnHandler.setTimeout(1); try { txnHandler.openTxns(new OpenTxnRequest(503, "me", "localhost")); Thread.sleep(10); txnHandler.performTimeOuts(); GetOpenTxnsInfoResponse rsp = txnHandler.getOpenTxnsInfo(); int numAborted = 0; for (TxnInfo txnInfo : rsp.getOpen_txns()) { assertEquals(TxnState.ABORTED, txnInfo.getState()); numAborted++; } assertEquals(503, numAborted); } finally { txnHandler.setTimeout(timeout); } }
@Test public void testReplTimeouts() throws Exception { long timeout = txnHandler.setTimeout(1); try { OpenTxnRequest request = new OpenTxnRequest(3, "me", "localhost"); OpenTxnsResponse response = txnHandler.openTxns(request); request.setReplPolicy("default.*"); request.setReplSrcTxnIds(response.getTxn_ids()); OpenTxnsResponse responseRepl = txnHandler.openTxns(request); Thread.sleep(10); txnHandler.performTimeOuts(); GetOpenTxnsInfoResponse rsp = txnHandler.getOpenTxnsInfo(); int numAborted = 0; int numOpen = 0; for (TxnInfo txnInfo : rsp.getOpen_txns()) { if (TxnState.ABORTED == txnInfo.getState()) { assertTrue(response.getTxn_ids().contains(txnInfo.getId())); numAborted++; } if (TxnState.OPEN == txnInfo.getState()) { assertTrue(responseRepl.getTxn_ids().contains(txnInfo.getId())); numOpen++; } } assertEquals(3, numAborted); assertEquals(3, numOpen); } finally { txnHandler.setTimeout(timeout); } }
String dbName = "default"; String tableName = "adp_table"; OpenTxnsResponse openTxns = txnHandler.openTxns(new OpenTxnRequest(1, "me", "localhost")); long txnId = openTxns.getTxn_ids().get(0);
protected void burnThroughTransactions(String dbName, String tblName, int num, Set<Long> open, Set<Long> aborted) throws MetaException, NoSuchTxnException, TxnAbortedException { OpenTxnsResponse rsp = txnHandler.openTxns(new OpenTxnRequest(num, "me", "localhost")); AllocateTableWriteIdsRequest awiRqst = new AllocateTableWriteIdsRequest(dbName, tblName); awiRqst.setTxnIds(rsp.getTxn_ids()); AllocateTableWriteIdsResponse awiResp = txnHandler.allocateTableWriteIds(awiRqst); int i = 0; for (long tid : rsp.getTxn_ids()) { assert(awiResp.getTxnToWriteIds().get(i++).getTxnId() == tid); if (aborted != null && aborted.contains(tid)) { txnHandler.abortTxn(new AbortTxnRequest(tid)); } else if (open == null || (open != null && !open.contains(tid))) { txnHandler.commitTxn(new CommitTxnRequest(tid)); } } }
hiveConf.setTimeVar(HiveConf.ConfVars.HIVE_COUNT_OPEN_TXNS_INTERVAL, 10, TimeUnit.MILLISECONDS); TxnStore txnHandler = TxnUtils.getTxnStore(hiveConf); OpenTxnsResponse openTxnsResponse = txnHandler.openTxns(new OpenTxnRequest(3, "me", "localhost")); txnHandler.openTxns(new OpenTxnRequest(1, "you", "localhost")); } catch (MetaException e) { exception = e; txnHandler.openTxns(new OpenTxnRequest(1, "him", "localhost")); } catch (MetaException e) { exception = e;
@Test public void testAbortTxn() throws Exception { OpenTxnsResponse openedTxns = txnHandler.openTxns(new OpenTxnRequest(3, "me", "localhost")); List<Long> txnList = openedTxns.getTxn_ids(); long first = txnList.get(0);
txnHandler.markCleaned(ci); txnHandler.openTxns(new OpenTxnRequest(1, "me", "localhost")); txnHandler.cleanEmptyAbortedTxns(); txnList = txnHandler.getOpenTxns();
@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()); }
@Override public OpenTxnsResponse open_txns(OpenTxnRequest rqst) throws TException { OpenTxnsResponse response = getTxnHandler().openTxns(rqst); List<Long> txnIds = response.getTxn_ids(); if (txnIds != null && listeners != null && !listeners.isEmpty()) { MetaStoreListenerNotifier.notifyEvent(listeners, EventType.OPEN_TXN, new OpenTxnEvent(txnIds, this)); } return response; }