Skip to content

Commit

Permalink
refactor: rename metadata cache to distinct value cache
Browse files Browse the repository at this point in the history
  • Loading branch information
hiltontj committed Jan 9, 2025
1 parent be79008 commit 192a2f7
Show file tree
Hide file tree
Showing 27 changed files with 451 additions and 418 deletions.
17 changes: 9 additions & 8 deletions influxdb3/src/commands/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Config {
},
..
})
| SubCommand::MetaCache(MetaCacheConfig {
| SubCommand::DistinctCache(DistinctCacheConfig {
influxdb3_config:
InfluxDb3Config {
host_url,
Expand Down Expand Up @@ -95,9 +95,9 @@ pub enum SubCommand {
/// Create a new last value cache
#[clap(name = "last_cache")]
LastCache(LastCacheConfig),
/// Create a new metadata cache
#[clap(name = "meta_cache")]
MetaCache(MetaCacheConfig),
/// Create a new distinct value cache
#[clap(name = "distinct_cache")]
DistinctCache(DistinctCacheConfig),
/// Create a new processing engine plugin
Plugin(PluginConfig),
/// Create a new table in a database
Expand Down Expand Up @@ -167,7 +167,7 @@ pub struct LastCacheConfig {
}

#[derive(Debug, clap::Args)]
pub struct MetaCacheConfig {
pub struct DistinctCacheConfig {
#[clap(flatten)]
influxdb3_config: InfluxDb3Config,

Expand Down Expand Up @@ -301,15 +301,16 @@ pub async fn command(config: Config) -> Result<(), Box<dyn Error>> {
None => println!("a cache already exists for the provided parameters"),
}
}
SubCommand::MetaCache(MetaCacheConfig {
SubCommand::DistinctCache(DistinctCacheConfig {
influxdb3_config: InfluxDb3Config { database_name, .. },
table,
cache_name,
columns,
max_cardinality,
max_age,
}) => {
let mut b = client.api_v3_configure_meta_cache_create(database_name, table, columns);
let mut b =
client.api_v3_configure_distinct_cache_create(database_name, table, columns);

// Add the optional stuff:
if let Some(name) = cache_name {
Expand All @@ -326,7 +327,7 @@ pub async fn command(config: Config) -> Result<(), Box<dyn Error>> {
Some(def) => println!(
"new cache created: {}",
serde_json::to_string_pretty(&def)
.expect("serialize meta cache definition as JSON")
.expect("serialize distinct cache definition as JSON")
),
None => println!("a cache already exists for the provided parameters"),
}
Expand Down
16 changes: 8 additions & 8 deletions influxdb3/src/commands/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Config {
},
..
})
| SubCommand::MetaCache(MetaCacheConfig {
| SubCommand::DistinctCache(DistinctCacheConfig {
influxdb3_config:
InfluxDb3Config {
host_url,
Expand Down Expand Up @@ -82,9 +82,9 @@ pub enum SubCommand {
/// Delete a last value cache
#[clap(name = "last_cache")]
LastCache(LastCacheConfig),
/// Delete a meta value cache
#[clap(name = "meta_cache")]
MetaCache(MetaCacheConfig),
/// Delete a distinct value cache
#[clap(name = "distinct_cache")]
DistinctCache(DistinctCacheConfig),
/// Delete an existing processing engine plugin
Plugin(PluginConfig),
/// Delete a table in a database
Expand Down Expand Up @@ -128,7 +128,7 @@ pub struct LastCacheConfig {
}

#[derive(Debug, clap::Args)]
pub struct MetaCacheConfig {
pub struct DistinctCacheConfig {
#[clap(flatten)]
influxdb3_config: InfluxDb3Config,

Expand Down Expand Up @@ -203,16 +203,16 @@ pub async fn command(config: Config) -> Result<(), Box<dyn Error>> {

println!("last cache deleted successfully");
}
SubCommand::MetaCache(MetaCacheConfig {
SubCommand::DistinctCache(DistinctCacheConfig {
influxdb3_config: InfluxDb3Config { database_name, .. },
table,
cache_name,
}) => {
client
.api_v3_configure_meta_cache_delete(database_name, table, cache_name)
.api_v3_configure_distinct_cache_delete(database_name, table, cache_name)
.await?;

println!("meta cache deleted successfully");
println!("distinct cache deleted successfully");
}
SubCommand::Plugin(PluginConfig {
influxdb3_config: InfluxDb3Config { database_name, .. },
Expand Down
22 changes: 11 additions & 11 deletions influxdb3/src/commands/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use anyhow::{bail, Context};
use datafusion_util::config::register_iox_object_store;
use influxdb3_cache::{
distinct_cache::DistinctCacheProvider,
last_cache::{self, LastCacheProvider},
meta_cache::MetaCacheProvider,
parquet_cache::create_cached_obj_store_and_oracle,
};
use influxdb3_clap_blocks::{
Expand Down Expand Up @@ -92,8 +92,8 @@ pub enum Error {
#[error("failed to initialize last cache: {0}")]
InitializeLastCache(#[source] last_cache::Error),

#[error("failed to initialize meta cache: {0:#}")]
InitializeMetaCache(#[source] influxdb3_cache::meta_cache::ProviderError),
#[error("failed to initialize distinct cache: {0:#}")]
InitializeDistinctCache(#[source] influxdb3_cache::distinct_cache::ProviderError),
}

pub type Result<T, E = Error> = std::result::Result<T, E>;
Expand Down Expand Up @@ -282,15 +282,15 @@ pub struct Config {
)]
pub last_cache_eviction_interval: humantime::Duration,

/// The interval on which to evict expired entries from the Last-N-Value cache, expressed as a
/// The interval on which to evict expired entries from the Distinct Value cache, expressed as a
/// human-readable time, e.g., "20s", "1m", "1h".
#[clap(
long = "meta-cache-eviction-interval",
env = "INFLUXDB3_META_CACHE_EVICTION_INTERVAL",
long = "distinct-cache-eviction-interval",
env = "INFLUXDB3_DISTINCT_CACHE_EVICTION_INTERVAL",
default_value = "10s",
action
)]
pub meta_cache_eviction_interval: humantime::Duration,
pub distinct_cache_eviction_interval: humantime::Duration,

/// The local directory that has python plugins and their test files.
#[clap(long = "plugin-dir", env = "INFLUXDB3_PLUGIN_DIR", action)]
Expand Down Expand Up @@ -473,18 +473,18 @@ pub async fn command(config: Config) -> Result<()> {
)
.map_err(Error::InitializeLastCache)?;

let meta_cache = MetaCacheProvider::new_from_catalog_with_background_eviction(
let distinct_cache = DistinctCacheProvider::new_from_catalog_with_background_eviction(
Arc::clone(&time_provider) as _,
Arc::clone(&catalog),
config.meta_cache_eviction_interval.into(),
config.distinct_cache_eviction_interval.into(),
)
.map_err(Error::InitializeMetaCache)?;
.map_err(Error::InitializeDistinctCache)?;

let write_buffer_impl = WriteBufferImpl::new(WriteBufferImplArgs {
persister: Arc::clone(&persister),
catalog: Arc::clone(&catalog),
last_cache,
meta_cache,
distinct_cache,
time_provider: Arc::<SystemProvider>::clone(&time_provider),
executor: Arc::clone(&exec),
wal_config,
Expand Down
19 changes: 10 additions & 9 deletions influxdb3/tests/server/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ async fn test_delete_missing_table() {
}

#[tokio::test]
async fn test_create_delete_meta_cache() {
async fn test_create_delete_distinct_cache() {
let server = TestServer::spawn().await;
let server_addr = server.client_addr();
let db_name = "foo";
Expand All @@ -381,7 +381,7 @@ async fn test_create_delete_meta_cache() {
// first create the cache:
let result = run(&[
"create",
"meta_cache",
"distinct_cache",
"--host",
&server_addr,
"--database",
Expand All @@ -396,7 +396,7 @@ async fn test_create_delete_meta_cache() {
// doing the same thing over again will be a no-op
let result = run(&[
"create",
"meta_cache",
"distinct_cache",
"--host",
&server_addr,
"--database",
Expand All @@ -414,7 +414,7 @@ async fn test_create_delete_meta_cache() {
// now delete it:
let result = run(&[
"delete",
"meta_cache",
"distinct_cache",
"--host",
&server_addr,
"--database",
Expand All @@ -423,11 +423,11 @@ async fn test_create_delete_meta_cache() {
table_name,
cache_name,
]);
assert_contains!(&result, "meta cache deleted successfully");
assert_contains!(&result, "distinct cache deleted successfully");
// trying to delete again should result in an error as the cache no longer exists:
let result = run_and_err(&[
"delete",
"meta_cache",
"distinct_cache",
"--host",
&server_addr,
"--database",
Expand All @@ -438,6 +438,7 @@ async fn test_create_delete_meta_cache() {
]);
assert_contains!(&result, "[404 Not Found]: cache not found");
}

#[test_log::test(tokio::test)]
async fn test_create_plugin() {
let server = TestServer::spawn().await;
Expand Down Expand Up @@ -802,7 +803,7 @@ fn test_create_token() {
}

#[tokio::test]
async fn meta_cache_create_and_delete() {
async fn distinct_cache_create_and_delete() {
let server = TestServer::spawn().await;
let db_name = "foo";
let server_addr = server.client_addr();
Expand All @@ -817,7 +818,7 @@ async fn meta_cache_create_and_delete() {

let result = run_with_confirmation(&[
"create",
"meta_cache",
"distinct_cache",
"-H",
&server_addr,
"-d",
Expand All @@ -837,7 +838,7 @@ async fn meta_cache_create_and_delete() {

let result = run_with_confirmation(&[
"delete",
"meta_cache",
"distinct_cache",
"-H",
&server_addr,
"-d",
Expand Down
12 changes: 6 additions & 6 deletions influxdb3/tests/server/configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use test_helpers::assert_contains;
use crate::TestServer;

#[tokio::test]
async fn api_v3_configure_meta_cache_create() {
async fn api_v3_configure_distinct_cache_create() {
let server = TestServer::spawn().await;
let client = reqwest::Client::new();
let url = format!(
"{base}/api/v3/configure/meta_cache",
"{base}/api/v3/configure/distinct_cache",
base = server.client_addr()
);

Expand Down Expand Up @@ -157,7 +157,7 @@ async fn api_v3_configure_meta_cache_create() {
.json(&body)
.send()
.await
.expect("send request to create meta cache");
.expect("send request to create distinct cache");
let status = resp.status();
assert_eq!(
tc.expected,
Expand All @@ -169,11 +169,11 @@ async fn api_v3_configure_meta_cache_create() {
}

#[tokio::test]
async fn api_v3_configure_meta_cache_delete() {
async fn api_v3_configure_distinct_cache_delete() {
let server = TestServer::spawn().await;
let client = reqwest::Client::new();
let url = format!(
"{base}/api/v3/configure/meta_cache",
"{base}/api/v3/configure/distinct_cache",
base = server.client_addr()
);

Expand Down Expand Up @@ -210,7 +210,7 @@ async fn api_v3_configure_meta_cache_delete() {
use Request::*;
let mut test_cases = [
TestCase {
description: "create a metadata cache",
description: "create a distinct cache",
request: Create(serde_json::json!({
"db": db_name,
"table": tbl_name,
Expand Down
2 changes: 1 addition & 1 deletion influxdb3/tests/server/flight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ async fn flight() -> Result<(), influxdb3_client::Error> {
"| public | information_schema | tables | VIEW |",
"| public | information_schema | views | VIEW |",
"| public | iox | cpu | BASE TABLE |",
"| public | system | distinct_caches | BASE TABLE |",
"| public | system | last_caches | BASE TABLE |",
"| public | system | meta_caches | BASE TABLE |",
"| public | system | parquet_files | BASE TABLE |",
"| public | system | processing_engine_plugins | BASE TABLE |",
"| public | system | processing_engine_triggers | BASE TABLE |",
Expand Down
12 changes: 6 additions & 6 deletions influxdb3/tests/server/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,34 +341,34 @@ impl TestServer {
.expect("failed to send request to delete last cache")
}

pub async fn api_v3_configure_meta_cache_create(
pub async fn api_v3_configure_distinct_cache_create(
&self,
request: &serde_json::Value,
) -> Response {
self.http_client
.post(format!(
"{base}/api/v3/configure/meta_cache",
"{base}/api/v3/configure/distinct_cache",
base = self.client_addr()
))
.json(request)
.send()
.await
.expect("failed to send request to create metadata cache")
.expect("failed to send request to create distinct cache")
}

pub async fn api_v3_configure_meta_cache_delete(
pub async fn api_v3_configure_distinct_cache_delete(
&self,
request: &serde_json::Value,
) -> Response {
self.http_client
.delete(format!(
"{base}/api/v3/configure/meta_cache",
"{base}/api/v3/configure/distinct_cache",
base = self.client_addr()
))
.json(request)
.send()
.await
.expect("failed to send request to delete metadata cache")
.expect("failed to send request to delete distinct cache")
}
}

Expand Down
8 changes: 4 additions & 4 deletions influxdb3/tests/server/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ async fn api_v1_query_uri_and_body() {
}

#[tokio::test]
async fn api_v3_query_sql_meta_cache() {
async fn api_v3_query_sql_distinct_cache() {
let server = TestServer::spawn().await;
server
.write_lp_to_db("foo", "cpu,region=us,host=a usage=99", Precision::Second)
Expand All @@ -1594,7 +1594,7 @@ async fn api_v3_query_sql_meta_cache() {
server
.http_client
.post(format!(
"{base}/api/v3/configure/meta_cache",
"{base}/api/v3/configure/distinct_cache",
base = server.client_addr()
))
.json(&serde_json::json!({
Expand Down Expand Up @@ -1623,7 +1623,7 @@ async fn api_v3_query_sql_meta_cache() {
.api_v3_query_sql(&[
("db", "foo"),
("format", "pretty"),
("q", "SELECT * FROM meta_cache('cpu')"),
("q", "SELECT * FROM distinct_cache('cpu')"),
])
.await
.text()
Expand All @@ -1647,7 +1647,7 @@ async fn api_v3_query_sql_meta_cache() {
.api_v3_query_sql(&[
("db", "foo"),
("format", "json"),
("q", "SELECT * FROM meta_cache('cpu')"),
("q", "SELECT * FROM distinct_cache('cpu')"),
])
.await
.json::<Value>()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: influxdb3/tests/server/cli.rs
expression: result
---
distinct cache deleted successfully
Loading

0 comments on commit 192a2f7

Please sign in to comment.