Skip to content

Commit

Permalink
Rename ObjectEntry to entry
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo committed Feb 9, 2023
1 parent c4564bf commit 4d8f277
Show file tree
Hide file tree
Showing 28 changed files with 112 additions and 124 deletions.
2 changes: 1 addition & 1 deletion src/docs/rfcs/0926_object_reader.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ We can avoid extra `HeadObject` calls by reusing that meta wisely, which could t
+ pub async fn reader(&self) -> Result<ObjectReader> {}
```

`ObjectReader` impls `BytesRead` too, so existing code will keep working. And `ObjectReader` will provide similiar APIs to `ObjectEntry`, for example:
`ObjectReader` impls `BytesRead` too, so existing code will keep working. And `ObjectReader` will provide similiar APIs to `Entry`, for example:

```rust
pub async fn content_length(&self) -> Option<u64> {}
Expand Down
4 changes: 2 additions & 2 deletions src/docs/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,13 @@ OpenDAL v0.18 introduces the following breaking changes:

- Deprecated feature flag `services-http` has been removed.
- All `DirXxx` items have been renamed to `ObjectXxx` to make them more consistent.
- `DirEntry` -> `ObjectEntry`
- `DirEntry` -> `Entry`
- `DirStream` -> `ObjectStream`
- `DirStreamer` -> `ObjectStream`
- `DirIterate` -> `ObjectIterate`
- `DirIterator` -> `ObjectIterator`

Besides, we also make a big change to our `ObjectEntry` API. Since v0.18, we can fully reuse the metadata that fetched during `list`. Take `entry.content_length()` for example:
Besides, we also make a big change to our `Entry` API. Since v0.18, we can fully reuse the metadata that fetched during `list`. Take `entry.content_length()` for example:

- If `content_lenght` is already known, we will return directly.
- If not, we will check if the object entry is `complete`:
Expand Down
4 changes: 2 additions & 2 deletions src/layers/concurrent_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ impl ConcurrentLimitPager {

#[async_trait]
impl output::ObjectPage for ConcurrentLimitPager {
async fn next_page(&mut self) -> Result<Option<Vec<output::ObjectEntry>>> {
async fn next_page(&mut self) -> Result<Option<Vec<output::Entry>>> {
self.inner.next_page().await
}
}
Expand All @@ -366,7 +366,7 @@ impl BlockingConcurrentLimitPager {
}

impl output::BlockingObjectPage for BlockingConcurrentLimitPager {
fn next_page(&mut self) -> Result<Option<Vec<output::ObjectEntry>>> {
fn next_page(&mut self) -> Result<Option<Vec<output::Entry>>> {
self.inner.next_page()
}
}
2 changes: 1 addition & 1 deletion src/layers/error_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ struct ObjectStreamErrorContextWrapper<T: output::ObjectPage> {

#[async_trait::async_trait]
impl<T: output::ObjectPage> output::ObjectPage for ObjectStreamErrorContextWrapper<T> {
async fn next_page(&mut self) -> Result<Option<Vec<output::ObjectEntry>>> {
async fn next_page(&mut self) -> Result<Option<Vec<output::Entry>>> {
self.inner.next_page().await.map_err(|err| {
err.with_operation("ObjectPage::next_page")
.with_context("service", self.scheme)
Expand Down
8 changes: 4 additions & 4 deletions src/layers/immutable_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl ImmutableDir {
Self { idx }
}

fn inner_next_page(&mut self) -> Option<Vec<output::ObjectEntry>> {
fn inner_next_page(&mut self) -> Option<Vec<output::Entry>> {
if self.idx.is_empty() {
return None;
}
Expand All @@ -204,7 +204,7 @@ impl ImmutableDir {
ObjectMode::FILE
};
let meta = ObjectMetadata::new(mode);
output::ObjectEntry::with(v, meta)
output::Entry::with(v, meta)
})
.collect(),
)
Expand All @@ -213,13 +213,13 @@ impl ImmutableDir {

#[async_trait]
impl output::ObjectPage for ImmutableDir {
async fn next_page(&mut self) -> Result<Option<Vec<output::ObjectEntry>>> {
async fn next_page(&mut self) -> Result<Option<Vec<output::Entry>>> {
Ok(self.inner_next_page())
}
}

impl output::BlockingObjectPage for ImmutableDir {
fn next_page(&mut self) -> Result<Option<Vec<output::ObjectEntry>>> {
fn next_page(&mut self) -> Result<Option<Vec<output::Entry>>> {
Ok(self.inner_next_page())
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/layers/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ impl LoggingPager {

#[async_trait]
impl output::ObjectPage for LoggingPager {
async fn next_page(&mut self) -> Result<Option<Vec<output::ObjectEntry>>> {
async fn next_page(&mut self) -> Result<Option<Vec<output::Entry>>> {
let res = self.inner.next_page().await;

match &res {
Expand Down Expand Up @@ -1455,7 +1455,7 @@ impl BlockingLoggingPager {
}

impl output::BlockingObjectPage for BlockingLoggingPager {
fn next_page(&mut self) -> Result<Option<Vec<output::ObjectEntry>>> {
fn next_page(&mut self) -> Result<Option<Vec<output::Entry>>> {
let res = self.inner.next_page();

match &res {
Expand Down
14 changes: 7 additions & 7 deletions src/layers/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ impl<P> RetryPager<P> {

#[async_trait]
impl<P: output::ObjectPage> output::ObjectPage for RetryPager<P> {
async fn next_page(&mut self) -> Result<Option<Vec<output::ObjectEntry>>> {
async fn next_page(&mut self) -> Result<Option<Vec<output::Entry>>> {
if let Some(sleep) = self.sleep.take() {
tokio::time::sleep(sleep).await;
}
Expand Down Expand Up @@ -740,7 +740,7 @@ impl<P: output::ObjectPage> output::ObjectPage for RetryPager<P> {
}

impl<P: output::BlockingObjectPage> output::BlockingObjectPage for RetryPager<P> {
fn next_page(&mut self) -> Result<Option<Vec<output::ObjectEntry>>> {
fn next_page(&mut self) -> Result<Option<Vec<output::Entry>>> {
{ || self.inner.next_page() }
.retry(&self.policy)
.when(|e| e.is_temporary())
Expand Down Expand Up @@ -866,7 +866,7 @@ mod tests {
}
#[async_trait]
impl output::ObjectPage for MockPager {
async fn next_page(&mut self) -> Result<Option<Vec<output::ObjectEntry>>> {
async fn next_page(&mut self) -> Result<Option<Vec<output::Entry>>> {
self.attempt += 1;
match self.attempt {
1 => Err(Error::new(
Expand All @@ -876,8 +876,8 @@ mod tests {
.set_temporary()),
2 => {
let entries = vec![
output::ObjectEntry::new("hello", ObjectMetadata::new(ObjectMode::FILE)),
output::ObjectEntry::new("world", ObjectMetadata::new(ObjectMode::FILE)),
output::Entry::new("hello", ObjectMetadata::new(ObjectMode::FILE)),
output::Entry::new("world", ObjectMetadata::new(ObjectMode::FILE)),
];
Ok(Some(entries))
}
Expand All @@ -887,8 +887,8 @@ mod tests {
),
4 => {
let entries = vec![
output::ObjectEntry::new("2023/", ObjectMetadata::new(ObjectMode::DIR)),
output::ObjectEntry::new("0208/", ObjectMetadata::new(ObjectMode::DIR)),
output::Entry::new("2023/", ObjectMetadata::new(ObjectMode::DIR)),
output::Entry::new("0208/", ObjectMetadata::new(ObjectMode::DIR)),
];
Ok(Some(entries))
}
Expand Down
4 changes: 2 additions & 2 deletions src/layers/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ impl TracingPager {
#[async_trait]
impl output::ObjectPage for TracingPager {
#[tracing::instrument(parent = &self.span, level = "debug", skip_all)]
async fn next_page(&mut self) -> Result<Option<Vec<output::ObjectEntry>>> {
async fn next_page(&mut self) -> Result<Option<Vec<output::Entry>>> {
self.inner.next_page().await
}
}
Expand All @@ -388,7 +388,7 @@ impl BlockingTracingPager {

impl output::BlockingObjectPage for BlockingTracingPager {
#[tracing::instrument(parent = &self.span, level = "debug", skip_all)]
fn next_page(&mut self) -> Result<Option<Vec<output::ObjectEntry>>> {
fn next_page(&mut self) -> Result<Option<Vec<output::Entry>>> {
self.inner.next_page()
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ mod tests {
assert_eq!(88, size_of::<AccessorMetadata>());
assert_eq!(16, size_of::<Operator>());
assert_eq!(16, size_of::<BatchOperator>());
assert_eq!(184, size_of::<output::ObjectEntry>());
assert_eq!(184, size_of::<output::Entry>());
assert_eq!(48, size_of::<Object>());
assert_eq!(160, size_of::<ObjectMetadata>());
assert_eq!(1, size_of::<ObjectMode>());
Expand Down
14 changes: 3 additions & 11 deletions src/object/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,12 @@ pub struct ObjectLister {
acc: FusedAccessor,
pager: Option<output::ObjectPager>,

buf: VecDeque<output::ObjectEntry>,
buf: VecDeque<output::Entry>,
/// We will move `pager` inside future and return it back while future is ready.
/// Thus, we should not allow calling other function while we already have
/// a future.
#[allow(clippy::type_complexity)]
fut: Option<
BoxFuture<
'static,
(
output::ObjectPager,
Result<Option<Vec<output::ObjectEntry>>>,
),
>,
>,
fut: Option<BoxFuture<'static, (output::ObjectPager, Result<Option<Vec<output::Entry>>>)>>,
}

impl ObjectLister {
Expand Down Expand Up @@ -144,7 +136,7 @@ impl Stream for ObjectLister {
pub struct BlockingObjectLister {
acc: FusedAccessor,
pager: output::BlockingObjectPager,
buf: VecDeque<output::ObjectEntry>,
buf: VecDeque<output::Entry>,
}

impl BlockingObjectLister {
Expand Down
2 changes: 1 addition & 1 deletion src/object/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::*;
///
/// mode and content_length are required metadata that all services
/// should provide during `stat` operation. But in `list` operation,
/// a.k.a., `ObjectEntry`'s content length could be `None`.
/// a.k.a., `Entry`'s content length could be `None`.
#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct ObjectMetadata {
/// Mark if this metadata is complete or not.
Expand Down
22 changes: 11 additions & 11 deletions src/object/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,9 +1160,9 @@ impl Object {
Ok(guard.clone())
}

/// The size of `ObjectEntry`'s corresponding object
/// The size of `Entry`'s corresponding object
///
/// `content_length` is a prefetched metadata field in `ObjectEntry`.
/// `content_length` is a prefetched metadata field in `Entry`.
pub async fn content_length(&self) -> Result<u64> {
{
let guard = self.meta.lock();
Expand All @@ -1178,12 +1178,12 @@ impl Object {
Ok(guard.content_length())
}

/// The MD5 message digest of `ObjectEntry`'s corresponding object
/// The MD5 message digest of `Entry`'s corresponding object
///
/// `content_md5` is a prefetched metadata field in `ObjectEntry`
/// `content_md5` is a prefetched metadata field in `Entry`
///
/// It doesn't mean this metadata field of object doesn't exist if `content_md5` is `None`.
/// Then you have to call `output::ObjectEntry::metadata()` to get the metadata you want.
/// Then you have to call `output::Entry::metadata()` to get the metadata you want.
pub async fn content_md5(&self) -> Result<Option<String>> {
{
let guard = self.meta.lock();
Expand All @@ -1200,12 +1200,12 @@ impl Object {
Ok(guard.content_md5().map(|v| v.to_string()))
}

/// The last modified UTC datetime of `ObjectEntry`'s corresponding object
/// The last modified UTC datetime of `Entry`'s corresponding object
///
/// `last_modified` is a prefetched metadata field in `ObjectEntry`
/// `last_modified` is a prefetched metadata field in `Entry`
///
/// It doesn't mean this metadata field of object doesn't exist if `last_modified` is `None`.
/// Then you have to call `output::ObjectEntry::metadata()` to get the metadata you want.
/// Then you have to call `output::Entry::metadata()` to get the metadata you want.
pub async fn last_modified(&self) -> Result<Option<OffsetDateTime>> {
{
let guard = self.meta.lock();
Expand All @@ -1222,12 +1222,12 @@ impl Object {
Ok(guard.last_modified())
}

/// The ETag string of `ObjectEntry`'s corresponding object
/// The ETag string of `Entry`'s corresponding object
///
/// `etag` is a prefetched metadata field in `ObjectEntry`.
/// `etag` is a prefetched metadata field in `Entry`.
///
/// It doesn't mean this metadata field of object doesn't exist if `etag` is `None`.
/// Then you have to call `output::ObjectEntry::metadata()` to get the metadata you want.
/// Then you have to call `output::Entry::metadata()` to get the metadata you want.
pub async fn etag(&self) -> Result<Option<String>> {
{
let guard = self.meta.lock();
Expand Down
12 changes: 6 additions & 6 deletions src/raw/io/output/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@ use crate::ObjectMetadata;
use crate::ObjectMode;
use crate::Operator;

/// ObjectEntry is returned by `ObjectPage` or `BlockingObjectPage`
/// Entry is returned by `ObjectPage` or `BlockingObjectPage`
/// during list operations.
#[derive(Debug, Clone)]
pub struct ObjectEntry {
pub struct Entry {
path: String,
meta: ObjectMetadata,
}

impl ObjectEntry {
impl Entry {
/// Create a new object entry by its corresponding underlying storage.
pub fn new(path: &str, meta: ObjectMetadata) -> ObjectEntry {
pub fn new(path: &str, meta: ObjectMetadata) -> Entry {
Self::with(path.to_string(), meta)
}

/// Create a new object entry with given value.
pub fn with(path: String, meta: ObjectMetadata) -> ObjectEntry {
pub fn with(path: String, meta: ObjectMetadata) -> Entry {
debug_assert!(
meta.mode().is_dir() == path.ends_with('/'),
"mode {:?} not match with path {}",
meta.mode(),
path
);

ObjectEntry { path, meta }
Entry { path, meta }
}

/// Set path for object entry.
Expand Down
2 changes: 1 addition & 1 deletion src/raw/io/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub use into_streamable::into_streamable_reader;
pub use into_streamable::IntoStreamableReader;

mod entry;
pub use entry::ObjectEntry;
pub use entry::Entry;

mod page;
pub use page::BlockingObjectPage;
Expand Down
20 changes: 10 additions & 10 deletions src/raw/io/output/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,59 +14,59 @@

use async_trait::async_trait;

use super::ObjectEntry;
use super::Entry;
use crate::*;

/// ObjectPage trait is used by [`Accessor`] to implement `list` operation.
///
/// `list` will return a boxed `ObjectPage` which allow users to call `next_page`
/// to fecth a new page of [`ObjectEntry`].
/// to fecth a new page of [`Entry`].
#[async_trait]
pub trait ObjectPage: Send + Sync + 'static {
/// Fetch a new page of [`ObjectEntry`]
/// Fetch a new page of [`Entry`]
///
/// `Ok(None)` means all object pages have been returned. Any following call
/// to `next_page` will always get the same result.
async fn next_page(&mut self) -> Result<Option<Vec<ObjectEntry>>>;
async fn next_page(&mut self) -> Result<Option<Vec<Entry>>>;
}

/// The boxed version of [`ObjectPage`]
pub type ObjectPager = Box<dyn ObjectPage>;

#[async_trait]
impl ObjectPage for ObjectPager {
async fn next_page(&mut self) -> Result<Option<Vec<ObjectEntry>>> {
async fn next_page(&mut self) -> Result<Option<Vec<Entry>>> {
self.as_mut().next_page().await
}
}

#[async_trait]
impl ObjectPage for () {
async fn next_page(&mut self) -> Result<Option<Vec<ObjectEntry>>> {
async fn next_page(&mut self) -> Result<Option<Vec<Entry>>> {
Ok(None)
}
}

/// BlockingObjectPage is the blocking version of [`ObjectPage`].
pub trait BlockingObjectPage: 'static {
/// Fetch a new page of [`ObjectEntry`]
/// Fetch a new page of [`Entry`]
///
/// `Ok(None)` means all object pages have been returned. Any following call
/// to `next_page` will always get the same result.
fn next_page(&mut self) -> Result<Option<Vec<ObjectEntry>>>;
fn next_page(&mut self) -> Result<Option<Vec<Entry>>>;
}

/// BlockingObjectPager is a boxed [`BlockingObjectPage`]
pub type BlockingObjectPager = Box<dyn BlockingObjectPage>;

impl BlockingObjectPage for BlockingObjectPager {
fn next_page(&mut self) -> Result<Option<Vec<ObjectEntry>>> {
fn next_page(&mut self) -> Result<Option<Vec<Entry>>> {
self.as_mut().next_page()
}
}

impl BlockingObjectPage for () {
fn next_page(&mut self) -> Result<Option<Vec<ObjectEntry>>> {
fn next_page(&mut self) -> Result<Option<Vec<Entry>>> {
Ok(None)
}
}
Loading

0 comments on commit 4d8f277

Please sign in to comment.