github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/master/workerrpc/interface.go (about) 1 // Copyright 2019 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 workerrpc 15 16 import ( 17 "context" 18 "time" 19 20 "github.com/pingcap/tiflow/dm/pb" 21 ) 22 23 // CmdType represents the concrete request type in Request or response type in Response. 24 type CmdType uint16 25 26 // CmdType values. 27 const ( 28 CmdStartSubTask CmdType = 1 + iota 29 CmdOperateSubTask 30 CmdUpdateSubTask 31 32 CmdQueryStatus 33 CmdQueryError 34 CmdQueryTaskOperation 35 CmdQueryWorkerConfig 36 37 CmdSwitchRelayMaster 38 CmdOperateRelay 39 CmdPurgeRelay 40 CmdUpdateRelay 41 CmdMigrateRelay 42 43 CmdFetchDDLInfo 44 45 CmdOperateSchema 46 47 CmdOperateV1Meta 48 CmdHandleError 49 CmdGetWorkerCfg 50 CmdCheckSubtasksCanUpdate 51 52 CmdGetValidationStatus 53 CmdGetValidationError 54 CmdOperateValidationError 55 CmdUpdateValidation 56 ) 57 58 // Request wraps all dm-worker rpc requests. 59 type Request struct { 60 Type CmdType 61 62 QueryStatus *pb.QueryStatusRequest 63 64 PurgeRelay *pb.PurgeRelayRequest 65 66 OperateSchema *pb.OperateWorkerSchemaRequest 67 68 OperateV1Meta *pb.OperateV1MetaRequest 69 HandleError *pb.HandleWorkerErrorRequest 70 GetWorkerCfg *pb.GetWorkerCfgRequest 71 72 CheckSubtasksCanUpdate *pb.CheckSubtasksCanUpdateRequest 73 74 GetValidationStatus *pb.GetValidationStatusRequest 75 GetValidationError *pb.GetValidationErrorRequest 76 OperateValidationError *pb.OperateValidationErrorRequest 77 UpdateValidation *pb.UpdateValidationWorkerRequest 78 } 79 80 // Response wraps all dm-worker rpc responses. 81 type Response struct { 82 Type CmdType 83 84 QueryStatus *pb.QueryStatusResponse 85 86 PurgeRelay *pb.CommonWorkerResponse 87 88 OperateSchema *pb.CommonWorkerResponse 89 90 OperateV1Meta *pb.OperateV1MetaResponse 91 HandleError *pb.CommonWorkerResponse 92 GetWorkerCfg *pb.GetWorkerCfgResponse 93 94 CheckSubtasksCanUpdate *pb.CheckSubtasksCanUpdateResponse 95 96 GetValidationStatus *pb.GetValidationStatusResponse 97 GetValidationError *pb.GetValidationErrorResponse 98 OperateValidationError *pb.OperateValidationErrorResponse 99 UpdateValidation *pb.CommonWorkerResponse 100 } 101 102 // Client is a client that sends RPC. 103 // It should not be used after calling Close(). 104 type Client interface { 105 // SendRequest sends Request 106 SendRequest(ctx context.Context, req *Request, timeout time.Duration) (*Response, error) 107 108 // Close closes client and releases all data 109 Close() error 110 } 111 112 // IsStreamAPI checks whether a request is streaming API based on CmdType. 113 func (req *Request) IsStreamAPI() bool { 114 return req.Type == CmdFetchDDLInfo 115 }