Skip to content

Commit

Permalink
Merge pull request #8978 from Xuanwo/disable-cache-by-default
Browse files Browse the repository at this point in the history
fix: Disable moka cache by default
  • Loading branch information
mergify[bot] authored Nov 26, 2022
2 parents 76b7dea + 3b94997 commit 310c17d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 20 deletions.
11 changes: 10 additions & 1 deletion src/common/storage/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Default for CacheConfig {
fn default() -> Self {
Self {
num_cpus: 0,
params: StorageParams::Moka(StorageMokaConfig::default()),
params: StorageParams::None,
}
}
}
Expand All @@ -91,6 +91,11 @@ pub enum StorageParams {
Oss(StorageOssConfig),
S3(StorageS3Config),
Redis(StorageRedisConfig),

/// None means this storage type is none.
///
/// This type is mostly for cache which mean bypass the cache logic.
None,
}

impl Default for StorageParams {
Expand Down Expand Up @@ -153,6 +158,9 @@ impl Display for StorageParams {
v.db, v.root, v.endpoint_url
)
}
StorageParams::None => {
write!(f, "none",)
}
}
}
}
Expand All @@ -177,6 +185,7 @@ impl StorageParams {
StorageParams::S3(v) => v.endpoint_url.starts_with("https://"),
StorageParams::Gcs(v) => v.endpoint_url.starts_with("https://"),
StorageParams::Redis(_) => false,
StorageParams::None => false,
}
}
}
Expand Down
33 changes: 21 additions & 12 deletions src/common/storage/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
// limitations under the License.

use std::env;
use std::io::Error;
use std::io::ErrorKind;
use std::io::Result;
use std::ops::Deref;
use std::time::Duration;

use anyhow::anyhow;
use backon::ExponentialBackoff;
use common_base::base::GlobalIORuntime;
use common_base::base::Singleton;
Expand Down Expand Up @@ -72,6 +75,12 @@ pub fn init_operator(cfg: &StorageParams) -> Result<Operator> {
StorageParams::S3(cfg) => init_s3_operator(cfg)?,
StorageParams::Oss(cfg) => init_oss_operator(cfg)?,
StorageParams::Redis(cfg) => init_redis_operator(cfg)?,
v => {
return Err(Error::new(
ErrorKind::InvalidInput,
anyhow!("Unsupported storage type: {:?}", v),
));
}
};

let op = op
Expand Down Expand Up @@ -412,15 +421,7 @@ impl DataOperator {
/// background auto evict at any time.
#[derive(Clone, Debug)]
pub struct CacheOperator {
op: Operator,
}

impl Deref for CacheOperator {
type Target = Operator;

fn deref(&self) -> &Self::Target {
&self.op
}
op: Option<Operator>,
}

static CACHE_OPERATOR: OnceCell<Singleton<CacheOperator>> = OnceCell::new();
Expand All @@ -437,6 +438,10 @@ impl CacheOperator {
}

pub async fn try_create(conf: &CacheConfig) -> common_exception::Result<CacheOperator> {
if conf.params == StorageParams::None {
return Ok(CacheOperator { op: None });
}

let operator = init_operator(&conf.params)?;

// OpenDAL will send a real request to underlying storage to check whether it works or not.
Expand All @@ -456,13 +461,17 @@ impl CacheOperator {
)));
}

Ok(CacheOperator { op: operator })
Ok(CacheOperator { op: Some(operator) })
}

pub fn instance() -> CacheOperator {
pub fn instance() -> Option<Operator> {
match CACHE_OPERATOR.get() {
None => panic!("CacheOperator is not init"),
Some(op) => op.get(),
Some(op) => op.get().inner(),
}
}

fn inner(&self) -> Option<Operator> {
self.op.clone()
}
}
4 changes: 4 additions & 0 deletions src/query/config/src/outer_v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ impl From<InnerCacheConfig> for CacheConfig {
};

match inner.params {
StorageParams::None => {
cfg.cache_type = "none".to_string();
}
StorageParams::Fs(v) => {
cfg.cache_type = "fs".to_string();
cfg.fs = v.into();
Expand All @@ -544,6 +547,7 @@ impl TryInto<InnerCacheConfig> for CacheConfig {
num_cpus: self.cache_num_cpus,
params: {
match self.cache_type.as_str() {
"none" => StorageParams::None,
"fs" => StorageParams::Fs(self.fs.try_into()?),
"moka" => StorageParams::Moka(self.moka.try_into()?),
"redis" => StorageParams::Redis(self.redis.try_into()?),
Expand Down
2 changes: 1 addition & 1 deletion src/query/service/tests/it/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ endpoint_url = ""
root = ""
[storage.cache]
type = "moka"
type = "none"
num_cpus = 0
[storage.cache.fs]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ DB.Table: 'system'.'configs', Table: configs-table_id:1, ver:0, Engine: SystemCo
| storage | cache.redis.password | | |
| storage | cache.redis.root | | |
| storage | cache.redis.username | | |
| storage | cache.type | moka | |
| storage | cache.type | none | |
| storage | fs.data_path | _data | |
| storage | gcs.bucket | | |
| storage | gcs.credential | | |
Expand Down
11 changes: 6 additions & 5 deletions src/query/storages/fuse/fuse/src/fuse_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use std::any::Any;
use std::collections::HashMap;
use std::convert::TryFrom;
use std::ops::Deref;
use std::str;
use std::sync::Arc;

Expand Down Expand Up @@ -115,12 +114,14 @@ impl FuseTable {
}
};
let data_metrics = Arc::new(StorageMetrics::default());
operator = operator
.layer(StorageMetricsLayer::new(data_metrics.clone()))
.layer(ContentCacheLayer::new(
CacheOperator::instance().deref().clone(),
operator = operator.layer(StorageMetricsLayer::new(data_metrics.clone()));
// If cache op is valid, layered with ContentCacheLayer.
if let Some(cache_op) = CacheOperator::instance() {
operator = operator.layer(ContentCacheLayer::new(
cache_op,
ContentCacheStrategy::Fixed(1024 * 1024),
));
}

Ok(Box::new(FuseTable {
table_info,
Expand Down

1 comment on commit 310c17d

@vercel
Copy link

@vercel vercel bot commented on 310c17d Nov 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

databend – ./

databend-databend.vercel.app
databend-git-main-databend.vercel.app
databend.vercel.app
databend.rs

Please sign in to comment.