* fix: flaky test_chunk_access_time (#3197) * chore: fix lint Co-authored-by: Edd Robinson <me@edd.io> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>pull/24376/head
parent
f5bbed878c
commit
42e3a41825
|
@ -22,8 +22,6 @@ use crate::{
|
|||
fixture_broken_catalog, wait_for_exact_chunk_states, DatabaseBuilder,
|
||||
},
|
||||
};
|
||||
use chrono::{DateTime, Utc};
|
||||
use std::convert::TryInto;
|
||||
use std::time::Instant;
|
||||
use tonic::Code;
|
||||
use uuid::Uuid;
|
||||
|
@ -1455,74 +1453,6 @@ async fn test_unload_read_buffer() {
|
|||
assert_eq!(chunks[0].storage, storage);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_chunk_access_time() {
|
||||
let fixture = ServerFixture::create_shared(ServerType::Database).await;
|
||||
let mut write_client = fixture.write_client();
|
||||
let mut management_client = fixture.management_client();
|
||||
let mut flight_client = fixture.flight_client();
|
||||
|
||||
let db_name = rand_name();
|
||||
DatabaseBuilder::new(db_name.clone())
|
||||
.build(fixture.grpc_channel())
|
||||
.await;
|
||||
|
||||
write_client
|
||||
.write_lp(&db_name, "cpu foo=1 10", 0)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let to_datetime = |a: Option<&generated_types::google::protobuf::Timestamp>| -> DateTime<Utc> {
|
||||
a.unwrap().clone().try_into().unwrap()
|
||||
};
|
||||
|
||||
let chunks = management_client.list_chunks(&db_name).await.unwrap();
|
||||
assert_eq!(chunks.len(), 1);
|
||||
let t0 = to_datetime(chunks[0].time_of_last_access.as_ref());
|
||||
|
||||
flight_client
|
||||
.perform_query(&db_name, "select * from cpu;")
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let chunks = management_client.list_chunks(&db_name).await.unwrap();
|
||||
assert_eq!(chunks.len(), 1);
|
||||
let t1 = to_datetime(chunks[0].time_of_last_access.as_ref());
|
||||
|
||||
flight_client
|
||||
.perform_query(&db_name, "select * from cpu;")
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let chunks = management_client.list_chunks(&db_name).await.unwrap();
|
||||
assert_eq!(chunks.len(), 1);
|
||||
let t2 = to_datetime(chunks[0].time_of_last_access.as_ref());
|
||||
|
||||
write_client
|
||||
.write_lp(&db_name, "cpu foo=1 20", 0)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let chunks = management_client.list_chunks(&db_name).await.unwrap();
|
||||
assert_eq!(chunks.len(), 1);
|
||||
let t3 = to_datetime(chunks[0].time_of_last_access.as_ref());
|
||||
|
||||
// This chunk should be pruned out and therefore not accessed by the query
|
||||
flight_client
|
||||
.perform_query(&db_name, "select * from cpu where foo = 2;")
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let chunks = management_client.list_chunks(&db_name).await.unwrap();
|
||||
assert_eq!(chunks.len(), 1);
|
||||
let t4 = to_datetime(chunks[0].time_of_last_access.as_ref());
|
||||
|
||||
assert!(t0 < t1, "{} {}", t0, t1);
|
||||
assert!(t1 < t2, "{} {}", t1, t2);
|
||||
assert!(t2 < t3, "{} {}", t2, t3);
|
||||
assert_eq!(t3, t4)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_drop_partition() {
|
||||
use data_types::chunk_metadata::ChunkStorage;
|
||||
|
|
|
@ -3697,6 +3697,56 @@ mod tests {
|
|||
assert_batches_sorted_eq!(&expected, &batches);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn chunk_times() {
|
||||
let t0 = Time::from_timestamp(11, 22);
|
||||
let time = Arc::new(time::MockProvider::new(t0));
|
||||
let db = TestDb::builder()
|
||||
.time_provider(Arc::<time::MockProvider>::clone(&time))
|
||||
.build()
|
||||
.await
|
||||
.db;
|
||||
|
||||
write_lp(db.as_ref(), "cpu foo=1 10").await;
|
||||
|
||||
let chunks = db.chunk_summaries().unwrap();
|
||||
assert_eq!(chunks.len(), 1);
|
||||
assert_eq!(chunks[0].time_of_first_write, t0);
|
||||
assert_eq!(chunks[0].time_of_last_write, t0);
|
||||
assert_eq!(chunks[0].time_of_last_access.unwrap(), t0);
|
||||
|
||||
let t1 = time.inc(Duration::from_secs(1));
|
||||
|
||||
run_query(Arc::clone(&db), "select * from cpu").await;
|
||||
|
||||
let chunks = db.chunk_summaries().unwrap();
|
||||
assert_eq!(chunks.len(), 1);
|
||||
assert_eq!(chunks[0].time_of_first_write, t0);
|
||||
assert_eq!(chunks[0].time_of_last_write, t0);
|
||||
assert_eq!(chunks[0].time_of_last_access.unwrap(), t1);
|
||||
|
||||
let t2 = time.inc(Duration::from_secs(1));
|
||||
|
||||
write_lp(db.as_ref(), "cpu foo=1 20").await;
|
||||
|
||||
let chunks = db.chunk_summaries().unwrap();
|
||||
assert_eq!(chunks.len(), 1);
|
||||
assert_eq!(chunks[0].time_of_first_write, t0);
|
||||
assert_eq!(chunks[0].time_of_last_write, t2);
|
||||
assert_eq!(chunks[0].time_of_last_access.unwrap(), t2);
|
||||
|
||||
time.inc(Duration::from_secs(1));
|
||||
|
||||
// This chunk should be pruned out and therefore not accessed by the query
|
||||
run_query(Arc::clone(&db), "select * from cpu where foo = 2;").await;
|
||||
|
||||
let chunks = db.chunk_summaries().unwrap();
|
||||
assert_eq!(chunks.len(), 1);
|
||||
assert_eq!(chunks[0].time_of_first_write, t0);
|
||||
assert_eq!(chunks[0].time_of_last_write, t2);
|
||||
assert_eq!(chunks[0].time_of_last_access.unwrap(), t2);
|
||||
}
|
||||
|
||||
async fn create_parquet_chunk(db: &Arc<Db>) -> (String, String, ChunkId) {
|
||||
write_lp(db, "cpu bar=1 10").await;
|
||||
let partition_key = "1970-01-01T00";
|
||||
|
|
Loading…
Reference in New Issue