/** * @param key object to be locked * Get the name of the last string. For eg. if you need to lock db/T/ds=1=/hr=1, * the last name would be db/T/ds=1/hr=1 **/ private static String getLastObjectName(String parent, HiveLockObject key) { return "/" + parent + "/" + key.getName(); }
public String getName() { return obj.getName(); } }
/** * @param key object to be locked * Get the name of the last string. For eg. if you need to lock db/T/ds=1=/hr=1, * the last name would be db/T/ds=1/hr=1 **/ private static String getLastObjectName(String parent, HiveLockObject key) { return "/" + parent + "/" + key.getName(); }
public String getName() { return obj.getName(); } }
/** * @param key object to be locked * Get the list of names for all the parents. * For eg: if you need to lock db/T/ds=1/hr=1, the following list will be returned: * {db, db/T, db/T/ds=1, db/T/ds=1/hr=1} **/ private List<String> getObjectNames(HiveLockObject key) { List<String> parents = new ArrayList<String>(); String curParent = "/" + parent + "/"; String[] names = key.getName().split("/"); for (String name : names) { curParent = curParent + name; parents.add(curParent); curParent = curParent + "/"; } return parents; }
/** * @param key object to be locked * Get the list of names for all the parents. * For eg: if you need to lock db/T/ds=1/hr=1, the following list will be returned: * {db, db/T, db/T/ds=1, db/T/ds=1/hr=1} **/ private List<String> getObjectNames(HiveLockObject key) { List<String> parents = new ArrayList<String>(); String curParent = "/" + parent + "/"; String[] names = key.getName().split("/"); for (String name : names) { curParent = curParent + name; parents.add(curParent); curParent = curParent + "/"; } return parents; }
/** * @param hiveLocks * list of hive locks to be released Release all the locks specified. If some of the * locks have already been released, ignore them **/ @Override public void releaseLocks(List<HiveLock> hiveLocks) { if (hiveLocks != null) { int len = hiveLocks.size(); for (int pos = len-1; pos >= 0; pos--) { HiveLock hiveLock = hiveLocks.get(pos); try { LOG.debug("About to release lock for {}", hiveLock.getHiveLockObject().getName()); unlock(hiveLock); } catch (LockException e) { // The lock may have been released. Ignore and continue LOG.warn("Error when releasing lock", e); } } } }
/** * @param hiveLocks * list of hive locks to be released Release all the locks specified. If some of the * locks have already been released, ignore them **/ @Override public void releaseLocks(List<HiveLock> hiveLocks) { if (hiveLocks != null) { int len = hiveLocks.size(); for (int pos = len-1; pos >= 0; pos--) { HiveLock hiveLock = hiveLocks.get(pos); try { LOG.debug("About to release lock for {}", hiveLock.getHiveLockObject().getName()); unlock(hiveLock); } catch (LockException e) { // The lock may have been released. Ignore and continue LOG.warn("Error when releasing lock", e); } } } }
@Override public HiveLock lock(HiveLockObject key, HiveLockMode mode, boolean keepAlive) throws LockException { LOG.debug("Acquiring lock for {} with mode {} {}", key.getName(), mode, key.getData().getLockMode()); return lock(key, mode, numRetriesForLock, sleepTime); }
@Override public int compare(HiveLock o1, HiveLock o2) { int cmp = o1.getHiveLockObject().getName().compareTo(o2.getHiveLockObject().getName()); if (cmp == 0) { if (o1.getHiveLockMode() == o2.getHiveLockMode()) { return cmp; } // EXCLUSIVE locks occur before SHARED locks if (o1.getHiveLockMode() == HiveLockMode.EXCLUSIVE) { return -1; } return +1; } return cmp; }
@Override public int compare(HiveLock o1, HiveLock o2) { int cmp = o1.getHiveLockObject().getName().compareTo(o2.getHiveLockObject().getName()); if (cmp == 0) { if (o1.getHiveLockMode() == o2.getHiveLockMode()) { return cmp; } // EXCLUSIVE locks occur before SHARED locks if (o1.getHiveLockMode() == HiveLockMode.EXCLUSIVE) { return -1; } return +1; } return cmp; }
private List<HiveLock> lock(List<HiveLockObj> objs, int numRetriesForLock, long sleepTime) throws LockException { sortLocks(objs); if (LOG.isDebugEnabled()) { for (HiveLockObj obj : objs) { LOG.debug("Acquiring lock for {} with mode {}", obj.getObj().getName(), obj.getMode()); } } for (int i = 0; i <= numRetriesForLock; i++) { if (i > 0) { sleep(sleepTime); } List<HiveLock> locks = lockPrimitive(objs, numRetriesForLock, sleepTime); if (locks != null) { return locks; } } return null; }
LOG.warn("Could not release lock {}", lock.getHiveLockObject().getName(), le);
private ZooKeeperHiveLock lock (HiveLockObject key, HiveLockMode mode, boolean keepAlive, boolean parentCreated) throws LockException { LOG.debug("Acquiring lock for {} with mode {} {}", key.getName(), mode, key.getData().getLockMode());
private ZooKeeperHiveLock lock (HiveLockObject key, HiveLockMode mode, boolean keepAlive, boolean parentCreated) throws LockException { LOG.debug("Acquiring lock for {} with mode {}", key.getName(), key.getData().getLockMode());
Assert.assertEquals(expectedLocks.size(), resultLocks.size()); Assert.assertEquals(expectedLocks.get(0).getHiveLockMode(), resultLocks.get(0).getHiveLockMode()); Assert.assertEquals(expectedLocks.get(0).getHiveLockObject().getName(), resultLocks.get(0).getHiveLockObject().getName()); Assert.assertEquals(expectedLocks.get(1).getHiveLockMode(), resultLocks.get(1).getHiveLockMode()); Assert.assertEquals(expectedLocks.get(0).getHiveLockObject().getName(), resultLocks.get(0).getHiveLockObject().getName());