Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSami Hiltunen <shiltunen@gitlab.com>2024-01-19 14:19:42 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2024-01-24 10:38:46 +0300
commit42a662b8dc137d1d18b6483de395a4d5d5f04300 (patch)
treed51b7e14edf354a91db2a8825e1113863d1643a0
parentdde45bd7b851b9f33e201ccc9519c78efa75caf6 (diff)
Disable daily maintenance with transactionssmh-disable-maintenance-with-txn
The daily maintenance worker does not use a transaction and accesses repositories directly. It thus conflicts with the work TransactionManager is doing. Changing daily maintenance to work with transactions is not worth it. We need to pack the repositories actively as they are written to since the file count impacts snapshotting efficiency. TransactionManager sees all changes and thus can trigger the maintenance when it is needed. Random daily walk is not useful in this context as Gitaly no longer leaves garbage in the repositories. The garbage left over by failures get cleaned up with the transactions. This commit disables daily maintenance when transactions are enabled. While at it, we only launch the daily maintenance worker if the feature is actually enabled.
-rw-r--r--internal/cli/gitaly/serve.go24
-rw-r--r--internal/gitaly/config/config.go5
-rw-r--r--internal/gitaly/maintenance/daily.go4
3 files changed, 19 insertions, 14 deletions
diff --git a/internal/cli/gitaly/serve.go b/internal/cli/gitaly/serve.go
index beee3407a..86df76547 100644
--- a/internal/cli/gitaly/serve.go
+++ b/internal/cli/gitaly/serve.go
@@ -507,17 +507,21 @@ func run(cfg config.Cfg, logger log.Logger) error {
}
bootstrapSpan.Finish()
- shutdownWorkers, err := maintenance.StartWorkers(
- ctx,
- logger,
- maintenance.DailyOptimizationWorker(cfg, maintenance.OptimizerFunc(func(ctx context.Context, logger log.Logger, repo storage.Repository) error {
- return housekeepingManager.OptimizeRepository(ctx, localrepo.New(logger, locator, gitCmdFactory, catfileCache, repo))
- })),
- )
- if err != nil {
- return fmt.Errorf("initialize auxiliary workers: %w", err)
+ if !cfg.DailyMaintenance.IsDisabled() && cfg.Transactions.Enabled {
+ logger.WarnContext(ctx, "Forcibly disabling daily maintenance worker due to transactions being enabled. Daily maintenance is not supported with transactions.")
+ } else if !cfg.DailyMaintenance.IsDisabled() {
+ shutdownWorkers, err := maintenance.StartWorkers(
+ ctx,
+ logger,
+ maintenance.DailyOptimizationWorker(cfg, maintenance.OptimizerFunc(func(ctx context.Context, logger log.Logger, repo storage.Repository) error {
+ return housekeepingManager.OptimizeRepository(ctx, localrepo.New(logger, locator, gitCmdFactory, catfileCache, repo))
+ })),
+ )
+ if err != nil {
+ return fmt.Errorf("initialize auxiliary workers: %w", err)
+ }
+ defer shutdownWorkers()
}
- defer shutdownWorkers()
gracefulStopTicker := helper.NewTimerTicker(cfg.GracefulRestartTimeout.Duration())
defer gracefulStopTicker.Stop()
diff --git a/internal/gitaly/config/config.go b/internal/gitaly/config/config.go
index 1e125bc8e..50f203278 100644
--- a/internal/gitaly/config/config.go
+++ b/internal/gitaly/config/config.go
@@ -52,6 +52,11 @@ type DailyJob struct {
Disabled bool `toml:"disabled,omitempty" json:"disabled"`
}
+// IsDisabled returns true if the daily job is disabled and should not run.
+func (dj DailyJob) IsDisabled() bool {
+ return dj.Duration == 0 || len(dj.Storages) == 0 || dj.Disabled
+}
+
// Validate runs validation on all fields and compose all found errors.
func (dj DailyJob) Validate(allowedStorages []string) error {
if dj.Disabled {
diff --git a/internal/gitaly/maintenance/daily.go b/internal/gitaly/maintenance/daily.go
index fdf3ced82..9fee61c66 100644
--- a/internal/gitaly/maintenance/daily.go
+++ b/internal/gitaly/maintenance/daily.go
@@ -41,10 +41,6 @@ func (dw DailyWorker) nextTime(hour, minute int) time.Time {
// StartDaily will run the provided job every day at the specified time for the
// specified duration. Only the specified storages wil be worked on.
func (dw DailyWorker) StartDaily(ctx context.Context, l log.Logger, schedule config.DailyJob, job StoragesJob) error {
- if schedule.Duration == 0 || len(schedule.Storages) == 0 || schedule.Disabled {
- return nil
- }
-
for {
nt := dw.nextTime(int(schedule.Hour), int(schedule.Minute))
l.WithField("scheduled", nt).Info("maintenance: daily scheduled")