github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/engine/servermaster/jobop/config.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 jobop
    15  
    16  import "time"
    17  
    18  const (
    19  	defaultBackoffInitInterval = 5 * time.Second
    20  	defaultBackoffMaxInterval  = 5 * time.Minute
    21  	defaultBackoffMultiplier   = 1.2
    22  	// If a job can keep running for more than 10 minutes, it won't be backoff
    23  	// If a job keeps failing, the max back interval is 5 minutes, and 10 minutes
    24  	// can keep at least one failed record.
    25  	defaultBackoffResetInterval = 2 * defaultBackoffMaxInterval
    26  	// with 1.2 as multiplier, it will cost approximately 32 minutes to reach max interval 5min,
    27  	// and it will keep trying for every 5min until approximate 48 hours. Then, it will quit.
    28  	defaultBackoffMaxTryTime = 600
    29  )
    30  
    31  // BackoffConfig is used to configure job backoff
    32  type BackoffConfig struct {
    33  	ResetInterval   time.Duration `toml:"reset-interval" json:"reset-interval"`
    34  	InitialInterval time.Duration `toml:"initial-interval" json:"initial-interval"`
    35  	MaxInterval     time.Duration `toml:"max-interval" json:"max-interval"`
    36  	Multiplier      float64       `toml:"multiplier" json:"multiplier"`
    37  	MaxTryTime      int           `toml:"max-try-time" json:"max-try-time"`
    38  }
    39  
    40  // NewDefaultBackoffConfig creates a default backoff config
    41  func NewDefaultBackoffConfig() *BackoffConfig {
    42  	return &BackoffConfig{
    43  		ResetInterval:   defaultBackoffResetInterval,
    44  		InitialInterval: defaultBackoffInitInterval,
    45  		MaxInterval:     defaultBackoffMaxInterval,
    46  		Multiplier:      defaultBackoffMultiplier,
    47  		MaxTryTime:      defaultBackoffMaxTryTime,
    48  	}
    49  }