Revision: 17471
http://sourceforge.net/p/gate/code/17471
Author: valyt
Date: 2014-02-27 14:48:17 +0000 (Thu, 27 Feb 2014)
Log Message:
-----------
Added support for converting old indexes to new 5.0 format from the admin UI.
It's not exactly pretty, but it works.
Modified Paths:
--------------
mimir/branches/5.0/mimir-cloud/.classpath
mimir/branches/5.0/mimir-core/src/gate/mimir/IndexConfig.java
mimir/branches/5.0/mimir-core/src/gate/mimir/MimirIndex.java
mimir/branches/5.0/mimir-core/src/gate/mimir/util/IndexUpgrader.java
mimir/branches/5.0/mimir-web/grails-app/controllers/gate/mimir/web/LocalIndexController.groovy
mimir/branches/5.0/mimir-web/grails-app/services/gate/mimir/web/LocalIndexService.groovy
mimir/branches/5.0/mimir-web/grails-app/views/localIndex/show.gsp
Modified: mimir/branches/5.0/mimir-cloud/.classpath
===================================================================
--- mimir/branches/5.0/mimir-cloud/.classpath 2014-02-27 14:36:20 UTC (rev
17470)
+++ mimir/branches/5.0/mimir-cloud/.classpath 2014-02-27 14:48:17 UTC (rev
17471)
@@ -147,16 +147,6 @@
<attribute
name="org.grails.ide.eclipse.core.SOURCE_FOLDER" value="true"/>
</attributes>
</classpathentry>
- <classpathentry
excluding="BuildConfig.groovy|*DataSource.groovy|UrlMappings.groovy|Config.groovy|BootStrap.groovy|spring/resources.groovy"
kind="src" path=".link_to_grails_plugins/webxml-1.4.1/grails-app/conf">
- <attributes>
- <attribute
name="org.grails.ide.eclipse.core.SOURCE_FOLDER" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="src"
path=".link_to_grails_plugins/webxml-1.4.1/src/groovy">
- <attributes>
- <attribute
name="org.grails.ide.eclipse.core.SOURCE_FOLDER" value="true"/>
- </attributes>
- </classpathentry>
<classpathentry exported="true" kind="src" path="/mimir-web">
<attributes>
<attribute
name="org.grails.ide.eclipse.core.SOURCE_FOLDER" value="true"/>
Modified: mimir/branches/5.0/mimir-core/src/gate/mimir/IndexConfig.java
===================================================================
--- mimir/branches/5.0/mimir-core/src/gate/mimir/IndexConfig.java
2014-02-27 14:36:20 UTC (rev 17470)
+++ mimir/branches/5.0/mimir-core/src/gate/mimir/IndexConfig.java
2014-02-27 14:48:17 UTC (rev 17471)
@@ -215,7 +215,7 @@
* <dt>7</dt><dd>MÃmir 5.0 live index.</dt>
* </dl>
*/
- private static final int FORMAT_VERSION = 7;
+ public static final int FORMAT_VERSION = 7;
/**
* The default feature name for obtaining document URIs (provided as features
Modified: mimir/branches/5.0/mimir-core/src/gate/mimir/MimirIndex.java
===================================================================
--- mimir/branches/5.0/mimir-core/src/gate/mimir/MimirIndex.java
2014-02-27 14:36:20 UTC (rev 17470)
+++ mimir/branches/5.0/mimir-core/src/gate/mimir/MimirIndex.java
2014-02-27 14:48:17 UTC (rev 17471)
@@ -490,6 +490,10 @@
this.indexConfig = IndexConfig.readConfigFromFile(indexConfigFile,
indexDirectory);
this.indexDirectory = this.indexConfig.getIndexDirectory();
+ if(indexConfig.getFormatVersion() < 7){
+ throw new IndexException("The index at " + indexDirectory +
+ " uses too old a format and cannot be opened.");
+ }
openIndex();
}
Modified: mimir/branches/5.0/mimir-core/src/gate/mimir/util/IndexUpgrader.java
===================================================================
--- mimir/branches/5.0/mimir-core/src/gate/mimir/util/IndexUpgrader.java
2014-02-27 14:36:20 UTC (rev 17470)
+++ mimir/branches/5.0/mimir-core/src/gate/mimir/util/IndexUpgrader.java
2014-02-27 14:48:17 UTC (rev 17471)
@@ -60,10 +60,11 @@
DiskBasedIndex.OFFSETS_EXTENSION
};
- public void upgradeIndex(File indexDirectory) throws IOException,
+ public static void upgradeIndex(File indexDirectory) throws IOException,
IndexException {
- IndexConfig indexConfig = IndexConfig.readConfigFromFile( new File(
- indexDirectory, MimirIndex.INDEX_CONFIG_FILENAME));
+ File indexConfigFile = new File(indexDirectory,
+ MimirIndex.INDEX_CONFIG_FILENAME);
+ IndexConfig indexConfig = IndexConfig.readConfigFromFile(indexConfigFile);
//test the version
if(indexConfig.getFormatVersion() > 6 || indexConfig.getFormatVersion() <
4){
throw new IndexException(
@@ -163,6 +164,9 @@
" even though it appears empty.");
}
}
+ //update the version number in the index config
+ indexConfig.setFormatVersion(IndexConfig.FORMAT_VERSION);
+ IndexConfig.writeConfigToFile(indexConfig, indexConfigFile);
}
/**
@@ -176,7 +180,7 @@
* @throws IndexException
* @throws IOException
*/
- protected void upgradeSubIndex(File indexDirectory, int subIndexIdx,
+ protected static void upgradeSubIndex(File indexDirectory, int subIndexIdx,
final boolean direct, SemanticIndexerConfig mentionsConfig) throws
IndexException, IOException {
File sourceDir = new File(indexDirectory, "mg4j");
// sanity checks
Modified:
mimir/branches/5.0/mimir-web/grails-app/controllers/gate/mimir/web/LocalIndexController.groovy
===================================================================
---
mimir/branches/5.0/mimir-web/grails-app/controllers/gate/mimir/web/LocalIndexController.groovy
2014-02-27 14:36:20 UTC (rev 17470)
+++
mimir/branches/5.0/mimir-web/grails-app/controllers/gate/mimir/web/LocalIndexController.groovy
2014-02-27 14:48:17 UTC (rev 17471)
@@ -43,11 +43,34 @@
flash.message = "LocalIndex not found with id ${params.id}"
redirect(controller:'indexManagement', action:'home')
}
- else { return [ localIndexInstance : localIndexInstance,
- indexedDocs:
localIndexService.getIndex(localIndexInstance)?.getIndexedDocumentsCount() ]
+ else {
+
+ return [
+ localIndexInstance : localIndexInstance,
+ indexedDocs:
localIndexService.getIndex(localIndexInstance)?.getIndexedDocumentsCount(),
+ oldVersion: localIndexService.isOldVersion(localIndexInstance)]
}
}
+
+ def upgradeFormat = {
+ def localIndexInstance = LocalIndex.get( params.id )
+ if(!localIndexInstance) {
+ flash.message = "LocalIndex not found with id ${params.id}"
+ redirect(controller:'indexManagement', action:'home')
+ } else {
+ try{
+ localIndexService.upgradeIndex(localIndexInstance)
+ flash.message = "Index converted"
+ } catch (Exception e) {
+ log.error(e)
+ flash.message = "There was an error while trying to convert the index."
+ }
+ redirect(action:'show', params:[id:localIndexInstance.id])
+ }
+ }
+
+
def deleteBin = {
def indexInstance = Index.findByIndexId(params.indexId)
localIndexService.deleteIndex(indexInstance,params.deleteFiles)
Modified:
mimir/branches/5.0/mimir-web/grails-app/services/gate/mimir/web/LocalIndexService.groovy
===================================================================
---
mimir/branches/5.0/mimir-web/grails-app/services/gate/mimir/web/LocalIndexService.groovy
2014-02-27 14:36:20 UTC (rev 17470)
+++
mimir/branches/5.0/mimir-web/grails-app/services/gate/mimir/web/LocalIndexService.groovy
2014-02-27 14:48:17 UTC (rev 17471)
@@ -14,6 +14,7 @@
*/
package gate.mimir.web;
+import java.io.File;
import java.util.concurrent.Callable;
import gate.mimir.web.Index;
@@ -128,8 +129,32 @@
public synchronized void undeleteDocuments(LocalIndex index,
Collection<Long> documentIds) {
getIndex(index).getQueryEngine().getIndex().undeleteDocuments(documentIds)
}
-
+ /**
+ * Checks if this local index is using an old on-disk format
+ * @param index the index to test
+ * @return
+ */
+ public boolean isOldVersion(LocalIndex index) {
+ File indexDirectory = new File(index.indexDirectory)
+ File indexConfigFile = new File(indexDirectory,
+ MimirIndex.INDEX_CONFIG_FILENAME);
+ IndexConfig indexConfig = IndexConfig.readConfigFromFile(indexConfigFile);
+ return indexConfig.getFormatVersion() < IndexConfig.FORMAT_VERSION
+ }
+
+
+ public void upgradeIndex(LocalIndex index) {
+ // unload if it was loaded
+ if(index) {
+ close(index)
+ IndexUpgrader.upgradeIndex(new File(index.indexDirectory))
+ // and re-open it
+ index.state = Index.READY
+ index.save(flush:true)
+ }
+ }
+
public synchronized MimirIndex getIndex (LocalIndex index){
MimirIndex mIndex = indexes[index.id]
QueryEngine engine = null
Modified: mimir/branches/5.0/mimir-web/grails-app/views/localIndex/show.gsp
===================================================================
--- mimir/branches/5.0/mimir-web/grails-app/views/localIndex/show.gsp
2014-02-27 14:36:20 UTC (rev 17470)
+++ mimir/branches/5.0/mimir-web/grails-app/views/localIndex/show.gsp
2014-02-27 14:48:17 UTC (rev 17471)
@@ -66,6 +66,17 @@
</td>
</tr>
+ <g:if test="${oldVersion}">
+ <tr class="prop">
+ <td><strong>Old format:</strong></td>
+ <td>This index has been produced with an older version of
+ Mímir and cannot be opened.<br>
+ <g:link controller="localIndex" action="upgradeFormat"
+ id="${localIndexInstance?.id}">Convert it to the current
format</g:link>
+ </td>
+ </tr>
+ </g:if>
+
<tr class="prop">
<td valign="top" class="name">Indexed documents count:</td>
<td valign="top" class="value">${indexedDocs}</td>
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs