You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2025/05/30 16:07:40 UTC

(opendal) 01/01: Save work

This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch add-foyer-services
in repository https://gitbox.apache.org/repos/asf/opendal.git

commit b4235b2535d025d7b6282fd53270c1913a451960
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Tue Apr 29 21:25:54 2025 +0800

    Save work
    
    Signed-off-by: Xuanwo <gi...@xuanwo.io>
---
 core/Cargo.lock                                  | 421 +++++++++++++++++-
 core/Cargo.toml                                  |   3 +
 core/src/services/foyer/backend.rs               |   0
 core/src/services/{fs => foyer}/config.rs        |  17 -
 core/src/services/foyer/core.rs                  |   0
 core/src/services/foyer/delete.rs                |   0
 core/src/services/{fs/config.rs => foyer/mod.rs} |  28 +-
 core/src/services/foyer/reader.rs                |   0
 core/src/services/foyer/writer.rs                |   0
 core/src/services/fs/backend.rs                  | 529 +----------------------
 core/src/services/fs/config.rs                   |  10 +-
 core/src/services/fs/core.rs                     |  68 +--
 12 files changed, 453 insertions(+), 623 deletions(-)

diff --git a/core/Cargo.lock b/core/Cargo.lock
index 653e745b2..40b4576a6 100644
--- a/core/Cargo.lock
+++ b/core/Cargo.lock
@@ -242,6 +242,15 @@ dependencies = [
  "password-hash",
 ]
 
+[[package]]
+name = "array-util"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7e509844de8f09b90a2c3444684a2b6695f4071360e13d2fda0af9f749cc2ed6"
+dependencies = [
+ "arrayvec",
+]
+
 [[package]]
 name = "arrayref"
 version = "0.3.9"
@@ -392,7 +401,7 @@ checksum = "29db05b624fb6352fc11bfe30c54ab1b16a1fe937d7c05a783f4e88ef1292b3b"
 dependencies = [
  "Inflector",
  "async-graphql-parser",
- "darling",
+ "darling 0.20.11",
  "proc-macro-crate",
  "proc-macro2",
  "quote",
@@ -609,6 +618,18 @@ dependencies = [
  "syn 2.0.100",
 ]
 
+[[package]]
+name = "auto_enums"
+version = "0.8.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9c170965892137a3a9aeb000b4524aa3cc022a310e709d848b6e1cdce4ab4781"
+dependencies = [
+ "derive_utils",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.100",
+]
+
 [[package]]
 name = "autocfg"
 version = "1.4.0"
@@ -1838,7 +1859,7 @@ dependencies = [
  "anstream",
  "anstyle",
  "clap_lex",
- "strsim",
+ "strsim 0.11.1",
  "terminal_size",
 ]
 
@@ -1869,6 +1890,15 @@ dependencies = [
  "cc",
 ]
 
+[[package]]
+name = "cmsketch"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "553c840ee51da812c6cd621f9f7e07dfb00a49f91283a8e6380c78cba4f61aba"
+dependencies = [
+ "paste",
+]
+
 [[package]]
 name = "coarsetime"
 version = "0.1.36"
@@ -2377,14 +2407,38 @@ dependencies = [
  "cipher",
 ]
 
+[[package]]
+name = "darling"
+version = "0.14.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850"
+dependencies = [
+ "darling_core 0.14.4",
+ "darling_macro 0.14.4",
+]
+
 [[package]]
 name = "darling"
 version = "0.20.11"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee"
 dependencies = [
- "darling_core",
- "darling_macro",
+ "darling_core 0.20.11",
+ "darling_macro 0.20.11",
+]
+
+[[package]]
+name = "darling_core"
+version = "0.14.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0"
+dependencies = [
+ "fnv",
+ "ident_case",
+ "proc-macro2",
+ "quote",
+ "strsim 0.10.0",
+ "syn 1.0.109",
 ]
 
 [[package]]
@@ -2397,17 +2451,28 @@ dependencies = [
  "ident_case",
  "proc-macro2",
  "quote",
- "strsim",
+ "strsim 0.11.1",
  "syn 2.0.100",
 ]
 
+[[package]]
+name = "darling_macro"
+version = "0.14.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e"
+dependencies = [
+ "darling_core 0.14.4",
+ "quote",
+ "syn 1.0.109",
+]
+
 [[package]]
 name = "darling_macro"
 version = "0.20.11"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead"
 dependencies = [
- "darling_core",
+ "darling_core 0.20.11",
  "quote",
  "syn 2.0.100",
 ]
@@ -2535,7 +2600,7 @@ version = "0.20.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "2d5bcf7b024d6835cfb3d473887cd966994907effbe9227e8c8219824d06c4e8"
 dependencies = [
- "darling",
+ "darling 0.20.11",
  "proc-macro2",
  "quote",
  "syn 2.0.100",
@@ -2575,6 +2640,17 @@ dependencies = [
  "syn 2.0.100",
 ]
 
+[[package]]
+name = "derive_utils"
+version = "0.15.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ccfae181bab5ab6c5478b2ccb69e4c68a02f8c3ec72f6616bfec9dbc599d2ee0"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.100",
+]
+
 [[package]]
 name = "des"
 version = "0.8.1"
@@ -2708,6 +2784,12 @@ version = "0.15.7"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
 
+[[package]]
+name = "downcast-rs"
+version = "1.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2"
+
 [[package]]
 name = "dtoa"
 version = "1.0.10"
@@ -3154,6 +3236,118 @@ dependencies = [
  "uuid",
 ]
 
+[[package]]
+name = "foyer"
+version = "0.16.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "59819ed1a4be90fe66aa13df94adff2365bbb94929ad1052fd977e06b478974e"
+dependencies = [
+ "ahash 0.8.11",
+ "anyhow",
+ "equivalent",
+ "fastrace",
+ "foyer-common",
+ "foyer-memory",
+ "foyer-storage",
+ "madsim-tokio",
+ "mixtrics",
+ "pin-project",
+ "serde",
+ "tokio",
+ "tracing",
+]
+
+[[package]]
+name = "foyer-common"
+version = "0.16.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "06d425cd90d221e1c2cad27717260414cc1d55fa325fd8d02bbd928e4930d7d8"
+dependencies = [
+ "ahash 0.8.11",
+ "bytes",
+ "cfg-if",
+ "fastrace",
+ "itertools 0.14.0",
+ "madsim-tokio",
+ "mixtrics",
+ "parking_lot 0.12.3",
+ "pin-project",
+ "thiserror 2.0.12",
+ "tokio",
+]
+
+[[package]]
+name = "foyer-intrusive-collections"
+version = "0.10.0-dev"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6e4fee46bea69e0596130e3210e65d3424e0ac1e6df3bde6636304bdf1ca4a3b"
+dependencies = [
+ "memoffset 0.9.1",
+]
+
+[[package]]
+name = "foyer-memory"
+version = "0.16.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fd2582199b44afa6f617464335cc50debdff3caaf9a93972369bbf7e42cc630d"
+dependencies = [
+ "ahash 0.8.11",
+ "arc-swap",
+ "bitflags 2.9.0",
+ "cmsketch",
+ "equivalent",
+ "fastrace",
+ "foyer-common",
+ "foyer-intrusive-collections",
+ "hashbrown 0.15.2",
+ "itertools 0.14.0",
+ "madsim-tokio",
+ "mixtrics",
+ "parking_lot 0.12.3",
+ "pin-project",
+ "serde",
+ "thiserror 2.0.12",
+ "tokio",
+ "tracing",
+]
+
+[[package]]
+name = "foyer-storage"
+version = "0.16.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ba8dbd31e2caa79d3816b6924c30cc7eb292eac731d8a2af9c59bec911c27924"
+dependencies = [
+ "ahash 0.8.11",
+ "allocator-api2",
+ "anyhow",
+ "array-util",
+ "auto_enums",
+ "bytes",
+ "clap",
+ "equivalent",
+ "fastrace",
+ "flume",
+ "foyer-common",
+ "foyer-memory",
+ "fs4",
+ "futures-core",
+ "futures-util",
+ "itertools 0.14.0",
+ "libc",
+ "lz4",
+ "madsim-tokio",
+ "ordered_hash_map",
+ "parking_lot 0.12.3",
+ "paste",
+ "pin-project",
+ "rand 0.9.0",
+ "thiserror 2.0.12",
+ "tokio",
+ "tracing",
+ "twox-hash",
+ "zstd",
+]
+
 [[package]]
 name = "fs2"
 version = "0.4.3"
@@ -3164,6 +3358,16 @@ dependencies = [
  "winapi",
 ]
 
+[[package]]
+name = "fs4"
+version = "0.13.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8640e34b88f7652208ce9e88b1a37a2ae95227d84abec377ccd3c5cfeb141ed4"
+dependencies = [
+ "rustix 1.0.5",
+ "windows-sys 0.59.0",
+]
+
 [[package]]
 name = "fs_extra"
 version = "1.3.0"
@@ -3626,6 +3830,15 @@ dependencies = [
  "ahash 0.7.8",
 ]
 
+[[package]]
+name = "hashbrown"
+version = "0.13.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e"
+dependencies = [
+ "ahash 0.8.11",
+]
+
 [[package]]
 name = "hashbrown"
 version = "0.14.5"
@@ -4772,6 +4985,25 @@ dependencies = [
  "linked-hash-map",
 ]
 
+[[package]]
+name = "lz4"
+version = "1.28.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a20b523e860d03443e98350ceaac5e71c6ba89aea7d960769ec3ce37f4de5af4"
+dependencies = [
+ "lz4-sys",
+]
+
+[[package]]
+name = "lz4-sys"
+version = "1.11.1+lz4-1.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6bd8c0d6c6ed0cd30b3652886bb8711dc4bb01d637a68105a3d5158039b418e6"
+dependencies = [
+ "cc",
+ "libc",
+]
+
 [[package]]
 name = "mac"
 version = "0.1.1"
@@ -4826,6 +5058,60 @@ dependencies = [
  "syn 2.0.100",
 ]
 
+[[package]]
+name = "madsim"
+version = "0.2.31"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b3c97f34bb19cf6a435a4da2187e90acc6bc59faa730e493b28b6d33e1bb9ccb"
+dependencies = [
+ "ahash 0.8.11",
+ "async-channel 2.3.1",
+ "async-stream",
+ "async-task",
+ "bincode",
+ "bytes",
+ "downcast-rs",
+ "futures-util",
+ "lazy_static",
+ "libc",
+ "madsim-macros",
+ "naive-timer",
+ "panic-message",
+ "rand 0.8.5",
+ "rand_xoshiro",
+ "rustversion",
+ "serde",
+ "spin",
+ "tokio",
+ "tokio-util",
+ "toml",
+ "tracing",
+ "tracing-subscriber",
+]
+
+[[package]]
+name = "madsim-macros"
+version = "0.2.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f3d248e97b1a48826a12c3828d921e8548e714394bf17274dd0a93910dc946e1"
+dependencies = [
+ "darling 0.14.4",
+ "proc-macro2",
+ "quote",
+ "syn 1.0.109",
+]
+
+[[package]]
+name = "madsim-tokio"
+version = "0.2.30"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7d3eb2acc57c82d21d699119b859e2df70a91dbdb84734885a1e72be83bdecb5"
+dependencies = [
+ "madsim",
+ "spin",
+ "tokio",
+]
+
 [[package]]
 name = "maplit"
 version = "1.0.2"
@@ -4905,6 +5191,15 @@ dependencies = [
  "autocfg",
 ]
 
+[[package]]
+name = "memoffset"
+version = "0.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
+dependencies = [
+ "autocfg",
+]
+
 [[package]]
 name = "metrics"
 version = "0.24.1"
@@ -5017,6 +5312,16 @@ dependencies = [
  "windows-sys 0.52.0",
 ]
 
+[[package]]
+name = "mixtrics"
+version = "0.0.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "41434672bd2f5df1b8ed58e0cee0a7a1000bf8dd711cea5a5540afcf41f7d7fb"
+dependencies = [
+ "itertools 0.14.0",
+ "parking_lot 0.12.3",
+]
+
 [[package]]
 name = "moka"
 version = "0.12.10"
@@ -5077,7 +5382,7 @@ dependencies = [
  "sha2",
  "socket2",
  "stringprep",
- "strsim",
+ "strsim 0.11.1",
  "take_mut",
  "thiserror 1.0.69",
  "tokio",
@@ -5157,6 +5462,12 @@ version = "0.10.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "defc4c55412d89136f966bbb339008b474350e5e6e78d2714439c386b3137a03"
 
+[[package]]
+name = "naive-timer"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "034a0ad7deebf0c2abcf2435950a6666c3c15ea9d8fad0c0f48efa8a7f843fed"
+
 [[package]]
 name = "nanoid"
 version = "0.4.0"
@@ -5245,7 +5556,7 @@ dependencies = [
  "bitflags 1.3.2",
  "cfg-if",
  "libc",
- "memoffset",
+ "memoffset 0.7.1",
  "pin-utils",
 ]
 
@@ -5465,6 +5776,7 @@ dependencies = [
  "fastrace-jaeger",
  "flume",
  "foundationdb",
+ "foyer",
  "futures",
  "futures-rustls",
  "getrandom 0.2.15",
@@ -5829,6 +6141,15 @@ dependencies = [
  "hashbrown 0.14.5",
 ]
 
+[[package]]
+name = "ordered_hash_map"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ab0e5f22bf6dd04abd854a8874247813a8fa2c8c1260eba6fbb150270ce7c176"
+dependencies = [
+ "hashbrown 0.13.2",
+]
+
 [[package]]
 name = "os_pipe"
 version = "1.2.1"
@@ -6816,6 +7137,15 @@ dependencies = [
  "rand_core 0.5.1",
 ]
 
+[[package]]
+name = "rand_xoshiro"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa"
+dependencies = [
+ "rand_core 0.6.4",
+]
+
 [[package]]
 name = "raw-cpuid"
 version = "11.5.0"
@@ -7732,6 +8062,15 @@ dependencies = [
  "serde",
 ]
 
+[[package]]
+name = "serde_spanned"
+version = "0.6.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1"
+dependencies = [
+ "serde",
+]
+
 [[package]]
 name = "serde_urlencoded"
 version = "0.7.1"
@@ -7768,7 +8107,7 @@ version = "3.12.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "8d00caa5193a3c8362ac2b73be6b9e768aa5a4b2f721d8f4b339600c3cb51f8e"
 dependencies = [
- "darling",
+ "darling 0.20.11",
  "proc-macro2",
  "quote",
  "syn 2.0.100",
@@ -8361,6 +8700,12 @@ dependencies = [
  "unicode-properties",
 ]
 
+[[package]]
+name = "strsim"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
+
 [[package]]
 name = "strsim"
 version = "0.11.1"
@@ -8525,7 +8870,7 @@ dependencies = [
  "sha2",
  "snap",
  "storekey",
- "strsim",
+ "strsim 0.11.1",
  "subtle",
  "sysinfo",
  "thiserror 1.0.69",
@@ -8964,11 +9309,26 @@ dependencies = [
  "tokio",
 ]
 
+[[package]]
+name = "toml"
+version = "0.8.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cd87a5cdd6ffab733b2f74bc4fd7ee5fff6634124999ac278c35fc78c6120148"
+dependencies = [
+ "serde",
+ "serde_spanned",
+ "toml_datetime",
+ "toml_edit",
+]
+
 [[package]]
 name = "toml_datetime"
 version = "0.6.8"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
+dependencies = [
+ "serde",
+]
 
 [[package]]
 name = "toml_edit"
@@ -8977,6 +9337,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474"
 dependencies = [
  "indexmap 2.9.0",
+ "serde",
+ "serde_spanned",
  "toml_datetime",
  "winnow",
 ]
@@ -9264,6 +9626,15 @@ dependencies = [
  "utf-8",
 ]
 
+[[package]]
+name = "twox-hash"
+version = "2.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e7b17f197b3050ba473acf9181f7b1d3b66d1cf7356c6cc57886662276e65908"
+dependencies = [
+ "rand 0.8.5",
+]
+
 [[package]]
 name = "typed-builder"
 version = "0.10.0"
@@ -10435,3 +10806,31 @@ checksum = "70b40401a28d86ce16a330b863b86fd7dbee4d7c940587ab09ab8c019f9e3fdf"
 dependencies = [
  "num-traits",
 ]
+
+[[package]]
+name = "zstd"
+version = "0.13.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a"
+dependencies = [
+ "zstd-safe",
+]
+
+[[package]]
+name = "zstd-safe"
+version = "7.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8f49c4d5f0abb602a93fb8736af2a4f4dd9512e36f7f570d66e65ff867ed3b9d"
+dependencies = [
+ "zstd-sys",
+]
+
+[[package]]
+name = "zstd-sys"
+version = "2.0.15+zstd.1.5.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eb81183ddd97d0c74cedf1d50d85c8d08c1b8b68ee863bdee9e706eedba1a237"
+dependencies = [
+ "cc",
+ "pkg-config",
+]
diff --git a/core/Cargo.toml b/core/Cargo.toml
index b02dfa2da..462de064a 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -139,6 +139,7 @@ services-dbfs = []
 services-dropbox = []
 services-etcd = ["dep:etcd-client", "dep:bb8"]
 services-foundationdb = ["dep:foundationdb"]
+services-foyer = ["dep:foyer"]
 services-fs = ["tokio/fs", "internal-tokio-rt"]
 services-ftp = [
   "dep:suppaftp",
@@ -333,6 +334,8 @@ redis = { version = "0.29", features = [
 rocksdb = { version = "0.21.0", default-features = false, optional = true }
 # for services-sled
 sled = { version = "0.34.7", optional = true }
+# for services-foyer
+foyer = { version = "0.16", optional = true }
 # for services-ftp
 futures-rustls = { version = "0.26.0", optional = true }
 rustls-native-certs = { version = "0.8", optional = true }
diff --git a/core/src/services/foyer/backend.rs b/core/src/services/foyer/backend.rs
new file mode 100644
index 000000000..e69de29bb
diff --git a/core/src/services/fs/config.rs b/core/src/services/foyer/config.rs
similarity index 68%
copy from core/src/services/fs/config.rs
copy to core/src/services/foyer/config.rs
index eb501ee8c..b248758bc 100644
--- a/core/src/services/fs/config.rs
+++ b/core/src/services/foyer/config.rs
@@ -14,20 +14,3 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
-
-use std::fmt::Debug;
-
-use serde::Deserialize;
-use serde::Serialize;
-
-/// config for file system
-#[derive(Default, Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
-#[serde(default)]
-#[non_exhaustive]
-pub struct FsConfig {
-    /// root dir for backend
-    pub root: Option<String>,
-
-    /// tmp dir for atomic write
-    pub atomic_write_dir: Option<String>,
-}
diff --git a/core/src/services/foyer/core.rs b/core/src/services/foyer/core.rs
new file mode 100644
index 000000000..e69de29bb
diff --git a/core/src/services/foyer/delete.rs b/core/src/services/foyer/delete.rs
new file mode 100644
index 000000000..e69de29bb
diff --git a/core/src/services/fs/config.rs b/core/src/services/foyer/mod.rs
similarity index 69%
copy from core/src/services/fs/config.rs
copy to core/src/services/foyer/mod.rs
index eb501ee8c..31f0a5e7b 100644
--- a/core/src/services/fs/config.rs
+++ b/core/src/services/foyer/mod.rs
@@ -15,19 +15,19 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use std::fmt::Debug;
+#[cfg(feature = "services-foyer")]
+mod core;
+#[cfg(feature = "services-foyer")]
+mod delete;
+#[cfg(feature = "services-foyer")]
+mod reader;
+#[cfg(feature = "services-foyer")]
+mod writer;
 
-use serde::Deserialize;
-use serde::Serialize;
+#[cfg(feature = "services-foyer")]
+mod backend;
+#[cfg(feature = "services-foyer")]
+pub use backend::FsBuilder as Fs;
 
-/// config for file system
-#[derive(Default, Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
-#[serde(default)]
-#[non_exhaustive]
-pub struct FsConfig {
-    /// root dir for backend
-    pub root: Option<String>,
-
-    /// tmp dir for atomic write
-    pub atomic_write_dir: Option<String>,
-}
+mod config;
+pub use config::FsConfig;
diff --git a/core/src/services/foyer/reader.rs b/core/src/services/foyer/reader.rs
new file mode 100644
index 000000000..e69de29bb
diff --git a/core/src/services/foyer/writer.rs b/core/src/services/foyer/writer.rs
new file mode 100644
index 000000000..e69de29bb
diff --git a/core/src/services/fs/backend.rs b/core/src/services/fs/backend.rs
index 1432b0ee8..4a13b48d0 100644
--- a/core/src/services/fs/backend.rs
+++ b/core/src/services/fs/backend.rs
@@ -15,6 +15,7 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use std::format::Debug;
 use std::io::SeekFrom;
 use std::path::Path;
 use std::path::PathBuf;
@@ -23,6 +24,7 @@ use std::sync::Arc;
 use chrono::DateTime;
 use log::debug;
 
+use super::config::*;
 use super::core::*;
 use super::delete::FsDeleter;
 use super::lister::FsLister;
@@ -30,121 +32,45 @@ use super::reader::FsReader;
 use super::writer::FsWriter;
 use super::writer::FsWriters;
 use crate::raw::*;
-use crate::services::FsConfig;
 use crate::*;
 
-impl Configurator for FsConfig {
-    type Builder = FsBuilder;
+impl Configurator for FoyerConfig {
+    type Builder = FoyerBuilder;
     fn into_builder(self) -> Self::Builder {
-        FsBuilder { config: self }
+        FoyerBuilder { config: self }
     }
 }
 
-/// POSIX file system support.
+/// Foyer service support
 #[doc = include_str!("docs.md")]
-#[derive(Default, Debug)]
-pub struct FsBuilder {
-    config: FsConfig,
+#[derive(Default)]
+pub struct FoyerBuilder {
+    config: FoyerConfig,
+    builder: foyer::HybridCacheBuilder<String, Buffer>,
 }
 
-impl FsBuilder {
-    /// Set root for backend.
-    pub fn root(mut self, root: &str) -> Self {
-        self.config.root = if root.is_empty() {
-            None
-        } else {
-            Some(root.to_string())
-        };
-
-        self
+impl Debug for FoyerBuilder {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("FoyerBuilder")
+            .field("config", &self.config)
+            .finish()
     }
+}
 
-    /// Set temp dir for atomic write.
-    ///
-    /// # Notes
-    ///
-    /// - When append is enabled, we will not use atomic write
-    ///   to avoid data loss and performance issue.
-    pub fn atomic_write_dir(mut self, dir: &str) -> Self {
-        if !dir.is_empty() {
-            self.config.atomic_write_dir = Some(dir.to_string());
-        }
-
+impl FoyerBuilder {
+    /// Set root for backend.
+    pub fn builder(mut self, builder: foyer::HybridCacheBuilder<String, Buffer>) -> Self {
+        self.builder = builder;
         self
     }
 }
 
-impl Builder for FsBuilder {
+impl Builder for FoyerBuilder {
     const SCHEME: Scheme = Scheme::Fs;
-    type Config = FsConfig;
+    type Config = FoyerConfig;
 
     fn build(self) -> Result<impl Access> {
-        debug!("backend build started: {:?}", &self);
-
-        let root = match self.config.root.map(PathBuf::from) {
-            Some(root) => Ok(root),
-            None => Err(Error::new(
-                ErrorKind::ConfigInvalid,
-                "root is not specified",
-            )),
-        }?;
-        debug!("backend use root {}", root.to_string_lossy());
-
-        // If root dir is not exist, we must create it.
-        if let Err(e) = std::fs::metadata(&root) {
-            if e.kind() == std::io::ErrorKind::NotFound {
-                std::fs::create_dir_all(&root).map_err(|e| {
-                    Error::new(ErrorKind::Unexpected, "create root dir failed")
-                        .with_operation("Builder::build")
-                        .with_context("root", root.to_string_lossy())
-                        .set_source(e)
-                })?;
-            }
-        }
-
-        let atomic_write_dir = self.config.atomic_write_dir.map(PathBuf::from);
-
-        // If atomic write dir is not exist, we must create it.
-        if let Some(d) = &atomic_write_dir {
-            if let Err(e) = std::fs::metadata(d) {
-                if e.kind() == std::io::ErrorKind::NotFound {
-                    std::fs::create_dir_all(d).map_err(|e| {
-                        Error::new(ErrorKind::Unexpected, "create atomic write dir failed")
-                            .with_operation("Builder::build")
-                            .with_context("atomic_write_dir", d.to_string_lossy())
-                            .set_source(e)
-                    })?;
-                }
-            }
-        }
-
-        // Canonicalize the root directory. This should work since we already know that we can
-        // get the metadata of the path.
-        let root = root.canonicalize().map_err(|e| {
-            Error::new(
-                ErrorKind::Unexpected,
-                "canonicalize of root directory failed",
-            )
-            .with_operation("Builder::build")
-            .with_context("root", root.to_string_lossy())
-            .set_source(e)
-        })?;
-
-        // Canonicalize the atomic_write_dir directory. This should work since we already know that
-        // we can get the metadata of the path.
-        let atomic_write_dir = atomic_write_dir
-            .map(|p| {
-                p.canonicalize().map(Some).map_err(|e| {
-                    Error::new(
-                        ErrorKind::Unexpected,
-                        "canonicalize of atomic_write_dir directory failed",
-                    )
-                    .with_operation("Builder::build")
-                    .with_context("root", root.to_string_lossy())
-                    .set_source(e)
-                })
-            })
-            .unwrap_or(Ok(None))?;
+        let cache = self.builder.build()?;
 
         Ok(FsBackend {
             core: Arc::new(FsCore {
@@ -194,412 +120,3 @@ impl Builder for FsBuilder {
 pub struct FsBackend {
     core: Arc<FsCore>,
 }
-
-impl Access for FsBackend {
-    type Reader = FsReader<tokio::fs::File>;
-    type Writer = FsWriters;
-    type Lister = Option<FsLister<tokio::fs::ReadDir>>;
-    type Deleter = oio::OneShotDeleter<FsDeleter>;
-    type BlockingReader = FsReader<std::fs::File>;
-    type BlockingWriter = FsWriter<std::fs::File>;
-    type BlockingLister = Option<FsLister<std::fs::ReadDir>>;
-    type BlockingDeleter = oio::OneShotDeleter<FsDeleter>;
-
-    fn info(&self) -> Arc<AccessorInfo> {
-        self.core.info.clone()
-    }
-
-    async fn create_dir(&self, path: &str, _: OpCreateDir) -> Result<RpCreateDir> {
-        let p = self.core.root.join(path.trim_end_matches('/'));
-
-        tokio::fs::create_dir_all(&p)
-            .await
-            .map_err(new_std_io_error)?;
-
-        Ok(RpCreateDir::default())
-    }
-
-    async fn stat(&self, path: &str, _: OpStat) -> Result<RpStat> {
-        let p = self.core.root.join(path.trim_end_matches('/'));
-
-        let meta = tokio::fs::metadata(&p).await.map_err(new_std_io_error)?;
-
-        let mode = if meta.is_dir() {
-            EntryMode::DIR
-        } else if meta.is_file() {
-            EntryMode::FILE
-        } else {
-            EntryMode::Unknown
-        };
-        let m = Metadata::new(mode)
-            .with_content_length(meta.len())
-            .with_last_modified(
-                meta.modified()
-                    .map(DateTime::from)
-                    .map_err(new_std_io_error)?,
-            );
-
-        Ok(RpStat::new(m))
-    }
-
-    /// # Notes
-    ///
-    /// There are three ways to get the total file length:
-    ///
-    /// - call std::fs::metadata directly and then open. (400ns)
-    /// - open file first, and then use `f.metadata()` (300ns)
-    /// - open file first, and then use `seek`. (100ns)
-    ///
-    /// Benchmark could be found [here](https://gist.github.com/Xuanwo/48f9cfbc3022ea5f865388bb62e1a70f)
-    async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::Reader)> {
-        let p = self.core.root.join(path.trim_end_matches('/'));
-
-        let mut f = tokio::fs::OpenOptions::new()
-            .read(true)
-            .open(&p)
-            .await
-            .map_err(new_std_io_error)?;
-
-        if args.range().offset() != 0 {
-            use tokio::io::AsyncSeekExt;
-
-            f.seek(SeekFrom::Start(args.range().offset()))
-                .await
-                .map_err(new_std_io_error)?;
-        }
-
-        let r = FsReader::new(
-            self.core.clone(),
-            f,
-            args.range().size().unwrap_or(u64::MAX) as _,
-        );
-        Ok((RpRead::new(), r))
-    }
-
-    async fn write(&self, path: &str, op: OpWrite) -> Result<(RpWrite, Self::Writer)> {
-        let (target_path, tmp_path) = if let Some(atomic_write_dir) = &self.core.atomic_write_dir {
-            let target_path = self
-                .core
-                .ensure_write_abs_path(&self.core.root, path)
-                .await?;
-            let tmp_path = self
-                .core
-                .ensure_write_abs_path(atomic_write_dir, &tmp_file_of(path))
-                .await?;
-
-            // If the target file exists, we should append to the end of it directly.
-            if op.append()
-                && tokio::fs::try_exists(&target_path)
-                    .await
-                    .map_err(new_std_io_error)?
-            {
-                (target_path, None)
-            } else {
-                (target_path, Some(tmp_path))
-            }
-        } else {
-            let p = self
-                .core
-                .ensure_write_abs_path(&self.core.root, path)
-                .await?;
-
-            (p, None)
-        };
-
-        let mut open_options = tokio::fs::OpenOptions::new();
-        if op.if_not_exists() {
-            open_options.create_new(true);
-        } else {
-            open_options.create(true);
-        }
-
-        open_options.write(true);
-
-        if op.append() {
-            open_options.append(true);
-        } else {
-            open_options.truncate(true);
-        }
-
-        let f = open_options
-            .open(tmp_path.as_ref().unwrap_or(&target_path))
-            .await
-            .map_err(|e| {
-                match e.kind() {
-                    std::io::ErrorKind::AlreadyExists => {
-                        // Map io AlreadyExists to opendal ConditionNotMatch
-                        Error::new(
-                            ErrorKind::ConditionNotMatch,
-                            "The file already exists in the filesystem",
-                        )
-                        .set_source(e)
-                    }
-                    _ => new_std_io_error(e),
-                }
-            })?;
-
-        let w = FsWriter::new(target_path, tmp_path, f);
-
-        let w = if op.append() {
-            FsWriters::One(w)
-        } else {
-            FsWriters::Two(oio::PositionWriter::new(
-                self.info().clone(),
-                w,
-                op.concurrent(),
-            ))
-        };
-
-        Ok((RpWrite::default(), w))
-    }
-
-    async fn delete(&self) -> Result<(RpDelete, Self::Deleter)> {
-        Ok((
-            RpDelete::default(),
-            oio::OneShotDeleter::new(FsDeleter::new(self.core.clone())),
-        ))
-    }
-
-    async fn list(&self, path: &str, _: OpList) -> Result<(RpList, Self::Lister)> {
-        let p = self.core.root.join(path.trim_end_matches('/'));
-
-        let f = match tokio::fs::read_dir(&p).await {
-            Ok(rd) => rd,
-            Err(e) => {
-                return if e.kind() == std::io::ErrorKind::NotFound {
-                    Ok((RpList::default(), None))
-                } else {
-                    Err(new_std_io_error(e))
-                };
-            }
-        };
-
-        let rd = FsLister::new(&self.core.root, path, f);
-        Ok((RpList::default(), Some(rd)))
-    }
-
-    async fn copy(&self, from: &str, to: &str, _args: OpCopy) -> Result<RpCopy> {
-        let from = self.core.root.join(from.trim_end_matches('/'));
-
-        // try to get the metadata of the source file to ensure it exists
-        tokio::fs::metadata(&from).await.map_err(new_std_io_error)?;
-
-        let to = self
-            .core
-            .ensure_write_abs_path(&self.core.root, to.trim_end_matches('/'))
-            .await?;
-
-        tokio::fs::copy(from, to).await.map_err(new_std_io_error)?;
-
-        Ok(RpCopy::default())
-    }
-
-    async fn rename(&self, from: &str, to: &str, _args: OpRename) -> Result<RpRename> {
-        let from = self.core.root.join(from.trim_end_matches('/'));
-
-        // try to get the metadata of the source file to ensure it exists
-        tokio::fs::metadata(&from).await.map_err(new_std_io_error)?;
-
-        let to = self
-            .core
-            .ensure_write_abs_path(&self.core.root, to.trim_end_matches('/'))
-            .await?;
-
-        tokio::fs::rename(from, to)
-            .await
-            .map_err(new_std_io_error)?;
-
-        Ok(RpRename::default())
-    }
-
-    fn blocking_create_dir(&self, path: &str, _: OpCreateDir) -> Result<RpCreateDir> {
-        let p = self.core.root.join(path.trim_end_matches('/'));
-
-        std::fs::create_dir_all(p).map_err(new_std_io_error)?;
-
-        Ok(RpCreateDir::default())
-    }
-
-    fn blocking_stat(&self, path: &str, _: OpStat) -> Result<RpStat> {
-        let p = self.core.root.join(path.trim_end_matches('/'));
-
-        let meta = std::fs::metadata(p).map_err(new_std_io_error)?;
-
-        let mode = if meta.is_dir() {
-            EntryMode::DIR
-        } else if meta.is_file() {
-            EntryMode::FILE
-        } else {
-            EntryMode::Unknown
-        };
-        let m = Metadata::new(mode)
-            .with_content_length(meta.len())
-            .with_last_modified(
-                meta.modified()
-                    .map(DateTime::from)
-                    .map_err(new_std_io_error)?,
-            );
-
-        Ok(RpStat::new(m))
-    }
-
-    fn blocking_read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::BlockingReader)> {
-        let p = self.core.root.join(path.trim_end_matches('/'));
-
-        let mut f = std::fs::OpenOptions::new()
-            .read(true)
-            .open(p)
-            .map_err(new_std_io_error)?;
-
-        if args.range().offset() != 0 {
-            use std::io::Seek;
-
-            f.seek(SeekFrom::Start(args.range().offset()))
-                .map_err(new_std_io_error)?;
-        }
-
-        let r = FsReader::new(
-            self.core.clone(),
-            f,
-            args.range().size().unwrap_or(u64::MAX) as _,
-        );
-        Ok((RpRead::new(), r))
-    }
-
-    fn blocking_write(&self, path: &str, op: OpWrite) -> Result<(RpWrite, Self::BlockingWriter)> {
-        let (target_path, tmp_path) = if let Some(atomic_write_dir) = &self.core.atomic_write_dir {
-            let target_path = self
-                .core
-                .blocking_ensure_write_abs_path(&self.core.root, path)?;
-            let tmp_path = self
-                .core
-                .blocking_ensure_write_abs_path(atomic_write_dir, &tmp_file_of(path))?;
-
-            // If the target file exists, we should append to the end of it directly.
-            if op.append()
-                && Path::new(&target_path)
-                    .try_exists()
-                    .map_err(new_std_io_error)?
-            {
-                (target_path, None)
-            } else {
-                (target_path, Some(tmp_path))
-            }
-        } else {
-            let p = self
-                .core
-                .blocking_ensure_write_abs_path(&self.core.root, path)?;
-
-            (p, None)
-        };
-
-        let mut f = std::fs::OpenOptions::new();
-
-        if op.if_not_exists() {
-            f.create_new(true);
-        } else {
-            f.create(true);
-        }
-
-        f.write(true);
-
-        if op.append() {
-            f.append(true);
-        } else {
-            f.truncate(true);
-        }
-
-        let f = f
-            .open(tmp_path.as_ref().unwrap_or(&target_path))
-            .map_err(|e| {
-                match e.kind() {
-                    std::io::ErrorKind::AlreadyExists => {
-                        // Map io AlreadyExists to opendal ConditionNotMatch
-                        Error::new(
-                            ErrorKind::ConditionNotMatch,
-                            "The file already exists in the filesystem",
-                        )
-                        .set_source(e)
-                    }
-                    _ => new_std_io_error(e),
-                }
-            })?;
-
-        Ok((RpWrite::new(), FsWriter::new(target_path, tmp_path, f)))
-    }
-
-    fn blocking_delete(&self) -> Result<(RpDelete, Self::BlockingDeleter)> {
-        Ok((
-            RpDelete::default(),
-            oio::OneShotDeleter::new(FsDeleter::new(self.core.clone())),
-        ))
-    }
-
-    fn blocking_list(&self, path: &str, _: OpList) -> Result<(RpList, Self::BlockingLister)> {
-        let p = self.core.root.join(path.trim_end_matches('/'));
-
-        let f = match std::fs::read_dir(p) {
-            Ok(rd) => rd,
-            Err(e) => {
-                return if e.kind() == std::io::ErrorKind::NotFound {
-                    Ok((RpList::default(), None))
-                } else {
-                    Err(new_std_io_error(e))
-                };
-            }
-        };
-
-        let rd = FsLister::new(&self.core.root, path, f);
-        Ok((RpList::default(), Some(rd)))
-    }
-
-    fn blocking_copy(&self, from: &str, to: &str, _args: OpCopy) -> Result<RpCopy> {
-        let from = self.core.root.join(from.trim_end_matches('/'));
-
-        // try to get the metadata of the source file to ensure it exists
-        std::fs::metadata(&from).map_err(new_std_io_error)?;
-
-        let to = self
-            .core
-            .blocking_ensure_write_abs_path(&self.core.root, to.trim_end_matches('/'))?;
-
-        std::fs::copy(from, to).map_err(new_std_io_error)?;
-
-        Ok(RpCopy::default())
-    }
-
-    fn blocking_rename(&self, from: &str, to: &str, _args: OpRename) -> Result<RpRename> {
-        let from = self.core.root.join(from.trim_end_matches('/'));
-
-        // try to get the metadata of the source file to ensure it exists
-        std::fs::metadata(&from).map_err(new_std_io_error)?;
-
-        let to = self
-            .core
-            .blocking_ensure_write_abs_path(&self.core.root, to.trim_end_matches('/'))?;
-
-        std::fs::rename(from, to).map_err(new_std_io_error)?;
-
-        Ok(RpRename::default())
-    }
-}
-
-#[cfg(test)]
-mod tests {
-    use super::*;
-
-    #[test]
-    fn test_tmp_file_of() {
-        let cases = vec![
-            ("hello.txt", "hello.txt"),
-            ("/tmp/opendal.log", "opendal.log"),
-            ("/abc/def/hello.parquet", "hello.parquet"),
-        ];
-
-        for (path, expected_prefix) in cases {
-            let tmp_file = tmp_file_of(path);
-            assert!(tmp_file.len() > expected_prefix.len());
-            assert!(tmp_file.starts_with(expected_prefix));
-        }
-    }
-}
diff --git a/core/src/services/fs/config.rs b/core/src/services/fs/config.rs
index eb501ee8c..fc8bb1927 100644
--- a/core/src/services/fs/config.rs
+++ b/core/src/services/fs/config.rs
@@ -20,14 +20,8 @@ use std::fmt::Debug;
 use serde::Deserialize;
 use serde::Serialize;
 
-/// config for file system
+/// config for foyer config
 #[derive(Default, Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
 #[serde(default)]
 #[non_exhaustive]
-pub struct FsConfig {
-    /// root dir for backend
-    pub root: Option<String>,
-
-    /// tmp dir for atomic write
-    pub atomic_write_dir: Option<String>,
-}
+pub struct FoyerConfig {}
diff --git a/core/src/services/fs/core.rs b/core/src/services/fs/core.rs
index e55d7ef1f..862963fce 100644
--- a/core/src/services/fs/core.rs
+++ b/core/src/services/fs/core.rs
@@ -26,71 +26,5 @@ use crate::*;
 #[derive(Debug)]
 pub struct FsCore {
     pub info: Arc<AccessorInfo>,
-    pub root: PathBuf,
-    pub atomic_write_dir: Option<PathBuf>,
-    pub buf_pool: oio::PooledBuf,
-}
-
-impl FsCore {
-    // Synchronously build write path and ensure the parent dirs created
-    pub fn blocking_ensure_write_abs_path(&self, parent: &Path, path: &str) -> Result<PathBuf> {
-        let p = parent.join(path);
-
-        // Create dir before write path.
-        //
-        // TODO(xuanwo): There are many works to do here:
-        //   - Is it safe to create dir concurrently?
-        //   - Do we need to extract this logic as new util functions?
-        //   - Is it better to check the parent dir exists before call mkdir?
-        let parent = PathBuf::from(&p)
-            .parent()
-            .ok_or_else(|| {
-                Error::new(
-                    ErrorKind::Unexpected,
-                    "path should have parent but not, it must be malformed",
-                )
-                .with_context("input", p.to_string_lossy())
-            })?
-            .to_path_buf();
-
-        std::fs::create_dir_all(parent).map_err(new_std_io_error)?;
-
-        Ok(p)
-    }
-
-    // Build write path and ensure the parent dirs created
-    pub async fn ensure_write_abs_path(&self, parent: &Path, path: &str) -> Result<PathBuf> {
-        let p = parent.join(path);
-
-        // Create dir before write path.
-        //
-        // TODO(xuanwo): There are many works to do here:
-        //   - Is it safe to create dir concurrently?
-        //   - Do we need to extract this logic as new util functions?
-        //   - Is it better to check the parent dir exists before call mkdir?
-        let parent = PathBuf::from(&p)
-            .parent()
-            .ok_or_else(|| {
-                Error::new(
-                    ErrorKind::Unexpected,
-                    "path should have parent but not, it must be malformed",
-                )
-                .with_context("input", p.to_string_lossy())
-            })?
-            .to_path_buf();
-
-        tokio::fs::create_dir_all(&parent)
-            .await
-            .map_err(new_std_io_error)?;
-
-        Ok(p)
-    }
-}
-
-#[inline]
-pub fn tmp_file_of(path: &str) -> String {
-    let name = get_basename(path);
-    let uuid = Uuid::new_v4().to_string();
-
-    format!("{name}.{uuid}")
+    pub cache: foyer::HybridCache<String, Buffer>,
 }