asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ian Maxon (Code Review)" <do-not-re...@asterixdb.incubator.apache.org>
Subject Change in asterixdb[master]: Fix for ASTERIXDB-1725
Date Wed, 02 Nov 2016 03:16:29 GMT
Ian Maxon has uploaded a new change for review.

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

Change subject: Fix for ASTERIXDB-1725
......................................................................

Fix for ASTERIXDB-1725

This is tricky, the best method I could think to fix this involved simply
putting the root page number in the metadata page rather than trying to
calculate it somehow going backwards from the end of the file.

I also fixed a bug discovered by Mike B where getLSNOffset was not
taking into consideration page header sizes.

Change-Id: I9f21e96ab045d331e4fc1c77b5c73b975e6260fa
---
M hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/IMetaDataPageManager.java
M hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/ITreeIndexMetaDataFrame.java
M hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/frames/LIFOMetaDataFrame.java
M hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/freepage/LinkedMetaDataPageManager.java
M hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/impls/AbstractTreeIndex.java
M hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/freepage/VirtualMetaDataPageManager.java
6 files changed, 85 insertions(+), 21 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/31/1331/1

diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/IMetaDataPageManager.java
b/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/IMetaDataPageManager.java
index 3982a3a..5d87f99 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/IMetaDataPageManager.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/IMetaDataPageManager.java
@@ -172,4 +172,8 @@
     long getLSNOffset() throws HyracksDataException;
 
     public long getLastMarkerLSN() throws HyracksDataException;
+
+    void setRootPage(int rootPage) throws HyracksDataException;
+
+    int getRootPage() throws HyracksDataException;
 }
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/ITreeIndexMetaDataFrame.java
b/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/ITreeIndexMetaDataFrame.java
index d4fbaa2..21e918d 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/ITreeIndexMetaDataFrame.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/ITreeIndexMetaDataFrame.java
@@ -25,7 +25,7 @@
 
     //Storage version #. Change this if you alter any tree frame formats to stop
     // possible corruption from old versions reading new formats.
-    public static final int VERSION = 2;
+    public static final int VERSION = 3;
 
     public void initBuffer(byte level);
 
@@ -74,4 +74,8 @@
     public long getLastMarkerLSN();
 
     public void setLastMarkerLSN(long lsn);
+
+    void setRootPageNumber(int rootPage);
+
+    int getRootPageNumber();
 }
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/frames/LIFOMetaDataFrame.java
b/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/frames/LIFOMetaDataFrame.java
index d4194c2..b35468f 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/frames/LIFOMetaDataFrame.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/frames/LIFOMetaDataFrame.java
@@ -49,7 +49,8 @@
     public static final int LSN_OFFSET = ADDITIONAL_FILTERING_PAGE_OFFSET + 4; // 33
     private static final int LAST_MARKER_LSN_OFFSET = LSN_OFFSET + 8; // 41
     public static final int STORAGE_VERSION_OFFSET = LAST_MARKER_LSN_OFFSET + 4; //45
-    private static final int HEADER_END_OFFSET = LAST_MARKER_LSN_OFFSET + 4; //49
+    public static final int ROOT_PAGE_NUMBER = STORAGE_VERSION_OFFSET + 4; //49
+    private static final int HEADER_END_OFFSET = ROOT_PAGE_NUMBER + 4; // 53
 
     protected ICachedPage page = null;
     protected ByteBuffer buf = null;
@@ -126,6 +127,7 @@
         buf.putInt(NEXT_PAGE_OFFSET, -1);
         buf.putInt(ADDITIONAL_FILTERING_PAGE_OFFSET, -1);
         buf.putLong(LAST_MARKER_LSN_OFFSET, -1L);
+        buf.putInt(ROOT_PAGE_NUMBER,0);
         buf.putInt(STORAGE_VERSION_OFFSET, VERSION);
         setValid(false);
     }
@@ -192,4 +194,14 @@
     public void setLSMComponentFilterPageId(int filterPage) {
         buf.putInt(ADDITIONAL_FILTERING_PAGE_OFFSET, filterPage);
     }
+
+    @Override
+    public void setRootPageNumber(int rootPage) {
+        buf.putInt(ROOT_PAGE_NUMBER, rootPage);
+    }
+
+    @Override
+    public int getRootPageNumber() {
+        return buf.getInt(ROOT_PAGE_NUMBER);
+    }
 }
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/freepage/LinkedMetaDataPageManager.java
b/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/freepage/LinkedMetaDataPageManager.java
index e7a1123..abe10df 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/freepage/LinkedMetaDataPageManager.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/freepage/LinkedMetaDataPageManager.java
@@ -18,7 +18,6 @@
  */
 package org.apache.hyracks.storage.am.common.freepage;
 
-
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.storage.am.common.api.IMetaDataPageManager;
 import org.apache.hyracks.storage.am.common.api.ITreeIndexMetaDataFrame;
@@ -64,7 +63,7 @@
                 int newPage = metaFrame.getFreePage();
                 if (newPage < 0) {
                     throw new HyracksDataException(
-                              "Inconsistent Meta Page State. It has no space, but it also
has no entries.");
+                            "Inconsistent Meta Page State. It has no space, but it also has
no entries.");
                 }
 
                 ICachedPage newNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId,
newPage), false);
@@ -471,7 +470,8 @@
     public long getLSNOffset() throws HyracksDataException {
         int metadataPageNum = getFirstMetadataPage();
         if (metadataPageNum != IBufferCache.INVALID_PAGEID) {
-            return ((long)metadataPageNum * bufferCache.getPageSize()) + LIFOMetaDataFrame.LSN_OFFSET;
+            return ((long) metadataPageNum * (bufferCache.getPageSize() + BufferCache.RESERVED_HEADER_BYTES))
+                    + LIFOMetaDataFrame.LSN_OFFSET;
         }
         return IMetaDataPageManager.INVALID_LSN_OFFSET;
     }
@@ -496,4 +496,48 @@
             }
         }
     }
+
+    @Override
+    public void setRootPage(int rootPage) throws HyracksDataException{
+        ICachedPage metaNode;
+        if (!appendOnly) {
+            metaNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, getFirstMetadataPage()),
false);
+        } else {
+            metaNode = confiscatedMetaNode;
+        }
+        ITreeIndexMetaDataFrame metaFrame = metaDataFrameFactory.createFrame();
+        metaNode.acquireWriteLatch();
+        try {
+            metaFrame.setPage(metaNode);
+            metaFrame.setRootPageNumber(rootPage);
+        } finally {
+            if (!appendOnly) {
+                metaNode.releaseWriteLatch(true);
+                bufferCache.unpin(metaNode);
+            } else {
+                metaNode.releaseWriteLatch(false);
+            }
+        }
+    }
+
+    @Override
+    public int getRootPage() throws HyracksDataException {
+        ICachedPage metaNode;
+        if (!appendOnly || confiscatedMetaNode == null) {
+            metaNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, getFirstMetadataPage()),
false);
+        } else {
+            metaNode = confiscatedMetaNode;
+        }
+        ITreeIndexMetaDataFrame metaFrame = metaDataFrameFactory.createFrame();
+        metaNode.acquireReadLatch();
+        try {
+            metaFrame.setPage(metaNode);
+            return metaFrame.getRootPageNumber();
+        } finally {
+            metaNode.releaseReadLatch();
+            if (!appendOnly || confiscatedMetaNode == null) {
+                bufferCache.unpin(metaNode);
+            }
+        }
+    }
 }
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/impls/AbstractTreeIndex.java
b/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/impls/AbstractTreeIndex.java
index 0dcfc90..5ac203e 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/impls/AbstractTreeIndex.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/impls/AbstractTreeIndex.java
@@ -114,7 +114,6 @@
         }
 
         freePageManager.open(fileId);
-        setRootAndMetadataPages(appendOnly);
         if (!appendOnly) {
             initEmptyTree();
             freePageManager.close();
@@ -122,6 +121,7 @@
             this.appendOnly = true;
             initCachedMetadataPage();
         }
+        setRootPage(appendOnly);
         bufferCache.closeFile(fileId);
     }
 
@@ -140,25 +140,14 @@
         }
     }
 
-    private void setRootAndMetadataPages(boolean appendOnly) throws HyracksDataException
{
+    private void setRootPage(boolean appendOnly) throws HyracksDataException {
         if (!appendOnly) {
             // regular or empty tree
             rootPage = 1;
             bulkloadLeafStart = 2;
         } else {
-            //the root page is either page n-2 (no filter) or n-3 (filter)
-            int numPages = bufferCache.getNumPagesOfFile(fileId);
-            if (numPages > MINIMAL_TREE_PAGE_COUNT) {
-                int filterPageId = freePageManager.getFilterPageId();
-                if (filterPageId > 0) {
-                    rootPage = numPages - MINIMAL_TREE_PAGE_COUNT_WITH_FILTER;
-                } else {
-                    rootPage = numPages - MINIMAL_TREE_PAGE_COUNT;
-                }
-            } else {
-                rootPage = 0;
-            }
-
+            //root page is stored in MD page
+            rootPage = freePageManager.getRootPage();
             //leaves start from the very beginning of the file.
             bulkloadLeafStart = 0;
         }
@@ -201,7 +190,7 @@
         } else {
             appendOnly = false;
         }
-        setRootAndMetadataPages(appendOnly);
+        setRootPage(appendOnly);
 
         // TODO: Should probably have some way to check that the tree is physically consistent
         // or that the file we just opened actually is a tree
@@ -424,6 +413,7 @@
 
                 }
             }
+            freePageManager.setRootPage(rootPage);
         }
 
         protected void addLevel() throws HyracksDataException {
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/freepage/VirtualMetaDataPageManager.java
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/freepage/VirtualMetaDataPageManager.java
index 158c68f..d6685af 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/freepage/VirtualMetaDataPageManager.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/freepage/VirtualMetaDataPageManager.java
@@ -184,4 +184,14 @@
         // Method doesn't make sense for this free page manager.
         return -1L;
     }
+
+    @Override
+    public void setRootPage(int rootPage) throws HyracksDataException {
+
+    }
+
+    @Override
+    public int getRootPage() throws HyracksDataException {
+        return 1;
+    }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9f21e96ab045d331e4fc1c77b5c73b975e6260fa
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Ian Maxon <imaxon@apache.org>

Mime
View raw message