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


##########
modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/PersistentPageMemory.java:
##########
@@ -1865,32 +1908,28 @@ private void copyPageForCheckpoint(
         // No need to write if exception occurred.
         boolean canWrite = false;
 
-        boolean locked = rwLock.tryWriteLock(absPtr + PAGE_LOCK_OFFSET, 
TAG_LOCK_ALWAYS);
-
-        if (!locked) {
-            // We release the page only once here because this page will be 
copied sometime later and
-            // will be released properly then.
+        if (!rwLock.tryWriteLock(absPtr + PAGE_LOCK_OFFSET, TAG_LOCK_ALWAYS)) {
+            // We release the page only once here because this page will be 
copied sometime later and will be released properly then.
             if (!pageSingleAcquire) {
                 PageHeader.releasePage(absPtr);
             }
 
+            // Since we failed to take the write lock, we will try to do it 
again later, for this we will need to invoke the writer with a
+            // special tag TRY_AGAIN_TAG and also return the page in the dirty 
pages of the segment.
+
             buf.clear();
 
-            if (isInCheckpoint(fullId)) {
-                pageStoreWriter.writePage(fullId, buf, TRY_AGAIN_TAG);
-            }
+            pageStoreWriter.writePage(fullId, buf, TRY_AGAIN_TAG);
 
-            return;
-        }
+            segment.readLock().lock();
 
-        if (!clearCheckpoint(fullId)) {
-            rwLock.writeUnlock(absPtr + PAGE_LOCK_OFFSET, TAG_LOCK_ALWAYS);
+            try {
+                addToCheckpoint(segment, fullId);
 
-            if (!pageSingleAcquire) {
-                PageHeader.releasePage(absPtr);
+                return;
+            } finally {
+                segment.readLock().unlock();
             }

Review Comment:
   I don't think this change was necessary. As far as I can tell (as you 
explained to me), you're trying to avoid a data race between checkpointer and 
replacer. But the issue is that there's no race.
   - in replacer, we only replace pages that are not acquired. We do this while 
holding a segment write lock.
   - we only acquire pages when we hold segment read lock.
   - right here, the page is obviously acquired, meaning that it cannot be 
replaced.
   
   Please make it the way it was and document why it worked.



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