meta_srv/handler/
mailbox_handler.rs

1// Copyright 2023 Greptime Team
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// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use api::v1::meta::{HeartbeatRequest, Role};
16
17use crate::error::Result;
18use crate::handler::{HandleControl, HeartbeatAccumulator, HeartbeatHandler};
19use crate::metasrv::Context;
20
21pub struct MailboxHandler;
22
23#[async_trait::async_trait]
24impl HeartbeatHandler for MailboxHandler {
25    fn is_acceptable(&self, _role: Role) -> bool {
26        true
27    }
28
29    async fn handle(
30        &self,
31        req: &HeartbeatRequest,
32        ctx: &mut Context,
33        _acc: &mut HeartbeatAccumulator,
34    ) -> Result<HandleControl> {
35        let Some(message) = &req.mailbox_message else {
36            return Ok(HandleControl::Continue);
37        };
38
39        ctx.mailbox.on_recv(message.id, Ok(message.clone())).await?;
40
41        Ok(HandleControl::Done)
42    }
43}