use of org.apache.hadoop.hive.ql.lockmgr.HiveLockObject.HiveLockObjectData in project hive by apache.
the class ZooKeeperHiveLockManager method printConflictingLocks.
private void printConflictingLocks(HiveLockObject key, HiveLockMode mode, Set<String> conflictingLocks) {
if (!conflictingLocks.isEmpty()) {
HiveLockObjectData requestedLock = new HiveLockObjectData(key.getData().toString());
LOG.debug("Requested lock " + key.getDisplayName() + ":: mode:" + requestedLock.getLockMode() + "," + mode + "; query:" + requestedLock.getQueryStr());
for (String conflictingLock : conflictingLocks) {
HiveLockObjectData conflictingLockData = new HiveLockObjectData(conflictingLock);
LOG.debug("Conflicting lock to " + key.getDisplayName() + ":: mode:" + conflictingLockData.getLockMode() + ";query:" + conflictingLockData.getQueryStr() + ";queryId:" + conflictingLockData.getQueryId() + ";clientIp:" + conflictingLockData.getClientIp());
}
}
}
use of org.apache.hadoop.hive.ql.lockmgr.HiveLockObject.HiveLockObjectData in project hive by apache.
the class ZooKeeperHiveLockManager method getLocks.
/**
* @param conf Hive configuration
* @param zkpClient The ZooKeeper client
* @param key The object to be compared against - if key is null, then get all locks
**/
private static List<HiveLock> getLocks(HiveConf conf, HiveLockObject key, String parent, boolean verifyTablePartition, boolean fetchData) throws LockException {
List<HiveLock> locks = new ArrayList<HiveLock>();
List<String> children;
boolean recurse = true;
String commonParent;
try {
if (key != null) {
commonParent = "/" + parent + "/" + key.getName();
children = curatorFramework.getChildren().forPath(commonParent);
recurse = false;
} else {
commonParent = "/" + parent;
children = curatorFramework.getChildren().forPath(commonParent);
}
} catch (Exception e) {
// no locks present
return locks;
}
Queue<String> childn = new LinkedList<String>();
if (children != null && !children.isEmpty()) {
for (String child : children) {
childn.add(commonParent + "/" + child);
}
}
while (true) {
String curChild = childn.poll();
if (curChild == null) {
return locks;
}
if (recurse) {
try {
children = curatorFramework.getChildren().forPath(curChild);
for (String child : children) {
childn.add(curChild + "/" + child);
}
} catch (Exception e) {
// nothing to do
}
}
HiveLockMode mode = getLockMode(curChild);
if (mode == null) {
continue;
}
HiveLockObjectData data = null;
// set the lock object with a dummy data, and then do a set if needed.
HiveLockObject obj = getLockObject(conf, curChild, mode, data, parent, verifyTablePartition);
if (obj == null) {
continue;
}
if ((key == null) || (obj.getName().equals(key.getName()))) {
if (fetchData) {
try {
data = new HiveLockObjectData(new String(curatorFramework.getData().watched().forPath(curChild)));
data.setClientIp(clientIp);
} catch (Exception e) {
LOG.error("Error in getting data for " + curChild, e);
// ignore error
}
}
obj.setData(data);
HiveLock lck = (new ZooKeeperHiveLock(curChild, obj, mode));
locks.add(lck);
}
}
}
use of org.apache.hadoop.hive.ql.lockmgr.HiveLockObject.HiveLockObjectData in project hive by apache.
the class EmbeddedLockManager method unlock.
public void unlock(HiveLock hiveLock, int numRetriesForUnLock, long sleepTime) throws LockException {
String[] paths = hiveLock.getHiveLockObject().getPaths();
HiveLockObjectData data = hiveLock.getHiveLockObject().getData();
for (int i = 0; i <= numRetriesForUnLock; i++) {
if (i > 0) {
sleep(sleepTime);
}
if (root.unlock(paths, data)) {
return;
}
}
throw new LockException("Failed to release lock " + hiveLock);
}
use of org.apache.hadoop.hive.ql.lockmgr.HiveLockObject.HiveLockObjectData in project hive by apache.
the class HiveTxnManagerImpl method lockDatabase.
@Override
public int lockDatabase(Hive hiveDB, LockDatabaseDesc lockDb) throws HiveException {
HiveLockManager lockMgr = getAndCheckLockManager();
HiveLockMode mode = HiveLockMode.valueOf(lockDb.getMode());
String dbName = lockDb.getDatabaseName();
Database dbObj = hiveDB.getDatabase(dbName);
if (dbObj == null) {
throw new HiveException("Database " + dbName + " does not exist ");
}
HiveLockObjectData lockData = new HiveLockObjectData(lockDb.getQueryId(), String.valueOf(System.currentTimeMillis()), "EXPLICIT", lockDb.getQueryStr());
HiveLock lck = lockMgr.lock(new HiveLockObject(dbObj.getName(), lockData), mode, true);
if (lck == null) {
return 1;
}
return 0;
}
use of org.apache.hadoop.hive.ql.lockmgr.HiveLockObject.HiveLockObjectData in project hive by apache.
the class TestHiveLockObject method testEqualsAndHashCode.
@Test
public void testEqualsAndHashCode() {
HiveLockObjectData data1 = new HiveLockObjectData("ID1", "SHARED", "1997-07-01", "select * from mytable");
HiveLockObjectData data2 = new HiveLockObjectData("ID1", "SHARED", "1997-07-01", "select * from mytable");
Assert.assertEquals(data1, data2);
Assert.assertEquals(data1.hashCode(), data2.hashCode());
HiveLockObject obj1 = new HiveLockObject("mytable", data1);
HiveLockObject obj2 = new HiveLockObject("mytable", data2);
Assert.assertEquals(obj1, obj2);
Assert.assertEquals(obj1.hashCode(), obj2.hashCode());
}
Aggregations