Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support rebuilding issue indexer manually #26546

Merged
merged 5 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions modules/indexer/issues/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package issues

import (
"context"
"fmt"
"os"
"runtime/pprof"
"sync/atomic"
Expand Down Expand Up @@ -202,11 +203,16 @@ func getIssueIndexerQueueHandler(ctx context.Context) func(items ...*IndexerMeta
func populateIssueIndexer(ctx context.Context) {
ctx, _, finished := process.GetManager().AddTypedContext(ctx, "Service: PopulateIssueIndexer", process.SystemProcessType, true)
defer finished()
if err := PopulateIssueIndexer(ctx, true); err != nil {
log.Error("Issue indexer population failed: %v", err)
}
}

func PopulateIssueIndexer(ctx context.Context, keepRetrying bool) error {
for page := 1; ; page++ {
select {
case <-ctx.Done():
log.Warn("Issue Indexer population shutdown before completion")
return
return fmt.Errorf("shutdown before completion: %w", ctx.Err())
default:
}
repos, _, err := repo_model.SearchRepositoryByName(ctx, &repo_model.SearchRepoOptions{
Expand All @@ -221,20 +227,22 @@ func populateIssueIndexer(ctx context.Context) {
}
if len(repos) == 0 {
log.Debug("Issue Indexer population complete")
return
return nil
}

for _, repo := range repos {
for {
select {
case <-ctx.Done():
log.Info("Issue Indexer population shutdown before completion")
return
return fmt.Errorf("shutdown before completion: %w", ctx.Err())
default:
}
if err := updateRepoIndexer(ctx, repo.ID); err != nil {
log.Warn("Retry to populate issue indexer for repo %d: %v", repo.ID, err)
continue
if keepRetrying && ctx.Err() == nil {
log.Warn("Retry to populate issue indexer for repo %d: %v", repo.ID, err)
continue
}
return fmt.Errorf("populate issue indexer for repo %d: %v", repo.ID, err)
}
break
}
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2752,6 +2752,7 @@ dashboard.stop_zombie_tasks = Stop zombie tasks
dashboard.stop_endless_tasks = Stop endless tasks
dashboard.cancel_abandoned_jobs = Cancel abandoned jobs
dashboard.sync_branch.started = Branches Sync started
dashboard.rebuild_issue_indexer = Rebuild issue indexer

users.user_manage_panel = User Account Management
users.new_account = Create User Account
Expand Down
12 changes: 12 additions & 0 deletions services/cron/tasks_extended.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/models/system"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/updatechecker"
repo_service "code.gitea.io/gitea/services/repository"
Expand Down Expand Up @@ -213,6 +214,16 @@ func registerGCLFS() {
})
}

func registerRebuildIssueIndexer() {
RegisterTaskFatal("rebuild_issue_indexer", &BaseConfig{
Enabled: false,
RunAtStart: false,
Schedule: "@annually",
}, func(ctx context.Context, _ *user_model.User, config Config) error {
return issue_indexer.PopulateIssueIndexer(ctx, false)
})
}

func initExtendedTasks() {
registerDeleteInactiveUsers()
registerDeleteRepositoryArchives()
Expand All @@ -227,4 +238,5 @@ func initExtendedTasks() {
registerUpdateGiteaChecker()
registerDeleteOldSystemNotices()
registerGCLFS()
registerRebuildIssueIndexer()
}
Loading