log_store/kafka/worker/
dump_index.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 common_telemetry::error;
16use rskafka::client::partition::OffsetAt;
17use snafu::ResultExt;
18
19use crate::error;
20use crate::kafka::worker::{BackgroundProducerWorker, DumpIndexRequest};
21
22impl BackgroundProducerWorker {
23    pub(crate) async fn dump_index(&mut self, req: DumpIndexRequest) {
24        match self
25            .client
26            .get_offset(OffsetAt::Latest)
27            .await
28            .context(error::GetOffsetSnafu {
29                topic: &self.provider.topic,
30            }) {
31            Ok(offset) => {
32                self.index_collector.set_latest_entry_id(offset as u64);
33                self.index_collector.dump(req.encoder.as_ref());
34                let _ = req.sender.send(());
35            }
36            Err(err) => error!(err; "Failed to do checkpoint"),
37        }
38    }
39}