wernerdv commented on code in PR #13554:
URL: https://github.com/apache/ignite/pull/13554#discussion_r4393076984


##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/AbstractFreeList.java:
##########
@@ -1134,8 +1257,194 @@ public int emptyDataPages() {
         }
     }
 
+    /** {@inheritDoc} */
+    @Override public long reserve(long rowSize, boolean bestEffort) throws 
IgniteOutOfMemoryException, IgniteCheckedException {
+        if (!reserveEnabled)
+            return 0;
+
+        long claimPages = requiredPages(rowSize);
+
+        if (!fitsRegion(claimPages)) {
+            if (bestEffort)
+                return 0; // Let the page memory decide.
+
+            throw outOfMemory();
+        }
+
+        long limitPages = limitPages(claimPages);
+
+        boolean recentStall = bestEffort && U.currentTimeMillis() - 
lastStallMillis < EVICTION_NO_PROGRESS_TIMEOUT_MILLIS;
+
+        long backoffNanos = EVICTION_BACKOFF_START_NANOS;
+
+        long lastProgressNanos = System.nanoTime();
+
+        while (true) {
+            long reserved = reservedPages.get();
+            long deficit = deficit(claimPages, limitPages, reserved);
+
+            if (deficit <= 0) {
+                if (reservedPages.compareAndSet(reserved, reserved + 
claimPages))
+                    return claimPages;
+
+                continue;
+            }
+
+            if (memMetrics.onPageEvictionsStarted()) {
+                U.warn(log, "Page-based evictions started." +
+                    " Consider increasing 'maxSize' on Data Region 
configuration: " + dataRegion.config().getName());
+            }
+
+            evictionTracker.evictDataPage();
+
+            memMetrics.updateEvictionRate();
+
+            if (deficit(claimPages, limitPages, reservedPages.get()) < 
deficit) {
+                lastProgressNanos = System.nanoTime();
+
+                backoffNanos = EVICTION_BACKOFF_START_NANOS;
+            }
+            else if (recentStall)
+                return 0;
+            else if (System.nanoTime() - lastProgressNanos > 
TimeUnit.MILLISECONDS.toNanos(EVICTION_NO_PROGRESS_TIMEOUT_MILLIS)) {
+                if (!bestEffort)
+                    throw outOfMemory();
+
+                lastStallMillis = U.currentTimeMillis();
+
+                LT.warn(log, "Page eviction made no progress, the row is 
inserted without a page reservation " +
+                    "[region=" + dataRegion.config().getName() + ", timeout=" 
+ EVICTION_NO_PROGRESS_TIMEOUT_MILLIS + "ms]");
+
+                return 0;
+            }
+            else {
+                LockSupport.parkNanos(backoffNanos);
+
+                backoffNanos = Math.min(backoffNanos << 1, 
EVICTION_BACKOFF_MAX_NANOS);
+            }

Review Comment:
   Done



-- 
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]

Reply via email to