refactor: move `querier::cache_system` into its own crate (#4592)

pull/24376/head
Marco Neumann 2022-05-13 15:12:07 +02:00 committed by GitHub
parent ff8241ea57
commit cb0a4176fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 77 additions and 35 deletions

19
Cargo.lock generated
View File

@ -587,6 +587,22 @@ dependencies = [
"tokio",
]
[[package]]
name = "cache_system"
version = "0.1.0"
dependencies = [
"async-trait",
"criterion",
"futures",
"iox_time",
"observability_deps",
"parking_lot 0.12.0",
"proptest",
"rand",
"tokio",
"workspace-hack",
]
[[package]]
name = "cast"
version = "0.2.7"
@ -4097,8 +4113,8 @@ dependencies = [
"assert_matches",
"async-trait",
"backoff 0.1.0",
"cache_system",
"client_util",
"criterion",
"data_types",
"datafusion 0.1.0",
"datafusion_util",
@ -4116,7 +4132,6 @@ dependencies = [
"parquet_file",
"pin-project",
"predicate",
"proptest",
"query",
"rand",
"schema",

View File

@ -3,6 +3,7 @@
members = [
"arrow_util",
"backoff",
"cache_system",
"clap_blocks",
"client_util",
"compactor",

22
cache_system/Cargo.toml Normal file
View File

@ -0,0 +1,22 @@
[package]
name = "cache_system"
version = "0.1.0"
edition = "2021"
[dependencies]
async-trait = "0.1.53"
futures = "0.3"
iox_time = { path = "../iox_time" }
observability_deps = { path = "../observability_deps" }
parking_lot = "0.12"
tokio = { version = "1.18", features = ["macros", "parking_lot", "rt-multi-thread", "sync", "time"] }
workspace-hack = { path = "../workspace-hack"}
[dev-dependencies]
criterion = "0.3"
proptest = { version = "1", default_features = false, features = ["std"] }
rand = "0.8.3"
[[bench]]
name = "addressable_heap"
harness = false

View File

@ -1,10 +1,10 @@
use std::mem::size_of;
use cache_system::backend::addressable_heap::AddressableHeap;
use criterion::{
criterion_group, criterion_main, measurement::WallTime, AxisScale, BatchSize, BenchmarkGroup,
BenchmarkId, Criterion, PlotConfiguration, SamplingMode,
};
use querier::AddressableHeap;
use rand::{prelude::SliceRandom, thread_rng, Rng};
/// Payload (`V`) for testing.

View File

@ -1,3 +1,4 @@
//! Implementation of an [`AddressableHeap`].
use std::{
collections::{HashMap, VecDeque},
hash::Hash,

View File

@ -1,3 +1,4 @@
//! Cross-populated two caches.
use std::{any::Any, fmt::Debug, hash::Hash, sync::Arc};
use parking_lot::Mutex;
@ -310,7 +311,7 @@ mod tests {
#[test]
fn test_generic1() {
use crate::cache_system::backend::test_util::test_generic;
use crate::backend::test_util::test_generic;
test_generic(|| {
let backend1 = Box::new(HashMap::<u8, String>::new());
@ -328,7 +329,7 @@ mod tests {
#[test]
fn test_generic2() {
use crate::cache_system::backend::test_util::test_generic;
use crate::backend::test_util::test_generic;
test_generic(|| {
let backend1 = Box::new(HashMap::<i8, String>::new());

View File

@ -1,3 +1,4 @@
//! Implements [`CacheBackend`] for [`HashMap`].
use std::{
any::Any,
collections::HashMap,
@ -43,7 +44,7 @@ mod tests {
#[test]
fn test_generic() {
use crate::cache_system::backend::test_util::test_generic;
use crate::backend::test_util::test_generic;
test_generic(HashMap::new);
}

View File

@ -9,7 +9,7 @@
//! sync::Arc,
//! };
//! use iox_time::SystemProvider;
//! use querier::{
//! use cache_system::backend::{
//! CacheBackend,
//! lru::{LruBackend, ResourcePool},
//! resource_consumption::{Resource, ResourceEstimator},
@ -1114,7 +1114,7 @@ mod tests {
#[test]
fn test_generic() {
use crate::cache_system::backend::test_util::test_generic;
use crate::backend::test_util::test_generic;
#[derive(Debug)]
struct ZeroSizeProvider {}

View File

@ -1,3 +1,4 @@
//! Storage backends to keep and manage cached entries.
use std::{any::Any, fmt::Debug, hash::Hash};
pub mod addressable_heap;

View File

@ -1,3 +1,4 @@
//! Time-to-live handling.
use std::{any::Any, fmt::Debug, hash::Hash, marker::PhantomData, sync::Arc, time::Duration};
use iox_time::{Time, TimeProvider};
@ -552,7 +553,7 @@ mod tests {
#[test]
fn test_generic() {
use crate::cache_system::backend::test_util::test_generic;
use crate::backend::test_util::test_generic;
test_generic(|| {
let ttl_provider = Arc::new(NeverTtlProvider::default());

View File

@ -1,3 +1,4 @@
//! Main data structure, see [`Cache`].
use std::{collections::HashMap, hash::Hash, sync::Arc};
use futures::{

14
cache_system/src/lib.rs Normal file
View File

@ -0,0 +1,14 @@
//! Flexible and modular cache system.
#![deny(rustdoc::broken_intra_doc_links, rust_2018_idioms)]
#![warn(
missing_copy_implementations,
missing_docs,
clippy::explicit_iter_loop,
clippy::future_not_send,
clippy::use_self,
clippy::clone_on_ref_ptr
)]
pub mod backend;
pub mod driver;
pub mod loader;

View File

@ -1,8 +1,9 @@
//! How to load new cache entries.
use async_trait::async_trait;
use futures::{future::BoxFuture, FutureExt};
use std::future::Future;
/// Loader for missing [`Cache`](crate::cache_system::driver::Cache) entries.
/// Loader for missing [`Cache`](crate::driver::Cache) entries.
#[async_trait]
pub trait Loader: std::fmt::Debug + Send + Sync + 'static {
/// Cache key.

View File

@ -7,6 +7,7 @@ edition = "2021"
arrow = "13"
async-trait = "0.1.53"
backoff = { path = "../backoff" }
cache_system = { path = "../cache_system" }
client_util = { path = "../client_util" }
data_types = { path = "../data_types" }
datafusion = { path = "../datafusion" }
@ -40,12 +41,6 @@ workspace-hack = { path = "../workspace-hack"}
[dev-dependencies]
arrow_util = { path = "../arrow_util" }
assert_matches = "1.5"
criterion = "0.3"
iox_tests = { path = "../iox_tests" }
mutable_batch_lp = { path = "../mutable_batch_lp" }
proptest = { version = "1", default_features = false, features = ["std"] }
test_helpers = { path = "../test_helpers" }
[[bench]]
name = "addressable_heap"
harness = false

View File

@ -1,6 +1,7 @@
//! Namespace cache.
use crate::cache_system::{
use backoff::{Backoff, BackoffConfig};
use cache_system::{
backend::{
dual::dual_backends,
ttl::{OptionalValueTtlProvider, TtlBackend},
@ -8,7 +9,6 @@ use crate::cache_system::{
driver::Cache,
loader::FunctionLoader,
};
use backoff::{Backoff, BackoffConfig};
use data_types::{NamespaceId, NamespaceSchema};
use iox_catalog::interface::{get_schema_by_name, Catalog};
use iox_time::TimeProvider;

View File

@ -1,7 +1,7 @@
//! Partition cache.
use crate::cache_system::{driver::Cache, loader::FunctionLoader};
use backoff::{Backoff, BackoffConfig};
use cache_system::{driver::Cache, loader::FunctionLoader};
use data_types::{PartitionId, SequencerId};
use iox_catalog::interface::Catalog;
use schema::sort::SortKey;

View File

@ -1,11 +1,11 @@
//! Processed tombstone cache.
use crate::cache_system::{
use backoff::{Backoff, BackoffConfig};
use cache_system::{
backend::ttl::{TtlBackend, TtlProvider},
driver::Cache,
loader::FunctionLoader,
};
use backoff::{Backoff, BackoffConfig};
use data_types::{ParquetFileId, TombstoneId};
use iox_catalog::interface::Catalog;
use iox_time::TimeProvider;

View File

@ -1,6 +1,7 @@
//! Table cache.
use crate::cache_system::{
use backoff::{Backoff, BackoffConfig};
use cache_system::{
backend::{
dual::dual_backends,
ttl::{OptionalValueTtlProvider, TtlBackend},
@ -8,7 +9,6 @@ use crate::cache_system::{
driver::Cache,
loader::FunctionLoader,
};
use backoff::{Backoff, BackoffConfig};
use data_types::{NamespaceId, Table, TableId};
use iox_catalog::interface::Catalog;
use iox_time::TimeProvider;

View File

@ -1,3 +0,0 @@
pub mod backend;
pub mod driver;
pub mod loader;

View File

@ -10,7 +10,6 @@
)]
pub mod cache;
mod cache_system;
pub mod chunk;
mod database;
mod handler;
@ -36,11 +35,3 @@ pub use ingester::{
};
pub use namespace::QuerierNamespace;
pub use server::QuerierServer;
// for benchmarks
pub use cache_system::backend::addressable_heap::AddressableHeap;
// for doctests
pub use cache_system::backend::lru;
pub use cache_system::backend::resource_consumption;
pub use cache_system::backend::CacheBackend;