This is an automated email from the ASF dual-hosted git repository.

wyk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git


The following commit(s) were added to refs/heads/master by this push:
     new be01a7358c [NO ISSUE] Ensure confiscated pages
be01a7358c is described below

commit be01a7358caef59535d2a1d929638e4a375f2bf5
Author: Wail Alkowaileet <[email protected]>
AuthorDate: Tue May 14 16:03:28 2024 -0700

    [NO ISSUE] Ensure confiscated pages
    
    - user model changes: no
    - storage format changes: no
    - interface changes: no
    
    Details:
    Simple patch to check if we suffered from confiscating
    a page that is already confiscated. There's a potetntial
    of a race condititon here.
    
    Change-Id: I771f29d7709d94f0c6683886edcd3a8ab0e9eec2
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18289
    Integration-Tests: Jenkins <[email protected]>
    Tested-by: Jenkins <[email protected]>
    Reviewed-by: Ian Maxon <[email protected]>
---
 .../hyracks/storage/common/buffercache/BufferCache.java | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/buffercache/BufferCache.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/buffercache/BufferCache.java
index d47b8e375e..53e27a987e 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/buffercache/BufferCache.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/buffercache/BufferCache.java
@@ -1176,7 +1176,7 @@ public class BufferCache implements IBufferCacheInternal, 
ILifeCycleComponent, I
     }
 
     private ICachedPage confiscateInner(long dpid, int multiplier) {
-        ICachedPage returnPage = null;
+        CachedPage returnPage = null;
         CachedPage victim = (CachedPage) 
pageReplacementStrategy.findVictim(multiplier);
         if (victim == null) {
             return victim;
@@ -1197,7 +1197,7 @@ public class BufferCache implements IBufferCacheInternal, 
ILifeCycleComponent, I
                 return null;
             }
             returnPage = victim;
-            ((CachedPage) returnPage).dpid = dpid;
+            returnPage.dpid = dpid;
         } else {
             // Case 2a/b
             int pageHash = hash(victim.getDiskPageId());
@@ -1240,7 +1240,7 @@ public class BufferCache implements IBufferCacheInternal, 
ILifeCycleComponent, I
                 }
                 if (found) {
                     returnPage = victim;
-                    ((CachedPage) returnPage).dpid = dpid;
+                    returnPage.dpid = dpid;
                 } //otherwise, someone took the same victim before we acquired 
the lock. try again!
             } finally {
                 bucket.bucketLock.unlock();
@@ -1248,12 +1248,17 @@ public class BufferCache implements 
IBufferCacheInternal, ILifeCycleComponent, I
         }
         // if we found a page after all that, go ahead and finish
         if (returnPage != null) {
-            ((CachedPage) returnPage).confiscated.set(true);
+            int pinCount = returnPage.pinCount.get();
+            if (!returnPage.confiscated.compareAndSet(false, true)) {
+                throw new IllegalStateException("Returned page is already 
confiscated");
+            } else if (pinCount != 1) {
+                throw new IllegalStateException("Returned page's pinCount is 
not 1. It is " + pinCount);
+            }
             if (DEBUG) {
                 confiscateLock.lock();
                 try {
-                    confiscatedPages.add((CachedPage) returnPage);
-                    confiscatedPagesOwner.put((CachedPage) returnPage, 
Thread.currentThread().getStackTrace());
+                    confiscatedPages.add(returnPage);
+                    confiscatedPagesOwner.put(returnPage, 
Thread.currentThread().getStackTrace());
                 } finally {
                     confiscateLock.unlock();
                 }

Reply via email to