github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/engine/framework/model/messages.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 model
    15  
    16  import (
    17  	"fmt"
    18  	"time"
    19  
    20  	"github.com/pingcap/tiflow/engine/pkg/clock"
    21  	"github.com/pingcap/tiflow/engine/pkg/p2p"
    22  )
    23  
    24  // HeartbeatPingTopic is heartbeat ping message topic, each master has a unique one.
    25  func HeartbeatPingTopic(masterID MasterID) p2p.Topic {
    26  	return fmt.Sprintf("heartbeat-ping-%s", masterID)
    27  }
    28  
    29  // HeartbeatPongTopic is heartbeat pong message topic, each worker has a unique one.
    30  func HeartbeatPongTopic(masterID MasterID, workerID WorkerID) p2p.Topic {
    31  	// TODO do we need hex-encoding here?
    32  	return fmt.Sprintf("heartbeat-pong-%s-%s", masterID, workerID)
    33  }
    34  
    35  // WorkerStatusChangeRequestTopic message topic used when updating worker status
    36  func WorkerStatusChangeRequestTopic(masterID MasterID, workerID WorkerID) p2p.Topic {
    37  	return fmt.Sprintf("worker-status-change-req-%s-%s", masterID, workerID)
    38  }
    39  
    40  // HeartbeatPingMessage ships information in heartbeat ping
    41  type HeartbeatPingMessage struct {
    42  	SendTime     clock.MonotonicTime `json:"send-time"`
    43  	FromWorkerID WorkerID            `json:"from-worker-id"`
    44  	Epoch        Epoch               `json:"epoch"`
    45  	WorkerEpoch  Epoch               `json:"worker-epoch"`
    46  	IsFinished   bool                `json:"is-finished"`
    47  }
    48  
    49  // HeartbeatPongMessage ships information in heartbeat pong
    50  type HeartbeatPongMessage struct {
    51  	SendTime   clock.MonotonicTime `json:"send-time"`
    52  	ReplyTime  time.Time           `json:"reply-time"`
    53  	ToWorkerID WorkerID            `json:"to-worker-id"`
    54  	Epoch      Epoch               `json:"epoch"`
    55  	IsFinished bool                `json:"is-finished"`
    56  }
    57  
    58  // StatusChangeRequest ships information when updating worker status
    59  type StatusChangeRequest struct {
    60  	SendTime     clock.MonotonicTime `json:"send-time"`
    61  	FromMasterID MasterID            `json:"from-master-id"`
    62  	Epoch        Epoch               `json:"epoch"`
    63  	ExpectState  WorkerState         `json:"expect-state"`
    64  }