From 512d2926cb744c551d9db09cfa1179a2b8ed9f21 Mon Sep 17 00:00:00 2001 From: zyy17 Date: Wed, 27 Aug 2025 10:31:56 -0700 Subject: [PATCH] refactor: add `enable_read_cache` config to support disable read cache explicitly Signed-off-by: zyy17 --- config/config.md | 2 ++ config/datanode.example.toml | 3 +++ config/standalone.example.toml | 3 +++ src/datanode/src/store.rs | 4 ++++ src/object-store/src/config.rs | 15 +++++++++++++++ 5 files changed, 27 insertions(+) diff --git a/config/config.md b/config/config.md index b600ec0de6..fd03131c88 100644 --- a/config/config.md +++ b/config/config.md @@ -103,6 +103,7 @@ | `storage` | -- | -- | The data storage options. | | `storage.data_home` | String | `./greptimedb_data` | The working home directory. | | `storage.type` | String | `File` | The storage type used to store the data.
- `File`: the data is stored in the local file system.
- `S3`: the data is stored in the S3 object storage.
- `Gcs`: the data is stored in the Google Cloud Storage.
- `Azblob`: the data is stored in the Azure Blob Storage.
- `Oss`: the data is stored in the Aliyun OSS. | +| `storage.enable_read_cache` | Bool | `true` | Whether to enable read cache. If not set, the read cache will be enabled by default. | | `storage.cache_path` | String | Unset | Read cache configuration for object storage such as 'S3' etc, it's configured by default when using object storage. It is recommended to configure it when using object storage for better performance.
A local file directory, defaults to `{data_home}`. An empty string means disabling. | | `storage.cache_capacity` | String | Unset | The local file cache capacity in bytes. If your disk space is sufficient, it is recommended to set it larger. | | `storage.bucket` | String | Unset | The S3 bucket name.
**It's only used when the storage type is `S3`, `Oss` and `Gcs`**. | @@ -494,6 +495,7 @@ | `storage.data_home` | String | `./greptimedb_data` | The working home directory. | | `storage.type` | String | `File` | The storage type used to store the data.
- `File`: the data is stored in the local file system.
- `S3`: the data is stored in the S3 object storage.
- `Gcs`: the data is stored in the Google Cloud Storage.
- `Azblob`: the data is stored in the Azure Blob Storage.
- `Oss`: the data is stored in the Aliyun OSS. | | `storage.cache_path` | String | Unset | Read cache configuration for object storage such as 'S3' etc, it's configured by default when using object storage. It is recommended to configure it when using object storage for better performance.
A local file directory, defaults to `{data_home}`. An empty string means disabling. | +| `storage.enable_read_cache` | Bool | `true` | Whether to enable read cache. If not set, the read cache will be enabled by default. | | `storage.cache_capacity` | String | Unset | The local file cache capacity in bytes. If your disk space is sufficient, it is recommended to set it larger. | | `storage.bucket` | String | Unset | The S3 bucket name.
**It's only used when the storage type is `S3`, `Oss` and `Gcs`**. | | `storage.root` | String | Unset | The S3 data will be stored in the specified prefix, for example, `s3://${bucket}/${root}`.
**It's only used when the storage type is `S3`, `Oss` and `Azblob`**. | diff --git a/config/datanode.example.toml b/config/datanode.example.toml index 7e04748059..ed1cec4629 100644 --- a/config/datanode.example.toml +++ b/config/datanode.example.toml @@ -274,6 +274,9 @@ type = "File" ## @toml2docs:none-default #+ cache_path = "" +## Whether to enable read cache. If not set, the read cache will be enabled by default. +enable_read_cache = true + ## The local file cache capacity in bytes. If your disk space is sufficient, it is recommended to set it larger. ## @toml2docs:none-default cache_capacity = "5GiB" diff --git a/config/standalone.example.toml b/config/standalone.example.toml index 22dd8105a9..be62ecc2d9 100644 --- a/config/standalone.example.toml +++ b/config/standalone.example.toml @@ -361,6 +361,9 @@ data_home = "./greptimedb_data" ## - `Oss`: the data is stored in the Aliyun OSS. type = "File" +## Whether to enable read cache. If not set, the read cache will be enabled by default. +enable_read_cache = true + ## Read cache configuration for object storage such as 'S3' etc, it's configured by default when using object storage. It is recommended to configure it when using object storage for better performance. ## A local file directory, defaults to `{data_home}`. An empty string means disabling. ## @toml2docs:none-default diff --git a/src/datanode/src/store.rs b/src/datanode/src/store.rs index 88b90883ef..c506a7e280 100644 --- a/src/datanode/src/store.rs +++ b/src/datanode/src/store.rs @@ -87,6 +87,10 @@ async fn build_cache_layer( store_config: &ObjectStoreConfig, data_home: &str, ) -> Result>> { + if !store_config.enable_read_cache() { + return Ok(None); + } + let (name, mut cache_path, cache_capacity) = match store_config { ObjectStoreConfig::S3(s3_config) => { let path = s3_config.cache.cache_path.clone(); diff --git a/src/object-store/src/config.rs b/src/object-store/src/config.rs index c692447c3a..893c98aa4c 100644 --- a/src/object-store/src/config.rs +++ b/src/object-store/src/config.rs @@ -69,6 +69,19 @@ impl ObjectStoreConfig { name } + + /// Returns whether to enable read cache. If not set, the read cache will be enabled by default. + pub fn enable_read_cache(&self) -> bool { + let enable_read_cache = match self { + Self::File(_) => Some(false), + Self::S3(s3) => s3.cache.enable_read_cache, + Self::Oss(oss) => oss.cache.enable_read_cache, + Self::Azblob(az) => az.cache.enable_read_cache, + Self::Gcs(gcs) => gcs.cache.enable_read_cache, + }; + + enable_read_cache.unwrap_or(true) + } } #[derive(Debug, Clone, Serialize, Default, Deserialize, Eq, PartialEq)] @@ -304,6 +317,8 @@ impl Default for HttpClientConfig { #[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)] #[serde(default)] pub struct ObjectStorageCacheConfig { + /// Whether to enable read cache. If not set, the read cache will be enabled by default. + pub enable_read_cache: Option, /// The local file cache directory pub cache_path: Option, /// The cache capacity in bytes