Uploaded image for project: 'Terrier Core'
  1. Terrier Core
  2. TR-105

Index should check version number, as it cant open older indices.

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.0
    • Fix Version/s: 3.5
    • Component/s: .structures
    • Labels:
      None

      Description

      Some people might still try to open existing indices, despite warnings in the documentation. Throw an error if the index is too old to open.

        Attachments

          Activity

          Hide
          craigm Craig Macdonald added a comment -

          Here is the patch:

          Index: src/core/org/terrier/structures/Index.java
          ===================================================================
          --- src/core/org/terrier/structures/Index.java	(revision 2991)
          +++ src/core/org/terrier/structures/Index.java	(working copy)
          @@ -60,6 +60,7 @@
           */
           public class Index implements Closeable, Flushable
           {
          +	protected final static int MINIMUM_INDEX_TERRIER_VERSION = 3;
           	protected final static String PROPERTIES_SUFFIX = ".properties";
           	protected static boolean RETRIEVAL_LOADING_PROFILE = Boolean.parseBoolean(ApplicationSetup.getProperty("terrier.index.retrievalLoadingProfile.default", "true"));
           	
          @@ -272,6 +273,19 @@
           			loadError = "Problem loading index properties: "+ ioe;
           			return false;
           		}
          +		if (properties.getProperty("index.terrier.version", null) == null)
          +		{
          +			logger.error("index.terrier.version not set in index, invalid index?");
          +			loadError = "index.terrier.version not set in index";
          +			return false;
          +		}
          +		final String versionString = properties.getProperty("index.terrier.version", null);
          +		final String[] versionStringParts = versionString.split("\\.");
          +		if (Integer.parseInt(versionStringParts[0]) < MINIMUM_INDEX_TERRIER_VERSION)
          +		{
          +			logger.error(loadError = "This index is too old. Need at least version "+MINIMUM_INDEX_TERRIER_VERSION +" index");
          +			return false;
          +		}
           		return true;
           	}
           
          
          Show
          craigm Craig Macdonald added a comment - Here is the patch: Index: src/core/org/terrier/structures/Index.java =================================================================== --- src/core/org/terrier/structures/Index.java (revision 2991) +++ src/core/org/terrier/structures/Index.java (working copy) @@ -60,6 +60,7 @@ */ public class Index implements Closeable, Flushable { + protected final static int MINIMUM_INDEX_TERRIER_VERSION = 3; protected final static String PROPERTIES_SUFFIX = ".properties" ; protected static boolean RETRIEVAL_LOADING_PROFILE = Boolean .parseBoolean(ApplicationSetup.getProperty( "terrier.index.retrievalLoadingProfile. default " , " true " )); @@ -272,6 +273,19 @@ loadError = "Problem loading index properties: " + ioe; return false ; } + if (properties.getProperty( "index.terrier.version" , null ) == null ) + { + logger.error( "index.terrier.version not set in index, invalid index?" ); + loadError = "index.terrier.version not set in index" ; + return false ; + } + final String versionString = properties.getProperty( "index.terrier.version" , null ); + final String [] versionStringParts = versionString.split( "\\." ); + if ( Integer .parseInt(versionStringParts[0]) < MINIMUM_INDEX_TERRIER_VERSION) + { + logger.error(loadError = "This index is too old. Need at least version " +MINIMUM_INDEX_TERRIER_VERSION + " index" ); + return false ; + } return true ; }
          Hide
          craigm Craig Macdonald added a comment - - edited

          Updated patch. This applies and works cleanly for Terrier 3.0:

          Index: src/core/org/terrier/structures/Index.java
          ===================================================================
          --- src/core/org/terrier/structures/Index.java	(revision 2991)
          +++ src/core/org/terrier/structures/Index.java	(working copy)
          @@ -60,6 +60,7 @@
           */
           public class Index implements Closeable, Flushable
           {
          +	protected final static int MINIMUM_INDEX_TERRIER_VERSION = 3;
           	protected final static String PROPERTIES_SUFFIX = ".properties";
           	protected static boolean RETRIEVAL_LOADING_PROFILE = Boolean.parseBoolean(ApplicationSetup.getProperty("terrier.index.retrievalLoadingProfile.default", "true"));
           	
          @@ -173,7 +174,7 @@
           			dirtyProperties = true;
           			loadSuccess = true;	
           		}
          -		else
          +		else if (indexExists)
           		{
           			logger.debug("Loading existing index : " + this.toString());
           			//note the order - some structures will require collection statistics, so load this first.
          @@ -268,10 +269,26 @@
           			}
           			
           		} catch (IOException ioe) {
          +			loadSuccess = false;
           			logger.error("Problem loading index properties", ioe);
           			loadError = "Problem loading index properties: "+ ioe;
           			return false;
           		}
          +		if (properties.getProperty("index.terrier.version", null) == null)
          +		{
          +			loadSuccess = false;
          +			logger.error("index.terrier.version not set in index, invalid index?");
          +			loadError = "index.terrier.version not set in index";
          +			return false;
          +		}
          +		final String versionString = properties.getProperty("index.terrier.version", null);
          +		final String[] versionStringParts = versionString.split("\\.");
          +		if (Integer.parseInt(versionStringParts[0]) < MINIMUM_INDEX_TERRIER_VERSION)
          +		{
          +			loadSuccess = false;
          +			logger.error(loadError = "This index is too old. Need at least version "+MINIMUM_INDEX_TERRIER_VERSION +" index");
          +			return false;
          +		}
           		return true;
           	}
           
          
          
          
          Show
          craigm Craig Macdonald added a comment - - edited Updated patch. This applies and works cleanly for Terrier 3.0: Index: src/core/org/terrier/structures/Index.java =================================================================== --- src/core/org/terrier/structures/Index.java (revision 2991) +++ src/core/org/terrier/structures/Index.java (working copy) @@ -60,6 +60,7 @@ */ public class Index implements Closeable, Flushable { + protected final static int MINIMUM_INDEX_TERRIER_VERSION = 3; protected final static String PROPERTIES_SUFFIX = ".properties" ; protected static boolean RETRIEVAL_LOADING_PROFILE = Boolean .parseBoolean(ApplicationSetup.getProperty( "terrier.index.retrievalLoadingProfile. default " , " true " )); @@ -173,7 +174,7 @@ dirtyProperties = true ; loadSuccess = true ; } - else + else if (indexExists) { logger.debug( "Loading existing index : " + this .toString()); //note the order - some structures will require collection statistics, so load this first. @@ -268,10 +269,26 @@ } } catch (IOException ioe) { + loadSuccess = false ; logger.error( "Problem loading index properties" , ioe); loadError = "Problem loading index properties: " + ioe; return false ; } + if (properties.getProperty( "index.terrier.version" , null ) == null ) + { + loadSuccess = false ; + logger.error( "index.terrier.version not set in index, invalid index?" ); + loadError = "index.terrier.version not set in index" ; + return false ; + } + final String versionString = properties.getProperty( "index.terrier.version" , null ); + final String [] versionStringParts = versionString.split( "\\." ); + if ( Integer .parseInt(versionStringParts[0]) < MINIMUM_INDEX_TERRIER_VERSION) + { + loadSuccess = false ; + logger.error(loadError = "This index is too old. Need at least version " +MINIMUM_INDEX_TERRIER_VERSION + " index" ); + return false ; + } return true ; }
          Hide
          craigm Craig Macdonald added a comment -

          Committed to trunk.

          Show
          craigm Craig Macdonald added a comment - Committed to trunk.

            People

            • Assignee:
              craigm Craig Macdonald
              Reporter:
              craigm Craig Macdonald
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: