Skip to content

Commit

Permalink
refactor: Remove deprecated APIs
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <github@xuanwo.io>
  • Loading branch information
Xuanwo committed Aug 28, 2022
1 parent 983beae commit 9d75767
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 295 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ layers-metrics = ["metrics"]
layers-retry = ["backon"]
# Enable layers tracing support.
layers-tracing = ["tracing"]
# DEPRACATED: use layers-retry instead
retry = ["layers-retry"]

# Enable services hdfs support
services-hdfs = ["hdrs"]
Expand Down
33 changes: 0 additions & 33 deletions src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,39 +224,6 @@ impl Operator {
}
}

/// Configure backoff for operators
///
/// This function only provided if feature `retry` is enabled.
///
/// # Examples
///
/// ```
/// # use std::sync::Arc;
/// # use anyhow::Result;
/// # use opendal::services::fs;
/// # use opendal::services::fs::Builder;
/// use backon::ExponentialBackoff;
/// use opendal::Operator;
/// use opendal::Scheme;
///
/// # #[tokio::main]
/// # async fn main() -> Result<()> {
/// let op = Operator::from_env(Scheme::Fs)?.with_backoff(ExponentialBackoff::default());
/// // All operations will be retried if the error is retryable
/// let _ = op.object("test_file").read();
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "layers-retry")]
#[must_use]
#[deprecated = "Use `Operator::layer` and `RetryLayer` directly"]
pub fn with_backoff(
self,
backoff: impl backon::Backoff + Send + Sync + std::fmt::Debug + 'static,
) -> Self {
self.layer(crate::layers::RetryLayer::new(backoff))
}

fn inner(&self) -> Arc<dyn Accessor> {
self.accessor.clone()
}
Expand Down
12 changes: 0 additions & 12 deletions src/services/azblob/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,6 @@ impl Builder {
_account_name: mem::take(&mut self.account_name).unwrap_or_default(),
})
}

/// Consume builder to build an azblob backend.
#[deprecated = "Use Builder::build() instead"]
pub async fn finish(&mut self) -> Result<Arc<dyn Accessor>> {
Ok(Arc::new(self.build()?))
}
}

/// Backend for azblob services.
Expand All @@ -243,12 +237,6 @@ pub struct Backend {
}

impl Backend {
/// Create a builder for azblob.
#[deprecated = "Use Builder::default() instead"]
pub fn build() -> Builder {
Builder::default()
}

pub(crate) fn from_iter(it: impl Iterator<Item = (String, String)>) -> Result<Self> {
let mut builder = Builder::default();

Expand Down
46 changes: 0 additions & 46 deletions src/services/fs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,46 +103,6 @@ impl Builder {
info!("backend build finished: {:?}", &self);
Ok(Backend { root })
}

/// Consume current builder to build an fs backend.
#[deprecated = "Use Builder::build() instead"]
pub async fn finish(&mut self) -> Result<Arc<dyn Accessor>> {
info!("backend build started: {:?}", &self);

// Make `/` as the default of root.
let root = match &self.root {
None => "/".to_string(),
Some(v) => {
debug_assert!(!v.is_empty());

let mut v = v.clone();

if !v.starts_with('/') {
return Err(other(BackendError::new(
HashMap::from([("root".to_string(), v.clone())]),
anyhow!("Root must start with /"),
)));
}
if !v.ends_with('/') {
v.push('/');
}

v
}
};

// If root dir is not exist, we must create it.
if let Err(e) = fs::metadata(&root).await {
if e.kind() == std::io::ErrorKind::NotFound {
fs::create_dir_all(&root)
.await
.map_err(|e| other(anyhow!("create dir in {} error {:?}", &root, e)))?;
}
}

info!("backend build finished: {:?}", &self);
Ok(Arc::new(Backend { root }))
}
}

/// Backend is used to serve `Accessor` support for posix alike fs.
Expand All @@ -152,12 +112,6 @@ pub struct Backend {
}

impl Backend {
/// Create a builder.
#[deprecated = "Use Builder::default() instead"]
pub fn build() -> Builder {
Builder::default()
}

pub(crate) fn from_iter(it: impl Iterator<Item = (String, String)>) -> Result<Self> {
let mut builder = Builder::default();

Expand Down
12 changes: 0 additions & 12 deletions src/services/hdfs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,6 @@ impl Builder {
client: Arc::new(client),
})
}

/// Finish the building and create hdfs backend.
#[deprecated = "Use Builder::build() instead"]
pub async fn finish(&mut self) -> Result<Arc<dyn Accessor>> {
Ok(Arc::new(self.build()?))
}
}

/// Backend for hdfs services.
Expand All @@ -172,12 +166,6 @@ unsafe impl Send for Backend {}
unsafe impl Sync for Backend {}

impl Backend {
/// Create a builder.
#[deprecated = "Use Builder::default() instead"]
pub fn build() -> Builder {
Builder::default()
}

pub(crate) fn from_iter(it: impl Iterator<Item = (String, String)>) -> Result<Self> {
let mut builder = Builder::default();

Expand Down
12 changes: 0 additions & 12 deletions src/services/http/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,6 @@ impl Builder {
index: Arc::new(Mutex::new(mem::take(&mut self.index))),
})
}

/// Build a HTTP backend.
#[deprecated = "Use Builder::build() instead"]
pub async fn finish(&mut self) -> Result<Arc<dyn Accessor>> {
Ok(Arc::new(self.build()?))
}
}

/// Backend is used to serve `Accessor` support for http.
Expand Down Expand Up @@ -238,12 +232,6 @@ impl Debug for Backend {
}

impl Backend {
/// Create a new builder for s3.
#[deprecated = "Use Builder::default() instead"]
pub fn build() -> Builder {
Builder::default()
}

pub(crate) fn from_iter(it: impl Iterator<Item = (String, String)>) -> Result<Self> {
let mut builder = Builder::default();

Expand Down
14 changes: 0 additions & 14 deletions src/services/memory/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ impl Builder {
inner: Arc::new(Mutex::new(HashMap::default())),
})
}

/// Consume builder to build a memory backend.
#[deprecated = "Use Builder::build() instead"]
pub async fn finish(&mut self) -> Result<Arc<dyn Accessor>> {
Ok(Arc::new(self.build()?))
}
}

/// Backend is used to serve `Accessor` support in memory.
Expand All @@ -74,14 +68,6 @@ pub struct Backend {
inner: Arc<Mutex<HashMap<String, Bytes>>>,
}

impl Backend {
/// Create a builder.
#[deprecated = "Use Builder::default() instead"]
pub fn build() -> Builder {
Builder::default()
}
}

#[async_trait]
impl Accessor for Backend {
fn metadata(&self) -> AccessorMetadata {
Expand Down
164 changes: 0 additions & 164 deletions src/services/s3/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,164 +680,6 @@ impl Builder {
server_side_encryption_customer_key_md5,
})
}

/// Finish the build process and create a new accessor.
#[deprecated = "Use Builder::build() instead"]
pub async fn finish(&mut self) -> Result<Arc<dyn Accessor>> {
info!("backend build started: {:?}", &self);

let root = match &self.root {
// Use "/" as root if user not specified.
None => "/".to_string(),
Some(v) => {
let mut v = v
.split('/')
.filter(|v| !v.is_empty())
.collect::<Vec<&str>>()
.join("/");
if !v.starts_with('/') {
v.insert(0, '/');
}
if !v.ends_with('/') {
v.push('/')
}
v
}
};
info!("backend use root {}", &root);

// Handle endpoint, region and bucket name.
let bucket = match self.bucket.is_empty() {
false => Ok(&self.bucket),
true => Err(other(BackendError::new(
HashMap::from([("bucket".to_string(), "".to_string())]),
anyhow!("bucket is empty"),
))),
}?;
debug!("backend use bucket {}", &bucket);

// Setup error context so that we don't need to construct many times.
let mut context: HashMap<String, String> =
HashMap::from([("bucket".to_string(), bucket.to_string())]);

let server_side_encryption = match &self.server_side_encryption {
None => None,
Some(v) => Some(v.parse().map_err(|e| {
other(BackendError::new(
context.clone(),
anyhow!("server_side_encryption value {} invalid: {}", v, e),
))
})?),
};

let server_side_encryption_aws_kms_key_id =
match &self.server_side_encryption_aws_kms_key_id {
None => None,
Some(v) => Some(v.parse().map_err(|e| {
other(BackendError::new(
context.clone(),
anyhow!(
"server_side_encryption_aws_kms_key_id value {} invalid: {}",
v,
e
),
))
})?),
};

let server_side_encryption_customer_algorithm =
match &self.server_side_encryption_customer_algorithm {
None => None,
Some(v) => Some(v.parse().map_err(|e| {
other(BackendError::new(
context.clone(),
anyhow!(
"server_side_encryption_customer_algorithm value {} invalid: {}",
v,
e
),
))
})?),
};

let server_side_encryption_customer_key = match &self.server_side_encryption_customer_key {
None => None,
Some(v) => Some(v.parse().map_err(|e| {
other(BackendError::new(
context.clone(),
anyhow!(
"server_side_encryption_customer_key value {} invalid: {}",
v,
e
),
))
})?),
};
let server_side_encryption_customer_key_md5 =
match &self.server_side_encryption_customer_key_md5 {
None => None,
Some(v) => Some(v.parse().map_err(|e| {
other(BackendError::new(
context.clone(),
anyhow!(
"server_side_encryption_customer_key_md5 value {} invalid: {}",
v,
e
),
))
})?),
};

let client = HttpClient::new();

let (mut endpoint, region) = self.detect_region(&client, bucket, &context)?;
// Construct endpoint which contains bucket name.
if self.enable_virtual_host_style {
endpoint = endpoint.replace("//", &format!("//{bucket}."))
} else {
write!(endpoint, "/{bucket}").expect("write into string must succeed");
}
context.insert("endpoint".to_string(), endpoint.clone());
context.insert("region".to_string(), region.clone());
debug!("backend use endpoint: {}, region: {}", &endpoint, &region);

let mut signer_builder = Signer::builder();
signer_builder.service("s3");
signer_builder.region(&region);
signer_builder.allow_anonymous();
if self.disable_credential_loader {
signer_builder.credential_loader({
let mut chain = CredentialLoadChain::default();
chain.push(DummyLoader {});

chain
});
}

if let (Some(ak), Some(sk)) = (&self.access_key_id, &self.secret_access_key) {
signer_builder.access_key(ak);
signer_builder.secret_key(sk);
}

let signer = signer_builder
.build()
.map_err(|e| other(BackendError::new(context, e)))?;

info!("backend build finished: {:?}", &self);
Ok(Arc::new(Backend {
root,
endpoint,
signer: Arc::new(signer),
bucket: self.bucket.clone(),
client,

server_side_encryption,
server_side_encryption_aws_kms_key_id,
server_side_encryption_customer_algorithm,
server_side_encryption_customer_key,
server_side_encryption_customer_key_md5,
}))
}
}

/// Backend for s3 services.
Expand All @@ -858,12 +700,6 @@ pub struct Backend {
}

impl Backend {
/// Create a new builder for s3.
#[deprecated = "Use Builder::default() instead"]
pub fn build() -> Builder {
Builder::default()
}

pub(crate) fn from_iter(it: impl Iterator<Item = (String, String)>) -> Result<Self> {
let mut builder = Builder::default();

Expand Down

1 comment on commit 9d75767

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for opendal ready!

✅ Preview
https://opendal-3fmiozm9m-databend.vercel.app

Built with commit 9d75767.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.