mirror of
https://github.com/wassname/ray.git
synced 2026-07-20 12:40:20 +08:00
[Streaming]Streaming queue support failover (#8161)
This commit is contained in:
+123
-25
@@ -28,10 +28,10 @@ class Message {
|
||||
buffer_(buffer) {}
|
||||
Message() {}
|
||||
virtual ~Message() {}
|
||||
ActorID ActorId() { return actor_id_; }
|
||||
ActorID PeerActorId() { return peer_actor_id_; }
|
||||
ObjectID QueueId() { return queue_id_; }
|
||||
std::shared_ptr<LocalMemoryBuffer> Buffer() { return buffer_; }
|
||||
inline ActorID ActorId() { return actor_id_; }
|
||||
inline ActorID PeerActorId() { return peer_actor_id_; }
|
||||
inline ObjectID QueueId() { return queue_id_; }
|
||||
inline std::shared_ptr<LocalMemoryBuffer> Buffer() { return buffer_; }
|
||||
|
||||
/// Serialize all meta data and data to a LocalMemoryBuffer, which can be sent through
|
||||
/// direct actor call. \return serialized buffer .
|
||||
@@ -44,6 +44,7 @@ class Message {
|
||||
/// All subclasses should implement `ToProtobuf` to serialize its own protobuf data.
|
||||
virtual void ToProtobuf(std::string *output) = 0;
|
||||
|
||||
void FillMessageCommon(queue::protobuf::MessageCommon *common);
|
||||
protected:
|
||||
ActorID actor_id_;
|
||||
ActorID peer_actor_id_;
|
||||
@@ -55,24 +56,36 @@ class Message {
|
||||
static const uint32_t MagicNum;
|
||||
};
|
||||
|
||||
/// MagicNum + MessageType
|
||||
constexpr uint32_t kItemMetaHeaderSize =
|
||||
sizeof(Message::MagicNum) + sizeof(queue::protobuf::StreamingQueueMessageType);
|
||||
/// kItemMetaHeaderSize + fbs length
|
||||
constexpr uint32_t kItemHeaderSize = kItemMetaHeaderSize + sizeof(uint64_t);
|
||||
|
||||
/// Wrap StreamingQueueDataMsg in streaming_queue.proto.
|
||||
/// DataMessage encapsulates the memory buffer of QueueItem, a one-to-one relationship
|
||||
/// exists between DataMessage and QueueItem.
|
||||
class DataMessage : public Message {
|
||||
public:
|
||||
DataMessage(const ActorID &actor_id, const ActorID &peer_actor_id, ObjectID queue_id,
|
||||
uint64_t seq_id, std::shared_ptr<LocalMemoryBuffer> buffer, bool raw)
|
||||
: Message(actor_id, peer_actor_id, queue_id, buffer), seq_id_(seq_id), raw_(raw) {}
|
||||
uint64_t seq_id, uint64_t msg_id_start, uint64_t msg_id_end, std::shared_ptr<LocalMemoryBuffer> buffer, bool raw)
|
||||
: Message(actor_id, peer_actor_id, queue_id, buffer), seq_id_(seq_id),
|
||||
msg_id_start_(msg_id_start),
|
||||
msg_id_end_(msg_id_end),raw_(raw) {}
|
||||
virtual ~DataMessage() {}
|
||||
|
||||
static std::shared_ptr<DataMessage> FromBytes(uint8_t *bytes);
|
||||
virtual void ToProtobuf(std::string *output);
|
||||
uint64_t SeqId() { return seq_id_; }
|
||||
bool IsRaw() { return raw_; }
|
||||
queue::protobuf::StreamingQueueMessageType Type() { return type_; }
|
||||
inline uint64_t SeqId() { return seq_id_; }
|
||||
inline uint64_t MsgIdStart() { return msg_id_start_; }
|
||||
inline uint64_t MsgIdEnd() { return msg_id_end_; }
|
||||
inline bool IsRaw() { return raw_; }
|
||||
inline queue::protobuf::StreamingQueueMessageType Type() { return type_; }
|
||||
|
||||
private:
|
||||
uint64_t seq_id_;
|
||||
uint64_t msg_id_start_;
|
||||
uint64_t msg_id_end_;
|
||||
bool raw_;
|
||||
|
||||
const queue::protobuf::StreamingQueueMessageType type_ =
|
||||
@@ -93,8 +106,8 @@ class NotificationMessage : public Message {
|
||||
static std::shared_ptr<NotificationMessage> FromBytes(uint8_t *bytes);
|
||||
virtual void ToProtobuf(std::string *output);
|
||||
|
||||
uint64_t SeqId() { return seq_id_; }
|
||||
queue::protobuf::StreamingQueueMessageType Type() { return type_; }
|
||||
inline uint64_t SeqId() { return seq_id_; }
|
||||
inline queue::protobuf::StreamingQueueMessageType Type() { return type_; }
|
||||
|
||||
private:
|
||||
uint64_t seq_id_;
|
||||
@@ -115,7 +128,7 @@ class CheckMessage : public Message {
|
||||
static std::shared_ptr<CheckMessage> FromBytes(uint8_t *bytes);
|
||||
virtual void ToProtobuf(std::string *output);
|
||||
|
||||
queue::protobuf::StreamingQueueMessageType Type() { return type_; }
|
||||
inline queue::protobuf::StreamingQueueMessageType Type() { return type_; }
|
||||
|
||||
private:
|
||||
const queue::protobuf::StreamingQueueMessageType type_ =
|
||||
@@ -134,8 +147,8 @@ class CheckRspMessage : public Message {
|
||||
|
||||
static std::shared_ptr<CheckRspMessage> FromBytes(uint8_t *bytes);
|
||||
virtual void ToProtobuf(std::string *output);
|
||||
queue::protobuf::StreamingQueueMessageType Type() { return type_; }
|
||||
queue::protobuf::StreamingQueueError Error() { return err_code_; }
|
||||
inline queue::protobuf::StreamingQueueMessageType Type() { return type_; }
|
||||
inline queue::protobuf::StreamingQueueError Error() { return err_code_; }
|
||||
|
||||
private:
|
||||
queue::protobuf::StreamingQueueError err_code_;
|
||||
@@ -143,6 +156,91 @@ class CheckRspMessage : public Message {
|
||||
queue::protobuf::StreamingQueueMessageType::StreamingQueueCheckRspMsgType;
|
||||
};
|
||||
|
||||
class PullRequestMessage : public Message {
|
||||
public:
|
||||
PullRequestMessage(const ActorID &actor_id, const ActorID &peer_actor_id,
|
||||
const ObjectID &queue_id, uint64_t msg_id)
|
||||
: Message(actor_id, peer_actor_id, queue_id), msg_id_(msg_id) {}
|
||||
virtual ~PullRequestMessage() {}
|
||||
|
||||
static std::shared_ptr<PullRequestMessage> FromBytes(uint8_t *bytes);
|
||||
virtual void ToProtobuf(std::string *output);
|
||||
inline uint64_t MsgId() { return msg_id_; }
|
||||
inline queue::protobuf::StreamingQueueMessageType Type() { return type_; }
|
||||
|
||||
private:
|
||||
uint64_t msg_id_;
|
||||
const queue::protobuf::StreamingQueueMessageType type_ =
|
||||
queue::protobuf::StreamingQueueMessageType::StreamingQueuePullRequestMsgType;
|
||||
};
|
||||
|
||||
class PullResponseMessage : public Message {
|
||||
public:
|
||||
PullResponseMessage(const ActorID &actor_id, const ActorID &peer_actor_id,
|
||||
const ObjectID &queue_id, uint64_t seq_id, uint64_t msg_id,
|
||||
queue::protobuf::StreamingQueueError err_code,
|
||||
bool is_upstream_first_pull)
|
||||
: Message(actor_id, peer_actor_id, queue_id),
|
||||
seq_id_(seq_id),
|
||||
msg_id_(msg_id),
|
||||
is_upstream_first_pull_(is_upstream_first_pull),
|
||||
err_code_(err_code) {}
|
||||
virtual ~PullResponseMessage() = default;
|
||||
|
||||
static std::shared_ptr<PullResponseMessage> FromBytes(uint8_t *bytes);
|
||||
virtual void ToProtobuf(std::string *output);
|
||||
inline uint64_t SeqId() { return seq_id_; }
|
||||
inline uint64_t MsgId() { return msg_id_; }
|
||||
inline queue::protobuf::StreamingQueueMessageType Type() { return type_; }
|
||||
inline queue::protobuf::StreamingQueueError Error() { return err_code_; }
|
||||
inline bool IsUpstreamFirstPull() { return is_upstream_first_pull_; }
|
||||
|
||||
private:
|
||||
uint64_t seq_id_;
|
||||
uint64_t msg_id_;
|
||||
bool is_upstream_first_pull_;
|
||||
queue::protobuf::StreamingQueueError err_code_;
|
||||
const queue::protobuf::StreamingQueueMessageType type_ =
|
||||
queue::protobuf::StreamingQueueMessageType::StreamingQueuePullResponseMsgType;
|
||||
};
|
||||
|
||||
class ResendDataMessage : public Message {
|
||||
public:
|
||||
ResendDataMessage(const ActorID &actor_id, const ActorID &peer_actor_id,
|
||||
ObjectID queue_id, uint64_t first_seq_id, uint64_t seq_id,
|
||||
uint64_t msg_id_start, uint64_t msg_id_end, uint64_t last_seq_id,
|
||||
std::shared_ptr<LocalMemoryBuffer> buffer, bool raw)
|
||||
: Message(actor_id, peer_actor_id, queue_id, buffer),
|
||||
first_seq_id_(first_seq_id),
|
||||
last_seq_id_(last_seq_id),
|
||||
seq_id_(seq_id),
|
||||
msg_id_start_(msg_id_start),
|
||||
msg_id_end_(msg_id_end),
|
||||
raw_(raw) {}
|
||||
virtual ~ResendDataMessage() {}
|
||||
|
||||
static std::shared_ptr<ResendDataMessage> FromBytes(uint8_t *bytes);
|
||||
virtual void ToProtobuf(std::string *output);
|
||||
inline uint64_t MsgIdStart() { return msg_id_start_; }
|
||||
inline uint64_t MsgIdEnd() { return msg_id_end_; }
|
||||
inline uint64_t SeqId() { return seq_id_; }
|
||||
inline uint64_t FirstSeqId() { return first_seq_id_; }
|
||||
inline uint64_t LastSeqId() { return last_seq_id_; }
|
||||
inline bool IsRaw() { return raw_; }
|
||||
inline queue::protobuf::StreamingQueueMessageType Type() { return type_; }
|
||||
|
||||
private:
|
||||
uint64_t first_seq_id_;
|
||||
uint64_t last_seq_id_;
|
||||
uint64_t seq_id_;
|
||||
uint64_t msg_id_start_;
|
||||
uint64_t msg_id_end_;
|
||||
bool raw_;
|
||||
|
||||
const queue::protobuf::StreamingQueueMessageType type_ =
|
||||
queue::protobuf::StreamingQueueMessageType::StreamingQueueResendDataMsgType;
|
||||
};
|
||||
|
||||
/// Wrap StreamingQueueTestInitMsg in streaming_queue.proto.
|
||||
/// TestInitMessage, used for test, driver sends to test workers to init test suite.
|
||||
class TestInitMessage : public Message {
|
||||
@@ -165,14 +263,14 @@ class TestInitMessage : public Message {
|
||||
|
||||
static std::shared_ptr<TestInitMessage> FromBytes(uint8_t *bytes);
|
||||
virtual void ToProtobuf(std::string *output);
|
||||
queue::protobuf::StreamingQueueMessageType Type() { return type_; }
|
||||
std::string ActorHandleSerialized() { return actor_handle_serialized_; }
|
||||
queue::protobuf::StreamingQueueTestRole Role() { return role_; }
|
||||
std::vector<ObjectID> QueueIds() { return queue_ids_; }
|
||||
std::vector<ObjectID> RescaleQueueIds() { return rescale_queue_ids_; }
|
||||
std::string TestSuiteName() { return test_suite_name_; }
|
||||
std::string TestName() { return test_name_; }
|
||||
uint64_t Param() { return param_; }
|
||||
inline queue::protobuf::StreamingQueueMessageType Type() { return type_; }
|
||||
inline std::string ActorHandleSerialized() { return actor_handle_serialized_; }
|
||||
inline queue::protobuf::StreamingQueueTestRole Role() { return role_; }
|
||||
inline std::vector<ObjectID> QueueIds() { return queue_ids_; }
|
||||
inline std::vector<ObjectID> RescaleQueueIds() { return rescale_queue_ids_; }
|
||||
inline std::string TestSuiteName() { return test_suite_name_; }
|
||||
inline std::string TestName() { return test_name_; }
|
||||
inline uint64_t Param() { return param_; }
|
||||
|
||||
std::string ToString() {
|
||||
std::ostringstream os;
|
||||
@@ -218,9 +316,9 @@ class TestCheckStatusRspMsg : public Message {
|
||||
|
||||
static std::shared_ptr<TestCheckStatusRspMsg> FromBytes(uint8_t *bytes);
|
||||
virtual void ToProtobuf(std::string *output);
|
||||
queue::protobuf::StreamingQueueMessageType Type() { return type_; }
|
||||
std::string TestName() { return test_name_; }
|
||||
bool Status() { return status_; }
|
||||
inline queue::protobuf::StreamingQueueMessageType Type() { return type_; }
|
||||
inline std::string TestName() { return test_name_; }
|
||||
inline bool Status() { return status_; }
|
||||
|
||||
private:
|
||||
const queue::protobuf::StreamingQueueMessageType type_ =
|
||||
|
||||
Reference in New Issue
Block a user