Skip to content

Commit 47fddaa

Browse files
wolfogreGiteaBot
andauthored
Support rebuilding issue indexer manually (#26546)
Provide a way to rebuild issue indexer manually. So if the indexer get outdated because of some bugs like #26539, we can rebuild it. <img width="1104" alt="image" src="https://github.com/go-gitea/gitea/assets/9418365/ac242e29-6f04-47ca-b3d0-801a796448d3"> Co-authored-by: Giteabot <[email protected]>
1 parent 940f997 commit 47fddaa

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

modules/indexer/issues/indexer.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package issues
55

66
import (
77
"context"
8+
"fmt"
89
"os"
910
"runtime/pprof"
1011
"sync/atomic"
@@ -202,11 +203,16 @@ func getIssueIndexerQueueHandler(ctx context.Context) func(items ...*IndexerMeta
202203
func populateIssueIndexer(ctx context.Context) {
203204
ctx, _, finished := process.GetManager().AddTypedContext(ctx, "Service: PopulateIssueIndexer", process.SystemProcessType, true)
204205
defer finished()
206+
if err := PopulateIssueIndexer(ctx, true); err != nil {
207+
log.Error("Issue indexer population failed: %v", err)
208+
}
209+
}
210+
211+
func PopulateIssueIndexer(ctx context.Context, keepRetrying bool) error {
205212
for page := 1; ; page++ {
206213
select {
207214
case <-ctx.Done():
208-
log.Warn("Issue Indexer population shutdown before completion")
209-
return
215+
return fmt.Errorf("shutdown before completion: %w", ctx.Err())
210216
default:
211217
}
212218
repos, _, err := repo_model.SearchRepositoryByName(ctx, &repo_model.SearchRepoOptions{
@@ -221,20 +227,22 @@ func populateIssueIndexer(ctx context.Context) {
221227
}
222228
if len(repos) == 0 {
223229
log.Debug("Issue Indexer population complete")
224-
return
230+
return nil
225231
}
226232

227233
for _, repo := range repos {
228234
for {
229235
select {
230236
case <-ctx.Done():
231-
log.Info("Issue Indexer population shutdown before completion")
232-
return
237+
return fmt.Errorf("shutdown before completion: %w", ctx.Err())
233238
default:
234239
}
235240
if err := updateRepoIndexer(ctx, repo.ID); err != nil {
236-
log.Warn("Retry to populate issue indexer for repo %d: %v", repo.ID, err)
237-
continue
241+
if keepRetrying && ctx.Err() == nil {
242+
log.Warn("Retry to populate issue indexer for repo %d: %v", repo.ID, err)
243+
continue
244+
}
245+
return fmt.Errorf("populate issue indexer for repo %d: %v", repo.ID, err)
238246
}
239247
break
240248
}

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2752,6 +2752,7 @@ dashboard.stop_zombie_tasks = Stop zombie tasks
27522752
dashboard.stop_endless_tasks = Stop endless tasks
27532753
dashboard.cancel_abandoned_jobs = Cancel abandoned jobs
27542754
dashboard.sync_branch.started = Branches Sync started
2755+
dashboard.rebuild_issue_indexer = Rebuild issue indexer
27552756

27562757
users.user_manage_panel = User Account Management
27572758
users.new_account = Create User Account

services/cron/tasks_extended.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"code.gitea.io/gitea/models/system"
1414
user_model "code.gitea.io/gitea/models/user"
1515
"code.gitea.io/gitea/modules/git"
16+
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
1617
"code.gitea.io/gitea/modules/setting"
1718
"code.gitea.io/gitea/modules/updatechecker"
1819
repo_service "code.gitea.io/gitea/services/repository"
@@ -213,6 +214,16 @@ func registerGCLFS() {
213214
})
214215
}
215216

217+
func registerRebuildIssueIndexer() {
218+
RegisterTaskFatal("rebuild_issue_indexer", &BaseConfig{
219+
Enabled: false,
220+
RunAtStart: false,
221+
Schedule: "@annually",
222+
}, func(ctx context.Context, _ *user_model.User, config Config) error {
223+
return issue_indexer.PopulateIssueIndexer(ctx, false)
224+
})
225+
}
226+
216227
func initExtendedTasks() {
217228
registerDeleteInactiveUsers()
218229
registerDeleteRepositoryArchives()
@@ -227,4 +238,5 @@ func initExtendedTasks() {
227238
registerUpdateGiteaChecker()
228239
registerDeleteOldSystemNotices()
229240
registerGCLFS()
241+
registerRebuildIssueIndexer()
230242
}

0 commit comments

Comments
 (0)