private HiveLock lockPrimitive(HiveLockObject key, HiveLockMode mode) throws LockException { if (root.lock(key.getPaths(), key.getData(), mode == HiveLockMode.EXCLUSIVE)) { return new SimpleHiveLock(key, mode); } return null; }
@Override public void releaseLocks(List<HiveLock> hiveLocks) throws LockException { if (lockMgr != null) { stopHeartbeat(); lockMgr.releaseLocks(hiveLocks); } }
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); }
@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 boolean equals(Object o) { if (!(o instanceof SimpleHiveLock)) { return false; } SimpleHiveLock simpleLock = (SimpleHiveLock) o; return lockObj.equals(simpleLock.getHiveLockObject()) && lockMode == simpleLock.getHiveLockMode(); } }
/** * we don't expect multiple threads to call this method concurrently but {@link #lockMgr} will * be read by a different threads than one writing it, thus it's {@code volatile} */ @Override public HiveLockManager getLockManager() throws LockException { init(); if (lockMgr == null) { lockMgr = new DbLockManager(conf, this); } return lockMgr; }
private void clearLocksAndHB() throws LockException { lockMgr.clearLocalLockRecords(); stopHeartbeat(); }
/** * @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(); }
@Override public long getTableWriteId(String dbName, String tableName) throws LockException { assert isTxnOpen(); return getTableWriteId(dbName, tableName, true); }
@Override public void setContext(HiveLockManagerCtx ctx) throws LockException { this.ctx = ctx; refresh(); }
@Override public int getStmtIdAndIncrement() { assert isTxnOpen(); return stmtId++; } @Override
HeartbeaterThread(Runnable target, String name) { super(target, name); setDaemon(true); } }
private HiveLock lockPrimitive(HiveLockObject key, HiveLockMode mode) throws LockException { if (root.lock(key.getPaths(), key.getData(), mode == HiveLockMode.EXCLUSIVE)) { return new SimpleHiveLock(key, mode); } return null; }
@Override public boolean equals(Object o) { if (!(o instanceof SimpleHiveLock)) { return false; } SimpleHiveLock simpleLock = (SimpleHiveLock) o; return lockObj.equals(simpleLock.getHiveLockObject()) && lockMode == simpleLock.getHiveLockMode(); } }
/** * we don't expect multiple thread to call this method concurrently but {@link #lockMgr} will * be read by a different threads that one writing it, thus it's {@code volatile} */ @Override public HiveLockManager getLockManager() throws LockException { init(); if (lockMgr == null) { lockMgr = new DbLockManager(conf, this); } return lockMgr; }
@Override public long getAllocatedTableWriteId(String dbName, String tableName) throws LockException { assert isTxnOpen(); // Calls getTableWriteId() with allocateIfNotYet being false // to return 0 if the dbName:tableName's writeId is yet allocated. // This happens when the current context is before // Driver.acquireLocks() is called. return getTableWriteId(dbName, tableName, false); }
@Override public int getCurrentStmtId() { assert isTxnOpen(); return stmtId; } @Override