github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/engine/pkg/externalresource/manager/interfaces.go (about)

     1  // Copyright 2022 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package manager
    15  
    16  import (
    17  	"context"
    18  
    19  	frameModel "github.com/pingcap/tiflow/engine/framework/model"
    20  	"github.com/pingcap/tiflow/engine/model"
    21  	resModel "github.com/pingcap/tiflow/engine/pkg/externalresource/model"
    22  	"github.com/pingcap/tiflow/engine/pkg/notifier"
    23  )
    24  
    25  // ExecutorInfoProvider describes an object that maintains a list
    26  // of all executors
    27  type ExecutorInfoProvider interface {
    28  	HasExecutor(executorID string) bool
    29  
    30  	// WatchExecutors returns a snapshot of all online executors plus
    31  	// a stream of events describing changes that happen to the executors
    32  	// after the snapshot is taken.
    33  	WatchExecutors(ctx context.Context) (
    34  		snap map[model.ExecutorID]string, stream *notifier.Receiver[model.ExecutorStatusChange], err error,
    35  	)
    36  }
    37  
    38  // JobStatus describes the a Job's status.
    39  type JobStatus = frameModel.MasterState
    40  
    41  // JobStatusesSnapshot describes the statuses of all jobs
    42  // at some time point.
    43  type JobStatusesSnapshot = map[frameModel.MasterID]JobStatus
    44  
    45  // JobStatusChangeType describes the type of job status changes.
    46  type JobStatusChangeType int32
    47  
    48  const (
    49  	// JobRemovedEvent means that a job has been removed.
    50  	JobRemovedEvent = JobStatusChangeType(iota + 1)
    51  	// TODO add more event types to support more features
    52  )
    53  
    54  // JobStatusChangeEvent is an event denoting a job status
    55  // has changed.
    56  type JobStatusChangeEvent struct {
    57  	EventType JobStatusChangeType
    58  	JobID     frameModel.MasterID
    59  }
    60  
    61  // JobStatusProvider describes an object that can be queried
    62  // on the status of jobs.
    63  type JobStatusProvider interface {
    64  	// GetJobStatuses returns the status of all jobs that are
    65  	// not deleted.
    66  	GetJobStatuses(ctx context.Context) (JobStatusesSnapshot, error)
    67  
    68  	// WatchJobStatuses listens on all job status changes followed by
    69  	// a snapshot.
    70  	WatchJobStatuses(
    71  		ctx context.Context,
    72  	) (JobStatusesSnapshot, *notifier.Receiver[JobStatusChangeEvent], error)
    73  }
    74  
    75  // GCCoordinator describes an object responsible for triggering
    76  // file resource garbage collection.
    77  type GCCoordinator interface {
    78  	Run(ctx context.Context) error
    79  	OnKeepAlive(resourceID resModel.ResourceID, workerID frameModel.WorkerID)
    80  }
    81  
    82  // GCRunner perform the actual GC operations.
    83  type GCRunner interface {
    84  	Run(ctx context.Context) error
    85  	GCNotify()
    86  	GCExecutors(context.Context, ...model.ExecutorID) error
    87  }