Skip to content

Commit

Permalink
feat(services/tikv): fix code
Browse files Browse the repository at this point in the history
Signed-off-by: owl <[email protected]>
  • Loading branch information
oowl committed Jul 23, 2023
1 parent 05eacb2 commit 07c89a6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
2 changes: 1 addition & 1 deletion core/src/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,4 @@ pub use self::redb::Redb;
#[cfg(feature = "services-tikv")]
mod tikv;
#[cfg(feature = "services-tikv")]
pub use self::tikv::TiKV;
pub use self::tikv::Tikv;
30 changes: 13 additions & 17 deletions core/src/services/tikv/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use std::fmt::Formatter;

/// TiKV backend builder
#[derive(Clone, Default)]
pub struct TiKVBuilder {
pub struct TikvBuilder {
/// network address of the TiKV service.
///
/// default is "127.0.0.1:2379"
Expand All @@ -49,10 +49,10 @@ pub struct TiKVBuilder {
key_path: Option<String>,
}

impl TiKVBuilder {
impl TikvBuilder {
/// Set the network address of the TiKV service.
pub fn endpoints(&mut self, endpoints: impl Into<Vec<String>>) -> &mut Self {
let ep: Vec<String> = endpoints.into().into_iter().collect();
pub fn endpoints(&mut self, endpoints: Vec<String>) -> &mut Self {
let ep: Vec<String> = endpoints.into_iter().collect();
if !ep.is_empty() {
self.endpoints = Some(ep)
}
Expand Down Expand Up @@ -90,12 +90,12 @@ impl TiKVBuilder {
}
}

impl Builder for TiKVBuilder {
impl Builder for TikvBuilder {
const SCHEME: Scheme = Scheme::Redb;
type Accessor = Backend;

fn from_map(map: HashMap<String, String>) -> Self {
let mut builder = TiKVBuilder::default();
let mut builder = TikvBuilder::default();

map.get("endpoints")
.map(|v| v.split(',').map(|s| s.to_owned()).collect::<Vec<String>>())
Expand All @@ -116,21 +116,21 @@ impl Builder for TiKVBuilder {
ErrorKind::ConfigInvalid,
"endpoints is required but not set",
)
.with_context("service", Scheme::TiKV)
.with_context("service", Scheme::Tikv)
})?;

if self.insecure {
if self.ca_path.is_some() || self.key_path.is_some() || self.cert_path.is_some() {
return Err(
Error::new(ErrorKind::ConfigInvalid, "invalid tls configuration")
.with_context("service", Scheme::TiKV)
.with_context("service", Scheme::Tikv)
.with_context("endpoints", format!("{:?}", endpoints)),
)?;
}
} else if !(self.ca_path.is_some() && self.key_path.is_some() && self.cert_path.is_some()) {
return Err(
Error::new(ErrorKind::ConfigInvalid, "invalid tls configuration")
.with_context("service", Scheme::TiKV)
.with_context("service", Scheme::Tikv)
.with_context("endpoints", format!("{:?}", endpoints)),
)?;
}
Expand Down Expand Up @@ -163,10 +163,6 @@ impl Debug for Adapter {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let mut ds = f.debug_struct("Adapter");
ds.field("endpoints", &self.endpoints);
ds.field("insecure", &self.insecure);
ds.field("ca_path", &self.ca_path);
ds.field("cert_path", &self.cert_path);
ds.field("key_path", &self.key_path);
ds.finish()
}
}
Expand All @@ -182,7 +178,7 @@ impl Adapter {
.await
.map_err(|err| {
Error::new(ErrorKind::ConfigInvalid, "invalid configuration")
.with_context("service", Scheme::TiKV)
.with_context("service", Scheme::Tikv)
.with_context("endpoints", format!("{:?}", self.endpoints))
.set_source(err)
})?
Expand All @@ -197,14 +193,14 @@ impl Adapter {
.await
.map_err(|err| {
Error::new(ErrorKind::ConfigInvalid, "invalid configuration")
.with_context("service", Scheme::TiKV)
.with_context("service", Scheme::Tikv)
.with_context("endpoints", format!("{:?}", self.endpoints))
.set_source(err)
})?
} else {
return Err(
Error::new(ErrorKind::ConfigInvalid, "invalid configuration")
.with_context("service", Scheme::TiKV)
.with_context("service", Scheme::Tikv)
.with_context("endpoints", format!("{:?}", self.endpoints)),
);
};
Expand All @@ -216,7 +212,7 @@ impl Adapter {
impl kv::Adapter for Adapter {
fn metadata(&self) -> kv::Metadata {
kv::Metadata::new(
Scheme::TiKV,
Scheme::Tikv,
"TiKV",
Capability {
read: true,
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/tikv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@

mod backend;

pub use backend::TiKVBuilder as TiKV;
pub use backend::TikvBuilder as Tikv;
6 changes: 3 additions & 3 deletions core/src/types/scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ pub enum Scheme {
Webhdfs,
/// [redb][crate::services::Redb]: Redb Services
Redb,
/// [tikv][crate::services::tikv]: TiKV Services
TiKV,
/// [tikv][crate::services::tikv]: Tikv Services
Tikv,
/// Custom that allow users to implement services outside of OpenDAL.
///
/// # NOTE
Expand Down Expand Up @@ -211,7 +211,7 @@ impl From<Scheme> for &'static str {
Scheme::Webdav => "webdav",
Scheme::Webhdfs => "webhdfs",
Scheme::Redb => "redb",
Scheme::TiKV => "tikv",
Scheme::Tikv => "tikv",
Scheme::Custom(v) => v,
}
}
Expand Down

0 comments on commit 07c89a6

Please sign in to comment.