use of org.apache.hadoop.hive.metastore.api.AbortTxnRequest in project hive by apache.
the class TestTxnHandler method testCheckLockTxnAborted.
@Test
public void testCheckLockTxnAborted() throws Exception {
// Test that when a transaction is aborted, the heartbeat fails
long txnid = openTxn();
LockComponent comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb");
comp.setTablename("mytable");
comp.setPartitionname("mypartition");
comp.setOperationType(DataOperationType.DELETE);
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);
long lockid = res.getLockid();
txnHandler.abortTxn(new AbortTxnRequest(txnid));
try {
// This will throw NoSuchLockException (even though it's the
// transaction we've closed) because that will have deleted the lock.
txnHandler.checkLock(new CheckLockRequest(lockid));
fail("Allowed to check lock on aborted transaction.");
} catch (NoSuchLockException e) {
}
}
use of org.apache.hadoop.hive.metastore.api.AbortTxnRequest in project hive by apache.
the class TestTxnHandler method testCheckLockAcquireAfterWaiting.
@Test
public void testCheckLockAcquireAfterWaiting() throws Exception {
LockComponent comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb");
comp.setTablename("mytable");
comp.setPartitionname("mypartition");
comp.setOperationType(DataOperationType.DELETE);
List<LockComponent> components = new ArrayList<LockComponent>(1);
components.add(comp);
LockRequest req = new LockRequest(components, "me", "localhost");
long txnId = openTxn();
req.setTxnid(txnId);
LockResponse res = txnHandler.lock(req);
long lockid1 = res.getLockid();
assertTrue(res.getState() == LockState.ACQUIRED);
comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb");
comp.setTablename("mytable");
comp.setPartitionname("mypartition");
comp.setOperationType(DataOperationType.UPDATE);
components.clear();
components.add(comp);
req = new LockRequest(components, "me", "localhost");
req.setTxnid(openTxn());
res = txnHandler.lock(req);
long lockid2 = res.getLockid();
assertTrue(res.getState() == LockState.WAITING);
txnHandler.abortTxn(new AbortTxnRequest(txnId));
res = txnHandler.checkLock(new CheckLockRequest(lockid2));
assertTrue(res.getState() == LockState.ACQUIRED);
}
use of org.apache.hadoop.hive.metastore.api.AbortTxnRequest in project hive by apache.
the class TestTxnHandler method testUnlockOnAbort.
@Test
public void testUnlockOnAbort() throws Exception {
// Test that committing unlocks
long txnid = openTxn();
LockComponent comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb");
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);
assertTrue(res.getState() == LockState.ACQUIRED);
txnHandler.abortTxn(new AbortTxnRequest(txnid));
assertEquals(0, txnHandler.numLocksInLockTable());
}
use of org.apache.hadoop.hive.metastore.api.AbortTxnRequest in project hive by apache.
the class TestTxnHandler method testHeartbeatTxnAborted.
@Test
public void testHeartbeatTxnAborted() throws Exception {
// Test that when a transaction is aborted, the heartbeat fails
openTxn();
txnHandler.abortTxn(new AbortTxnRequest(1));
HeartbeatRequest h = new HeartbeatRequest();
h.setTxnid(1);
try {
txnHandler.heartbeat(h);
fail("Told there was a txn, when it should have been aborted.");
} catch (TxnAbortedException e) {
}
}
use of org.apache.hadoop.hive.metastore.api.AbortTxnRequest in project hive by apache.
the class TestInitiator method majorCompactOnPartitionTooManyAborts.
@Test
public void majorCompactOnPartitionTooManyAborts() throws Exception {
Table t = newTable("default", "mcoptma", true);
Partition p = newPartition(t, "today");
HiveConf.setIntVar(conf, HiveConf.ConfVars.HIVE_COMPACTOR_ABORTEDTXN_THRESHOLD, 10);
for (int i = 0; i < 11; i++) {
long txnid = openTxn();
LockComponent comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.TABLE, "default");
comp.setTablename("mcoptma");
comp.setPartitionname("ds=today");
comp.setOperationType(DataOperationType.DELETE);
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));
}
startInitiator();
ShowCompactResponse rsp = txnHandler.showCompact(new ShowCompactRequest());
List<ShowCompactResponseElement> compacts = rsp.getCompacts();
Assert.assertEquals(1, compacts.size());
Assert.assertEquals("initiated", compacts.get(0).getState());
Assert.assertEquals("mcoptma", compacts.get(0).getTablename());
Assert.assertEquals("ds=today", compacts.get(0).getPartitionname());
Assert.assertEquals(CompactionType.MAJOR, compacts.get(0).getType());
}
Aggregations