mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-13 16:52:56 +00:00
* load tls Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * impl tls Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * pass options Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * implement require mode Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * clean up Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * update config Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * fix clippy Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * default to prefer Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * update example config Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * adjust example config Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * handle client cert and key properly Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * implement verify_ca and verify_full Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * update integration test for config api Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * change config name and default mode Signed-off-by: Ruihang Xia <waynestxia@gmail.com> --------- Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
117 lines
4.5 KiB
Rust
117 lines
4.5 KiB
Rust
// Copyright 2023 Greptime Team
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
use std::sync::Arc;
|
|
|
|
use clap::Parser;
|
|
use common_error::ext::BoxedError;
|
|
use common_meta::kv_backend::chroot::ChrootKvBackend;
|
|
use common_meta::kv_backend::etcd::EtcdStore;
|
|
use common_meta::kv_backend::KvBackendRef;
|
|
use meta_srv::bootstrap::create_etcd_client;
|
|
use meta_srv::metasrv::BackendImpl;
|
|
|
|
use crate::error::{EmptyStoreAddrsSnafu, UnsupportedMemoryBackendSnafu};
|
|
|
|
#[derive(Debug, Default, Parser)]
|
|
pub(crate) struct StoreConfig {
|
|
/// The endpoint of store. one of etcd, postgres or mysql.
|
|
///
|
|
/// For postgres store, the format is:
|
|
/// "password=password dbname=postgres user=postgres host=localhost port=5432"
|
|
///
|
|
/// For etcd store, the format is:
|
|
/// "127.0.0.1:2379"
|
|
///
|
|
/// For mysql store, the format is:
|
|
/// "mysql://user:password@ip:port/dbname"
|
|
#[clap(long, alias = "store-addr", value_delimiter = ',', num_args = 1..)]
|
|
store_addrs: Vec<String>,
|
|
|
|
/// The maximum number of operations in a transaction. Only used when using [etcd-store].
|
|
#[clap(long, default_value = "128")]
|
|
max_txn_ops: usize,
|
|
|
|
/// The metadata store backend.
|
|
#[clap(long, value_enum, default_value = "etcd-store")]
|
|
backend: BackendImpl,
|
|
|
|
/// The key prefix of the metadata store.
|
|
#[clap(long, default_value = "")]
|
|
store_key_prefix: String,
|
|
|
|
/// The table name in RDS to store metadata. Only used when using [postgres-store] or [mysql-store].
|
|
#[cfg(any(feature = "pg_kvbackend", feature = "mysql_kvbackend"))]
|
|
#[clap(long, default_value = common_meta::kv_backend::DEFAULT_META_TABLE_NAME)]
|
|
meta_table_name: String,
|
|
}
|
|
|
|
impl StoreConfig {
|
|
/// Builds a [`KvBackendRef`] from the store configuration.
|
|
pub async fn build(&self) -> Result<KvBackendRef, BoxedError> {
|
|
let max_txn_ops = self.max_txn_ops;
|
|
let store_addrs = &self.store_addrs;
|
|
if store_addrs.is_empty() {
|
|
EmptyStoreAddrsSnafu.fail().map_err(BoxedError::new)
|
|
} else {
|
|
let kvbackend = match self.backend {
|
|
BackendImpl::EtcdStore => {
|
|
let etcd_client = create_etcd_client(store_addrs)
|
|
.await
|
|
.map_err(BoxedError::new)?;
|
|
Ok(EtcdStore::with_etcd_client(etcd_client, max_txn_ops))
|
|
}
|
|
#[cfg(feature = "pg_kvbackend")]
|
|
BackendImpl::PostgresStore => {
|
|
let table_name = &self.meta_table_name;
|
|
let pool = meta_srv::bootstrap::create_postgres_pool(store_addrs, None)
|
|
.await
|
|
.map_err(BoxedError::new)?;
|
|
Ok(common_meta::kv_backend::rds::PgStore::with_pg_pool(
|
|
pool,
|
|
table_name,
|
|
max_txn_ops,
|
|
)
|
|
.await
|
|
.map_err(BoxedError::new)?)
|
|
}
|
|
#[cfg(feature = "mysql_kvbackend")]
|
|
BackendImpl::MysqlStore => {
|
|
let table_name = &self.meta_table_name;
|
|
let pool = meta_srv::bootstrap::create_mysql_pool(store_addrs)
|
|
.await
|
|
.map_err(BoxedError::new)?;
|
|
Ok(common_meta::kv_backend::rds::MySqlStore::with_mysql_pool(
|
|
pool,
|
|
table_name,
|
|
max_txn_ops,
|
|
)
|
|
.await
|
|
.map_err(BoxedError::new)?)
|
|
}
|
|
BackendImpl::MemoryStore => UnsupportedMemoryBackendSnafu
|
|
.fail()
|
|
.map_err(BoxedError::new),
|
|
};
|
|
if self.store_key_prefix.is_empty() {
|
|
kvbackend
|
|
} else {
|
|
let chroot_kvbackend =
|
|
ChrootKvBackend::new(self.store_key_prefix.as_bytes().to_vec(), kvbackend?);
|
|
Ok(Arc::new(chroot_kvbackend))
|
|
}
|
|
}
|
|
}
|
|
}
|