use of org.apache.hadoop.hive.metastore.api.LockComponent in project hive by apache.
the class TestTxnHandler method testLockTableLocksPartition.
@Test
public void testLockTableLocksPartition() throws Exception {
// Test that locking a table prevents locking of partitions of the table
LockComponent comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb");
comp.setTablename("mytable");
comp.setOperationType(DataOperationType.NO_TXN);
List<LockComponent> components = new ArrayList<LockComponent>(1);
components.add(comp);
LockRequest req = new LockRequest(components, "me", "localhost");
LockResponse res = txnHandler.lock(req);
assertTrue(res.getState() == LockState.ACQUIRED);
comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb");
comp.setTablename("mytable");
comp.setPartitionname("mypartition");
comp.setOperationType(DataOperationType.NO_TXN);
components.clear();
components.add(comp);
req = new LockRequest(components, "me", "localhost");
res = txnHandler.lock(req);
assertTrue(res.getState() == LockState.WAITING);
}
use of org.apache.hadoop.hive.metastore.api.LockComponent in project hive by apache.
the class TestTxnHandler method testLockDbDoesNotLockTableInDifferentDB.
@Test
public void testLockDbDoesNotLockTableInDifferentDB() throws Exception {
// Test that locking a database prevents locking of tables in the database
LockComponent comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb");
comp.setOperationType(DataOperationType.NO_TXN);
List<LockComponent> components = new ArrayList<LockComponent>(1);
components.add(comp);
LockRequest req = new LockRequest(components, "me", "localhost");
LockResponse res = txnHandler.lock(req);
assertTrue(res.getState() == LockState.ACQUIRED);
comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "yourdb");
comp.setOperationType(DataOperationType.NO_TXN);
comp.setTablename("mytable");
components.clear();
components.add(comp);
req = new LockRequest(components, "me", "localhost");
res = txnHandler.lock(req);
assertTrue(res.getState() == LockState.ACQUIRED);
}
use of org.apache.hadoop.hive.metastore.api.LockComponent in project hive by apache.
the class TestTxnHandler method testHeartbeatLock.
@Test
public void testHeartbeatLock() throws Exception {
conf.setTimeVar(HiveConf.ConfVars.HIVE_TXN_TIMEOUT, 1, TimeUnit.SECONDS);
HeartbeatRequest h = new HeartbeatRequest();
LockComponent comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb");
comp.setTablename("mytable");
comp.setPartitionname("mypartition");
comp.setOperationType(DataOperationType.NO_TXN);
List<LockComponent> components = new ArrayList<LockComponent>(1);
components.add(comp);
LockRequest req = new LockRequest(components, "me", "localhost");
LockResponse res = txnHandler.lock(req);
assertTrue(res.getState() == LockState.ACQUIRED);
h.setLockid(res.getLockid());
for (int i = 0; i < 30; i++) {
try {
txnHandler.heartbeat(h);
} catch (NoSuchLockException e) {
fail("Told there was no lock, when the heartbeat should have kept it.");
}
}
}
use of org.apache.hadoop.hive.metastore.api.LockComponent in project hive by apache.
the class TestTxnHandler method testLockESRE.
@Test
public void testLockESRE() throws Exception {
// Test that exclusive blocks read and exclusive
LockComponent comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb");
comp.setTablename("mytable");
comp.setPartitionname("mypartition");
comp.setOperationType(DataOperationType.NO_TXN);
List<LockComponent> components = new ArrayList<LockComponent>(1);
components.add(comp);
LockRequest req = new LockRequest(components, "me", "localhost");
LockResponse res = txnHandler.lock(req);
assertTrue(res.getState() == LockState.ACQUIRED);
comp = new LockComponent(LockType.SHARED_READ, LockLevel.DB, "mydb");
comp.setTablename("mytable");
comp.setPartitionname("mypartition");
comp.setOperationType(DataOperationType.SELECT);
components.clear();
components.add(comp);
req = new LockRequest(components, "me", "localhost");
res = txnHandler.lock(req);
assertTrue(res.getState() == LockState.WAITING);
comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb");
comp.setTablename("mytable");
comp.setPartitionname("mypartition");
comp.setOperationType(DataOperationType.NO_TXN);
components.clear();
components.add(comp);
req = new LockRequest(components, "me", "localhost");
res = txnHandler.lock(req);
assertTrue(res.getState() == LockState.WAITING);
}
use of org.apache.hadoop.hive.metastore.api.LockComponent in project hive by apache.
the class TestTxnHandler method showLocks.
@Test
public void showLocks() throws Exception {
long begining = System.currentTimeMillis();
LockComponent comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb");
comp.setOperationType(DataOperationType.NO_TXN);
List<LockComponent> components = new ArrayList<LockComponent>(1);
components.add(comp);
LockRequest req = new LockRequest(components, "me", "localhost");
LockResponse res = txnHandler.lock(req);
// Open txn
long txnid = openTxn();
comp = new LockComponent(LockType.SHARED_READ, LockLevel.TABLE, "mydb");
comp.setTablename("mytable");
comp.setOperationType(DataOperationType.SELECT);
components = new ArrayList<LockComponent>(1);
components.add(comp);
req = new LockRequest(components, "me", "localhost");
req.setTxnid(txnid);
res = txnHandler.lock(req);
// Locks not associated with a txn
components = new ArrayList<LockComponent>(1);
comp = new LockComponent(LockType.SHARED_READ, LockLevel.PARTITION, "yourdb");
comp.setTablename("yourtable");
comp.setPartitionname("yourpartition");
comp.setOperationType(DataOperationType.INSERT);
components.add(comp);
req = new LockRequest(components, "you", "remotehost");
res = txnHandler.lock(req);
ShowLocksResponse rsp = txnHandler.showLocks(new ShowLocksRequest());
List<ShowLocksResponseElement> locks = rsp.getLocks();
assertEquals(3, locks.size());
boolean[] saw = new boolean[locks.size()];
for (int i = 0; i < saw.length; i++) saw[i] = false;
for (ShowLocksResponseElement lock : locks) {
if (lock.getLockid() == 1) {
assertEquals(0, lock.getTxnid());
assertEquals("mydb", lock.getDbname());
assertNull(lock.getTablename());
assertNull(lock.getPartname());
assertEquals(LockState.ACQUIRED, lock.getState());
assertEquals(LockType.EXCLUSIVE, lock.getType());
assertTrue(lock.toString(), 0 != lock.getLastheartbeat());
assertTrue("Expected acquired at " + lock.getAcquiredat() + " to be between " + begining + " and " + System.currentTimeMillis(), begining <= lock.getAcquiredat() && System.currentTimeMillis() >= lock.getAcquiredat());
assertEquals("me", lock.getUser());
assertEquals("localhost", lock.getHostname());
saw[0] = true;
} else if (lock.getLockid() == 2) {
assertEquals(1, lock.getTxnid());
assertEquals("mydb", lock.getDbname());
assertEquals("mytable", lock.getTablename());
assertNull(lock.getPartname());
assertEquals(LockState.WAITING, lock.getState());
assertEquals(LockType.SHARED_READ, lock.getType());
assertTrue(lock.toString(), 0 == lock.getLastheartbeat() && lock.getTxnid() != 0);
assertEquals(0, lock.getAcquiredat());
assertEquals("me", lock.getUser());
assertEquals("localhost", lock.getHostname());
saw[1] = true;
} else if (lock.getLockid() == 3) {
assertEquals(0, lock.getTxnid());
assertEquals("yourdb", lock.getDbname());
assertEquals("yourtable", lock.getTablename());
assertEquals("yourpartition", lock.getPartname());
assertEquals(LockState.ACQUIRED, lock.getState());
assertEquals(LockType.SHARED_READ, lock.getType());
assertTrue(lock.toString(), begining <= lock.getLastheartbeat() && System.currentTimeMillis() >= lock.getLastheartbeat());
assertTrue(begining <= lock.getAcquiredat() && System.currentTimeMillis() >= lock.getAcquiredat());
assertEquals("you", lock.getUser());
assertEquals("remotehost", lock.getHostname());
saw[2] = true;
} else {
fail("Unknown lock id");
}
}
for (int i = 0; i < saw.length; i++) assertTrue("Didn't see lock id " + i, saw[i]);
}
Aggregations