github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/scheduler/rexport.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 scheduler
    15  
    16  import (
    17  	"context"
    18  
    19  	"github.com/pingcap/tiflow/cdc/model"
    20  	"github.com/pingcap/tiflow/cdc/redo"
    21  	"github.com/pingcap/tiflow/cdc/scheduler/internal"
    22  	v3 "github.com/pingcap/tiflow/cdc/scheduler/internal/v3"
    23  	v3agent "github.com/pingcap/tiflow/cdc/scheduler/internal/v3/agent"
    24  	"github.com/pingcap/tiflow/pkg/config"
    25  	"github.com/pingcap/tiflow/pkg/etcd"
    26  	"github.com/pingcap/tiflow/pkg/p2p"
    27  	"github.com/pingcap/tiflow/pkg/upstream"
    28  	"github.com/prometheus/client_golang/prometheus"
    29  )
    30  
    31  // TableExecutor is an abstraction for "Processor".
    32  //
    33  // This interface is so designed that it would be the least problematic
    34  // to adapt the current Processor implementation to it.
    35  // TODO find a way to make the semantics easier to understand.
    36  type TableExecutor internal.TableExecutor
    37  
    38  // Scheduler is an interface for scheduling tables.
    39  // Since in our design, we do not record checkpoints per table,
    40  // how we calculate the global watermarks (checkpoint-ts and resolved-ts)
    41  // is heavily coupled with how tables are scheduled.
    42  // That is why we have a scheduler interface that also reports the global watermarks.
    43  type Scheduler internal.Scheduler
    44  
    45  // InfoProvider is the interface to get information about the internal states of the scheduler.
    46  // We need this interface so that we can provide the information through HTTP API.
    47  type InfoProvider internal.InfoProvider
    48  
    49  // Query is for open api can access the scheduler
    50  type Query internal.Query
    51  
    52  // Agent is an interface for an object inside Processor that is responsible
    53  // for receiving commands from the Owner.
    54  // Ideally the processor should drive the Agent by Tick.
    55  //
    56  // Note that Agent is not thread-safe
    57  type Agent internal.Agent
    58  
    59  // CheckpointCannotProceed is a placeholder indicating that the
    60  // Owner should not advance the global checkpoint TS just yet.
    61  const CheckpointCannotProceed = internal.CheckpointCannotProceed
    62  
    63  // NewAgent returns two-phase agent.
    64  func NewAgent(
    65  	ctx context.Context,
    66  	captureID model.CaptureID,
    67  	liveness *model.Liveness,
    68  	messageServer *p2p.MessageServer,
    69  	messageRouter p2p.MessageRouter,
    70  	ownerInfoClient etcd.OwnerCaptureInfoClient,
    71  	executor TableExecutor,
    72  	changefeedID model.ChangeFeedID,
    73  	changefeedEpoch uint64,
    74  	cfg *config.SchedulerConfig,
    75  ) (Agent, error) {
    76  	return v3agent.NewAgent(
    77  		ctx, captureID, liveness, changefeedID,
    78  		messageServer, messageRouter, ownerInfoClient, executor, changefeedEpoch, cfg)
    79  }
    80  
    81  // NewScheduler returns two-phase scheduler.
    82  func NewScheduler(
    83  	ctx context.Context,
    84  	captureID model.CaptureID,
    85  	changeFeedID model.ChangeFeedID,
    86  	messageServer *p2p.MessageServer,
    87  	messageRouter p2p.MessageRouter,
    88  	ownerRevision int64,
    89  	changefeedEpoch uint64,
    90  	up *upstream.Upstream,
    91  	cfg *config.SchedulerConfig,
    92  	redoMetaManager redo.MetaManager,
    93  ) (Scheduler, error) {
    94  	return v3.NewCoordinator(
    95  		ctx, captureID, changeFeedID, messageServer, messageRouter, ownerRevision,
    96  		changefeedEpoch, up, cfg, redoMetaManager)
    97  }
    98  
    99  // InitMetrics registers all metrics used in scheduler
   100  func InitMetrics(registry *prometheus.Registry) {
   101  	v3.InitMetrics(registry)
   102  }