private void removeLastLockAttempt(Consumer<LockAttempt> completeLockAttempt) {
        LockAttempt lockAttempt = lockAttemptsStack.pollLast();
        if (lockAttempt == null) {
            logger.warning("Unable to remove last lock attempt as the lock attempt stack is empty");
            return;
        }

        completeLockAttempt.accept(lockAttempt);

        LockStats.getGlobal().maybeSample(lockAttempt);
    }
Tries to detect whether acquiring a given lock path would deadlock.

<p>Thread T0 will deadlock if it tries to acquire a lock on a path L1 held by T1,
and T1 is waiting on L2 held by T2, and so forth, and TN is waiting on L0 held by T0.</p>


<p>Since the underlying data structures are concurrently being modified (as an optimization,
no lock is taken for this calculation), a cycle may be detected not involving T0.</p>

<p>This method is a best-effort attempt at detecting deadlocks:  A deadlock may in fact be
resolved even though this method throws, if e.g. locks are released just after this
method.</p>
zkfacade/src/main/java/com/yahoo/vespa/curator/stats/ThreadLockStats.java