summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorEthan Koenig <ethantkoenig@gmail.com>2017-09-22 14:30:56 -0700
committerLauris BH <lauris@nix.lv>2017-09-23 00:30:56 +0300
commitccff57103ae250ad8187926e3740f28c1e23a815 (patch)
treebe05be74d43fb1e7ade49a48a09cef7281b86fae /modules
parent28f4de205fbeb8eede27ed7ede00305cd32332d0 (diff)
downloadgitea-ccff57103ae250ad8187926e3740f28c1e23a815.tar.gz
gitea-ccff57103ae250ad8187926e3740f28c1e23a815.zip
Automatically regenerate indexer for incompatible versions (#2524)
Diffstat (limited to 'modules')
-rw-r--r--modules/indexer/issue.go37
1 files changed, 18 insertions, 19 deletions
diff --git a/modules/indexer/issue.go b/modules/indexer/issue.go
index 2503a78825..050a623ce2 100644
--- a/modules/indexer/issue.go
+++ b/modules/indexer/issue.go
@@ -15,6 +15,7 @@ import (
"github.com/blevesearch/bleve/analysis/token/lowercase"
"github.com/blevesearch/bleve/analysis/token/unicodenorm"
"github.com/blevesearch/bleve/analysis/tokenizer/unicode"
+ "github.com/blevesearch/bleve/index/upsidedown"
)
// issueIndexer (thread-safe) index for searching issues
@@ -39,27 +40,25 @@ const issueIndexerAnalyzer = "issueIndexer"
// InitIssueIndexer initialize issue indexer
func InitIssueIndexer(populateIndexer func() error) {
_, err := os.Stat(setting.Indexer.IssuePath)
- if err != nil {
- if os.IsNotExist(err) {
- if err = createIssueIndexer(); err != nil {
- log.Fatal(4, "CreateIssuesIndexer: %v", err)
- }
- if err = populateIndexer(); err != nil {
- log.Fatal(4, "PopulateIssuesIndex: %v", err)
- }
- } else {
- log.Fatal(4, "InitIssuesIndexer: %v", err)
- }
- } else {
+ if err != nil && !os.IsNotExist(err) {
+ log.Fatal(4, "InitIssueIndexer: %v", err)
+ } else if err == nil {
issueIndexer, err = bleve.Open(setting.Indexer.IssuePath)
- if err != nil {
- log.Error(4, "Unable to open issues indexer (%s)."+
- " If the error is due to incompatible versions, try deleting the indexer files;"+
- " gitea will recreate them with the appropriate version the next time it runs."+
- " Deleting the indexer files will not result in loss of data.",
- setting.Indexer.IssuePath)
- log.Fatal(4, "InitIssuesIndexer, open index: %v", err)
+ if err == nil {
+ return
+ } else if err != upsidedown.IncompatibleVersion {
+ log.Fatal(4, "InitIssueIndexer, open index: %v", err)
}
+ log.Warn("Incompatible bleve version, deleting and recreating issue indexer")
+ if err = os.RemoveAll(setting.Indexer.IssuePath); err != nil {
+ log.Fatal(4, "InitIssueIndexer: remove index, %v", err)
+ }
+ }
+ if err = createIssueIndexer(); err != nil {
+ log.Fatal(4, "InitIssuesIndexer: create index, %v", err)
+ }
+ if err = populateIndexer(); err != nil {
+ log.Fatal(4, "InitIssueIndexer: populate index, %v", err)
}
}