Search in sources :

Example 1 with HiveLockObject

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;
}
Also used : HiveLockObject(org.apache.hadoop.hive.ql.lockmgr.HiveLockObject) HiveLock(org.apache.hadoop.hive.ql.lockmgr.HiveLock)

Example 2 with HiveLockObject

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;
        }
    }
}
Also used : TestingServer(org.apache.curator.test.TestingServer) HiveLockObject(org.apache.hadoop.hive.ql.lockmgr.HiveLockObject) RetryOneTime(org.apache.curator.retry.RetryOneTime) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) HiveLockObjectData(org.apache.hadoop.hive.ql.lockmgr.HiveLockObject.HiveLockObjectData) HiveConf(org.apache.hadoop.hive.conf.HiveConf) LockException(org.apache.hadoop.hive.ql.lockmgr.LockException) KeeperException(org.apache.zookeeper.KeeperException) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) Before(org.junit.Before)

Example 3 with HiveLockObject

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);
}
Also used : Hive(org.apache.hadoop.hive.ql.metadata.Hive) Table(org.apache.hadoop.hive.ql.metadata.Table) HiveLockObject(org.apache.hadoop.hive.ql.lockmgr.HiveLockObject) HiveLockObj(org.apache.hadoop.hive.ql.lockmgr.HiveLockObj) TableDesc(org.apache.hadoop.hive.ql.plan.TableDesc) LoadTableDesc(org.apache.hadoop.hive.ql.plan.LoadTableDesc) CreateTableDesc(org.apache.hadoop.hive.ql.ddl.table.create.CreateTableDesc) WriteEntity(org.apache.hadoop.hive.ql.hooks.WriteEntity) HiveLockMode(org.apache.hadoop.hive.ql.lockmgr.HiveLockMode)

Aggregations

HiveLockObject (org.apache.hadoop.hive.ql.lockmgr.HiveLockObject)3 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)1 RetryOneTime (org.apache.curator.retry.RetryOneTime)1 TestingServer (org.apache.curator.test.TestingServer)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 CreateTableDesc (org.apache.hadoop.hive.ql.ddl.table.create.CreateTableDesc)1 WriteEntity (org.apache.hadoop.hive.ql.hooks.WriteEntity)1 HiveLock (org.apache.hadoop.hive.ql.lockmgr.HiveLock)1 HiveLockMode (org.apache.hadoop.hive.ql.lockmgr.HiveLockMode)1 HiveLockObj (org.apache.hadoop.hive.ql.lockmgr.HiveLockObj)1 HiveLockObjectData (org.apache.hadoop.hive.ql.lockmgr.HiveLockObject.HiveLockObjectData)1 LockException (org.apache.hadoop.hive.ql.lockmgr.LockException)1 Hive (org.apache.hadoop.hive.ql.metadata.Hive)1 Table (org.apache.hadoop.hive.ql.metadata.Table)1 LoadTableDesc (org.apache.hadoop.hive.ql.plan.LoadTableDesc)1 TableDesc (org.apache.hadoop.hive.ql.plan.TableDesc)1 KeeperException (org.apache.zookeeper.KeeperException)1 Before (org.junit.Before)1