Phillippko commented on code in PR #7514:
URL: https://github.com/apache/ignite-3/pull/7514#discussion_r2758800023
##########
modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/tree/BplusTree.java:
##########
@@ -1281,15 +1281,15 @@ public <R> Cursor<R> find(
} catch (CorruptedDataStructureException e) {
throw e;
} catch (IgniteInternalCheckedException e) {
- throw new IgniteInternalCheckedException("Runtime failure on
bounds: [lower=" + lower + ", upper=" + upper + "]", e);
+ throw new IgniteInternalCheckedException("Runtime failure on
bounds [lower=" + lower + ", upper=" + upper + "]", e);
Review Comment:
All changes in this class seem unrelated to the ticket?
##########
modules/core/src/main/java/org/apache/ignite/internal/util/OffheapReadWriteLock.java:
##########
@@ -507,14 +536,73 @@ private boolean waitAcquireWriteLock(long lock, int
lockIdx, int tag) {
}
}
+ private boolean tryReleaseReadWaiter(long lock, int lockIdx, long state) {
Review Comment:
Let's unify these methods?
##########
modules/core/src/main/java/org/apache/ignite/internal/util/OffheapReadWriteLock.java:
##########
@@ -507,14 +536,73 @@ private boolean waitAcquireWriteLock(long lock, int
lockIdx, int tag) {
}
}
+ private boolean tryReleaseReadWaiter(long lock, int lockIdx, long state) {
+ long updated = updateState(state, 0, -1, 0);
+
+ if (GridUnsafe.compareAndSwapLong(null, lock, state, updated)) {
+ int writeWaitCnt = writersWaitCount(updated);
+
+ signalNextWaiter(writeWaitCnt, lockIdx);
+
+ return true;
+ }
+
+ return false;
+ }
+
+ private boolean tryReleaseWriteWaiter(long lock, int lockIdx, long state) {
+ long updated = updateState(state, 0, 0, -1);
+
+ if (GridUnsafe.compareAndSwapLong(null, lock, state, updated)) {
+ int writeWaitCnt = writersWaitCount(updated);
+
+ signalNextWaiter(writeWaitCnt, lockIdx);
+
+ return true;
+ }
+
+ return false;
+ }
+
+ @SuppressWarnings("AwaitNotInLoop")
+ private void awaitCondition(
+ long lock, int lockIdx, int tag, long startTimeNanos, Condition
waitCond, boolean readLock
+ ) throws InterruptedException {
+ if (timeoutNanos == 0) {
+ waitCond.await();
+ } else {
+ long passedNanos = System.nanoTime() - startTimeNanos;
+
+ if (passedNanos >= timeoutNanos) {
+ //noinspection InfiniteLoopStatement
+ while (true) {
+ long state = GridUnsafe.getLongVolatile(null, lock);
+
+ if (readLock ? tryReleaseReadWaiter(lock, lockIdx, state)
: tryReleaseWriteWaiter(lock, lockIdx, state)) {
+ throw new LockTimeoutException(S.toString("Timeout
waiting for lock acquisition",
+ "lock", hexLong(lock), false,
+ "state", hexLong(state), false,
+ "tag", hexInt(tag), false,
+ "idx", lockIdx, false,
+ "cond", waitCond.toString(), false,
+ "timeout",
TimeUnit.NANOSECONDS.toMillis(timeoutNanos) + "ms", false
Review Comment:
```suggestion
"timeoutMillis",
TimeUnit.NANOSECONDS.toMillis(timeoutNanos) + "ms", false
```
##########
modules/core/src/main/java/org/apache/ignite/internal/util/OffheapReadWriteLock.java:
##########
@@ -70,16 +76,37 @@ public class OffheapReadWriteLock {
/** Mask to extract stripe index from the hash. */
private final int monitorsMask;
+ /** Lock timeout in nanoseconds. {@code 0L} if unlimited. */
+ private final long timeoutNanos;
+
+ /** An exception that's thrown by {@code *Lock} methods if the lock has
not been acquired within a configured timeout. */
+ public static class LockTimeoutException extends RuntimeException {
+ private static final long serialVersionUID = 0L;
+
+ /**
+ * Constructor.
+ *
+ * @param message Exception message.
+ */
+ LockTimeoutException(String message) {
+ super(message);
+ }
+ }
+
/**
* Constructor.
*
* @param concLvl Concurrency level, must be a power of two.
+ * @param timeout Lock acquisition timeout.
Review Comment:
let's add here that 0 means unlimited timeout
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]