asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject asterixdb git commit: ASTERIXDB-1479: Change storage valid int and add explicit version
Date Thu, 04 Aug 2016 00:07:07 GMT
Repository: asterixdb
Updated Branches:
  refs/heads/master 9f110ab01 -> ca3b9b28f


ASTERIXDB-1479: Change storage valid int and add explicit version

This change will stop old versions from possibly corrupting data written
by newer versions of Hyracks. It also adds an explicit version to the
tree metadata that must match the version at runtime.

Change-Id: I888ff0eacf5b3cb6ad7ec002c74f113c6ffcd496
Reviewed-on: https://asterix-gerrit.ics.uci.edu/919
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: 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/ca3b9b28
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/ca3b9b28
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/ca3b9b28

Branch: refs/heads/master
Commit: ca3b9b28f681382b88781d8c62aa1e0fd53a2659
Parents: 9f110ab
Author: Ian Maxon <imaxon@apache.org>
Authored: Fri Jul 29 15:51:28 2016 -0700
Committer: Ian Maxon <imaxon@apache.org>
Committed: Wed Aug 3 17:06:21 2016 -0700

----------------------------------------------------------------------
 .../metadata/bootstrap/MetadataBootstrap.java   |  3 +-
 .../PersistentLocalResourceFactory.java         |  6 ++-
 .../PersistentLocalResourceRepository.java      | 15 +++++--
 .../am/common/api/ITreeIndexMetaDataFrame.java  |  7 ++++
 .../am/common/dataflow/IndexDataflowHelper.java |  3 +-
 .../am/common/frames/LIFOMetaDataFrame.java     | 22 +++++++---
 .../freepage/LinkedMetaDataPageManager.java     |  2 +-
 .../impls/AbstractLSMIndexFileManager.java      | 43 ++++++++++++++------
 .../common/file/ILocalResourceFactory.java      |  3 +-
 .../storage/common/file/LocalResource.java      | 10 ++++-
 .../file/TransientLocalResourceFactory.java     |  6 ++-
 11 files changed, 89 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ca3b9b28/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/bootstrap/MetadataBootstrap.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/bootstrap/MetadataBootstrap.java
b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/bootstrap/MetadataBootstrap.java
index c180be4..757694d 100644
--- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/bootstrap/MetadataBootstrap.java
+++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/bootstrap/MetadataBootstrap.java
@@ -77,6 +77,7 @@ import org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory;
 import org.apache.hyracks.api.dataflow.value.ITypeTraits;
 import org.apache.hyracks.api.io.FileReference;
 import org.apache.hyracks.api.io.IIOManager;
+import org.apache.hyracks.storage.am.common.frames.LIFOMetaDataFrame;
 import org.apache.hyracks.storage.am.lsm.btree.impls.LSMBTree;
 import org.apache.hyracks.storage.am.lsm.btree.util.LSMBTreeUtils;
 import org.apache.hyracks.storage.am.lsm.common.api.ILSMMergePolicyFactory;
@@ -373,7 +374,7 @@ public class MetadataBootstrap {
                     localResourceMetadata, LocalResource.LSMBTreeResource);
             ILocalResourceFactory localResourceFactory = localResourceFactoryProvider.getLocalResourceFactory();
             localResourceRepository.insert(localResourceFactory.createLocalResource(resourceID,
resourceName,
-                    metadataPartition.getPartitionId(), absolutePath));
+                    metadataPartition.getPartitionId(), LIFOMetaDataFrame.VERSION, absolutePath));
             dataLifecycleManager.register(absolutePath, lsmBtree);
         } else {
             final LocalResource resource = localResourceRepository.getResourceByPath(absolutePath);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ca3b9b28/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/PersistentLocalResourceFactory.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/PersistentLocalResourceFactory.java
b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/PersistentLocalResourceFactory.java
index 15224e2..33e5bf2 100644
--- a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/PersistentLocalResourceFactory.java
+++ b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/PersistentLocalResourceFactory.java
@@ -33,7 +33,9 @@ public class PersistentLocalResourceFactory implements ILocalResourceFactory
{
     }
 
     @Override
-    public LocalResource createLocalResource(long resourceId, String resourceName, int partition,
String resourcePath) {
-        return new LocalResource(resourceId, resourceName, partition, resourcePath, resourceType,
localResourceMetadata);
+    public LocalResource createLocalResource(long resourceId, String resourceName, int partition,
int storageVersion,
+            String resourcePath) {
+        return new LocalResource(resourceId, resourceName, partition, resourcePath, resourceType,
storageVersion,
+                localResourceMetadata);
     }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ca3b9b28/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/PersistentLocalResourceRepository.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/PersistentLocalResourceRepository.java
b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/PersistentLocalResourceRepository.java
index fc79ae0..420e479 100644
--- a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/PersistentLocalResourceRepository.java
+++ b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/PersistentLocalResourceRepository.java
@@ -40,6 +40,7 @@ import java.util.logging.Logger;
 
 import org.apache.asterix.common.cluster.ClusterPartition;
 import org.apache.asterix.common.config.AsterixMetadataProperties;
+import org.apache.asterix.common.exceptions.AsterixException;
 import org.apache.asterix.common.replication.AsterixReplicationJob;
 import org.apache.asterix.common.replication.IReplicationManager;
 import org.apache.asterix.common.utils.StoragePathUtil;
@@ -49,6 +50,7 @@ import org.apache.hyracks.api.io.IODeviceHandle;
 import org.apache.hyracks.api.replication.IReplicationJob.ReplicationExecutionType;
 import org.apache.hyracks.api.replication.IReplicationJob.ReplicationJobType;
 import org.apache.hyracks.api.replication.IReplicationJob.ReplicationOperation;
+import org.apache.hyracks.storage.am.common.frames.LIFOMetaDataFrame;
 import org.apache.hyracks.storage.common.file.ILocalResourceRepository;
 import org.apache.hyracks.storage.common.file.LocalResource;
 
@@ -63,6 +65,7 @@ public class PersistentLocalResourceRepository implements ILocalResourceReposito
     private static final String STORAGE_METADATA_FILE_NAME_PREFIX = ".asterix_root_metadata";
     private static final long STORAGE_LOCAL_RESOURCE_ID = -4321;
     public static final String METADATA_FILE_NAME = ".metadata";
+    public static final int STORAGE_VERSION = LIFOMetaDataFrame.VERSION;
     private final Cache<String, LocalResource> resourceCache;
     private final String nodeId;
     private static final int MAX_CACHED_RESOURCES = 1000;
@@ -136,15 +139,15 @@ public class PersistentLocalResourceRepository implements ILocalResourceReposito
 
             String storageRootDirPath;
             if (storageRootDirName.startsWith(System.getProperty("file.separator"))) {
-                storageRootDirPath = mountPoints[i] +
-                        storageRootDirName.substring(System.getProperty("file.separator").length());
+                storageRootDirPath = mountPoints[i]
+                        + storageRootDirName.substring(System.getProperty("file.separator").length());
             } else {
                 storageRootDirPath = mountPoints[i] + storageRootDirName;
             }
 
             LocalResource rootLocalResource = new LocalResource(STORAGE_LOCAL_RESOURCE_ID,
                     storageMetadataFile.getAbsolutePath(), 0, storageMetadataFile.getAbsolutePath(),
0,
-                    storageRootDirPath);
+                    LIFOMetaDataFrame.VERSION, storageRootDirPath);
             insert(rootLocalResource);
             LOGGER.log(Level.INFO, "created the root-metadata-file: " + storageMetadataFile.getAbsolutePath());
         }
@@ -309,7 +312,11 @@ public class PersistentLocalResourceRepository implements ILocalResourceReposito
         try (FileInputStream fis = new FileInputStream(file);
                 ObjectInputStream oisFromFis = new ObjectInputStream(fis)) {
             LocalResource resource = (LocalResource) oisFromFis.readObject();
-            return resource;
+            if (resource.getVersion() == PersistentLocalResourceRepository.STORAGE_VERSION)
{
+                return resource;
+            } else {
+                throw new AsterixException("Storage version mismatch.");
+            }
         } catch (Exception e) {
             throw new HyracksDataException(e);
         }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ca3b9b28/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/ITreeIndexMetaDataFrame.java
----------------------------------------------------------------------
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 bdfa9e1..d4fbaa2 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
@@ -22,6 +22,11 @@ package org.apache.hyracks.storage.am.common.api;
 import org.apache.hyracks.storage.common.buffercache.ICachedPage;
 
 public interface ITreeIndexMetaDataFrame {
+
+    //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 void initBuffer(byte level);
 
     public void setPage(ICachedPage page);
@@ -63,6 +68,8 @@ public interface ITreeIndexMetaDataFrame {
 
     public void setLSN(long lsn);
 
+    public int getVersion();
+
     // Special placeholder for LSN information of a marker log. used for rollback information
     public long getLastMarkerLSN();
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ca3b9b28/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexDataflowHelper.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexDataflowHelper.java
b/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexDataflowHelper.java
index 7110e4b..2e45c7c 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexDataflowHelper.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexDataflowHelper.java
@@ -27,6 +27,7 @@ import org.apache.hyracks.api.io.FileReference;
 import org.apache.hyracks.storage.am.common.api.IIndex;
 import org.apache.hyracks.storage.am.common.api.IIndexDataflowHelper;
 import org.apache.hyracks.storage.am.common.api.IIndexLifecycleManager;
+import org.apache.hyracks.storage.am.common.frames.LIFOMetaDataFrame;
 import org.apache.hyracks.storage.am.common.util.IndexFileNameUtil;
 import org.apache.hyracks.storage.common.file.ILocalResourceFactory;
 import org.apache.hyracks.storage.common.file.ILocalResourceRepository;
@@ -93,7 +94,7 @@ public abstract class IndexDataflowHelper implements IIndexDataflowHelper
{
                 String resourceName = opDesc.getFileSplitProvider().getFileSplits()[partition].getLocalFile().getFile()
                         .getPath();
                 localResourceRepository.insert(localResourceFactory.createLocalResource(resourceID,
resourceName,
-                        resourcePartition, resourcePath));
+                        resourcePartition, LIFOMetaDataFrame.VERSION, resourcePath));
             } catch (IOException e) {
                 throw new HyracksDataException(e);
             }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ca3b9b28/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/frames/LIFOMetaDataFrame.java
----------------------------------------------------------------------
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 38b43c5..d4194c2 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
@@ -32,7 +32,8 @@ import org.apache.hyracks.storage.common.buffercache.ICachedPage;
 public class LIFOMetaDataFrame implements ITreeIndexMetaDataFrame {
 
     // Arbitrarily chosen magic integer.
-    protected static final int MAGIC_VALID_INT = 0x5bd1e995;
+    protected static final int OBSOLETE_MAGIC_VALID_INT = 0x5bd1e995;
+    protected static final int MAGIC_VALID_INT = 0x1B16DA7A;
 
     protected static final int TUPLE_COUNT_OFFSET = 0; //0
     protected static final int FREE_SPACE_OFFSET = TUPLE_COUNT_OFFSET + 4; //4
@@ -41,13 +42,14 @@ public class LIFOMetaDataFrame implements ITreeIndexMetaDataFrame {
     protected static final int NEXT_PAGE_OFFSET = LEVEL_OFFSET + 1; // 21
     protected static final int VALID_OFFSET = NEXT_PAGE_OFFSET + 4; // 25
 
-    // The additionalFilteringPageOff is used only for LSM indexes.
+    // The ADDITIONAL_FILTERING_PAGE_OFF is used only for LSM indexes.
     // We store the page id that will be used to store the information of the the filter
that is associated with a disk component.
     // It is only set in the first meta page other meta pages (i.e., with level -2) have
junk in the max page field.
     private static final int ADDITIONAL_FILTERING_PAGE_OFFSET = VALID_OFFSET + 4; // 29
     public static final int LSN_OFFSET = ADDITIONAL_FILTERING_PAGE_OFFSET + 4; // 33
     private static final int LAST_MARKER_LSN_OFFSET = LSN_OFFSET + 8; // 41
-    private static final int HEADER_END_OFFSET = LAST_MARKER_LSN_OFFSET + 8;
+    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
 
     protected ICachedPage page = null;
     protected ByteBuffer buf = null;
@@ -124,6 +126,7 @@ public class LIFOMetaDataFrame implements ITreeIndexMetaDataFrame {
         buf.putInt(NEXT_PAGE_OFFSET, -1);
         buf.putInt(ADDITIONAL_FILTERING_PAGE_OFFSET, -1);
         buf.putLong(LAST_MARKER_LSN_OFFSET, -1L);
+        buf.putInt(STORAGE_VERSION_OFFSET, VERSION);
         setValid(false);
     }
 
@@ -139,7 +142,7 @@ public class LIFOMetaDataFrame implements ITreeIndexMetaDataFrame {
 
     @Override
     public boolean isValid() {
-        return buf.getInt(VALID_OFFSET) == MAGIC_VALID_INT;
+        return buf.getInt(VALID_OFFSET) == MAGIC_VALID_INT || buf.getInt(VALID_OFFSET) ==
OBSOLETE_MAGIC_VALID_INT;
     }
 
     @Override
@@ -162,6 +165,15 @@ public class LIFOMetaDataFrame implements ITreeIndexMetaDataFrame {
     }
 
     @Override
+    public int getVersion() {
+        if (buf.getInt(VALID_OFFSET) == OBSOLETE_MAGIC_VALID_INT) {
+            return VERSION * -1;
+        } else {
+            return buf.getInt(STORAGE_VERSION_OFFSET);
+        }
+    }
+
+    @Override
     public long getLastMarkerLSN() {
         return buf.getLong(LAST_MARKER_LSN_OFFSET);
     }
@@ -180,4 +192,4 @@ public class LIFOMetaDataFrame implements ITreeIndexMetaDataFrame {
     public void setLSMComponentFilterPageId(int filterPage) {
         buf.putInt(ADDITIONAL_FILTERING_PAGE_OFFSET, filterPage);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ca3b9b28/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 4d56a80..fbb16b2 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
@@ -473,7 +473,7 @@ public class LinkedMetaDataPageManager implements IMetaDataPageManager
{
     public long getLSNOffset() throws HyracksDataException {
         int metadataPageNum = getFirstMetadataPage();
         if (metadataPageNum != IBufferCache.INVALID_PAGEID) {
-            return (metadataPageNum * (long) bufferCache.getPageSize()) + LIFOMetaDataFrame.LSN_OFFSET;
+            return ((long)metadataPageNum * bufferCache.getPageSize()) + LIFOMetaDataFrame.LSN_OFFSET;
         }
         return IMetaDataPageManager.INVALID_LSN_OFFSET;
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ca3b9b28/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMIndexFileManager.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMIndexFileManager.java
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMIndexFileManager.java
index c5fccdc..ed9cad0 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMIndexFileManager.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMIndexFileManager.java
@@ -50,6 +50,12 @@ public abstract class AbstractLSMIndexFileManager implements ILSMIndexFileManage
     protected static final String BLOOM_FILTER_STRING = "f";
     protected static final String TRANSACTION_PREFIX = ".T";
 
+    public enum TreeIndexState {
+        INVALID,
+        VERSION_MISMATCH,
+        VALID
+    }
+
     protected final IFileMapProvider fileMapProvider;
 
     // baseDir should reflect dataset name and partition name.
@@ -62,7 +68,7 @@ public abstract class AbstractLSMIndexFileManager implements ILSMIndexFileManage
     private String prevTimestamp = null;
 
     public AbstractLSMIndexFileManager(IFileMapProvider fileMapProvider, FileReference file,
-            TreeIndexFactory<? extends ITreeIndex> treeFactory) {
+                                       TreeIndexFactory<? extends ITreeIndex> treeFactory)
{
         this.baseDir = file.getFile().getPath();
         if (!baseDir.endsWith(System.getProperty("file.separator"))) {
             baseDir += System.getProperty("file.separator");
@@ -78,13 +84,13 @@ public abstract class AbstractLSMIndexFileManager implements ILSMIndexFileManage
         }
     };
 
-    protected boolean isValidTreeIndex(ITreeIndex treeIndex) throws HyracksDataException
{
+    protected TreeIndexState isValidTreeIndex(ITreeIndex treeIndex) throws HyracksDataException
{
         IBufferCache bufferCache = treeIndex.getBufferCache();
         treeIndex.activate();
         try {
             int metadataPage = treeIndex.getMetaManager().getFirstMetadataPage();
-            if(metadataPage <0 ){
-                return false;
+            if (metadataPage < 0) {
+                return TreeIndexState.INVALID;
             }
             ITreeIndexMetaDataFrame metadataFrame = treeIndex.getMetaManager().getMetaDataFrameFactory()
                     .createFrame();
@@ -93,7 +99,13 @@ public abstract class AbstractLSMIndexFileManager implements ILSMIndexFileManage
             page.acquireReadLatch();
             try {
                 metadataFrame.setPage(page);
-                return metadataFrame.isValid();
+                if (!metadataFrame.isValid()) {
+                    return TreeIndexState.INVALID;
+                } else if (metadataFrame.getVersion() != ITreeIndexMetaDataFrame.VERSION)
{
+                    return TreeIndexState.VERSION_MISMATCH;
+                } else {
+                    return TreeIndexState.VALID;
+                }
             } finally {
                 page.releaseReadLatch();
                 bufferCache.unpin(page);
@@ -104,24 +116,31 @@ public abstract class AbstractLSMIndexFileManager implements ILSMIndexFileManage
     }
 
     protected void cleanupAndGetValidFilesInternal(FilenameFilter filter,
-            TreeIndexFactory<? extends ITreeIndex> treeFactory, ArrayList<ComparableFileName>
allFiles)
-                    throws HyracksDataException, IndexException {
+                                                   TreeIndexFactory<? extends ITreeIndex>
treeFactory,
+                                                   ArrayList<ComparableFileName> allFiles)
+            throws HyracksDataException, IndexException {
         File dir = new File(baseDir);
         String[] files = dir.list(filter);
         for (String fileName : files) {
             File file = new File(dir.getPath() + File.separator + fileName);
             FileReference fileRef = new FileReference(file);
-            if (treeFactory == null || isValidTreeIndex(treeFactory.createIndexInstance(fileRef)))
{
+            if (treeFactory == null) {
                 allFiles.add(new ComparableFileName(fileRef));
-            } else {
+                continue;
+            }
+            TreeIndexState idxState = isValidTreeIndex(treeFactory.createIndexInstance(fileRef));
+            if (idxState == TreeIndexState.VALID) {
+                allFiles.add(new ComparableFileName(fileRef));
+            } else if (idxState == TreeIndexState.INVALID) {
                 file.delete();
             }
         }
     }
 
     protected void validateFiles(HashSet<String> groundTruth, ArrayList<ComparableFileName>
validFiles,
-            FilenameFilter filter, TreeIndexFactory<? extends ITreeIndex> treeFactory)
throws HyracksDataException,
-            IndexException {
+                                 FilenameFilter filter,
+                                 TreeIndexFactory<? extends ITreeIndex> treeFactory
+    ) throws HyracksDataException, IndexException {
         ArrayList<ComparableFileName> tmpAllInvListsFiles = new ArrayList<ComparableFileName>();
         cleanupAndGetValidFilesInternal(filter, treeFactory, tmpAllInvListsFiles);
         for (ComparableFileName cmpFileName : tmpAllInvListsFiles) {
@@ -413,7 +432,7 @@ public abstract class AbstractLSMIndexFileManager implements ILSMIndexFileManage
 
     /**
      * @return The string format of the current timestamp.
-     *         The returned results of this method are guaranteed to not have duplicates.
+     * The returned results of this method are guaranteed to not have duplicates.
      */
     protected String getCurrentTimestamp() {
         Date date = new Date();

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ca3b9b28/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/ILocalResourceFactory.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/ILocalResourceFactory.java
b/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/ILocalResourceFactory.java
index f5e7010..1b8d617 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/ILocalResourceFactory.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/ILocalResourceFactory.java
@@ -19,5 +19,6 @@
 package org.apache.hyracks.storage.common.file;
 
 public interface ILocalResourceFactory {
-    public LocalResource createLocalResource(long resourceId, String resourceName, int partition,
String resourcePath);
+    public LocalResource createLocalResource(long resourceId, String resourceName, int partition,
int storageVersion,
+            String resourcePath);
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ca3b9b28/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/LocalResource.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/LocalResource.java
b/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/LocalResource.java
index eba0119..ef69664 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/LocalResource.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/LocalResource.java
@@ -21,13 +21,14 @@ package org.apache.hyracks.storage.common.file;
 import java.io.Serializable;
 
 public class LocalResource implements Serializable {
-    private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 2L;
     private final long resourceId;
     private final String resourceName;
     private final int partition;
     private final int resourceType;
     private final Object object;
     private String resourcePath;
+    private int storageVersion;
 
     public static final int TransientResource = 0;
     public static final int LSMBTreeResource = 1;
@@ -38,13 +39,14 @@ public class LocalResource implements Serializable {
     public static final int ExternalBTreeWithBuddyResource = 6;
 
     public LocalResource(long resourceId, String resourceName, int partition, String resourcePath,
int resourceType,
-            Object object) {
+            int storageVersion, Object object) {
         this.resourceId = resourceId;
         this.resourceName = resourceName;
         this.partition = partition;
         this.resourcePath = resourcePath;
         this.resourceType = resourceType;
         this.object = object;
+        this.storageVersion = storageVersion;
     }
 
     public long getResourceId() {
@@ -71,6 +73,10 @@ public class LocalResource implements Serializable {
         return resourcePath;
     }
 
+    public int getVersion() {
+        return storageVersion;
+    }
+
     public void setResourcePath(String resourcePath) {
         this.resourcePath = resourcePath;
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ca3b9b28/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/TransientLocalResourceFactory.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/TransientLocalResourceFactory.java
b/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/TransientLocalResourceFactory.java
index 527f55e..4ace129 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/TransientLocalResourceFactory.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/TransientLocalResourceFactory.java
@@ -21,7 +21,9 @@ package org.apache.hyracks.storage.common.file;
 public class TransientLocalResourceFactory implements ILocalResourceFactory {
 
     @Override
-    public LocalResource createLocalResource(long resourceId, String resourceName, int partition,
String resourcePath) {
-        return new LocalResource(resourceId, resourceName, partition, resourcePath, LocalResource.TransientResource,
null);
+    public LocalResource createLocalResource(long resourceId, String resourceName, int partition,
int storageVersion,
+            String resourcePath) {
+        return new LocalResource(resourceId, resourceName, partition, resourcePath, LocalResource.TransientResource,
+                storageVersion, null);
     }
 }


Mime
View raw message