First cut

This commit is contained in:
Eugene Livis 2021-01-24 09:34:04 -05:00
parent 8b103706ef
commit 17bcd8c133
2 changed files with 28 additions and 1 deletions

View File

@ -37,6 +37,7 @@ class IndexFinder {
private static final String KWS_DATA_FOLDER_NAME = "data"; private static final String KWS_DATA_FOLDER_NAME = "data";
private static final String INDEX_FOLDER_NAME = "index"; private static final String INDEX_FOLDER_NAME = "index";
private static final String CURRENT_SOLR_VERSION = "8"; private static final String CURRENT_SOLR_VERSION = "8";
private static final int CURRENT_SOLR_VERSION_INT = 8;
private static final String CURRENT_SOLR_SCHEMA_VERSION = "2.3"; private static final String CURRENT_SOLR_SCHEMA_VERSION = "2.3";
static String getCurrentSolrVersion() { static String getCurrentSolrVersion() {
@ -79,7 +80,11 @@ class IndexFinder {
Index bestCandidateIndex = null; Index bestCandidateIndex = null;
double solrVerFound = 0.0; double solrVerFound = 0.0;
double schemaVerFound = 0.0; double schemaVerFound = 0.0;
for (Index index : allIndexes) { for (Index index : allIndexes) {
if (NumberUtils.toDouble(index.getSolrVersion()) > CURRENT_SOLR_VERSION_INT) {
// "legacy" Solr server cannot open "future" versions of Solr indexes
continue;
}
// higher Solr version takes priority because it may negate index upgrade // higher Solr version takes priority because it may negate index upgrade
if (NumberUtils.toDouble(index.getSolrVersion()) >= solrVerFound) { if (NumberUtils.toDouble(index.getSolrVersion()) >= solrVerFound) {
// if same solr version, pick the one with highest schema version // if same solr version, pick the one with highest schema version
@ -92,4 +97,23 @@ class IndexFinder {
} }
return bestCandidateIndex; return bestCandidateIndex;
} }
/**
* Checks if a the list of indexes contains an index from a "future" version
* of Solr. This happens when a "legacy" version of Autopsy attempts to open
* a Solr index created by Autopsy that uses later version of Solr.
*
* @param allIndexes List of Index objects
*
* @return True if later version of index is present, false othewise
*/
static boolean isFutureIndexPresent(List<Index> allIndexes) {
for (Index index : allIndexes) {
if (NumberUtils.toDouble(index.getSolrVersion()) > CURRENT_SOLR_VERSION_INT) {
// "legacy" Solr server cannot open "future" versions of Solr indexes
return true;
}
}
return false;
}
} }

View File

@ -321,6 +321,9 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService {
Index indexToUse = IndexFinder.identifyIndexToUse(indexes); Index indexToUse = IndexFinder.identifyIndexToUse(indexes);
if (indexToUse == null) { if (indexToUse == null) {
// unable to find index that can be used // unable to find index that can be used
if (IndexFinder.isFutureIndexPresent(indexes)) {
throw new AutopsyServiceException("The text index is from a 'future' version of Solr");
}
throw new AutopsyServiceException("Unable to find index that can be used for this case"); throw new AutopsyServiceException("Unable to find index that can be used for this case");
} }