summaryrefslogtreecommitdiffstats
path: root/modules/indexer/code/repo.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/indexer/code/repo.go')
-rw-r--r--modules/indexer/code/repo.go35
1 files changed, 34 insertions, 1 deletions
diff --git a/modules/indexer/code/repo.go b/modules/indexer/code/repo.go
index 31f0fa7f3d..bc5f317b7d 100644
--- a/modules/indexer/code/repo.go
+++ b/modules/indexer/code/repo.go
@@ -5,9 +5,13 @@
package code
import (
+ "context"
+ "os"
"strings"
"sync"
+ "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -104,21 +108,50 @@ func (update RepoIndexerUpdate) AddToFlushingBatch(batch rupture.FlushingBatch)
func initRepoIndexer(populateIndexer func() error) {
indexer, err := openIndexer(setting.Indexer.RepoPath, repoIndexerLatestVersion)
if err != nil {
- log.Fatal("InitRepoIndexer: %v", err)
+ log.Fatal("InitRepoIndexer %s: %v", setting.Indexer.RepoPath, err)
}
if indexer != nil {
indexerHolder.set(indexer)
+ closeAtTerminate()
+
+ // Continue population from where left off
+ if err = populateIndexer(); err != nil {
+ log.Fatal("PopulateRepoIndex: %v", err)
+ }
return
}
if err = createRepoIndexer(setting.Indexer.RepoPath, repoIndexerLatestVersion); err != nil {
log.Fatal("CreateRepoIndexer: %v", err)
}
+ closeAtTerminate()
+
+ // if there is any existing repo indexer metadata in the DB, delete it
+ // since we are starting afresh. Also, xorm requires deletes to have a
+ // condition, and we want to delete everything, thus 1=1.
+ if err := models.DeleteAllRecords("repo_indexer_status"); err != nil {
+ log.Fatal("DeleteAllRepoIndexerStatus: %v", err)
+ }
+
if err = populateIndexer(); err != nil {
log.Fatal("PopulateRepoIndex: %v", err)
}
}
+func closeAtTerminate() {
+ graceful.GetManager().RunAtTerminate(context.Background(), func() {
+ log.Debug("Closing repo indexer")
+ indexer := indexerHolder.get()
+ if indexer != nil {
+ err := indexer.Close()
+ if err != nil {
+ log.Error("Error whilst closing the repository indexer: %v", err)
+ }
+ }
+ log.Info("PID: %d Repository Indexer closed", os.Getpid())
+ })
+}
+
// createRepoIndexer create a repo indexer if one does not already exist
func createRepoIndexer(path string, latestVersion int) error {
docMapping := bleve.NewDocumentMapping()