github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/pkg/version/creator_version_gate.go (about)

     1  // Copyright 2021 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 version
    15  
    16  import (
    17  	"github.com/coreos/go-semver/semver"
    18  )
    19  
    20  // CreatorVersionGate determines the introduced version and compatibility
    21  // of some features based on the creator's version value.
    22  type CreatorVersionGate struct {
    23  	version string
    24  }
    25  
    26  // changefeedStateFromAdminJobVersions specifies the version before
    27  // which we use the admin job type to control the state of the changefeed.
    28  var changefeedStateFromAdminJobVersions = []semver.Version{
    29  	// Introduced in https://github.com/pingcap/tiflow/pull/3014.
    30  	*semver.New("4.0.16"),
    31  	// Introduced in https://github.com/pingcap/tiflow/pull/2946.
    32  	*semver.New("5.0.6"),
    33  }
    34  
    35  // changefeedAcceptUnknownProtocolsVersion specifies the version
    36  // of TiCDC for which changefeed supports accepting unknown protocols.
    37  // Introduced in https://github.com/pingcap/ticdc/pull/3811.
    38  var changefeedAcceptUnknownProtocolsVersion = *semver.New("5.4.0")
    39  
    40  // NewCreatorVersionGate creates the creator version gate.
    41  func NewCreatorVersionGate(version string) *CreatorVersionGate {
    42  	return &CreatorVersionGate{
    43  		version: version,
    44  	}
    45  }
    46  
    47  // ChangefeedStateFromAdminJob determines if admin job is the state
    48  // of changefeed based on the version of the creator.
    49  func (g *CreatorVersionGate) ChangefeedStateFromAdminJob() bool {
    50  	// Introduced in https://github.com/pingcap/tiflow/pull/1341.
    51  	// The changefeed before it was introduced was using the old owner.
    52  	if g.version == "" {
    53  		return true
    54  	}
    55  
    56  	creatorVersion := semver.New(SanitizeVersion(g.version))
    57  	for _, version := range changefeedStateFromAdminJobVersions {
    58  		// NOTICE: To compare against the same major version.
    59  		if creatorVersion.Major == version.Major &&
    60  			creatorVersion.LessThan(version) {
    61  			return true
    62  		}
    63  	}
    64  
    65  	return false
    66  }
    67  
    68  // ChangefeedAcceptUnknownProtocols determines whether to accept
    69  // unknown protocols based on the creator's version.
    70  func (g *CreatorVersionGate) ChangefeedAcceptUnknownProtocols() bool {
    71  	// Introduced in https://github.com/pingcap/ticdc/pull/1341.
    72  	// So it was supported at the time.
    73  	if g.version == "" {
    74  		return true
    75  	}
    76  
    77  	creatorVersion := semver.New(SanitizeVersion(g.version))
    78  	return creatorVersion.LessThan(changefeedAcceptUnknownProtocolsVersion)
    79  }
    80  
    81  var changefeedAcceptProtocolInMysqlSinURI = *semver.New("6.1.1")
    82  
    83  // ChangefeedAcceptProtocolInMysqlSinURI determines whether to accept
    84  // protocol in mysql sink uri or configure based on the creator's version.
    85  func (g *CreatorVersionGate) ChangefeedAcceptProtocolInMysqlSinURI() bool {
    86  	// Introduced in https://github.com/pingcap/ticdc/pull/1341.
    87  	// So it was supported at the time.
    88  	if g.version == "" {
    89  		return true
    90  	}
    91  
    92  	creatorVersion := semver.New(SanitizeVersion(g.version))
    93  	return creatorVersion.LessThan(changefeedAcceptProtocolInMysqlSinURI)
    94  }
    95  
    96  // ChangefeedInheritSchedulerConfigFromV66 determines whether to inherit
    97  // changefeed scheduler config created by v6.6.0.
    98  func (g *CreatorVersionGate) ChangefeedInheritSchedulerConfigFromV66() bool {
    99  	if g.version == "" {
   100  		return false
   101  	}
   102  
   103  	creatorVersion := semver.New(SanitizeVersion(g.version))
   104  	return creatorVersion.Major == 6 && creatorVersion.Minor == 6
   105  }