Search in sources :

Example 1 with HiveLockMode

use of org.apache.hadoop.hive.ql.lockmgr.HiveLockMode 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

CreateTableDesc (org.apache.hadoop.hive.ql.ddl.table.create.CreateTableDesc)1 WriteEntity (org.apache.hadoop.hive.ql.hooks.WriteEntity)1 HiveLockMode (org.apache.hadoop.hive.ql.lockmgr.HiveLockMode)1 HiveLockObj (org.apache.hadoop.hive.ql.lockmgr.HiveLockObj)1 HiveLockObject (org.apache.hadoop.hive.ql.lockmgr.HiveLockObject)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