asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject asterixdb git commit: Fixes related to ASTERIXDB-1534
Date Fri, 26 Aug 2016 19:20:08 GMT
Repository: asterixdb
Updated Branches:
  refs/heads/master fb7f4d32c -> 82ac2f006


Fixes related to ASTERIXDB-1534

- Cleanup boolean conditions and exceptions from SonarQube comments
- Fix issue where filter page in on-disk LSM components
  can be confused with root page on restart

Change-Id: If51e0cd183f9d5ed6edaebef4a0568a6c67062e3
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1111
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Jianfeng Jia <jianfeng.jia@gmail.com>
Reviewed-by: Michael Blow <mblow@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/82ac2f00
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/82ac2f00
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/82ac2f00

Branch: refs/heads/master
Commit: 82ac2f006453ac88ad3c7f742a5933f1424a73ea
Parents: fb7f4d3
Author: Ian Maxon <imaxon@apache.org>
Authored: Wed Aug 24 16:56:36 2016 -0700
Committer: Ian Maxon <imaxon@apache.org>
Committed: Fri Aug 26 12:19:37 2016 -0700

----------------------------------------------------------------------
 .../freepage/LinkedMetaDataPageManager.java     | 22 ++++-----
 .../am/common/impls/AbstractTreeIndex.java      | 51 +++++++++++---------
 2 files changed, 38 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/82ac2f00/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/freepage/LinkedMetaDataPageManager.java
----------------------------------------------------------------------
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 fbb16b2..e7a1123 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 java.util.logging.Logger;
 
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.storage.am.common.api.IMetaDataPageManager;
@@ -44,7 +43,6 @@ public class LinkedMetaDataPageManager implements IMetaDataPageManager {
     private boolean appendOnly = false;
     ICachedPage confiscatedMetaNode;
     ICachedPage filterPage;
-    private static Logger LOGGER = Logger.getLogger(LinkedMetaDataPageManager.class.getName());
 
     public LinkedMetaDataPageManager(IBufferCache bufferCache, ITreeIndexMetaDataFrameFactory
metaDataFrameFactory) {
         this.bufferCache = bufferCache;
@@ -65,7 +63,8 @@ public class LinkedMetaDataPageManager implements IMetaDataPageManager {
                 // allocate a new page in the chain of meta pages
                 int newPage = metaFrame.getFreePage();
                 if (newPage < 0) {
-                    throw new Exception("Inconsistent Meta Page State. It has no space, but
it also has no entries.");
+                    throw new HyracksDataException(
+                              "Inconsistent Meta Page State. It has no space, but it also
has no entries.");
                 }
 
                 ICachedPage newNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId,
newPage), false);
@@ -87,8 +86,6 @@ public class LinkedMetaDataPageManager implements IMetaDataPageManager {
                     bufferCache.unpin(newNode);
                 }
             }
-        } catch (Exception e) {
-            e.printStackTrace();
         } finally {
             metaNode.releaseWriteLatch(true);
             bufferCache.unpin(metaNode);
@@ -181,7 +178,7 @@ public class LinkedMetaDataPageManager implements IMetaDataPageManager
{
     @Override
     public int getMaxPage(ITreeIndexMetaDataFrame metaFrame) throws HyracksDataException
{
         ICachedPage metaNode;
-        if (!appendOnly || (appendOnly && confiscatedMetaNode == null)) {
+        if (!appendOnly || confiscatedMetaNode == null) {
             int mdPage = getFirstMetadataPage();
             if (mdPage < 0) {
                 return IBufferCache.INVALID_PAGEID;
@@ -197,7 +194,7 @@ public class LinkedMetaDataPageManager implements IMetaDataPageManager
{
             maxPage = metaFrame.getMaxPage();
         } finally {
             metaNode.releaseReadLatch();
-            if (!appendOnly || (appendOnly && confiscatedMetaNode == null)) {
+            if (!appendOnly || confiscatedMetaNode == null) {
                 bufferCache.unpin(metaNode);
             }
         }
@@ -235,7 +232,7 @@ public class LinkedMetaDataPageManager implements IMetaDataPageManager
{
     public int getFilterPageId() throws HyracksDataException {
         ICachedPage metaNode;
         int filterPageId = NO_FILTER_IN_PLACE;
-        if (!appendOnly || (appendOnly && confiscatedMetaNode == null)) {
+        if (!appendOnly || confiscatedMetaNode == null) {
             metaNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, getFirstMetadataPage()),
false);
         } else {
             metaNode = confiscatedMetaNode;
@@ -251,7 +248,7 @@ public class LinkedMetaDataPageManager implements IMetaDataPageManager
{
             }
         } finally {
             metaNode.releaseReadLatch();
-            if (!appendOnly || (appendOnly && confiscatedMetaNode == null)) {
+            if (!appendOnly || confiscatedMetaNode == null) {
                 bufferCache.unpin(metaNode);
             }
         }
@@ -316,7 +313,7 @@ public class LinkedMetaDataPageManager implements IMetaDataPageManager
{
 
     @Override
     public boolean isMetaPage(ITreeIndexMetaDataFrame metaFrame) {
-        return (metaFrame.getLevel() == META_PAGE_LEVEL_INDICATOR);
+        return metaFrame.getLevel() == META_PAGE_LEVEL_INDICATOR;
     }
 
     @Override
@@ -345,6 +342,7 @@ public class LinkedMetaDataPageManager implements IMetaDataPageManager
{
             ITreeIndexMetaDataFrame metaFrame = metaDataFrameFactory.createFrame();
             metaFrame.setPage(confiscatedMetaNode);
             int finalFilterPage = getFreePage(metaFrame);
+            setFilterPageId(finalFilterPage);
             bufferCache.setPageDiskId(filterPage, BufferedFileHandle.getDiskPageId(fileId,
finalFilterPage));
             queue.put(filterPage);
         }
@@ -413,7 +411,7 @@ public class LinkedMetaDataPageManager implements IMetaDataPageManager
{
     @Override
     public long getLSN() throws HyracksDataException {
         ICachedPage metaNode;
-        if (!appendOnly || (appendOnly && confiscatedMetaNode == null)) {
+        if (!appendOnly || confiscatedMetaNode == null) {
             metaNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, getFirstMetadataPage()),
false);
         } else {
             metaNode = confiscatedMetaNode;
@@ -425,7 +423,7 @@ public class LinkedMetaDataPageManager implements IMetaDataPageManager
{
             return metaFrame.getLSN();
         } finally {
             metaNode.releaseReadLatch();
-            if (!appendOnly || (appendOnly && confiscatedMetaNode == null)) {
+            if (!appendOnly || confiscatedMetaNode == null) {
                 bufferCache.unpin(metaNode);
             }
         }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/82ac2f00/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/impls/AbstractTreeIndex.java
----------------------------------------------------------------------
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 3a7eb77..0dcfc90 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
@@ -46,6 +46,7 @@ import org.apache.hyracks.storage.common.file.IFileMapProvider;
 public abstract class AbstractTreeIndex implements ITreeIndex {
 
     public static final int MINIMAL_TREE_PAGE_COUNT = 2;
+    public static final int MINIMAL_TREE_PAGE_COUNT_WITH_FILTER = 3;
     protected int rootPage = 1;
 
     protected final IBufferCache bufferCache;
@@ -70,12 +71,10 @@ public abstract class AbstractTreeIndex implements ITreeIndex {
 
     protected int bulkloadLeafStart = 0;
 
-
     public AbstractTreeIndex(IBufferCache bufferCache, IFileMapProvider fileMapProvider,
-                             IMetaDataPageManager freePageManager, ITreeIndexFrameFactory
interiorFrameFactory,
-                             ITreeIndexFrameFactory leafFrameFactory, IBinaryComparatorFactory[]
cmpFactories,
-                             int fieldCount,
-                             FileReference file) {
+            IMetaDataPageManager freePageManager, ITreeIndexFrameFactory interiorFrameFactory,
+            ITreeIndexFrameFactory leafFrameFactory, IBinaryComparatorFactory[] cmpFactories,
int fieldCount,
+            FileReference file) {
         this.bufferCache = bufferCache;
         this.fileMapProvider = fileMapProvider;
         this.freePageManager = freePageManager;
@@ -141,16 +140,25 @@ public abstract class AbstractTreeIndex implements ITreeIndex {
         }
     }
 
-    private void setRootAndMetadataPages(boolean appendOnly) throws HyracksDataException{
+    private void setRootAndMetadataPages(boolean appendOnly) throws HyracksDataException
{
         if (!appendOnly) {
             // regular or empty tree
             rootPage = 1;
             bulkloadLeafStart = 2;
         } else {
-            // bulkload-only tree (used e.g. for HDFS). -1 is meta page, -2 is root page
+            //the root page is either page n-2 (no filter) or n-3 (filter)
             int numPages = bufferCache.getNumPagesOfFile(fileId);
-            //the root page is the last page before the metadata page
-            rootPage = numPages > MINIMAL_TREE_PAGE_COUNT ? numPages - MINIMAL_TREE_PAGE_COUNT
: 0;
+            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;
+            }
+
             //leaves start from the very beginning of the file.
             bulkloadLeafStart = 0;
         }
@@ -188,10 +196,9 @@ public abstract class AbstractTreeIndex implements ITreeIndex {
         int mdPageLoc = freePageManager.getFirstMetadataPage();
         ITreeIndexMetaDataFrame metaFrame = freePageManager.getMetaDataFrameFactory().createFrame();
         int numPages = freePageManager.getMaxPage(metaFrame);
-        if(mdPageLoc > 1 || (mdPageLoc == 1 && numPages <= MINIMAL_TREE_PAGE_COUNT
-1)) { //md page doesn't count itself
+        if (mdPageLoc > 1 || (mdPageLoc == 1 && numPages <= MINIMAL_TREE_PAGE_COUNT
- 1)) { //md page doesn't count
             appendOnly = true;
-        }
-        else{
+        } else {
             appendOnly = false;
         }
         setRootAndMetadataPages(appendOnly);
@@ -245,7 +252,7 @@ public abstract class AbstractTreeIndex implements ITreeIndex {
         if (rootPage == -1) {
             return true;
         }
-        if(freePageManager.appendOnlyMode() && bufferCache.getNumPagesOfFile(fileId)
<= MINIMAL_TREE_PAGE_COUNT){
+        if (freePageManager.appendOnlyMode() && bufferCache.getNumPagesOfFile(fileId)
<= MINIMAL_TREE_PAGE_COUNT) {
             return true;
         }
         ICachedPage rootNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, rootPage),
false);
@@ -263,8 +270,6 @@ public abstract class AbstractTreeIndex implements ITreeIndex {
         }
     }
 
-
-
     public byte getTreeHeight(ITreeIndexFrame frame) throws HyracksDataException {
         ICachedPage rootNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, rootPage),
false);
         rootNode.acquireReadLatch();
@@ -331,8 +336,8 @@ public abstract class AbstractTreeIndex implements ITreeIndex {
         protected final IFIFOPageQueue queue;
         protected List<ICachedPage> pagesToWrite;
 
-        public AbstractTreeIndexBulkLoader(float fillFactor, boolean appendOnly) throws TreeIndexException,
-                HyracksDataException {
+        public AbstractTreeIndexBulkLoader(float fillFactor, boolean appendOnly)
+                throws TreeIndexException, HyracksDataException {
             //Initialize the tree
             if (appendOnly) {
                 create(appendOnly);
@@ -359,8 +364,8 @@ public abstract class AbstractTreeIndex implements ITreeIndex {
 
             NodeFrontier leafFrontier = new NodeFrontier(leafFrame.createTupleReference());
             leafFrontier.pageId = freePageManager.getFreePage(metaFrame);
-            leafFrontier.page = bufferCache.confiscatePage(
-                    BufferedFileHandle.getDiskPageId(fileId, leafFrontier.pageId));
+            leafFrontier.page = bufferCache
+                    .confiscatePage(BufferedFileHandle.getDiskPageId(fileId, leafFrontier.pageId));
 
             interiorFrame.setPage(leafFrontier.page);
             interiorFrame.initBuffer((byte) 0);
@@ -382,10 +387,10 @@ public abstract class AbstractTreeIndex implements ITreeIndex {
             for (NodeFrontier nodeFrontier : nodeFrontiers) {
                 ICachedPage frontierPage = nodeFrontier.page;
                 if (frontierPage.confiscated()) {
-                    bufferCache.returnPage(frontierPage,false);
+                    bufferCache.returnPage(frontierPage, false);
                 }
             }
-            for(ICachedPage pageToDiscard: pagesToWrite){
+            for (ICachedPage pageToDiscard : pagesToWrite) {
                 bufferCache.returnPage(pageToDiscard, false);
             }
             releasedLatches = true;
@@ -400,8 +405,8 @@ public abstract class AbstractTreeIndex implements ITreeIndex {
                 newRoot.acquireWriteLatch();
                 //root will be the highest frontier
                 NodeFrontier lastNodeFrontier = nodeFrontiers.get(nodeFrontiers.size() -
1);
-                ICachedPage oldRoot = bufferCache.pin(
-                        BufferedFileHandle.getDiskPageId(fileId, lastNodeFrontier.pageId),
false);
+                ICachedPage oldRoot = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId,
lastNodeFrontier.pageId),
+                        false);
                 oldRoot.acquireReadLatch();
                 lastNodeFrontier.page = oldRoot;
                 try {


Mime
View raw message