log_store/
raft_engine.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 crate::raft_engine::protos::logstore::EntryImpl;
16
17mod backend;
18pub mod log_store;
19
20pub use backend::RaftEngineBackend;
21pub use raft_engine::Config;
22use store_api::logstore::entry::{Entry, NaiveEntry};
23use store_api::logstore::provider::Provider;
24use store_api::storage::RegionId;
25
26#[allow(renamed_and_removed_lints)]
27pub mod protos {
28    include!(concat!(env!("OUT_DIR"), concat!("/", "protos/", "mod.rs")));
29}
30
31impl EntryImpl {
32    pub fn create(id: u64, ns: u64, data: Vec<u8>) -> Self {
33        Self {
34            id,
35            namespace_id: ns,
36            data,
37            ..Default::default()
38        }
39    }
40}
41
42impl From<EntryImpl> for Entry {
43    fn from(
44        EntryImpl {
45            id,
46            namespace_id,
47            data,
48            ..
49        }: EntryImpl,
50    ) -> Self {
51        Entry::Naive(NaiveEntry {
52            provider: Provider::raft_engine_provider(namespace_id),
53            region_id: RegionId::from_u64(namespace_id),
54            entry_id: id,
55            data,
56        })
57    }
58}