github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/engine/pkg/rpcutil/checker.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 rpcutil 15 16 // ForwardChecker is used for checking whether a request should be forwarded or not. 17 type ForwardChecker[T any] interface { 18 // LeaderOnly returns whether the request is only allowed to handle by the leader. 19 LeaderOnly(method string) bool 20 // IsLeader returns whether the current node is the leader. 21 IsLeader() bool 22 // LeaderClient returns the leader client. If there is no leader, it should return 23 // nil and errors.ErrMasterNoLeader. 24 LeaderClient() (T, error) 25 } 26 27 // FeatureChecker defines an interface that checks whether a feature is available 28 // or under degradation. 29 type FeatureChecker interface { 30 Available(method string) bool 31 }