use of org.apache.hadoop.hive.metastore.api.GetOpenTxnsResponse in project hive by apache.
the class TestTxnHandler method testValidTxnsSomeOpen.
@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]);
}
use of org.apache.hadoop.hive.metastore.api.GetOpenTxnsResponse in project hive by apache.
the class TestAcidTxnCleanerService method cleansEmptyAbortedBatchTxns.
@Test
public void cleansEmptyAbortedBatchTxns() throws Exception {
// add one non-empty aborted txn
openNonEmptyThenAbort();
// add a batch of empty, aborted txns
txnHandler.setOpenTxnTimeOutMillis(30000);
MetastoreConf.setLongVar(conf, MetastoreConf.ConfVars.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.setOpenTxnTimeOutMillis(1);
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());
underTest.run();
openTxns = txnHandler.getOpenTxns();
Assert.assertEquals(2, openTxns.getOpen_txnsSize());
Assert.assertTrue("The max txnId should be at least", getMaxTxnId() >= TxnStore.TIMED_OUT_TXN_ABORT_BATCH_SIZE + 50 + 1);
}
use of org.apache.hadoop.hive.metastore.api.GetOpenTxnsResponse in project hive by apache.
the class TestOpenTxn method testGapWithOldOpen.
@Test
public void testGapWithOldOpen() throws Exception {
OpenTxnRequest openTxnRequest = new OpenTxnRequest(1, "me", "localhost");
txnHandler.openTxns(openTxnRequest);
Thread.sleep(1000);
long second = txnHandler.openTxns(openTxnRequest).getTxn_ids().get(0);
deleteTransaction(second);
txnHandler.openTxns(openTxnRequest);
GetOpenTxnsResponse openTxns = txnHandler.getOpenTxns();
Assert.assertEquals(3, openTxns.getOpen_txnsSize());
}
use of org.apache.hadoop.hive.metastore.api.GetOpenTxnsResponse in project hive by apache.
the class TestOpenTxn method testGap.
@Test
public void testGap() throws Exception {
OpenTxnRequest openTxnRequest = new OpenTxnRequest(1, "me", "localhost");
txnHandler.openTxns(openTxnRequest);
long second = txnHandler.openTxns(openTxnRequest).getTxn_ids().get(0);
deleteTransaction(second);
txnHandler.openTxns(openTxnRequest);
GetOpenTxnsResponse openTxns = txnHandler.getOpenTxns();
Assert.assertEquals(3, openTxns.getOpen_txnsSize());
}
use of org.apache.hadoop.hive.metastore.api.GetOpenTxnsResponse in project hive by apache.
the class OpenTxnList method toOpenTxnsResponse.
public GetOpenTxnsResponse toOpenTxnsResponse(List<TxnType> excludeTxnTypes) {
List<Long> openList = new ArrayList<>();
long minOpenTxn = Long.MAX_VALUE;
BitSet abortedBits = new BitSet();
for (OpenTxn openTxn : getOpenTxnList()) {
if (openTxn.getStatus() == OPEN) {
minOpenTxn = Math.min(minOpenTxn, openTxn.getTxnId());
}
if (excludeTxnTypes.contains(openTxn.getType())) {
continue;
}
openList.add(openTxn.getTxnId());
if (openTxn.getStatus() == ABORTED) {
abortedBits.set(openList.size() - 1);
}
}
ByteBuffer byteBuffer = ByteBuffer.wrap(abortedBits.toByteArray());
GetOpenTxnsResponse otr = new GetOpenTxnsResponse(getHwm(), openList, byteBuffer);
if (minOpenTxn < Long.MAX_VALUE) {
otr.setMin_open_txn(minOpenTxn);
}
return otr;
}
Aggregations