[TR-105] Index should check version number, as it cant open older indices. Created: 12/Mar/10  Updated: 06/May/10  Resolved: 06/May/10

Status: Resolved
Project: Terrier Core
Component/s: .structures
Affects Version/s: 3.0
Fix Version/s: 3.5

Type: Improvement Priority: Major
Reporter: Craig Macdonald Assignee: Craig Macdonald
Resolution: Fixed  
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.

 Comments   
Comment by Craig Macdonald [ 12/Mar/10 ]

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;
 	}
 
Comment by Craig Macdonald [ 12/Mar/10 ]

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;
 	}
 


Comment by Craig Macdonald [ 06/May/10 ]

Committed to trunk.

Generated at Wed Dec 13 08:52:27 GMT 2017 using JIRA 7.1.1#71004-sha1:d6b2c0d9b7051e9fb5e4eb8ce177ca56d91d7bd8.