Skip to content

Commit 8a27427

Browse files
committed
refactor!: move get to ObjectStoreExt
See apache#385 and apache#405.
1 parent cb85a61 commit 8a27427

File tree

9 files changed

+46
-68
lines changed

9 files changed

+46
-68
lines changed

src/azure/credential.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ mod tests {
10731073
use super::*;
10741074
use crate::azure::MicrosoftAzureBuilder;
10751075
use crate::client::mock_server::MockServer;
1076-
use crate::{ObjectStore, Path};
1076+
use crate::{ObjectStoreExt, Path};
10771077

10781078
#[tokio::test]
10791079
async fn test_managed_identity() {

src/buffered.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ pub const DEFAULT_BUFFER_SIZE: usize = 1024 * 1024;
4545
/// very [high first-byte latencies], on the order of 100-200ms, and so avoiding unnecessary
4646
/// round-trips is critical to throughput.
4747
///
48-
/// Systems looking to sequentially scan a file should instead consider using [`ObjectStore::get`],
48+
/// Systems looking to sequentially scan a file should instead consider using [`ObjectStoreExt::get`],
4949
/// or [`ObjectStore::get_opts`], or [`ObjectStore::get_range`] to read a particular range.
5050
///
5151
/// Systems looking to read multiple ranges of a file should instead consider using
5252
/// [`ObjectStore::get_ranges`], which will optimise the vectored IO.
5353
///
5454
/// [high first-byte latencies]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/optimizing-performance.html
55+
/// [`ObjectStoreExt::get`]: crate::ObjectStoreExt::get
5556
pub struct BufReader {
5657
/// The object store to fetch data from
5758
store: Arc<dyn ObjectStore>,

src/client/get.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ mod http_tests {
487487
use crate::client::{HttpError, HttpErrorKind, HttpResponseBody};
488488
use crate::http::HttpBuilder;
489489
use crate::path::Path;
490-
use crate::{ClientOptions, ObjectStore, RetryConfig};
490+
use crate::{ClientOptions, ObjectStoreExt, RetryConfig};
491491
use bytes::Bytes;
492492
use futures::FutureExt;
493493
use http::header::{CONTENT_LENGTH, CONTENT_RANGE, ETAG, RANGE};

src/lib.rs

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,15 @@
204204
//!
205205
//! # Fetch objects
206206
//!
207-
//! Use the [`ObjectStore::get`] method to fetch the data bytes
207+
//! Use the [`ObjectStoreExt::get`] / [`ObjectStore::get_opts`] method to fetch the data bytes
208208
//! from remote storage or files in the local filesystem as a stream.
209209
//!
210210
//! ```ignore-wasm32
211211
//! # use futures::TryStreamExt;
212212
//! # use object_store::local::LocalFileSystem;
213213
//! # use std::sync::Arc;
214214
//! # use bytes::Bytes;
215-
//! # use object_store::{path::Path, ObjectStore, GetResult};
215+
//! # use object_store::{path::Path, ObjectStore, ObjectStoreExt, GetResult};
216216
//! # fn get_object_store() -> Arc<dyn ObjectStore> {
217217
//! # Arc::new(LocalFileSystem::new())
218218
//! # }
@@ -403,7 +403,7 @@
403403
//! ```
404404
//! # use std::collections::btree_map::Entry;
405405
//! # use std::collections::HashMap;
406-
//! # use object_store::{GetOptions, GetResult, ObjectStore, Result, Error};
406+
//! # use object_store::{GetOptions, GetResult, ObjectStore, ObjectStoreExt, Result, Error};
407407
//! # use std::sync::Arc;
408408
//! # use std::time::{Duration, Instant};
409409
//! # use bytes::Bytes;
@@ -468,7 +468,7 @@
468468
//! storage, without relying on a separate DBMS.
469469
//!
470470
//! ```
471-
//! # use object_store::{Error, ObjectStore, PutMode, UpdateVersion};
471+
//! # use object_store::{Error, ObjectStore, ObjectStoreExt, PutMode, UpdateVersion};
472472
//! # use std::sync::Arc;
473473
//! # use bytes::Bytes;
474474
//! # use tokio::io::AsyncWriteExt;
@@ -651,38 +651,6 @@ pub trait ObjectStore: std::fmt::Display + Send + Sync + Debug + 'static {
651651
opts: PutMultipartOptions,
652652
) -> Result<Box<dyn MultipartUpload>>;
653653

654-
/// Return the bytes that are stored at the specified location.
655-
///
656-
/// ## Example
657-
///
658-
/// This example uses a basic local filesystem object store to get an object.
659-
///
660-
/// ```ignore-wasm32
661-
/// # use object_store::local::LocalFileSystem;
662-
/// # use tempfile::tempdir;
663-
/// # use object_store::{path::Path, ObjectStore, ObjectStoreExt};
664-
/// async fn get_example() {
665-
/// let tmp = tempdir().unwrap();
666-
/// let store = LocalFileSystem::new_with_prefix(tmp.path()).unwrap();
667-
/// let location = Path::from("example.txt");
668-
/// let content = b"Hello, Object Store!";
669-
///
670-
/// // Put the object into the store
671-
/// store
672-
/// .put(&location, content.as_ref().into())
673-
/// .await
674-
/// .expect("Failed to put object");
675-
///
676-
/// // Get the object from the store
677-
/// let get_result = store.get(&location).await.expect("Failed to get object");
678-
/// let bytes = get_result.bytes().await.expect("Failed to read bytes");
679-
/// println!("Retrieved content: {}", String::from_utf8_lossy(&bytes));
680-
/// }
681-
/// ```
682-
async fn get(&self, location: &Path) -> Result<GetResult> {
683-
self.get_opts(location, GetOptions::default()).await
684-
}
685-
686654
/// Perform a get request with options
687655
///
688656
/// ## Example
@@ -1115,10 +1083,6 @@ macro_rules! as_ref_impl {
11151083
self.as_ref().put_multipart_opts(location, opts).await
11161084
}
11171085

1118-
async fn get(&self, location: &Path) -> Result<GetResult> {
1119-
self.as_ref().get(location).await
1120-
}
1121-
11221086
async fn get_opts(&self, location: &Path, options: GetOptions) -> Result<GetResult> {
11231087
self.as_ref().get_opts(location, options).await
11241088
}
@@ -1212,6 +1176,36 @@ pub trait ObjectStoreExt: ObjectStore {
12121176
&self,
12131177
location: &Path,
12141178
) -> impl Future<Output = Result<Box<dyn MultipartUpload>>>;
1179+
1180+
/// Return the bytes that are stored at the specified location.
1181+
///
1182+
/// ## Example
1183+
///
1184+
/// This example uses a basic local filesystem object store to get an object.
1185+
///
1186+
/// ```ignore-wasm32
1187+
/// # use object_store::local::LocalFileSystem;
1188+
/// # use tempfile::tempdir;
1189+
/// # use object_store::{path::Path, ObjectStore, ObjectStoreExt};
1190+
/// async fn get_example() {
1191+
/// let tmp = tempdir().unwrap();
1192+
/// let store = LocalFileSystem::new_with_prefix(tmp.path()).unwrap();
1193+
/// let location = Path::from("example.txt");
1194+
/// let content = b"Hello, Object Store!";
1195+
///
1196+
/// // Put the object into the store
1197+
/// store
1198+
/// .put(&location, content.as_ref().into())
1199+
/// .await
1200+
/// .expect("Failed to put object");
1201+
///
1202+
/// // Get the object from the store
1203+
/// let get_result = store.get(&location).await.expect("Failed to get object");
1204+
/// let bytes = get_result.bytes().await.expect("Failed to read bytes");
1205+
/// println!("Retrieved content: {}", String::from_utf8_lossy(&bytes));
1206+
/// }
1207+
/// ```
1208+
fn get(&self, location: &Path) -> impl Future<Output = Result<GetResult>>;
12151209
}
12161210

12171211
impl<T> ObjectStoreExt for T
@@ -1227,6 +1221,10 @@ where
12271221
self.put_multipart_opts(location, PutMultipartOptions::default())
12281222
.await
12291223
}
1224+
1225+
async fn get(&self, location: &Path) -> Result<GetResult> {
1226+
self.get_opts(location, GetOptions::default()).await
1227+
}
12301228
}
12311229

12321230
/// Result of a list call that includes objects, prefixes (directories) and a

src/limit.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,6 @@ impl<T: ObjectStore> ObjectStore for LimitStore<T> {
9393
}))
9494
}
9595

96-
async fn get(&self, location: &Path) -> Result<GetResult> {
97-
let permit = Arc::clone(&self.semaphore).acquire_owned().await.unwrap();
98-
let r = self.inner.get(location).await?;
99-
Ok(permit_get_result(r, permit))
100-
}
101-
10296
async fn get_opts(&self, location: &Path, options: GetOptions) -> Result<GetResult> {
10397
let permit = Arc::clone(&self.semaphore).acquire_owned().await.unwrap();
10498
let r = self.inner.get_opts(location, options).await?;

src/local.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1756,7 +1756,7 @@ mod unix_test {
17561756
use tempfile::TempDir;
17571757

17581758
use crate::local::LocalFileSystem;
1759-
use crate::{ObjectStore, Path};
1759+
use crate::{ObjectStore, ObjectStoreExt, Path};
17601760

17611761
#[tokio::test]
17621762
async fn test_fifo() {

src/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ mod tests {
401401
#[tokio::test]
402402
#[cfg(all(feature = "http", not(target_arch = "wasm32")))]
403403
async fn test_url_http() {
404-
use crate::client::mock_server::MockServer;
404+
use crate::{ObjectStoreExt, client::mock_server::MockServer};
405405
use http::{Response, header::USER_AGENT};
406406

407407
let server = MockServer::new().await;

src/prefix.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,6 @@ impl<T: ObjectStore> ObjectStore for PrefixStore<T> {
113113
self.inner.put_multipart_opts(&full_path, opts).await
114114
}
115115

116-
async fn get(&self, location: &Path) -> Result<GetResult> {
117-
let full_path = self.full_path(location);
118-
self.inner.get(&full_path).await
119-
}
120-
121116
async fn get_range(&self, location: &Path, range: Range<u64>) -> Result<Bytes> {
122117
let full_path = self.full_path(location);
123118
self.inner.get_range(&full_path, range).await

src/throttle.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub struct ThrottleConfig {
4040
/// the operation.
4141
pub wait_delete_per_call: Duration,
4242

43-
/// Sleep duration for every byte received during [`get`](ThrottledStore::get).
43+
/// Sleep duration for every byte received during [`get_opts`](ThrottledStore::get_opts).
4444
///
4545
/// Sleeping is performed after the underlying store returned and only for successful gets. The
4646
/// sleep duration is additive to [`wait_get_per_call`](Self::wait_get_per_call).
@@ -50,7 +50,7 @@ pub struct ThrottleConfig {
5050
/// resulting sleep time will be partial as well.
5151
pub wait_get_per_byte: Duration,
5252

53-
/// Sleep duration for every call to [`get`](ThrottledStore::get).
53+
/// Sleep duration for every call to [`get_opts`](ThrottledStore::get_opts).
5454
///
5555
/// Sleeping is done before the underlying store is called and independently of the success of
5656
/// the operation. The sleep duration is additive to
@@ -170,16 +170,6 @@ impl<T: ObjectStore> ObjectStore for ThrottledStore<T> {
170170
}))
171171
}
172172

173-
async fn get(&self, location: &Path) -> Result<GetResult> {
174-
sleep(self.config().wait_get_per_call).await;
175-
176-
// need to copy to avoid moving / referencing `self`
177-
let wait_get_per_byte = self.config().wait_get_per_byte;
178-
179-
let result = self.inner.get(location).await?;
180-
Ok(throttle_get(result, wait_get_per_byte))
181-
}
182-
183173
async fn get_opts(&self, location: &Path, options: GetOptions) -> Result<GetResult> {
184174
sleep(self.config().wait_get_per_call).await;
185175

0 commit comments

Comments
 (0)