github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/pkg/pipeline/message.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 pipeline 15 16 import "github.com/pingcap/ticdc/cdc/model" 17 18 // MessageType is the type of Message 19 type MessageType int 20 21 // types of Message 22 const ( 23 MessageTypeUnknown MessageType = iota 24 MessageTypeCommand 25 MessageTypePolymorphicEvent 26 MessageTypeBarrier 27 MessageTypeTick 28 ) 29 30 // Message is a vehicle for transferring information between nodes 31 type Message struct { 32 // TODO add more kind of messages 33 // Tp is the type of Message 34 Tp MessageType 35 // Command is the command in this message 36 Command *Command 37 // PolymorphicEvent represents the row change event 38 PolymorphicEvent *model.PolymorphicEvent 39 // BarrierTs 40 BarrierTs model.Ts 41 } 42 43 // PolymorphicEventMessage creates the message of PolymorphicEvent 44 func PolymorphicEventMessage(event *model.PolymorphicEvent) Message { 45 return Message{ 46 Tp: MessageTypePolymorphicEvent, 47 PolymorphicEvent: event, 48 } 49 } 50 51 // CommandMessage creates the message of Command 52 func CommandMessage(command *Command) Message { 53 return Message{ 54 Tp: MessageTypeCommand, 55 Command: command, 56 } 57 } 58 59 // BarrierMessage creates the message of Command 60 func BarrierMessage(barrierTs model.Ts) Message { 61 return Message{ 62 Tp: MessageTypeBarrier, 63 BarrierTs: barrierTs, 64 } 65 } 66 67 // TickMessage creates the message of Tick 68 // Note: the returned message is READ-ONLY. 69 func TickMessage() Message { 70 return Message{ 71 Tp: MessageTypeTick, 72 } 73 } 74 75 // CommandType is the type of Command 76 type CommandType int 77 78 const ( 79 // CommandTypeUnknown is unknown message type 80 CommandTypeUnknown CommandType = iota 81 // CommandTypeStop means the table pipeline should stop at once 82 CommandTypeStop 83 ) 84 85 // Command is the command about table pipeline 86 type Command struct { 87 Tp CommandType 88 }