style: format imports

Re-order and re-format the imports so that they follow a consistent
pattern.

This helps eliminate conflicts due to imports.
pull/24376/head
Dom Dwyer 2022-10-26 16:24:49 +02:00
parent 69a2e6b871
commit 0c5eb3f70f
23 changed files with 120 additions and 71 deletions

View File

@ -1,3 +1,5 @@
use std::{collections::BTreeSet, iter, sync::Arc};
use criterion::{criterion_group, criterion_main, Criterion, Throughput};
use data_types::{PartitionTemplate, TemplatePart};
use hyper::{Body, Request};
@ -12,7 +14,6 @@ use router::{
shard::Shard,
};
use sharder::JumpHash;
use std::{collections::BTreeSet, iter, sync::Arc};
use tokio::runtime::Runtime;
use write_buffer::{
core::WriteBufferWriting,

View File

@ -1,3 +1,5 @@
use std::{iter, sync::Arc};
use criterion::{
criterion_group, criterion_main, measurement::WallTime, BatchSize, BenchmarkGroup, Criterion,
Throughput,
@ -12,7 +14,6 @@ use router::{
namespace_cache::{MemoryNamespaceCache, ShardedCache},
};
use schema::selection::Selection;
use std::{iter, sync::Arc};
use tokio::runtime::Runtime;
static NAMESPACE: Lazy<DatabaseName<'static>> = Lazy::new(|| "bananas".try_into().unwrap());

View File

@ -1,8 +1,9 @@
use super::{DmlError, DmlHandler};
use async_trait::async_trait;
use data_types::{DatabaseName, DeletePredicate};
use trace::ctx::SpanContext;
use super::{DmlError, DmlHandler};
/// An extension trait to chain together the execution of a pair of
/// [`DmlHandler`] implementations.
pub trait DmlHandlerChainExt: DmlHandler + Sized {

View File

@ -1,10 +1,12 @@
use super::DmlHandler;
use std::{fmt::Debug, marker::PhantomData};
use async_trait::async_trait;
use data_types::{DatabaseName, DeletePredicate};
use futures::{stream::FuturesUnordered, TryStreamExt};
use std::{fmt::Debug, marker::PhantomData};
use trace::ctx::SpanContext;
use super::DmlHandler;
/// A [`FanOutAdaptor`] takes an iterator of DML write operation inputs and
/// executes them concurrently against the inner handler, returning once all
/// operations are complete.

View File

@ -1,4 +1,3 @@
use super::DmlHandler;
use async_trait::async_trait;
use data_types::{DatabaseName, DeletePredicate};
use iox_time::{SystemProvider, TimeProvider};
@ -8,6 +7,8 @@ use trace::{
span::{SpanExt, SpanRecorder},
};
use super::DmlHandler;
/// An instrumentation decorator recording call latencies for [`DmlHandler`] implementations.
///
/// Metrics are broken down by operation (write/delete) and result (success/error).
@ -135,15 +136,17 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::dml_handlers::{mock::MockDmlHandler, DmlError};
use std::sync::Arc;
use assert_matches::assert_matches;
use data_types::TimestampRange;
use metric::Attributes;
use std::sync::Arc;
use trace::{span::SpanStatus, RingBufferTraceCollector, TraceCollector};
use write_summary::WriteSummary;
use super::*;
use crate::dml_handlers::{mock::MockDmlHandler, DmlError};
const HANDLER_NAME: &str = "bananas";
fn assert_metric_hit(

View File

@ -1,11 +1,13 @@
use super::{DmlError, DmlHandler};
use std::{collections::VecDeque, fmt::Debug};
use async_trait::async_trait;
use data_types::{DatabaseName, DeletePredicate};
use parking_lot::Mutex;
use std::{collections::VecDeque, fmt::Debug};
use trace::ctx::SpanContext;
use write_summary::WriteSummary;
use super::{DmlError, DmlHandler};
/// A captured call to a [`MockDmlHandler`], generic over `W`, the captured
/// [`DmlHandler::WriteInput`] type.
#[derive(Debug, Clone)]

View File

@ -1,12 +1,14 @@
//! A NOP implementation of [`DmlHandler`].
use super::{DmlError, DmlHandler};
use std::{fmt::Debug, marker::PhantomData};
use async_trait::async_trait;
use data_types::{DatabaseName, DeletePredicate};
use observability_deps::tracing::*;
use std::{fmt::Debug, marker::PhantomData};
use trace::ctx::SpanContext;
use super::{DmlError, DmlHandler};
/// A [`DmlHandler`] implementation that does nothing.
#[derive(Debug)]
pub struct NopDmlHandler<T>(PhantomData<T>);

View File

@ -1,13 +1,15 @@
use super::DmlHandler;
use crate::namespace_cache::NamespaceCache;
use std::{fmt::Debug, marker::PhantomData, sync::Arc};
use async_trait::async_trait;
use data_types::{DatabaseName, DeletePredicate, QueryPoolId, TopicId};
use iox_catalog::interface::Catalog;
use observability_deps::tracing::*;
use std::{fmt::Debug, marker::PhantomData, sync::Arc};
use thiserror::Error;
use trace::ctx::SpanContext;
use super::DmlHandler;
use crate::namespace_cache::NamespaceCache;
/// An error auto-creating the request namespace.
#[derive(Debug, Error)]
pub enum NamespaceCreationError {
@ -130,11 +132,13 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::namespace_cache::MemoryNamespaceCache;
use std::sync::Arc;
use data_types::{Namespace, NamespaceId, NamespaceSchema};
use iox_catalog::mem::MemCatalog;
use std::sync::Arc;
use super::*;
use crate::namespace_cache::MemoryNamespaceCache;
#[tokio::test]
async fn test_cache_hit() {

View File

@ -1,4 +1,3 @@
use super::DmlHandler;
use async_trait::async_trait;
use data_types::{DatabaseName, DeletePredicate, PartitionKey, PartitionTemplate};
use hashbrown::HashMap;
@ -7,6 +6,8 @@ use observability_deps::tracing::*;
use thiserror::Error;
use trace::ctx::SpanContext;
use super::DmlHandler;
/// An error raised by the [`Partitioner`] handler.
#[derive(Debug, Error)]
pub enum PartitionError {
@ -112,10 +113,11 @@ impl DmlHandler for Partitioner {
#[cfg(test)]
mod tests {
use super::*;
use assert_matches::assert_matches;
use data_types::TemplatePart;
use super::*;
/// The default timestamp applied to test LP if the write does not specify
/// one.
const DEFAULT_TIMESTAMP_NANOS: i64 = 42000000000000000;

View File

@ -1,5 +1,5 @@
use super::DmlHandler;
use crate::namespace_cache::{metrics::InstrumentedCache, MemoryNamespaceCache, NamespaceCache};
use std::{ops::DerefMut, sync::Arc};
use async_trait::async_trait;
use data_types::{DatabaseName, DeletePredicate, NamespaceSchema};
use hashbrown::HashMap;
@ -10,10 +10,12 @@ use iox_catalog::{
use metric::U64Counter;
use mutable_batch::MutableBatch;
use observability_deps::tracing::*;
use std::{ops::DerefMut, sync::Arc};
use thiserror::Error;
use trace::ctx::SpanContext;
use super::DmlHandler;
use crate::namespace_cache::{metrics::InstrumentedCache, MemoryNamespaceCache, NamespaceCache};
/// Errors emitted during schema validation.
#[derive(Debug, Error)]
pub enum SchemaError {
@ -328,12 +330,14 @@ fn validate_column_limits(
#[cfg(test)]
mod tests {
use super::*;
use std::sync::Arc;
use assert_matches::assert_matches;
use data_types::{ColumnType, TimestampRange};
use iox_tests::util::{TestCatalog, TestNamespace};
use once_cell::sync::Lazy;
use std::sync::Arc;
use super::*;
static NAMESPACE: Lazy<DatabaseName<'static>> = Lazy::new(|| "bananas".try_into().unwrap());

View File

@ -1,7 +1,10 @@
//! Logic to shard writes/deletes and push them into a write buffer shard.
use super::Partitioned;
use crate::{dml_handlers::DmlHandler, shard::Shard};
use std::{
fmt::{Debug, Display},
sync::Arc,
};
use async_trait::async_trait;
use data_types::{DatabaseName, DeletePredicate, NonEmptyString};
use dml::{DmlDelete, DmlMeta, DmlOperation, DmlWrite};
@ -10,14 +13,13 @@ use hashbrown::HashMap;
use mutable_batch::MutableBatch;
use observability_deps::tracing::*;
use sharder::Sharder;
use std::{
fmt::{Debug, Display},
sync::Arc,
};
use thiserror::Error;
use trace::ctx::SpanContext;
use write_buffer::core::WriteBufferError;
use super::Partitioned;
use crate::{dml_handlers::DmlHandler, shard::Shard};
/// Errors occurring while writing to one or more write buffer shards.
#[derive(Debug, Error)]
pub enum ShardError {
@ -211,14 +213,16 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::dml_handlers::DmlHandler;
use std::sync::Arc;
use assert_matches::assert_matches;
use data_types::{ShardIndex, TimestampRange};
use sharder::mock::{MockSharder, MockSharderCall, MockSharderPayload};
use std::sync::Arc;
use write_buffer::mock::{MockBufferForWriting, MockBufferSharedState};
use super::*;
use crate::dml_handlers::DmlHandler;
// Parse `lp` into a table-keyed MutableBatch map.
fn lp_to_writes(lp: &str) -> Partitioned<HashMap<String, MutableBatch>> {
let (writes, _) = mutable_batch_lp::lines_to_batches_stats(lp, 42)

View File

@ -1,10 +1,12 @@
use super::{partitioner::PartitionError, NamespaceCreationError, SchemaError, ShardError};
use std::{error::Error, fmt::Debug, sync::Arc};
use async_trait::async_trait;
use data_types::{DatabaseName, DeletePredicate};
use std::{error::Error, fmt::Debug, sync::Arc};
use thiserror::Error;
use trace::ctx::SpanContext;
use super::{partitioner::PartitionError, NamespaceCreationError, SchemaError, ShardError};
/// Errors emitted by a [`DmlHandler`] implementation during DML request
/// processing.
#[derive(Debug, Error)]

View File

@ -1,11 +1,13 @@
use super::DmlHandler;
use std::fmt::Debug;
use async_trait::async_trait;
use data_types::{DatabaseName, DeletePredicate};
use dml::DmlMeta;
use std::fmt::Debug;
use trace::ctx::SpanContext;
use write_summary::WriteSummary;
use super::DmlHandler;
/// A [`WriteSummaryAdapter`] wraps DML Handler that produces
/// `Vec<Vec<DmlMeta>>` for each write, and produces a WriteSummary,
/// suitable for

View File

@ -8,9 +8,10 @@ pub use sharded_cache::*;
pub mod metrics;
use data_types::{DatabaseName, NamespaceSchema};
use std::{fmt::Debug, sync::Arc};
use data_types::{DatabaseName, NamespaceSchema};
/// An abstract cache of [`NamespaceSchema`].
pub trait NamespaceCache: Debug + Send + Sync {
/// Return the [`NamespaceSchema`] for `namespace`.

View File

@ -1,8 +1,10 @@
use super::NamespaceCache;
use std::sync::Arc;
use data_types::{DatabaseName, NamespaceSchema};
use hashbrown::HashMap;
use parking_lot::RwLock;
use std::sync::Arc;
use super::NamespaceCache;
/// An in-memory cache of [`NamespaceSchema`] backed by a hashmap protected with
/// a read-write mutex.
@ -27,9 +29,10 @@ impl NamespaceCache for Arc<MemoryNamespaceCache> {
#[cfg(test)]
mod tests {
use super::*;
use data_types::{NamespaceId, QueryPoolId, TopicId};
use super::*;
#[test]
fn test_put_get() {
let ns = DatabaseName::new("test").expect("database name is valid");

View File

@ -1,10 +1,12 @@
//! Metric instrumentation for a [`NamespaceCache`] implementation.
use super::NamespaceCache;
use std::sync::Arc;
use data_types::{DatabaseName, NamespaceSchema};
use iox_time::{SystemProvider, TimeProvider};
use metric::{DurationHistogram, Metric, U64Gauge};
use std::sync::Arc;
use super::NamespaceCache;
/// An [`InstrumentedCache`] decorates a [`NamespaceCache`] with cache read
/// hit/miss and cache put insert/update metrics.
@ -151,13 +153,15 @@ impl NamespaceStats {
#[cfg(test)]
mod tests {
use super::*;
use crate::namespace_cache::MemoryNamespaceCache;
use std::collections::BTreeMap;
use data_types::{
ColumnId, ColumnSchema, ColumnType, NamespaceId, QueryPoolId, TableId, TableSchema, TopicId,
};
use metric::{Attributes, MetricObserver, Observation};
use std::collections::BTreeMap;
use super::*;
use crate::namespace_cache::MemoryNamespaceCache;
/// Deterministically generate a schema containing tables with the specified
/// column cardinality.

View File

@ -1,7 +1,9 @@
use super::NamespaceCache;
use std::sync::Arc;
use data_types::{DatabaseName, NamespaceSchema};
use sharder::JumpHash;
use std::sync::Arc;
use super::NamespaceCache;
/// A decorator sharding the [`NamespaceCache`] keyspace into a set of `T`.
#[derive(Debug)]
@ -38,11 +40,13 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::namespace_cache::MemoryNamespaceCache;
use std::{collections::HashMap, iter};
use data_types::{NamespaceId, QueryPoolId, TopicId};
use rand::{distributions::Alphanumeric, thread_rng, Rng};
use std::{collections::HashMap, iter};
use super::*;
use crate::namespace_cache::MemoryNamespaceCache;
fn rand_namespace() -> DatabaseName<'static> {
thread_rng()

View File

@ -1,11 +1,13 @@
//! Router server entrypoint.
use std::sync::Arc;
use hashbrown::HashMap;
use mutable_batch::MutableBatch;
use trace::TraceCollector;
use self::{grpc::GrpcDelegate, http::HttpDelegate};
use crate::dml_handlers::DmlHandler;
use hashbrown::HashMap;
use mutable_batch::MutableBatch;
use std::sync::Arc;
use trace::TraceCollector;
pub mod grpc;
pub mod http;

View File

@ -2,8 +2,8 @@
pub mod sharder;
use self::sharder::ShardService;
use crate::shard::Shard;
use std::sync::Arc;
use ::sharder::Sharder;
use generated_types::influxdata::iox::{
catalog::v1::*, object_store::v1::*, schema::v1::*, sharder::v1::*,
@ -13,7 +13,9 @@ use object_store::DynObjectStore;
use service_grpc_catalog::CatalogService;
use service_grpc_object_store::ObjectStoreService;
use service_grpc_schema::SchemaService;
use std::sync::Arc;
use self::sharder::ShardService;
use crate::shard::Shard;
/// This type is responsible for managing all gRPC services exposed by `router`.
#[derive(Debug)]

View File

@ -1,6 +1,7 @@
//! A gRPC service to provide shard mappings to external clients.
use crate::shard::Shard;
use std::sync::Arc;
use data_types::{DatabaseName, ShardId, ShardIndex, TopicMetadata};
use generated_types::influxdata::iox::sharder::v1::{
shard_service_server, MapToShardRequest, MapToShardResponse,
@ -8,9 +9,10 @@ use generated_types::influxdata::iox::sharder::v1::{
use hashbrown::HashMap;
use iox_catalog::interface::Catalog;
use sharder::Sharder;
use std::sync::Arc;
use tonic::{Request, Response};
use crate::shard::Shard;
/// A [`ShardService`] exposes a [gRPC endpoint] for external systems to discover the shard mapping
/// for specific tables.
///

View File

@ -2,8 +2,8 @@
mod delete_predicate;
use self::delete_predicate::parse_http_delete_request;
use crate::dml_handlers::{DmlError, DmlHandler, PartitionError, SchemaError};
use std::{str::Utf8Error, sync::Arc, time::Instant};
use bytes::{Bytes, BytesMut};
use data_types::{org_and_bucket_to_database, OrgBucketMappingError};
use futures::StreamExt;
@ -16,13 +16,14 @@ use mutable_batch_lp::LinesConverter;
use observability_deps::tracing::*;
use predicate::delete_predicate::parse_delete_predicate;
use serde::Deserialize;
use std::time::Instant;
use std::{str::Utf8Error, sync::Arc};
use thiserror::Error;
use tokio::sync::{Semaphore, TryAcquireError};
use trace::ctx::SpanContext;
use write_summary::WriteSummary;
use self::delete_predicate::parse_http_delete_request;
use crate::dml_handlers::{DmlError, DmlHandler, PartitionError, SchemaError};
const WRITE_TOKEN_HTTP_HEADER: &str = "X-IOx-Write-Token";
/// Errors returned by the `router` HTTP request handler.
@ -521,7 +522,6 @@ mod tests {
use std::{io::Write, iter, sync::Arc, time::Duration};
use assert_matches::assert_matches;
use flate2::{write::GzEncoder, Compression};
use hyper::header::HeaderValue;
use metric::{Attributes, Metric};
@ -530,9 +530,8 @@ mod tests {
use test_helpers::timeout::FutureTimeout;
use tokio_stream::wrappers::ReceiverStream;
use crate::dml_handlers::mock::{MockDmlHandler, MockDmlHandlerCall};
use super::*;
use crate::dml_handlers::mock::{MockDmlHandler, MockDmlHandlerCall};
const MAX_BYTES: usize = 1024;

View File

@ -1,10 +1,11 @@
//! A representation of a single operation shard.
use std::{borrow::Cow, hash::Hash, sync::Arc};
use data_types::ShardIndex;
use dml::{DmlMeta, DmlOperation};
use iox_time::{SystemProvider, TimeProvider};
use metric::{DurationHistogram, Metric};
use std::{borrow::Cow, hash::Hash, sync::Arc};
use write_buffer::core::{WriteBufferError, WriteBufferWriting};
/// A shard tags a write buffer with a shard index (Kafka partition).

View File

@ -1,3 +1,5 @@
use std::{collections::BTreeSet, iter, string::String, sync::Arc};
use assert_matches::assert_matches;
use data_types::{ColumnType, PartitionTemplate, QueryPoolId, ShardIndex, TemplatePart, TopicId};
use dml::DmlOperation;
@ -17,7 +19,6 @@ use router::{
shard::Shard,
};
use sharder::JumpHash;
use std::{collections::BTreeSet, iter, string::String, sync::Arc};
use write_buffer::{
core::WriteBufferWriting,
mock::{MockBufferForWriting, MockBufferSharedState},