use of org.apache.hadoop.hive.metastore.api.ShowLocksResponse in project hive by apache.
the class ReplDumpTask method isTxnPresentInHiveLocks.
/**
* Get if there is an entry for the txn id in the hive locks table. It can be in waiting state or acquired state.
* @param txnId
* @return true if the entry for the txn id is present in hive locks.
* @throws LockException
*/
private boolean isTxnPresentInHiveLocks(long txnId) throws LockException {
ShowLocksRequest request = new ShowLocksRequest();
request.setTxnid(txnId);
HiveLockManager lockManager = getTxnMgr().getLockManager();
ShowLocksResponse showLocksResponse = ((DbLockManager) lockManager).getLocks(request);
return !showLocksResponse.getLocks().isEmpty();
}
use of org.apache.hadoop.hive.metastore.api.ShowLocksResponse in project hive by apache.
the class ReplDumpTask method getOpenTxns.
List<Long> getOpenTxns(ValidTxnList validTxnList, String dbName) throws LockException {
HiveLockManager lockManager = getTxnMgr().getLockManager();
long[] invalidTxns = validTxnList.getInvalidTransactions();
List<Long> openTxns = new ArrayList<>();
Set<Long> dbTxns = new HashSet<>();
if (lockManager instanceof DbLockManager) {
ShowLocksRequest request = new ShowLocksRequest();
request.setDbname(dbName.toLowerCase());
ShowLocksResponse showLocksResponse = ((DbLockManager) lockManager).getLocks(request);
for (ShowLocksResponseElement showLocksResponseElement : showLocksResponse.getLocks()) {
dbTxns.add(showLocksResponseElement.getTxnid());
}
for (long invalidTxn : invalidTxns) {
if (dbTxns.contains(invalidTxn) && !validTxnList.isTxnAborted(invalidTxn)) {
openTxns.add(invalidTxn);
}
}
} else {
for (long invalidTxn : invalidTxns) {
if (!validTxnList.isTxnAborted(invalidTxn)) {
openTxns.add(invalidTxn);
}
}
}
return openTxns;
}
use of org.apache.hadoop.hive.metastore.api.ShowLocksResponse in project hive by apache.
the class TestDbTxnManager2 method getLocksWithFilterOptions.
private List<ShowLocksResponseElement> getLocksWithFilterOptions(HiveTxnManager txnMgr, String dbName, String tblName, Map<String, String> partSpec) throws Exception {
if (dbName == null && tblName != null) {
dbName = SessionState.get().getCurrentDatabase();
}
ShowLocksRequest rqst = new ShowLocksRequest();
rqst.setDbname(dbName);
rqst.setTablename(tblName);
if (partSpec != null) {
String partName = FileUtils.makePartName(new ArrayList<>(partSpec.keySet()), new ArrayList<>(partSpec.values()));
rqst.setPartname(partName);
}
ShowLocksResponse rsp = ((DbLockManager) txnMgr.getLockManager()).getLocks(rqst);
return rsp.getLocks();
}
use of org.apache.hadoop.hive.metastore.api.ShowLocksResponse 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=yourvalue");
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=yourvalue", 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]);
}
use of org.apache.hadoop.hive.metastore.api.ShowLocksResponse in project hive by apache.
the class TestAcidOnTez method testGetSplitsLocksWithMaterializedView.
@Test
public void testGetSplitsLocksWithMaterializedView() throws Exception {
// Need to test this with LLAP settings, which requires some additional configurations set.
HiveConf modConf = new HiveConf(hiveConf);
setupTez(modConf);
modConf.setVar(ConfVars.HIVE_EXECUTION_ENGINE, "tez");
modConf.setVar(ConfVars.HIVEFETCHTASKCONVERSION, "more");
modConf.setVar(HiveConf.ConfVars.LLAP_DAEMON_SERVICE_HOSTS, "localhost");
// SessionState/Driver needs to be restarted with the Tez conf settings.
restartSessionAndDriver(modConf);
TxnStore txnHandler = TxnUtils.getTxnStore(modConf);
String mvName = "mv_acidTbl";
try {
runStatementOnDriver("create materialized view " + mvName + " as select a from " + Table.ACIDTBL + " where a > 5");
// Request LLAP splits for a table.
String queryParam = "select a from " + Table.ACIDTBL + " where a > 5";
runStatementOnDriver("select get_splits(\"" + queryParam + "\", 1)");
// The get_splits call should have resulted in a lock on ACIDTBL and materialized view mv_acidTbl
ShowLocksResponse slr = txnHandler.showLocks(new ShowLocksRequest());
TestDbTxnManager2.checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", Table.ACIDTBL.name, null, slr.getLocks());
TestDbTxnManager2.checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", mvName, null, slr.getLocks());
assertEquals(2, slr.getLocksSize());
} finally {
// Close the session which should free up the TxnHandler/locks held by the session.
// Done in the finally block to make sure we free up the locks; otherwise
// the cleanup in tearDown() will get stuck waiting on the lock held here on ACIDTBL.
restartSessionAndDriver(hiveConf);
runStatementOnDriver("drop materialized view if exists " + mvName);
}
// Lock should be freed up now.
ShowLocksResponse slr = txnHandler.showLocks(new ShowLocksRequest());
assertEquals(0, slr.getLocksSize());
List<String> rows = runStatementOnDriver("show transactions");
// Transactions should be committed.
// No transactions - just the header row
assertEquals(1, rows.size());
}
Aggregations