diff options
author | Florian Zschocke <florian.zschocke@devolo.de> | 2017-03-05 16:45:44 +0100 |
---|---|---|
committer | Florian Zschocke <florian.zschocke@devolo.de> | 2017-03-05 20:27:31 +0100 |
commit | 71a27ddc781e0c2a684f747c794f8948c65cbf5c (patch) | |
tree | e5f45ec86b5256708a3ce459cf93856a3e246a22 /src/main/java/com/gitblit/tickets | |
parent | bf1b35aac29b6c0d5e918f00d99a0632e4925b51 (diff) | |
download | gitblit-71a27ddc781e0c2a684f747c794f8948c65cbf5c.tar.gz gitblit-71a27ddc781e0c2a684f747c794f8948c65cbf5c.zip |
Introduce an index version for the ticket index
In order to be able to update the index definition, the ticket index
is assigned a version number, 2. This way the definiton can be updated
and compatability with existing index files can be checked.
The actual index is stored in a directory of name `indexVersion_codecVersion`.
This wayit is veriy easy to check if an index of a certain version exists on the
filesystem. It allows to have multiple indexes of different versions present,
so that a downgrade of the software is possible without having to reindex
again. Of coure, this is only possible if no new tickets were created since these
would be missing in the old index.
A new class `LuceneIndexStore` is introduced, which abstracts away the versioned
index directory. The idea is, that this provides one place to keep the Lucene
codec version and to allow to code compatibility rules into this class, so that
older indices can still be used if they are compatible.
Diffstat (limited to 'src/main/java/com/gitblit/tickets')
-rw-r--r-- | src/main/java/com/gitblit/tickets/TicketIndexer.java | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/main/java/com/gitblit/tickets/TicketIndexer.java b/src/main/java/com/gitblit/tickets/TicketIndexer.java index 8aab74ba..bc08fc88 100644 --- a/src/main/java/com/gitblit/tickets/TicketIndexer.java +++ b/src/main/java/com/gitblit/tickets/TicketIndexer.java @@ -62,7 +62,7 @@ import com.gitblit.models.TicketModel; import com.gitblit.models.TicketModel.Attachment; import com.gitblit.models.TicketModel.Patchset; import com.gitblit.models.TicketModel.Status; -import com.gitblit.utils.FileUtils; +import com.gitblit.utils.LuceneIndexStore; import com.gitblit.utils.StringUtils; /** @@ -110,6 +110,8 @@ public class TicketIndexer { priority(Type.INT), severity(Type.INT); + final static int INDEX_VERSION = 2; + final Type fieldType; Lucene(Type fieldType) { @@ -169,14 +171,15 @@ public class TicketIndexer { private final Logger log = LoggerFactory.getLogger(getClass()); - private final File luceneDir; + private final LuceneIndexStore indexStore; private IndexWriter writer; private IndexSearcher searcher; public TicketIndexer(IRuntimeManager runtimeManager) { - this.luceneDir = runtimeManager.getFileOrFolder(Keys.tickets.indexFolder, "${baseFolder}/tickets/lucene"); + File luceneDir = runtimeManager.getFileOrFolder(Keys.tickets.indexFolder, "${baseFolder}/tickets/lucene"); + this.indexStore = new LuceneIndexStore(luceneDir, Lucene.INDEX_VERSION); } /** @@ -192,7 +195,7 @@ public class TicketIndexer { */ public void deleteAll() { close(); - FileUtils.delete(luceneDir); + indexStore.delete(); } /** @@ -441,12 +444,9 @@ public class TicketIndexer { private IndexWriter getWriter() throws IOException { if (writer == null) { - Directory directory = FSDirectory.open(luceneDir.toPath()); - - if (!luceneDir.exists()) { - luceneDir.mkdirs(); - } + indexStore.create(); + Directory directory = FSDirectory.open(indexStore.getPath()); StandardAnalyzer analyzer = new StandardAnalyzer(); IndexWriterConfig config = new IndexWriterConfig(analyzer); config.setOpenMode(OpenMode.CREATE_OR_APPEND); |