standalone/
metadata.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 std::sync::Arc;
16
17use common_config::KvBackendConfig;
18use common_error::ext::BoxedError;
19use common_meta::kv_backend::KvBackendRef;
20use common_telemetry::info;
21use log_store::raft_engine::RaftEngineBackend;
22use snafu::ResultExt;
23
24use crate::error::{OpenMetadataKvBackendSnafu, Result};
25
26/// Builds the metadata kvbackend.
27pub fn build_metadata_kvbackend(dir: String, config: KvBackendConfig) -> Result<KvBackendRef> {
28    info!(
29        "Creating metadata kvbackend with dir: {}, config: {:?}",
30        dir, config
31    );
32    let kv_backend = RaftEngineBackend::try_open_with_cfg(dir, &config)
33        .map_err(BoxedError::new)
34        .context(OpenMetadataKvBackendSnafu)?;
35
36    Ok(Arc::new(kv_backend))
37}