Search in sources :

Example 6 with HiveLockObjectData

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

Example 7 with HiveLockObjectData

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

Example 8 with HiveLockObjectData

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

Example 9 with HiveLockObjectData

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;
}
Also used : HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) HiveLockObjectData(org.apache.hadoop.hive.ql.lockmgr.HiveLockObject.HiveLockObjectData) Database(org.apache.hadoop.hive.metastore.api.Database)

Example 10 with HiveLockObjectData

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

Aggregations

HiveLockObjectData (org.apache.hadoop.hive.ql.lockmgr.HiveLockObject.HiveLockObjectData)10 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)3 KeeperException (org.apache.zookeeper.KeeperException)3 Test (org.junit.Test)2 DataOutputStream (java.io.DataOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)1 RetryOneTime (org.apache.curator.retry.RetryOneTime)1 TestingServer (org.apache.curator.test.TestingServer)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 Metrics (org.apache.hadoop.hive.common.metrics.common.Metrics)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)1 Database (org.apache.hadoop.hive.metastore.api.Database)1 EnvironmentContext (org.apache.hadoop.hive.metastore.api.EnvironmentContext)1