Automatically regenerate indexer for incompatible versions (#2524)

tokarchuk/v1.17
Ethan Koenig 7 years ago committed by Lauris BH
parent 28f4de205f
commit ccff57103a
  1. 37
      modules/indexer/issue.go

@ -15,6 +15,7 @@ import (
"github.com/blevesearch/bleve/analysis/token/lowercase" "github.com/blevesearch/bleve/analysis/token/lowercase"
"github.com/blevesearch/bleve/analysis/token/unicodenorm" "github.com/blevesearch/bleve/analysis/token/unicodenorm"
"github.com/blevesearch/bleve/analysis/tokenizer/unicode" "github.com/blevesearch/bleve/analysis/tokenizer/unicode"
"github.com/blevesearch/bleve/index/upsidedown"
) )
// issueIndexer (thread-safe) index for searching issues // issueIndexer (thread-safe) index for searching issues
@ -39,27 +40,25 @@ const issueIndexerAnalyzer = "issueIndexer"
// InitIssueIndexer initialize issue indexer // InitIssueIndexer initialize issue indexer
func InitIssueIndexer(populateIndexer func() error) { func InitIssueIndexer(populateIndexer func() error) {
_, err := os.Stat(setting.Indexer.IssuePath) _, err := os.Stat(setting.Indexer.IssuePath)
if err != nil { if err != nil && !os.IsNotExist(err) {
if os.IsNotExist(err) { log.Fatal(4, "InitIssueIndexer: %v", err)
if err = createIssueIndexer(); err != nil { } else if 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 {
issueIndexer, err = bleve.Open(setting.Indexer.IssuePath) issueIndexer, err = bleve.Open(setting.Indexer.IssuePath)
if err != nil { if err == nil {
log.Error(4, "Unable to open issues indexer (%s)."+ return
" If the error is due to incompatible versions, try deleting the indexer files;"+ } else if err != upsidedown.IncompatibleVersion {
" gitea will recreate them with the appropriate version the next time it runs."+ log.Fatal(4, "InitIssueIndexer, open index: %v", err)
" Deleting the indexer files will not result in loss of data.",
setting.Indexer.IssuePath)
log.Fatal(4, "InitIssuesIndexer, 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)
} }
} }

Loading…
Cancel
Save