ibessonov commented on code in PR #6354:
URL: https://github.com/apache/ignite-3/pull/6354#discussion_r2247596026


##########
modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/PersistentPageMemory.java:
##########
@@ -1115,25 +1115,64 @@ private long writeLockPage(long absPtr, FullPageId 
fullId, boolean checkTag) {
     private long postWriteLockPage(long absPtr, FullPageId fullId) {
         writeTimestamp(absPtr, coarseCurrentTimeMillis());
 
+        copyPageIfInCheckpoint(absPtr, fullId);
+
+        assert getCrc(absPtr + PAGE_OVERHEAD) == 0; // TODO IGNITE-16612
+
+        return absPtr + PAGE_OVERHEAD;
+    }
+
+    private void copyPageIfInCheckpoint(long absPtr, FullPageId fullId) {
+        Segment seg = segment(fullId);
+
+        if (!seg.isInCheckpoint(fullId) || tempBufferPointer(absPtr) != 
INVALID_REL_PTR) {
+            return;
+        }
+
         // Create a buffer copy if the page is scheduled for a checkpoint.
-        if (isInCheckpoint(fullId) && tempBufferPointer(absPtr) == 
INVALID_REL_PTR) {
-            long tmpRelPtr;
+        long tmpRelPtr;
 
-            PagePool checkpointPool = this.checkpointPool;
+        PagePool checkpointPool = this.checkpointPool;
 
-            while (true) {
-                tmpRelPtr = 
checkpointPool.borrowOrAllocateFreePage(tag(fullId.pageId()));
+        while (true) {
+            int tag = tag(fullId.pageId());

Review Comment:
   I'm not sure what you tried to achieve by extracting this variable. Is it OK 
to ask you for explanation?



##########
modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/util/PageHandler.java:
##########
@@ -237,6 +242,12 @@ static <X, R> R writePage(
                     pageMem.writeUnlock(groupId, pageId, page, ok);
                 }
             }
+        } catch (Throwable t) {
+            // This logging was added because of the case when an exception 
was thrown from "pageMem.writeLock" and it was not got in the
+            // "catch" in the calling code of this method, the exception seems 
to disappear.
+            LOG.error("Error writing page: [grpId={}, pageId={}]", t, groupId, 
hexLong(page));

Review Comment:
   Can it lead to unexpected excessive logs if handler threw an exception? I 
think it can, so I don't like this solution. I don't want to duplicate 
exceptions in logs, let's come up with something else.
   
   > it was not got in the "catch" in the calling code of this method
   
   Can we catch these exceptions in those places instead?



##########
modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/PersistentPageMemory.java:
##########
@@ -1115,25 +1115,64 @@ private long writeLockPage(long absPtr, FullPageId 
fullId, boolean checkTag) {
     private long postWriteLockPage(long absPtr, FullPageId fullId) {
         writeTimestamp(absPtr, coarseCurrentTimeMillis());
 
+        copyPageIfInCheckpoint(absPtr, fullId);
+
+        assert getCrc(absPtr + PAGE_OVERHEAD) == 0; // TODO IGNITE-16612
+
+        return absPtr + PAGE_OVERHEAD;
+    }
+
+    private void copyPageIfInCheckpoint(long absPtr, FullPageId fullId) {

Review Comment:
   I would use a more explicit naming, something like 
`maybeCopyToCheckpointBuffer`. Because the word `copy` doesn't explain the 
destination. Or you can just write some javadoc for this method, that would 
clarify what happens



##########
modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/PersistentPageMemory.java:
##########
@@ -1115,25 +1115,64 @@ private long writeLockPage(long absPtr, FullPageId 
fullId, boolean checkTag) {
     private long postWriteLockPage(long absPtr, FullPageId fullId) {
         writeTimestamp(absPtr, coarseCurrentTimeMillis());
 
+        copyPageIfInCheckpoint(absPtr, fullId);
+
+        assert getCrc(absPtr + PAGE_OVERHEAD) == 0; // TODO IGNITE-16612
+
+        return absPtr + PAGE_OVERHEAD;
+    }
+
+    private void copyPageIfInCheckpoint(long absPtr, FullPageId fullId) {
+        Segment seg = segment(fullId);
+
+        if (!seg.isInCheckpoint(fullId) || tempBufferPointer(absPtr) != 
INVALID_REL_PTR) {
+            return;
+        }
+
         // Create a buffer copy if the page is scheduled for a checkpoint.
-        if (isInCheckpoint(fullId) && tempBufferPointer(absPtr) == 
INVALID_REL_PTR) {
-            long tmpRelPtr;
+        long tmpRelPtr;
 
-            PagePool checkpointPool = this.checkpointPool;
+        PagePool checkpointPool = this.checkpointPool;
 
-            while (true) {
-                tmpRelPtr = 
checkpointPool.borrowOrAllocateFreePage(tag(fullId.pageId()));
+        while (true) {
+            int tag = tag(fullId.pageId());
+            tmpRelPtr = checkpointPool.borrowOrAllocateFreePage(tag);
 
-                if (tmpRelPtr != INVALID_REL_PTR) {
-                    break;
-                }
+            if (tmpRelPtr != INVALID_REL_PTR) {
+                break;
+            }
 
-                // TODO https://issues.apache.org/jira/browse/IGNITE-23106 
Replace spin-wait with a proper wait.
-                try {
-                    Thread.sleep(1);
-                } catch (InterruptedException ignore) {
-                    // No-op.
-                }
+            // TODO https://issues.apache.org/jira/browse/IGNITE-23106 Replace 
spin-wait with a proper wait.
+            try {
+                Thread.sleep(1);
+            } catch (InterruptedException ignore) {
+                // No-op.
+            }
+        }
+
+        // The partition could have been deleted in parallel and we could get 
an empty page.
+        seg.writeLock().lock();
+
+        try {
+            // Double check to see if we need to clear the page because it has 
already been partitioned.

Review Comment:
   Comment says "Double check". Where's the first check?



-- 
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: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to