asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Murtadha Hubail (Code Review)" <do-not-re...@asterixdb.incubator.apache.org>
Subject Change in hyracks[master]: ASTERIXDB-1137: Prevent file from being deleted while a page...
Date Tue, 17 Nov 2015 18:23:16 GMT
Murtadha Hubail has submitted this change and it was merged.

Change subject: ASTERIXDB-1137: Prevent file from being deleted while a page is being flushed.
......................................................................


ASTERIXDB-1137: Prevent file from being deleted while a page is being flushed.

Change-Id: I256a84c416bf9d7251b1ee788d028d6b2928e747
Reviewed-on: https://asterix-gerrit.ics.uci.edu/499
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Ian Maxon <imaxon@apache.org>
---
M hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/io/IOManager.java
M hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/buffercache/BufferCache.java
2 files changed, 20 insertions(+), 13 deletions(-)

Approvals:
  Ian Maxon: Looks good to me, approved
  Jenkins: Verified



diff --git a/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/io/IOManager.java
b/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/io/IOManager.java
index 3b88f02..f673a07 100644
--- a/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/io/IOManager.java
+++ b/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/io/IOManager.java
@@ -86,13 +86,16 @@
     @Override
     public int syncWrite(IFileHandle fHandle, long offset, ByteBuffer data) throws HyracksDataException
{
         try {
+            if (fHandle == null) {
+                throw new IllegalStateException("Trying to write to a deleted file.");
+            }
             int n = 0;
             int remaining = data.remaining();
             while (remaining > 0) {
                 int len = ((FileHandle) fHandle).getFileChannel().write(data, offset);
                 if (len < 0) {
-                    throw new HyracksDataException("Error writing to file: "
-                            + ((FileHandle) fHandle).getFileReference().toString());
+                    throw new HyracksDataException(
+                            "Error writing to file: " + ((FileHandle) fHandle).getFileReference().toString());
                 }
                 remaining -= len;
                 offset += len;
diff --git a/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/buffercache/BufferCache.java
b/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/buffercache/BufferCache.java
index 58ba988..3892e0a 100644
--- a/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/buffercache/BufferCache.java
+++ b/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/buffercache/BufferCache.java
@@ -427,13 +427,15 @@
 
     private void write(CachedPage cPage) throws HyracksDataException {
         BufferedFileHandle fInfo = getFileInfo(cPage);
-        if (fInfo.fileHasBeenDeleted()) {
-            return;
+        //synchronize on fInfo to prevent the file handle from being deleted until the page
is written.
+        synchronized (fInfo) {
+            if (!fInfo.fileHasBeenDeleted()) {
+                cPage.buffer.position(0);
+                cPage.buffer.limit(pageSize);
+                ioManager.syncWrite(fInfo.getFileHandle(), (long) BufferedFileHandle.getPageId(cPage.dpid)
* pageSize,
+                        cPage.buffer);
+            }
         }
-        cPage.buffer.position(0);
-        cPage.buffer.limit(pageSize);
-        ioManager.syncWrite(fInfo.getFileHandle(), (long) BufferedFileHandle.getPageId(cPage.dpid)
* pageSize,
-                cPage.buffer);
     }
 
     @Override
@@ -516,8 +518,8 @@
                         }
                     }
                 } else if (shutdownStart) {
-                    throw new IllegalStateException("Cache closed, but unable to acquire
read lock on dirty page: "
-                            + cPage.dpid);
+                    throw new IllegalStateException(
+                            "Cache closed, but unable to acquire read lock on dirty page:
" + cPage.dpid);
                 }
             }
         }
@@ -765,9 +767,11 @@
                     // Mark the fInfo as deleted,
                     // such that when its pages are reclaimed in openFile(),
                     // the pages are not flushed to disk but only invalidated.
-                    if (!fInfo.fileHasBeenDeleted()) {
-                        ioManager.close(fInfo.getFileHandle());
-                        fInfo.markAsDeleted();
+                    synchronized (fInfo) {
+                        if (!fInfo.fileHasBeenDeleted()) {
+                            ioManager.close(fInfo.getFileHandle());
+                            fInfo.markAsDeleted();
+                        }
                     }
                 }
             }

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/499
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I256a84c416bf9d7251b1ee788d028d6b2928e747
Gerrit-PatchSet: 3
Gerrit-Project: hyracks
Gerrit-Branch: master
Gerrit-Owner: Murtadha Hubail <hubailmor@gmail.com>
Gerrit-Reviewer: Ian Maxon <imaxon@apache.org>
Gerrit-Reviewer: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Murtadha Hubail <hubailmor@gmail.com>
Gerrit-Reviewer: Till Westmann <tillw@apache.org>

Mime
View raw message