fix: flaky test_chunk_access_time (#3197) (#3200)

* 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
Raphael Taylor-Davies 2021-11-23 17:39:57 +00:00 committed by GitHub
parent f5bbed878c
commit 42e3a41825
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 70 deletions

View File

@ -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;

View File

@ -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";