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 06:25:29 GMT
Murtadha Hubail has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/499

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
---
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, 22 insertions(+), 13 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/hyracks refs/changes/99/499/1

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..af8f0e1 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,17 @@
 
     private void write(CachedPage cPage) throws HyracksDataException {
         BufferedFileHandle fInfo = getFileInfo(cPage);
-        if (fInfo.fileHasBeenDeleted()) {
-            return;
+        if (!fInfo.fileHasBeenDeleted()) {
+            //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 +520,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 +769,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: newchange
Gerrit-Change-Id: I256a84c416bf9d7251b1ee788d028d6b2928e747
Gerrit-PatchSet: 1
Gerrit-Project: hyracks
Gerrit-Branch: master
Gerrit-Owner: Murtadha Hubail <hubailmor@gmail.com>

Mime
View raw message