use of org.apache.hadoop.hive.metastore.api.CommitTxnRequest in project hive by apache.
the class TestTxnCommands2 method testOpenTxnsCounter.
@Test
public void testOpenTxnsCounter() throws Exception {
hiveConf.setIntVar(HiveConf.ConfVars.HIVE_MAX_OPEN_TXNS, 3);
hiveConf.setTimeVar(HiveConf.ConfVars.HIVE_COUNT_OPEN_TXNS_INTERVAL, 10, TimeUnit.MILLISECONDS);
OpenTxnsResponse openTxnsResponse = txnHandler.openTxns(new OpenTxnRequest(3, "me", "localhost"));
AcidOpenTxnsCounterService openTxnsCounterService = new AcidOpenTxnsCounterService();
openTxnsCounterService.setConf(hiveConf);
// will update current number of open txns to 3
openTxnsCounterService.run();
MetaException exception = null;
// This should fail once it finds out the threshold has been reached
try {
txnHandler.openTxns(new OpenTxnRequest(1, "you", "localhost"));
} catch (MetaException e) {
exception = e;
}
Assert.assertNotNull("Opening new transaction shouldn't be allowed", exception);
Assert.assertTrue(exception.getMessage().equals("Maximum allowed number of open transactions has been reached. See hive.max.open.txns."));
// new transactions should be allowed to open
for (long txnid : openTxnsResponse.getTxn_ids()) {
txnHandler.commitTxn(new CommitTxnRequest(txnid));
}
// will update current number of open txns back to 0
openTxnsCounterService.run();
exception = null;
try {
txnHandler.openTxns(new OpenTxnRequest(1, "him", "localhost"));
} catch (MetaException e) {
exception = e;
}
Assert.assertNull(exception);
}
use of org.apache.hadoop.hive.metastore.api.CommitTxnRequest in project hive by apache.
the class TestTxnHandler method testUnlockOnCommit.
@Test
public void testUnlockOnCommit() throws Exception {
// Test that committing unlocks
long txnid = openTxn();
LockComponent comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb");
comp.setTablename("mytable");
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);
assertTrue(res.getState() == LockState.ACQUIRED);
txnHandler.commitTxn(new CommitTxnRequest(txnid));
assertEquals(0, txnHandler.numLocksInLockTable());
}
use of org.apache.hadoop.hive.metastore.api.CommitTxnRequest in project hive by apache.
the class TestInitiator method noCompactTableNotEnoughDeltas.
@Test
public void noCompactTableNotEnoughDeltas() throws Exception {
Table t = newTable("default", "nctned", false);
addBaseFile(t, null, 200L, 200);
addDeltaFile(t, null, 201L, 205L, 5);
addDeltaFile(t, null, 206L, 211L, 6);
burnThroughTransactions("default", "nctned", 210);
long txnid = openTxn();
LockComponent comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.TABLE, "default");
comp.setTablename("nctned");
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);
long writeid = allocateWriteId("default", "nctned", txnid);
Assert.assertEquals(211, writeid);
txnHandler.commitTxn(new CommitTxnRequest(txnid));
startInitiator();
ShowCompactResponse rsp = txnHandler.showCompact(new ShowCompactRequest());
Assert.assertEquals(0, rsp.getCompactsSize());
}
use of org.apache.hadoop.hive.metastore.api.CommitTxnRequest in project hive by apache.
the class TestInitiator method compactTableTooManyDeltas.
@Test
public void compactTableTooManyDeltas() throws Exception {
Table t = newTable("default", "cttmd", false);
addBaseFile(t, null, 200L, 200);
addDeltaFile(t, null, 201L, 201L, 1);
addDeltaFile(t, null, 202L, 202L, 1);
addDeltaFile(t, null, 203L, 203L, 1);
addDeltaFile(t, null, 204L, 204L, 1);
addDeltaFile(t, null, 205L, 205L, 1);
addDeltaFile(t, null, 206L, 206L, 1);
addDeltaFile(t, null, 207L, 207L, 1);
addDeltaFile(t, null, 208L, 208L, 1);
addDeltaFile(t, null, 209L, 209L, 1);
addDeltaFile(t, null, 210L, 210L, 1);
addDeltaFile(t, null, 211L, 211L, 1);
burnThroughTransactions("default", "cttmd", 210);
long txnid = openTxn();
LockComponent comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.TABLE, "default");
comp.setTablename("cttmd");
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);
long writeid = allocateWriteId("default", "cttmd", txnid);
Assert.assertEquals(211, writeid);
txnHandler.commitTxn(new CommitTxnRequest(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("cttmd", compacts.get(0).getTablename());
Assert.assertEquals(CompactionType.MINOR, compacts.get(0).getType());
}
use of org.apache.hadoop.hive.metastore.api.CommitTxnRequest in project hive by apache.
the class TestInitiator method compactTableHighDeltaPct.
@Test
public void compactTableHighDeltaPct() throws Exception {
Table t = newTable("default", "cthdp", false);
addBaseFile(t, null, 20L, 20);
addDeltaFile(t, null, 21L, 22L, 2);
addDeltaFile(t, null, 23L, 24L, 2);
burnThroughTransactions("default", "cthdp", 23);
long txnid = openTxn();
LockComponent comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.TABLE, "default");
comp.setTablename("cthdp");
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);
long writeid = allocateWriteId("default", "cthdp", txnid);
Assert.assertEquals(24, writeid);
txnHandler.commitTxn(new CommitTxnRequest(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("cthdp", compacts.get(0).getTablename());
Assert.assertEquals(CompactionType.MAJOR, compacts.get(0).getType());
}
Aggregations