You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "Xuanwo (via GitHub)" <gi...@apache.org> on 2023/08/15 15:07:47 UTC

[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2869: docs: Add blog on how opendal read data

Xuanwo commented on code in PR #2869:
URL: https://github.com/apache/incubator-opendal/pull/2869#discussion_r1294724375


##########
website/blog/2023-08-15-how-opendal-read-data/index.md:
##########
@@ -0,0 +1,158 @@
+---
+title: "OpenDAL Internal: Data Reading"
+date: 2023-08-15
+slug: how-opendal-read-data
+tags: [internal]
+description: "The first article will discuss OpenDAL's most commonly used data reading function. I will start from the outermost interface and then gradually unfold according to the calling sequence of OpenDAL."
+authors:
+  - name: Xuanwo
+    url: https://github.com/Xuanwo
+    image_url: https://github.com/Xuanwo.png
+---
+
+As the OpenDAL community continues to grow, new abstractions are constantly being added, which has brought some burdens to new contributors participating in development. Many maintainers hope to have a deeper understanding of OpenDAL's internal implementation. At the same time, OpenDAL's core design has not changed significantly for a long time, making it possible to write a series on internal implementation. I believe now is the time to write a series of articles on OpenDAL's internal implementation, to explain from the maintainer's perspective how OpenDAL is designed, implemented, and how it can be expanded. With the impending release of OpenDAL v0.40, I hope this series of articles will better help the community understand the past, master the present, and shape the future.
+
+The first article will discuss OpenDAL's most commonly used data reading function. I will start from the outermost interface and then gradually unfold according to the calling sequence of OpenDAL. Let's get started!
+
+## Overall Framework
+
+Before starting to introduce the specific OpenDAL interface, let's first get familiar with the OpenDAL project.
+
+[OpenDAL](https://github.com/apache/incubator-opendal) is an Apache Incubator project aimed at helping users access data from various storage services in a unified, convenient, and efficient way. Its project [vision](https://opendal.apache.org/docs/vision) is "free access to data":
+
+- Free from services: Any service can be accessed freely through native interfaces
+- Free from implementations: No matter how the underlying implementation is, it can be called in a unified way
+- Free to integrate: Able to freely integrate with various services and languages
+- Free to zero cost: Users don't have to pay for features they don't use
+
+On this philosophical foundation, OpenDAL Rust Core can be mainly divided into the following components:
+
+- Operator: The outer interface exposed to users
+- Layers: Specific implementation of different middleware
+- Services: Specific implementation of different services
+
+From a macroscopic perspective, OpenDAL's data reading call stack would look like this:
+
+![](1.png)
+
+All Layers and Services have implemented a unified Accessor interface, erasing all type information when building the Operator. For the Operator, regardless of what services are used or how many middleware are added, all call logic is consistent. This design splits OpenDAL's API into Public API and Raw API, where the Public API is directly exposed to users, providing convenient top-level interfaces, and Raw API is provided to OpenDAL internal developers, maintaining a unified internal interface and providing some convenient implementation.
+
+## Operator
+
+OpenDAL's Operator API will adhere to a consistent calling paradigm as much as possible, reducing users' learning and usage costs. For example, OpenDAL offers the following APIs for `read`:
+
+- `op.read(path)`: Reads the entire content of the specified file
+- `op.reader(path)`: Creates a Reader for streaming reading
+- `op.read_with(path).range(1..1024)`: Reads file content using specified parameters, such as range
+- `op.reader_with(path).range(1..1024)`: Creates a Reader for streaming reading with specified parameters
+
+It's not hard to see that `read` is more like syntactic sugar, allowing users to quickly read files without considering various traits like `AsyncRead`. The `reader` provides more flexibility, implementing widely-used community traits like `AsyncSeek`, `AsyncRead`, allowing more flexible data reading. `read_with` and `reader_with` assist users in specifying various parameters in a more natural way through Future Builder functions.
+
+The internal logic of the Operator would look like this:
+
+![](2.png)
+
+Its main job is to encapsulate the interface for the user:
+
+- Completing the construction of `OpRead`
+- Calling the `read` function provided by `Accessor`
+- Wrapping the returned value as `Reader` and implementing interfaces like `AsyncSeek`, `AsyncRead`, etc., based on `Reader`
+
+## Layers
+
+A little secret here is that OpenDAL will automatically apply some Layers to the Service to implement some internal logic. As of the completion of this article, OpenDAL's automatically added Layers include:
+
+- `ErrorContextLayer`: Injects context information, such as `scheme`, `path`, etc., into all returned errors of Operation

Review Comment:
   This article is not intended for users who have no knowledge about OpenDAL...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org