Skip to content

Commit

Permalink
Add enable-backup-compaction flag
Browse files Browse the repository at this point in the history
  • Loading branch information
timuthy committed Nov 15, 2021
1 parent 0847242 commit bb41a11
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
24 changes: 14 additions & 10 deletions controllers/compaction_lease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,16 @@ func (lc *CompactionLeaseController) reconcileJob(ctx context.Context, logger lo
RequeueAfter: 10 * time.Second,
}, fmt.Errorf("error while fetching compaction job: %v", err)
}
// Required job doesn't exist. Create new
job, err = lc.createCompactJob(ctx, logger, etcd)
logger.Info("Job Creation")
if err != nil {
return ctrl.Result{
RequeueAfter: 10 * time.Second,
}, fmt.Errorf("error during compaction job creation: %v", err)

if lc.config.CompactionEnabled {
// Required job doesn't exist. Create new
job, err = lc.createCompactJob(ctx, logger, etcd)
logger.Info("Job Creation")
if err != nil {
return ctrl.Result{
RequeueAfter: 10 * time.Second,
}, fmt.Errorf("error during compaction job creation: %v", err)
}
}
}

Expand Down Expand Up @@ -529,9 +532,10 @@ func (lc *CompactionLeaseController) SetupWithManager(mgr ctrl.Manager, workers
MaxConcurrentReconciles: workers,
})

builder = builder.WithEventFilter(buildPredicateForLC()).For(&druidv1alpha1.Etcd{})
builder = builder.Owns(&coordinationv1.Lease{})
return builder.Complete(lc)
return builder.
WithEventFilter(buildPredicateForLC()).For(&druidv1alpha1.Etcd{}).
Owns(&coordinationv1.Lease{}).
Complete(lc)
}

func buildPredicateForLC() predicate.Predicate {
Expand Down
2 changes: 2 additions & 0 deletions controllers/config/compaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import "time"

// CompactionLeaseConfig contains configuration for the compaction controller.
type CompactionLeaseConfig struct {
// CompactionEnabled defines of compaction jobs should be created.
CompactionEnabled bool
// ActiveDeadlineDuration is the duration after which a running compaction job will be killed (Ex: "300ms", "20s", "-1.5h" or "2h45m")
ActiveDeadlineDuration time.Duration
// EventsThreshold is total number of etcd events that can be allowed before a backup compaction job is triggered
Expand Down
1 change: 1 addition & 0 deletions controllers/controllers_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ var _ = BeforeSuite(func(done Done) {
Expect(err).NotTo(HaveOccurred())

lc, err := NewCompactionLeaseControllerWithImageVector(mgr, controllersconfig.CompactionLeaseConfig{
CompactionEnabled: true,
EventsThreshold: 1000000,
ActiveDeadlineDuration: activeDeadlineDuration,
})
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func main() {
var (
metricsAddr string
enableLeaderElection bool
enableBackupCompaction bool
leaderElectionID string
leaderElectionResourceLock string
etcdWorkers int
Expand All @@ -75,6 +76,8 @@ func main() {
flag.IntVar(&custodianWorkers, "custodian-workers", 3, "Number of worker threads of the custodian controller.")
flag.IntVar(&etcdCopyBackupsTaskWorkers, "etcd-copy-backups-task-workers", 3, "Number of worker threads of the EtcdCopyBackupsTask controller.")
flag.DurationVar(&custodianSyncPeriod, "custodian-sync-period", 30*time.Second, "Sync period of the custodian controller.")
flag.BoolVar(&enableBackupCompaction, "enable-backup-compaction", false,
"Enable automatic compaction of etcd backups.")
flag.IntVar(&compactionWorkers, "compaction-workers", 3, "Number of worker threads of the CompactionJob controller. The controller creates a backup compaction job if a certain etcd event threshold is reached. Setting this flag to 0 disabled the controller.")
flag.Int64Var(&eventsThreshold, "etcd-events-threshold", 1000000, "Total number of etcd events that can be allowed before a backup compaction job is triggered.")
flag.DurationVar(&activeDeadlineDuration, "active-deadline-duration", 3*time.Hour, "Duration after which a running backup compaction job will be killed (Ex: \"300ms\", \"20s\", \"-1.5h\" or \"2h45m\").")
Expand Down Expand Up @@ -148,6 +151,7 @@ func main() {
}

lc, err := controllers.NewCompactionLeaseControllerWithImageVector(mgr, controllersconfig.CompactionLeaseConfig{
CompactionEnabled: enableBackupCompaction,
EventsThreshold: eventsThreshold,
ActiveDeadlineDuration: activeDeadlineDuration,
})
Expand Down

0 comments on commit bb41a11

Please sign in to comment.