Skip to content

Commit cd043e8

Browse files
committed
feat: Cleanup tasks bbolt entries during org deletion
1 parent ba5455f commit cd043e8

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

cmd/influxd/launcher/launcher.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ func (m *Launcher) run(ctx context.Context, opts *InfluxdOpts) (err error) {
277277
}
278278

279279
m.kvService = kv.NewService(m.log.With(zap.String("store", "kv")), m.kvStore, ts, serviceConfig)
280+
ts.Apply(tenant.WithTaskService(m.kvService))
280281

281282
var (
282283
opLogSvc = tenant.NewOpLogService(m.kvStore, m.kvService)

tenant/service.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/influxdata/influxdb/v2/kit/metric"
88
"github.com/influxdata/influxdb/v2/label"
99
"github.com/influxdata/influxdb/v2/secret"
10+
"github.com/influxdata/influxdb/v2/task/taskmodel"
1011
"github.com/prometheus/client_golang/prometheus"
1112
"go.uber.org/zap"
1213
)
@@ -35,6 +36,7 @@ type Service struct {
3536
influxdb.UserResourceMappingService
3637
influxdb.OrganizationService
3738
influxdb.BucketService
39+
taskmodel.TaskService
3840
}
3941

4042
func (s *Service) RLock() {
@@ -62,6 +64,18 @@ func (s *Service) SetUserOptions(opts ...func(*UserSvc)) {
6264
s.userSvc.SetOptions(opts...)
6365
}
6466

67+
type ServiceOption func(*Service)
68+
69+
func WithTaskService(ts taskmodel.TaskService) ServiceOption {
70+
return func(s *Service) { s.TaskService = ts }
71+
}
72+
73+
func (s *Service) Apply(opts ...ServiceOption) {
74+
for _, opt := range opts {
75+
opt(s)
76+
}
77+
}
78+
6579
// creates a new Service with logging and metrics middleware wrappers.
6680
func NewSystem(store *Store, log *zap.Logger, reg prometheus.Registerer, strongPasswords bool, metricOpts ...metric.ClientOptFn) *Service {
6781
ts := NewService(store, WithPasswordChecking(strongPasswords))

tenant/service_org.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
icontext "github.com/influxdata/influxdb/v2/context"
88
"github.com/influxdata/influxdb/v2/kit/platform"
99
"github.com/influxdata/influxdb/v2/kv"
10+
"github.com/influxdata/influxdb/v2/task/taskmodel"
1011
)
1112

1213
type OrgSvc struct {
@@ -212,6 +213,16 @@ func (s *OrgSvc) DeleteOrganization(ctx context.Context, id platform.ID) error {
212213
return err
213214
}
214215

216+
tasks, _, err := s.svc.FindTasks(ctx, taskmodel.TaskFilter{OrganizationID: &id})
217+
if err != nil {
218+
return err
219+
}
220+
for _, t := range tasks {
221+
if err := s.svc.DeleteTask(ctx, t.ID); err != nil && err != taskmodel.ErrTaskNotFound {
222+
return err
223+
}
224+
}
225+
215226
return s.removeResourceRelations(ctx, id)
216227
}
217228

0 commit comments

Comments
 (0)