github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/pkg/scheduler/interface.go (about)

     1  // Copyright 2020 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  	"github.com/pingcap/log"
    18  	"github.com/pingcap/ticdc/cdc/model"
    19  )
    20  
    21  // Scheduler is an abstraction for anything that provide the schedule table feature
    22  type Scheduler interface {
    23  	// ResetWorkloads resets the workloads info of the capture
    24  	ResetWorkloads(captureID model.CaptureID, workloads model.TaskWorkload)
    25  	// AlignCapture makes sure that the workloads of the capture is matched with the specified captureIDs
    26  	AlignCapture(captureIDs map[model.CaptureID]struct{})
    27  	// Skewness returns the skewness
    28  	Skewness() float64
    29  	// CalRebalanceOperates calculates the rebalance operates
    30  	// returns  * the skewness after rebalance
    31  	//          * the move jobs need by rebalance
    32  	CalRebalanceOperates(targetSkewness float64) (
    33  		skewness float64, moveTableJobs map[model.TableID]*model.MoveTableJob)
    34  	// DistributeTables distributes the new tables to the captures
    35  	// returns the operations of the new tables
    36  	DistributeTables(tableIDs map[model.TableID]model.Ts) map[model.CaptureID]map[model.TableID]*model.TableOperation
    37  }
    38  
    39  // NewScheduler creates a new Scheduler
    40  func NewScheduler(tp string) Scheduler {
    41  	switch tp {
    42  	case "table-number":
    43  		return newTableNumberScheduler()
    44  	default:
    45  		log.Info("invalid scheduler type, using default scheduler")
    46  		return newTableNumberScheduler()
    47  	}
    48  }