use of org.apache.hadoop.hive.ql.lockmgr.HiveLockObject in project hive by apache.
the class ShowLocksOperation method getLocksForOldFormat.
private List<HiveLock> getLocksForOldFormat(HiveLockManager lockMgr) throws LockException, HiveException {
List<HiveLock> locks = null;
if (desc.getTableName() == null) {
// TODO should be doing security check here. Users should not be able to see each other's locks.
locks = lockMgr.getLocks(false, desc.isExt());
} else {
HiveLockObject lockObject = HiveLockObject.createFrom(context.getDb(), desc.getTableName(), desc.getPartSpec());
locks = lockMgr.getLocks(lockObject, true, desc.isExt());
}
Collections.sort(locks, new Comparator<HiveLock>() {
@Override
public int compare(HiveLock o1, HiveLock o2) {
int cmp = o1.getHiveLockObject().getName().compareTo(o2.getHiveLockObject().getName());
if (cmp != 0) {
return cmp;
}
if (o1.getHiveLockMode() == o2.getHiveLockMode()) {
return 0;
}
// EXCLUSIVE locks occur before SHARED locks
return (o1.getHiveLockMode() == HiveLockMode.EXCLUSIVE) ? -1 : +1;
}
});
return locks;
}
use of org.apache.hadoop.hive.ql.lockmgr.HiveLockObject in project hive by apache.
the class TestZookeeperLockManager method setup.
@Before
public void setup() {
conf = new HiveConf();
conf.setVar(ConfVars.HIVE_LOCK_SLEEP_BETWEEN_RETRIES, "100ms");
lockObjData = new HiveLockObjectData("1", "10", "SHARED", "show tables", conf);
hiveLock = new HiveLockObject(TABLE, lockObjData);
zLock = new ZooKeeperHiveLock(TABLE_LOCK_PATH, hiveLock, HiveLockMode.SHARED);
while (server == null) {
try {
server = new TestingServer();
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
client = builder.connectString(server.getConnectString()).retryPolicy(new RetryOneTime(1)).build();
client.start();
} catch (Exception e) {
System.err.println("Getting bind exception - retrying to allocate server");
server = null;
}
}
}
use of org.apache.hadoop.hive.ql.lockmgr.HiveLockObject in project hive by apache.
the class MoveTask method acquireLockForFileMove.
private LocalTableLock acquireLockForFileMove(LoadTableDesc loadTableWork) throws HiveException {
LockFileMoveMode mode = LockFileMoveMode.fromConf(conf);
if (mode == LockFileMoveMode.NONE) {
return new LocalTableLock();
}
if (mode == LockFileMoveMode.DP && loadTableWork.getDPCtx() == null) {
return new LocalTableLock();
}
WriteEntity output = context.getLoadTableOutputMap().get(loadTableWork);
List<HiveLockObj> lockObjects = context.getOutputLockObjects().get(output);
if (lockObjects == null) {
return new LocalTableLock();
}
TableDesc table = loadTableWork.getTable();
if (table == null) {
return new LocalTableLock();
}
Hive db = getHive();
Table baseTable = db.getTable(loadTableWork.getTable().getTableName());
HiveLockObject.HiveLockObjectData lockData = new HiveLockObject.HiveLockObjectData(queryPlan.getQueryId(), String.valueOf(System.currentTimeMillis()), "IMPLICIT", queryPlan.getQueryStr(), conf);
HiveLockObject lock = new HiveLockObject(baseTable, lockData);
for (HiveLockObj hiveLockObj : lockObjects) {
if (Arrays.equals(hiveLockObj.getObj().getPaths(), lock.getPaths())) {
HiveLockMode l = hiveLockObj.getMode();
if (l == HiveLockMode.EXCLUSIVE || l == HiveLockMode.SEMI_SHARED) {
// no need to lock ; already owns a more powerful one
return new LocalTableLock();
}
}
}
return new LocalTableLock(lock);
}
Aggregations