in hbase-oss/src/main/java/org/apache/hadoop/hbase/oss/sync/TreeLockManager.java [265:305]
protected void treeWriteLock(Path path, Depth depth) throws IOException {
int outerRetries = 0;
long outerInitAttempt = System.currentTimeMillis();
do {
int innerRetries = 0;
long innerInitAttempt = System.currentTimeMillis();
do {
// If there's already a write-lock above or below us in the tree, wait for it to leave
if (writeLockAbove(path) || writeLockBelow(path, depth)) {
if (this.warnIfAboveThreshold(innerInitAttempt,
"Blocked on some parent write lock, waiting: {}", path.toString())) {
innerInitAttempt = System.currentTimeMillis();
}
continue;
}
break;
} while (retryBackoff(innerRetries++));
// Try obtain the write lock just for our node
writeLock(path);
// If there's now a write-lock above or below us in the tree, release and retry
if (writeLockAbove(path) || writeLockBelow(path, depth)) {
if (this.warnIfAboveThreshold(outerInitAttempt,
"Blocked on some other write lock, retrying: {}", path.toString())) {
outerInitAttempt = System.currentTimeMillis();
}
writeUnlock(path);
continue;
}
break;
} while (retryBackoff(outerRetries++));
// Once we know we're the only write-lock in our path, drain all read-locks below
int drainReadLocksRetries = 0;
do {
if (readLockBelow(path, depth)) {
LOG.warn("Blocked on some child read lock, writing: {}", path);
continue;
}
break;
} while (retryBackoff(drainReadLocksRetries++));
}