From 2f8d9984d02c34d7e9e00b047b4ac3fd579ec908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Wed, 30 Aug 2023 13:45:03 +0200 Subject: [PATCH 01/43] topology->metadata --- scylla/src/transport/cluster.rs | 4 ++-- scylla/src/transport/connection.rs | 4 ++-- scylla/src/transport/connection_pool.rs | 4 ++-- scylla/src/transport/host_filter.rs | 4 ++-- scylla/src/transport/load_balancing/default.rs | 4 ++-- scylla/src/transport/locator/mod.rs | 2 +- scylla/src/transport/locator/precomputed_replicas.rs | 4 ++-- scylla/src/transport/locator/test.rs | 2 +- scylla/src/transport/{topology.rs => metadata.rs} | 0 scylla/src/transport/mod.rs | 2 +- scylla/src/transport/node.rs | 2 +- scylla/src/transport/session.rs | 2 +- scylla/src/transport/session_builder.rs | 2 +- scylla/src/transport/session_test.rs | 8 ++++---- 14 files changed, 22 insertions(+), 22 deletions(-) rename scylla/src/transport/{topology.rs => metadata.rs} (100%) diff --git a/scylla/src/transport/cluster.rs b/scylla/src/transport/cluster.rs index 503d14519d..a3a12f2e8d 100644 --- a/scylla/src/transport/cluster.rs +++ b/scylla/src/transport/cluster.rs @@ -8,9 +8,9 @@ use crate::transport::{ connection::{Connection, VerifiedKeyspaceName}, connection_pool::PoolConfig, errors::QueryError, + metadata::{Keyspace, Metadata, MetadataReader}, node::Node, partitioner::PartitionerName, - topology::{Keyspace, Metadata, MetadataReader}, }; use arc_swap::ArcSwap; @@ -29,8 +29,8 @@ use uuid::Uuid; use super::node::{KnownNode, NodeAddr}; use super::locator::ReplicaLocator; +use super::metadata::Strategy; use super::partitioner::calculate_token_for_partition_key; -use super::topology::Strategy; /// Cluster manages up to date information and connections to database nodes. /// All data can be accessed by cloning Arc in the `data` field diff --git a/scylla/src/transport/connection.rs b/scylla/src/transport/connection.rs index bd12ed0614..75156aa99d 100644 --- a/scylla/src/transport/connection.rs +++ b/scylla/src/transport/connection.rs @@ -39,8 +39,8 @@ use std::{ use super::errors::{BadKeyspaceName, DbError, QueryError}; use super::iterator::RowIterator; +use super::metadata::{PeerEndpoint, UntranslatedEndpoint, UntranslatedPeer}; use super::session::AddressTranslator; -use super::topology::{PeerEndpoint, UntranslatedEndpoint, UntranslatedPeer}; use super::NodeAddr; #[cfg(feature = "cloud")] use crate::cloud::CloudConfig; @@ -1765,8 +1765,8 @@ mod tests { use super::ConnectionConfig; use crate::query::Query; use crate::transport::connection::open_connection; + use crate::transport::metadata::UntranslatedEndpoint; use crate::transport::node::ResolvedContactPoint; - use crate::transport::topology::UntranslatedEndpoint; use crate::utils::test_utils::unique_keyspace_name; use crate::{IntoTypedRows, SessionBuilder}; use futures::{StreamExt, TryStreamExt}; diff --git a/scylla/src/transport/connection_pool.rs b/scylla/src/transport/connection_pool.rs index f26ea36ac2..849e1d2735 100644 --- a/scylla/src/transport/connection_pool.rs +++ b/scylla/src/transport/connection_pool.rs @@ -11,9 +11,9 @@ use crate::transport::{ #[cfg(feature = "cloud")] use super::node::resolve_hostname; +use super::metadata::{PeerEndpoint, UntranslatedEndpoint}; #[cfg(feature = "cloud")] use super::node::ResolvedContactPoint; -use super::topology::{PeerEndpoint, UntranslatedEndpoint}; use super::NodeAddr; use arc_swap::ArcSwap; @@ -1260,8 +1260,8 @@ mod tests { use super::open_connection_to_shard_aware_port; use crate::routing::{ShardCount, Sharder}; use crate::transport::connection::ConnectionConfig; + use crate::transport::metadata::UntranslatedEndpoint; use crate::transport::node::ResolvedContactPoint; - use crate::transport::topology::UntranslatedEndpoint; use std::net::{SocketAddr, ToSocketAddrs}; // Open many connections to a node diff --git a/scylla/src/transport/host_filter.rs b/scylla/src/transport/host_filter.rs index d59f90a49a..9bce4a3dc0 100644 --- a/scylla/src/transport/host_filter.rs +++ b/scylla/src/transport/host_filter.rs @@ -1,7 +1,7 @@ //! Host filters. //! //! Host filters are essentially just a predicate over -//! [`Peer`](crate::transport::topology::Peer)s. Currently, they are used +//! [`Peer`](crate::transport::metadata::Peer)s. Currently, they are used //! by the [`Session`](crate::transport::session::Session) to determine whether //! connections should be opened to a given node or not. @@ -9,7 +9,7 @@ use std::collections::HashSet; use std::io::Error; use std::net::{SocketAddr, ToSocketAddrs}; -use crate::transport::topology::Peer; +use crate::transport::metadata::Peer; /// The `HostFilter` trait. pub trait HostFilter: Send + Sync { diff --git a/scylla/src/transport/load_balancing/default.rs b/scylla/src/transport/load_balancing/default.rs index 3c2097c9dc..48ffb98f24 100644 --- a/scylla/src/transport/load_balancing/default.rs +++ b/scylla/src/transport/load_balancing/default.rs @@ -4,7 +4,7 @@ pub use self::latency_awareness::LatencyAwarenessBuilder; use super::{FallbackPlan, LoadBalancingPolicy, NodeRef, RoutingInfo}; use crate::{ routing::Token, - transport::{cluster::ClusterData, locator::ReplicaSet, node::Node, topology::Strategy}, + transport::{cluster::ClusterData, locator::ReplicaSet, metadata::Strategy, node::Node}, }; use itertools::{Either, Itertools}; use rand::{prelude::SliceRandom, thread_rng, Rng}; @@ -896,7 +896,7 @@ mod tests { routing::Token, transport::{ locator::test::{id_to_invalid_addr, mock_metadata_for_token_aware_tests}, - topology::{Metadata, Peer}, + metadata::{Metadata, Peer}, ClusterData, }, }; diff --git a/scylla/src/transport/locator/mod.rs b/scylla/src/transport/locator/mod.rs index db55b9fe69..185fb00d94 100644 --- a/scylla/src/transport/locator/mod.rs +++ b/scylla/src/transport/locator/mod.rs @@ -8,7 +8,7 @@ mod token_ring; use rand::{seq::IteratorRandom, Rng}; pub use token_ring::TokenRing; -use super::{topology::Strategy, Node, NodeRef}; +use super::{metadata::Strategy, Node, NodeRef}; use crate::routing::Token; use itertools::Itertools; use precomputed_replicas::PrecomputedReplicas; diff --git a/scylla/src/transport/locator/precomputed_replicas.rs b/scylla/src/transport/locator/precomputed_replicas.rs index de6d5e1a63..4208166e12 100644 --- a/scylla/src/transport/locator/precomputed_replicas.rs +++ b/scylla/src/transport/locator/precomputed_replicas.rs @@ -15,8 +15,8 @@ use super::replication_info::ReplicationInfo; use super::TokenRing; use crate::routing::Token; +use crate::transport::metadata::Strategy; use crate::transport::node::Node; -use crate::transport::topology::Strategy; use std::cmp; use std::collections::BTreeSet; @@ -218,7 +218,7 @@ mod tests { routing::Token, transport::{ locator::test::{create_ring, mock_metadata_for_token_aware_tests, A, C, D, E, F, G}, - topology::{Keyspace, Strategy}, + metadata::{Keyspace, Strategy}, }, }; diff --git a/scylla/src/transport/locator/test.rs b/scylla/src/transport/locator/test.rs index d09a22d7c1..266c05e58f 100644 --- a/scylla/src/transport/locator/test.rs +++ b/scylla/src/transport/locator/test.rs @@ -6,7 +6,7 @@ use super::{ReplicaLocator, ReplicaSet}; use crate::routing::Token; use crate::transport::{ connection_pool::PoolConfig, - topology::{Keyspace, Metadata, Peer, Strategy}, + metadata::{Keyspace, Metadata, Peer, Strategy}, Node, }; use crate::transport::{NodeAddr, NodeRef}; diff --git a/scylla/src/transport/topology.rs b/scylla/src/transport/metadata.rs similarity index 100% rename from scylla/src/transport/topology.rs rename to scylla/src/transport/metadata.rs diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs index 6025bf639f..c57e5bb496 100644 --- a/scylla/src/transport/mod.rs +++ b/scylla/src/transport/mod.rs @@ -8,6 +8,7 @@ pub mod host_filter; pub mod iterator; pub mod load_balancing; pub mod locator; +pub mod metadata; pub(crate) mod metrics; mod node; pub mod partitioner; @@ -16,7 +17,6 @@ pub mod retry_policy; pub mod session; pub mod session_builder; pub mod speculative_execution; -pub mod topology; pub use crate::frame::{Authenticator, Compression}; pub use execution_profile::ExecutionProfile; diff --git a/scylla/src/transport/node.rs b/scylla/src/transport/node.rs index 97b2679461..0bd424210e 100644 --- a/scylla/src/transport/node.rs +++ b/scylla/src/transport/node.rs @@ -21,7 +21,7 @@ use std::{ }, }; -use super::topology::{PeerEndpoint, UntranslatedEndpoint}; +use super::metadata::{PeerEndpoint, UntranslatedEndpoint}; /// This enum is introduced to support address translation only upon opening a connection, /// as well as to cope with a bug present in older Cassandra and Scylla releases. diff --git a/scylla/src/transport/session.rs b/scylla/src/transport/session.rs index 790f840400..0802f45477 100644 --- a/scylla/src/transport/session.rs +++ b/scylla/src/transport/session.rs @@ -38,11 +38,11 @@ use super::connection::QueryResponse; use super::connection::SslConfig; use super::errors::{NewSessionError, QueryError}; use super::execution_profile::{ExecutionProfile, ExecutionProfileHandle, ExecutionProfileInner}; +use super::metadata::UntranslatedPeer; #[cfg(feature = "cloud")] use super::node::CloudEndpoint; use super::node::KnownNode; use super::partitioner::PartitionerName; -use super::topology::UntranslatedPeer; use super::NodeRef; use crate::cql_to_rust::FromRow; use crate::frame::response::cql_to_rust::FromRowError; diff --git a/scylla/src/transport/session_builder.rs b/scylla/src/transport/session_builder.rs index 394a348ca2..6c9f3e5bcc 100644 --- a/scylla/src/transport/session_builder.rs +++ b/scylla/src/transport/session_builder.rs @@ -254,7 +254,7 @@ impl GenericSessionBuilder { /// # use std::sync::Arc; /// # use scylla::{Session, SessionBuilder}; /// # use scylla::transport::session::{AddressTranslator, TranslationError}; - /// # use scylla::transport::topology::UntranslatedPeer; + /// # use scylla::transport::metadata::UntranslatedPeer; /// struct IdentityTranslator; /// /// #[async_trait] diff --git a/scylla/src/transport/session_test.rs b/scylla/src/transport/session_test.rs index 6bc9f0e4f1..36852f7e4d 100644 --- a/scylla/src/transport/session_test.rs +++ b/scylla/src/transport/session_test.rs @@ -10,13 +10,13 @@ use crate::statement::Consistency; use crate::tracing::TracingInfo; use crate::transport::cluster::Datacenter; use crate::transport::errors::{BadKeyspaceName, BadQuery, DbError, QueryError}; +use crate::transport::metadata::Strategy::NetworkTopologyStrategy; +use crate::transport::metadata::{ + CollectionType, ColumnKind, CqlType, NativeType, UserDefinedType, +}; use crate::transport::partitioner::{ calculate_token_for_partition_key, Murmur3Partitioner, Partitioner, PartitionerName, }; -use crate::transport::topology::Strategy::NetworkTopologyStrategy; -use crate::transport::topology::{ - CollectionType, ColumnKind, CqlType, NativeType, UserDefinedType, -}; use crate::utils::test_utils::{ create_new_session_builder, supports_feature, unique_keyspace_name, }; From 6e3dc3844988c20891871c5ca6cff914a850bb46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Wed, 30 Aug 2023 13:53:43 +0200 Subject: [PATCH 02/43] AddressTranslator session->connection --- scylla/src/transport/connection.rs | 60 ++++++++++++++++++++++- scylla/src/transport/session.rs | 63 +------------------------ scylla/src/transport/session_builder.rs | 3 +- 3 files changed, 62 insertions(+), 64 deletions(-) diff --git a/scylla/src/transport/connection.rs b/scylla/src/transport/connection.rs index 75156aa99d..72d6f36dd3 100644 --- a/scylla/src/transport/connection.rs +++ b/scylla/src/transport/connection.rs @@ -1,3 +1,4 @@ +use async_trait::async_trait; use bytes::Bytes; use futures::{future::RemoteHandle, FutureExt}; use scylla_cql::errors::TranslationError; @@ -16,6 +17,7 @@ use uuid::Uuid; use std::borrow::Cow; #[cfg(feature = "ssl")] use std::pin::Pin; +use std::str::FromStr; use std::sync::atomic::AtomicU64; use std::time::Duration; #[cfg(feature = "ssl")] @@ -40,7 +42,6 @@ use std::{ use super::errors::{BadKeyspaceName, DbError, QueryError}; use super::iterator::RowIterator; use super::metadata::{PeerEndpoint, UntranslatedEndpoint, UntranslatedPeer}; -use super::session::AddressTranslator; use super::NodeAddr; #[cfg(feature = "cloud")] use crate::cloud::CloudConfig; @@ -1303,6 +1304,63 @@ impl Connection { } } +/// Translates IP addresses received from ScyllaDB nodes into locally reachable addresses. +/// +/// The driver auto-detects new ScyllaDB nodes added to the cluster through server side pushed +/// notifications and through checking the system tables. For each node, the address the driver +/// receives corresponds to the address set as `rpc_address` in the node yaml file. In most +/// cases, this is the correct address to use by the driver and that is what is used by default. +/// However, sometimes the addresses received through this mechanism will either not be reachable +/// directly by the driver or should not be the preferred address to use to reach the node (for +/// instance, the `rpc_address` set on ScyllaDB nodes might be a private IP, but some clients +/// may have to use a public IP, or pass by a router, e.g. through NAT, to reach that node). +/// This interface allows to deal with such cases, by allowing to translate an address as sent +/// by a ScyllaDB node to another address to be used by the driver for connection. +/// +/// Please note that the "known nodes" addresses provided while creating the [`Session`] +/// instance are not translated, only IP address retrieved from or sent by Cassandra nodes +/// to the driver are. +#[async_trait] +pub trait AddressTranslator: Send + Sync { + async fn translate_address( + &self, + untranslated_peer: &UntranslatedPeer, + ) -> Result; +} + +#[async_trait] +impl AddressTranslator for HashMap { + async fn translate_address( + &self, + untranslated_peer: &UntranslatedPeer, + ) -> Result { + match self.get(&untranslated_peer.untranslated_address) { + Some(&translated_addr) => Ok(translated_addr), + None => Err(TranslationError::NoRuleForAddress), + } + } +} + +#[async_trait] +// Notice: this is unefficient, but what else can we do with such poor representation as str? +// After all, the cluster size is small enough to make this irrelevant. +impl AddressTranslator for HashMap<&'static str, &'static str> { + async fn translate_address( + &self, + untranslated_peer: &UntranslatedPeer, + ) -> Result { + for (&rule_addr_str, &translated_addr_str) in self.iter() { + if let Ok(rule_addr) = SocketAddr::from_str(rule_addr_str) { + if rule_addr == untranslated_peer.untranslated_address { + return SocketAddr::from_str(translated_addr_str) + .map_err(|_| TranslationError::InvalidAddressInRule); + } + } + } + Err(TranslationError::NoRuleForAddress) + } +} + async fn maybe_translated_addr( endpoint: UntranslatedEndpoint, address_translator: Option<&dyn AddressTranslator>, diff --git a/scylla/src/transport/session.rs b/scylla/src/transport/session.rs index 0802f45477..e415060bac 100644 --- a/scylla/src/transport/session.rs +++ b/scylla/src/transport/session.rs @@ -9,7 +9,6 @@ use crate::history::HistoryListener; use crate::utils::pretty::{CommaSeparatedDisplayer, CqlValueDisplayer}; use crate::utils::unzip_option; use arc_swap::ArcSwapOption; -use async_trait::async_trait; use bytes::Bytes; use futures::future::join_all; use futures::future::try_join_all; @@ -18,12 +17,10 @@ pub use scylla_cql::errors::TranslationError; use scylla_cql::frame::response::result::{deser_cql_value, ColumnSpec, Rows}; use scylla_cql::frame::response::NonErrorResponse; use std::borrow::Borrow; -use std::collections::HashMap; use std::fmt::Display; use std::future::Future; use std::net::SocketAddr; use std::num::NonZeroU32; -use std::str::FromStr; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; use std::sync::Arc; @@ -32,13 +29,12 @@ use tokio::time::timeout; use tracing::{debug, trace, trace_span, Instrument}; use uuid::Uuid; -use super::connection::NonErrorQueryResponse; use super::connection::QueryResponse; #[cfg(feature = "ssl")] use super::connection::SslConfig; +use super::connection::{AddressTranslator, NonErrorQueryResponse}; use super::errors::{NewSessionError, QueryError}; use super::execution_profile::{ExecutionProfile, ExecutionProfileHandle, ExecutionProfileInner}; -use super::metadata::UntranslatedPeer; #[cfg(feature = "cloud")] use super::node::CloudEndpoint; use super::node::KnownNode; @@ -78,63 +74,6 @@ use crate::authentication::AuthenticatorProvider; #[cfg(feature = "ssl")] use openssl::ssl::SslContext; -/// Translates IP addresses received from ScyllaDB nodes into locally reachable addresses. -/// -/// The driver auto-detects new ScyllaDB nodes added to the cluster through server side pushed -/// notifications and through checking the system tables. For each node, the address the driver -/// receives corresponds to the address set as `rpc_address` in the node yaml file. In most -/// cases, this is the correct address to use by the driver and that is what is used by default. -/// However, sometimes the addresses received through this mechanism will either not be reachable -/// directly by the driver or should not be the preferred address to use to reach the node (for -/// instance, the `rpc_address` set on ScyllaDB nodes might be a private IP, but some clients -/// may have to use a public IP, or pass by a router, e.g. through NAT, to reach that node). -/// This interface allows to deal with such cases, by allowing to translate an address as sent -/// by a ScyllaDB node to another address to be used by the driver for connection. -/// -/// Please note that the "known nodes" addresses provided while creating the [`Session`] -/// instance are not translated, only IP address retrieved from or sent by Cassandra nodes -/// to the driver are. -#[async_trait] -pub trait AddressTranslator: Send + Sync { - async fn translate_address( - &self, - untranslated_peer: &UntranslatedPeer, - ) -> Result; -} - -#[async_trait] -impl AddressTranslator for HashMap { - async fn translate_address( - &self, - untranslated_peer: &UntranslatedPeer, - ) -> Result { - match self.get(&untranslated_peer.untranslated_address) { - Some(&translated_addr) => Ok(translated_addr), - None => Err(TranslationError::NoRuleForAddress), - } - } -} - -#[async_trait] -// Notice: this is unefficient, but what else can we do with such poor representation as str? -// After all, the cluster size is small enough to make this irrelevant. -impl AddressTranslator for HashMap<&'static str, &'static str> { - async fn translate_address( - &self, - untranslated_peer: &UntranslatedPeer, - ) -> Result { - for (&rule_addr_str, &translated_addr_str) in self.iter() { - if let Ok(rule_addr) = SocketAddr::from_str(rule_addr_str) { - if rule_addr == untranslated_peer.untranslated_address { - return SocketAddr::from_str(translated_addr_str) - .map_err(|_| TranslationError::InvalidAddressInRule); - } - } - } - Err(TranslationError::NoRuleForAddress) - } -} - /// `Session` manages connections to the cluster and allows to perform queries pub struct Session { cluster: Cluster, diff --git a/scylla/src/transport/session_builder.rs b/scylla/src/transport/session_builder.rs index 6c9f3e5bcc..2a78c90b5c 100644 --- a/scylla/src/transport/session_builder.rs +++ b/scylla/src/transport/session_builder.rs @@ -1,8 +1,9 @@ //! SessionBuilder provides an easy way to create new Sessions +use super::connection::AddressTranslator; use super::errors::NewSessionError; use super::execution_profile::ExecutionProfileHandle; -use super::session::{AddressTranslator, Session, SessionConfig}; +use super::session::{Session, SessionConfig}; use super::Compression; #[cfg(feature = "cloud")] From e28ac5b72088f5894e06fb75db0224ad9ef85e55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Wed, 30 Aug 2023 13:56:31 +0200 Subject: [PATCH 03/43] routing->sharding --- examples/compare-tokens.rs | 2 +- scylla/src/lib.rs | 2 +- scylla/src/{routing.rs => sharding.rs} | 0 scylla/src/statement/prepared_statement.rs | 2 +- scylla/src/transport/cluster.rs | 2 +- scylla/src/transport/connection.rs | 2 +- scylla/src/transport/connection_pool.rs | 4 ++-- scylla/src/transport/load_balancing/default.rs | 8 ++++---- scylla/src/transport/load_balancing/mod.rs | 2 +- scylla/src/transport/locator/mod.rs | 4 ++-- scylla/src/transport/locator/precomputed_replicas.rs | 4 ++-- scylla/src/transport/locator/replication_info.rs | 4 ++-- scylla/src/transport/locator/test.rs | 2 +- scylla/src/transport/locator/token_ring.rs | 4 ++-- scylla/src/transport/metadata.rs | 2 +- scylla/src/transport/node.rs | 2 +- scylla/src/transport/partitioner.rs | 2 +- scylla/src/transport/session.rs | 2 +- scylla/src/transport/session_test.rs | 2 +- scylla/tests/integration/consistency.rs | 2 +- 20 files changed, 27 insertions(+), 27 deletions(-) rename scylla/src/{routing.rs => sharding.rs} (100%) diff --git a/examples/compare-tokens.rs b/examples/compare-tokens.rs index 5c56aa5f4d..76cca047e6 100644 --- a/examples/compare-tokens.rs +++ b/examples/compare-tokens.rs @@ -1,6 +1,6 @@ use anyhow::Result; use scylla::frame::value::ValueList; -use scylla::routing::Token; +use scylla::sharding::Token; use scylla::transport::NodeAddr; use scylla::{Session, SessionBuilder}; use std::env; diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index b1c8770eb0..b69c28597a 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -106,7 +106,7 @@ pub mod authentication; pub mod cloud; pub mod history; -pub mod routing; +pub mod sharding; pub mod statement; pub mod tracing; pub mod transport; diff --git a/scylla/src/routing.rs b/scylla/src/sharding.rs similarity index 100% rename from scylla/src/routing.rs rename to scylla/src/sharding.rs diff --git a/scylla/src/statement/prepared_statement.rs b/scylla/src/statement/prepared_statement.rs index b57d5d4b23..88a100284d 100644 --- a/scylla/src/statement/prepared_statement.rs +++ b/scylla/src/statement/prepared_statement.rs @@ -15,7 +15,7 @@ use crate::frame::types::{Consistency, SerialConsistency}; use crate::frame::value::SerializedValues; use crate::history::HistoryListener; use crate::retry_policy::RetryPolicy; -use crate::routing::Token; +use crate::sharding::Token; use crate::transport::execution_profile::ExecutionProfileHandle; use crate::transport::partitioner::{Partitioner, PartitionerHasher, PartitionerName}; diff --git a/scylla/src/transport/cluster.rs b/scylla/src/transport/cluster.rs index a3a12f2e8d..57c6e9f216 100644 --- a/scylla/src/transport/cluster.rs +++ b/scylla/src/transport/cluster.rs @@ -2,7 +2,7 @@ use crate::frame::response::event::{Event, StatusChangeEvent}; use crate::frame::value::ValueList; use crate::prepared_statement::TokenCalculationError; -use crate::routing::Token; +use crate::sharding::Token; use crate::transport::host_filter::HostFilter; use crate::transport::{ connection::{Connection, VerifiedKeyspaceName}, diff --git a/scylla/src/transport/connection.rs b/scylla/src/transport/connection.rs index 72d6f36dd3..d06bba0bcb 100644 --- a/scylla/src/transport/connection.rs +++ b/scylla/src/transport/connection.rs @@ -57,7 +57,7 @@ use crate::frame::{ FrameParams, SerializedRequest, }; use crate::query::Query; -use crate::routing::ShardInfo; +use crate::sharding::ShardInfo; use crate::statement::prepared_statement::PreparedStatement; use crate::statement::Consistency; use crate::transport::session::IntoTypedRows; diff --git a/scylla/src/transport/connection_pool.rs b/scylla/src/transport/connection_pool.rs index 849e1d2735..7c5ba4138c 100644 --- a/scylla/src/transport/connection_pool.rs +++ b/scylla/src/transport/connection_pool.rs @@ -1,7 +1,7 @@ #[cfg(feature = "cloud")] use crate::cloud::set_ssl_config_for_scylla_cloud_host; -use crate::routing::{Shard, ShardCount, Sharder, Token}; +use crate::sharding::{Shard, ShardCount, Sharder, Token}; use crate::transport::errors::QueryError; use crate::transport::{ connection, @@ -1258,7 +1258,7 @@ async fn open_connection_to_shard_aware_port( #[cfg(test)] mod tests { use super::open_connection_to_shard_aware_port; - use crate::routing::{ShardCount, Sharder}; + use crate::sharding::{ShardCount, Sharder}; use crate::transport::connection::ConnectionConfig; use crate::transport::metadata::UntranslatedEndpoint; use crate::transport::node::ResolvedContactPoint; diff --git a/scylla/src/transport/load_balancing/default.rs b/scylla/src/transport/load_balancing/default.rs index 48ffb98f24..f107bb48c4 100644 --- a/scylla/src/transport/load_balancing/default.rs +++ b/scylla/src/transport/load_balancing/default.rs @@ -3,7 +3,7 @@ pub use self::latency_awareness::LatencyAwarenessBuilder; use super::{FallbackPlan, LoadBalancingPolicy, NodeRef, RoutingInfo}; use crate::{ - routing::Token, + sharding::Token, transport::{cluster::ClusterData, locator::ReplicaSet, metadata::Strategy, node::Node}, }; use itertools::{Either, Itertools}; @@ -877,7 +877,7 @@ mod tests { load_balancing::{ default::tests::framework::mock_cluster_data_for_token_aware_tests, RoutingInfo, }, - routing::Token, + sharding::Token, transport::{ locator::test::{KEYSPACE_NTS_RF_2, KEYSPACE_NTS_RF_3, KEYSPACE_SS_RF_2}, ClusterData, @@ -893,7 +893,7 @@ mod tests { use crate::{ load_balancing::{LoadBalancingPolicy, Plan, RoutingInfo}, - routing::Token, + sharding::Token, transport::{ locator::test::{id_to_invalid_addr, mock_metadata_for_token_aware_tests}, metadata::{Metadata, Peer}, @@ -2724,7 +2724,7 @@ mod latency_awareness { default::tests::test_default_policy_with_given_cluster_and_routing_info, RoutingInfo, }, - routing::Token, + sharding::Token, transport::{ locator::test::{ id_to_invalid_addr, A, B, C, D, E, F, G, KEYSPACE_NTS_RF_2, KEYSPACE_NTS_RF_3, diff --git a/scylla/src/transport/load_balancing/mod.rs b/scylla/src/transport/load_balancing/mod.rs index d4095743c3..16c54d58f2 100644 --- a/scylla/src/transport/load_balancing/mod.rs +++ b/scylla/src/transport/load_balancing/mod.rs @@ -3,7 +3,7 @@ //! See [the book](https://rust-driver.docs.scylladb.com/stable/load-balancing/load-balancing.html) for more information use super::{cluster::ClusterData, NodeRef}; -use crate::routing::Token; +use crate::sharding::Token; use scylla_cql::{errors::QueryError, frame::types}; use std::time::Duration; diff --git a/scylla/src/transport/locator/mod.rs b/scylla/src/transport/locator/mod.rs index 185fb00d94..59b884cc05 100644 --- a/scylla/src/transport/locator/mod.rs +++ b/scylla/src/transport/locator/mod.rs @@ -9,7 +9,7 @@ use rand::{seq::IteratorRandom, Rng}; pub use token_ring::TokenRing; use super::{metadata::Strategy, Node, NodeRef}; -use crate::routing::Token; +use crate::sharding::Token; use itertools::Itertools; use precomputed_replicas::PrecomputedReplicas; use replicas::{ReplicasArray, EMPTY_REPLICAS}; @@ -740,7 +740,7 @@ impl<'a> IntoIterator for ReplicasOrdered<'a> { #[cfg(test)] mod tests { - use crate::{routing::Token, transport::locator::test::*}; + use crate::{sharding::Token, transport::locator::test::*}; #[tokio::test] async fn test_replicas_ordered() { diff --git a/scylla/src/transport/locator/precomputed_replicas.rs b/scylla/src/transport/locator/precomputed_replicas.rs index 4208166e12..330b00d0cf 100644 --- a/scylla/src/transport/locator/precomputed_replicas.rs +++ b/scylla/src/transport/locator/precomputed_replicas.rs @@ -14,7 +14,7 @@ use super::replication_info::ReplicationInfo; use super::TokenRing; -use crate::routing::Token; +use crate::sharding::Token; use crate::transport::metadata::Strategy; use crate::transport::node::Node; @@ -215,7 +215,7 @@ mod tests { use std::collections::HashMap; use crate::{ - routing::Token, + sharding::Token, transport::{ locator::test::{create_ring, mock_metadata_for_token_aware_tests, A, C, D, E, F, G}, metadata::{Keyspace, Strategy}, diff --git a/scylla/src/transport/locator/replication_info.rs b/scylla/src/transport/locator/replication_info.rs index d17ed361ba..a4f1fab746 100644 --- a/scylla/src/transport/locator/replication_info.rs +++ b/scylla/src/transport/locator/replication_info.rs @@ -1,7 +1,7 @@ use itertools::Itertools; use super::TokenRing; -use crate::routing::Token; +use crate::sharding::Token; use crate::transport::node::Node; use std::cmp; @@ -204,7 +204,7 @@ where #[cfg(test)] mod tests { use crate::{ - routing::Token, + sharding::Token, transport::locator::test::{ create_ring, mock_metadata_for_token_aware_tests, A, B, C, D, E, F, G, }, diff --git a/scylla/src/transport/locator/test.rs b/scylla/src/transport/locator/test.rs index 266c05e58f..d981348d3e 100644 --- a/scylla/src/transport/locator/test.rs +++ b/scylla/src/transport/locator/test.rs @@ -3,7 +3,7 @@ use rand_chacha::ChaCha8Rng; use uuid::Uuid; use super::{ReplicaLocator, ReplicaSet}; -use crate::routing::Token; +use crate::sharding::Token; use crate::transport::{ connection_pool::PoolConfig, metadata::{Keyspace, Metadata, Peer, Strategy}, diff --git a/scylla/src/transport/locator/token_ring.rs b/scylla/src/transport/locator/token_ring.rs index 686d8e0a90..ff2a9ef840 100644 --- a/scylla/src/transport/locator/token_ring.rs +++ b/scylla/src/transport/locator/token_ring.rs @@ -1,4 +1,4 @@ -use crate::routing::Token; +use crate::sharding::Token; /// A token ring is a continuous hash ring. It defines association by hashing a key /// onto the ring and then walking the ring in one direction. @@ -72,7 +72,7 @@ impl TokenRing { #[cfg(test)] mod tests { use super::TokenRing; - use crate::routing::Token; + use crate::sharding::Token; #[test] fn test_token_ring() { diff --git a/scylla/src/transport/metadata.rs b/scylla/src/transport/metadata.rs index 63ee14f5b2..e0bc07a24b 100644 --- a/scylla/src/transport/metadata.rs +++ b/scylla/src/transport/metadata.rs @@ -1,5 +1,5 @@ use crate::frame::response::event::Event; -use crate::routing::Token; +use crate::sharding::Token; use crate::statement::query::Query; use crate::transport::connection::{Connection, ConnectionConfig}; use crate::transport::connection_pool::{NodeConnectionPool, PoolConfig, PoolSize}; diff --git a/scylla/src/transport/node.rs b/scylla/src/transport/node.rs index 0bd424210e..96ac0e0d46 100644 --- a/scylla/src/transport/node.rs +++ b/scylla/src/transport/node.rs @@ -3,7 +3,7 @@ use tracing::warn; use uuid::Uuid; /// Node represents a cluster node along with it's data and connections -use crate::routing::{Sharder, Token}; +use crate::sharding::{Sharder, Token}; use crate::transport::connection::Connection; use crate::transport::connection::VerifiedKeyspaceName; use crate::transport::connection_pool::{NodeConnectionPool, PoolConfig}; diff --git a/scylla/src/transport/partitioner.rs b/scylla/src/transport/partitioner.rs index 9c8a542325..95624e9db1 100644 --- a/scylla/src/transport/partitioner.rs +++ b/scylla/src/transport/partitioner.rs @@ -2,7 +2,7 @@ use bytes::Buf; use std::num::Wrapping; use crate::{ - frame::value::SerializedValues, prepared_statement::TokenCalculationError, routing::Token, + frame::value::SerializedValues, prepared_statement::TokenCalculationError, sharding::Token, }; #[allow(clippy::upper_case_acronyms)] diff --git a/scylla/src/transport/session.rs b/scylla/src/transport/session.rs index e415060bac..2cf3218c58 100644 --- a/scylla/src/transport/session.rs +++ b/scylla/src/transport/session.rs @@ -48,7 +48,7 @@ use crate::frame::value::{ }; use crate::prepared_statement::PreparedStatement; use crate::query::Query; -use crate::routing::Token; +use crate::sharding::Token; use crate::statement::Consistency; use crate::tracing::{TracingEvent, TracingInfo}; use crate::transport::cluster::{Cluster, ClusterData, ClusterNeatDebug}; diff --git a/scylla/src/transport/session_test.rs b/scylla/src/transport/session_test.rs index 36852f7e4d..642b4474a4 100644 --- a/scylla/src/transport/session_test.rs +++ b/scylla/src/transport/session_test.rs @@ -5,7 +5,7 @@ use crate::frame::value::ValueList; use crate::prepared_statement::PreparedStatement; use crate::query::Query; use crate::retry_policy::{QueryInfo, RetryDecision, RetryPolicy, RetrySession}; -use crate::routing::Token; +use crate::sharding::Token; use crate::statement::Consistency; use crate::tracing::TracingInfo; use crate::transport::cluster::Datacenter; diff --git a/scylla/tests/integration/consistency.rs b/scylla/tests/integration/consistency.rs index 93a0ad8f89..f22339e59d 100644 --- a/scylla/tests/integration/consistency.rs +++ b/scylla/tests/integration/consistency.rs @@ -4,7 +4,7 @@ use scylla::execution_profile::{ExecutionProfileBuilder, ExecutionProfileHandle} use scylla::load_balancing::{DefaultPolicy, LoadBalancingPolicy, RoutingInfo}; use scylla::prepared_statement::PreparedStatement; use scylla::retry_policy::FallthroughRetryPolicy; -use scylla::routing::Token; +use scylla::sharding::Token; use scylla::test_utils::unique_keyspace_name; use scylla::transport::session::Session; use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; From c4073c46740af0b9b853c5c441a88ad264af7eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Wed, 30 Aug 2023 14:25:42 +0200 Subject: [PATCH 04/43] move session out of transport --- docs/source/load-balancing/load-balancing.md | 2 +- examples/basic.rs | 2 +- examples/cql-time-types.rs | 2 +- examples/execution_profile.rs | 2 +- examples/get_by_name.rs | 2 +- examples/logging.rs | 2 +- examples/query_history.rs | 2 +- examples/schema_agreement.rs | 2 +- examples/tls.rs | 2 +- scylla/src/lib.rs | 7 +++-- scylla/src/session/mod.rs | 9 ++++++ scylla/src/{transport => session}/session.rs | 29 ++++++++++--------- .../{transport => session}/session_builder.rs | 18 ++++++------ .../{transport => session}/session_test.rs | 0 scylla/src/transport/connection.rs | 2 +- scylla/src/transport/cql_types_test.rs | 4 +-- scylla/src/transport/host_filter.rs | 2 +- scylla/src/transport/iterator.rs | 2 +- scylla/src/transport/mod.rs | 10 ++----- scylla/src/transport/query_result.rs | 2 +- scylla/src/utils/test_utils.rs | 4 +-- scylla/tests/integration/consistency.rs | 2 +- scylla/tests/integration/lwt_optimisation.rs | 2 +- scylla/tests/integration/retries.rs | 2 +- 24 files changed, 60 insertions(+), 53 deletions(-) create mode 100644 scylla/src/session/mod.rs rename scylla/src/{transport => session}/session.rs (99%) rename scylla/src/{transport => session}/session_builder.rs (98%) rename scylla/src/{transport => session}/session_test.rs (100%) diff --git a/docs/source/load-balancing/load-balancing.md b/docs/source/load-balancing/load-balancing.md index cf5c699baf..a1efebc403 100644 --- a/docs/source/load-balancing/load-balancing.md +++ b/docs/source/load-balancing/load-balancing.md @@ -50,7 +50,7 @@ The newly created execution profile is then converted to a handle using use scylla::SessionBuilder; use scylla::load_balancing::DefaultPolicy; use scylla::transport::ExecutionProfile; -use scylla::transport::session::Session; +use scylla::session::Session; use std::sync::Arc; let policy = Arc::new(DefaultPolicy::default()); diff --git a/examples/basic.rs b/examples/basic.rs index 01fb4848b0..ea5fb277f5 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -1,6 +1,6 @@ use anyhow::Result; use scylla::macros::FromRow; -use scylla::transport::session::{IntoTypedRows, Session}; +use scylla::session::{IntoTypedRows, Session}; use scylla::SessionBuilder; use std::env; diff --git a/examples/cql-time-types.rs b/examples/cql-time-types.rs index ac4da4831e..9d705f49ac 100644 --- a/examples/cql-time-types.rs +++ b/examples/cql-time-types.rs @@ -5,7 +5,7 @@ use anyhow::Result; use chrono::{Duration, NaiveDate}; use scylla::frame::response::result::CqlValue; use scylla::frame::value::{Date, Time, Timestamp}; -use scylla::transport::session::{IntoTypedRows, Session}; +use scylla::session::{IntoTypedRows, Session}; use scylla::SessionBuilder; use std::env; diff --git a/examples/execution_profile.rs b/examples/execution_profile.rs index d8d1b1eed9..24843f76ed 100644 --- a/examples/execution_profile.rs +++ b/examples/execution_profile.rs @@ -2,9 +2,9 @@ use anyhow::Result; use scylla::load_balancing; use scylla::query::Query; use scylla::retry_policy::{DefaultRetryPolicy, FallthroughRetryPolicy}; +use scylla::session::Session; use scylla::speculative_execution::PercentileSpeculativeExecutionPolicy; use scylla::statement::{Consistency, SerialConsistency}; -use scylla::transport::session::Session; use scylla::transport::ExecutionProfile; use scylla::{SessionBuilder, SessionConfig}; use std::env; diff --git a/examples/get_by_name.rs b/examples/get_by_name.rs index 0b94b1e898..fdc47f2f9b 100644 --- a/examples/get_by_name.rs +++ b/examples/get_by_name.rs @@ -1,5 +1,5 @@ use anyhow::{anyhow, Result}; -use scylla::transport::session::Session; +use scylla::session::Session; use scylla::SessionBuilder; use std::env; diff --git a/examples/logging.rs b/examples/logging.rs index 0ee57340c7..6e0c2bb4a0 100644 --- a/examples/logging.rs +++ b/examples/logging.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use scylla::transport::session::Session; +use scylla::session::Session; use scylla::SessionBuilder; use std::env; use tracing::info; diff --git a/examples/query_history.rs b/examples/query_history.rs index f95001c2e3..3782d03ec5 100644 --- a/examples/query_history.rs +++ b/examples/query_history.rs @@ -4,7 +4,7 @@ use anyhow::Result; use futures::StreamExt; use scylla::history::{HistoryCollector, StructuredHistory}; use scylla::query::Query; -use scylla::transport::session::Session; +use scylla::session::Session; use scylla::SessionBuilder; use std::env; use std::sync::Arc; diff --git a/examples/schema_agreement.rs b/examples/schema_agreement.rs index 08e5a59384..2393e33aae 100644 --- a/examples/schema_agreement.rs +++ b/examples/schema_agreement.rs @@ -1,6 +1,6 @@ use anyhow::{bail, Result}; +use scylla::session::{IntoTypedRows, Session}; use scylla::transport::errors::QueryError; -use scylla::transport::session::{IntoTypedRows, Session}; use scylla::SessionBuilder; use std::env; use std::time::Duration; diff --git a/examples/tls.rs b/examples/tls.rs index 49006c1602..1f9b49ce90 100644 --- a/examples/tls.rs +++ b/examples/tls.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use scylla::transport::session::{IntoTypedRows, Session}; +use scylla::session::{IntoTypedRows, Session}; use scylla::SessionBuilder; use std::env; use std::fs; diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index b69c28597a..f579e40a07 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -106,6 +106,7 @@ pub mod authentication; pub mod cloud; pub mod history; +pub mod session; pub mod sharding; pub mod statement; pub mod tracing; @@ -125,14 +126,14 @@ pub use statement::query; pub use frame::response::cql_to_rust; pub use frame::response::cql_to_rust::FromRow; +pub use session::SessionBuilder; +pub use session::{IntoTypedRows, Session, SessionConfig}; pub use transport::caching_session::CachingSession; pub use transport::execution_profile::ExecutionProfile; pub use transport::query_result::QueryResult; -pub use transport::session::{IntoTypedRows, Session, SessionConfig}; -pub use transport::session_builder::SessionBuilder; #[cfg(feature = "cloud")] -pub use transport::session_builder::CloudSessionBuilder; +pub use session::CloudSessionBuilder; pub use transport::execution_profile; pub use transport::host_filter; diff --git a/scylla/src/session/mod.rs b/scylla/src/session/mod.rs new file mode 100644 index 0000000000..e2c89c49bc --- /dev/null +++ b/scylla/src/session/mod.rs @@ -0,0 +1,9 @@ +mod session; +pub mod session_builder; +#[cfg(test)] +mod session_test; + +pub use session::*; +#[cfg(feature = "cloud")] +pub use session_builder::CloudSessionBuilder; +pub use session_builder::SessionBuilder; diff --git a/scylla/src/transport/session.rs b/scylla/src/session/session.rs similarity index 99% rename from scylla/src/transport/session.rs rename to scylla/src/session/session.rs index 2cf3218c58..7387c8c3e5 100644 --- a/scylla/src/transport/session.rs +++ b/scylla/src/session/session.rs @@ -29,17 +29,6 @@ use tokio::time::timeout; use tracing::{debug, trace, trace_span, Instrument}; use uuid::Uuid; -use super::connection::QueryResponse; -#[cfg(feature = "ssl")] -use super::connection::SslConfig; -use super::connection::{AddressTranslator, NonErrorQueryResponse}; -use super::errors::{NewSessionError, QueryError}; -use super::execution_profile::{ExecutionProfile, ExecutionProfileHandle, ExecutionProfileInner}; -#[cfg(feature = "cloud")] -use super::node::CloudEndpoint; -use super::node::KnownNode; -use super::partitioner::PartitionerName; -use super::NodeRef; use crate::cql_to_rust::FromRow; use crate::frame::response::cql_to_rust::FromRowError; use crate::frame::response::result; @@ -52,23 +41,35 @@ use crate::sharding::Token; use crate::statement::Consistency; use crate::tracing::{TracingEvent, TracingInfo}; use crate::transport::cluster::{Cluster, ClusterData, ClusterNeatDebug}; +use crate::transport::connection::QueryResponse; +#[cfg(feature = "ssl")] +use crate::transport::connection::SslConfig; +use crate::transport::connection::{AddressTranslator, NonErrorQueryResponse}; use crate::transport::connection::{Connection, ConnectionConfig, VerifiedKeyspaceName}; use crate::transport::connection_pool::PoolConfig; +use crate::transport::errors::{NewSessionError, QueryError}; +use crate::transport::execution_profile::{ + ExecutionProfile, ExecutionProfileHandle, ExecutionProfileInner, +}; use crate::transport::host_filter::HostFilter; use crate::transport::iterator::{PreparedIteratorConfig, RowIterator}; use crate::transport::load_balancing::{self, RoutingInfo}; use crate::transport::metrics::Metrics; +#[cfg(feature = "cloud")] +use crate::transport::node::CloudEndpoint; use crate::transport::node::Node; +use crate::transport::partitioner::PartitionerName; use crate::transport::query_result::QueryResult; use crate::transport::retry_policy::{QueryInfo, RetryDecision, RetrySession}; use crate::transport::speculative_execution; use crate::transport::Compression; +use crate::transport::{KnownNode, NodeRef}; use crate::{ batch::{Batch, BatchStatement}, statement::StatementConfig, }; -pub use crate::transport::connection_pool::PoolSize; +use crate::transport::connection_pool::PoolSize; use crate::authentication::AuthenticatorProvider; #[cfg(feature = "ssl")] @@ -385,7 +386,7 @@ pub(crate) enum RunQueryResult { impl Session { /// Estabilishes a CQL session with the database /// - /// Usually it's easier to use [SessionBuilder](crate::transport::session_builder::SessionBuilder) + /// Usually it's easier to use [SessionBuilder](crate::session_builder::SessionBuilder) /// instead of calling `Session::connect` directly, because it's more convenient. /// # Arguments /// * `config` - Connection configuration - known nodes, Compression, etc. @@ -863,7 +864,7 @@ impl Session { /// Executes a previously prepared statement with previously received paging state /// # Arguments /// - /// * `prepared` - a statement prepared with [prepare](crate::transport::session::Session::prepare) + /// * `prepared` - a statement prepared with [prepare](crate::session::Session::prepare) /// * `values` - values bound to the query /// * `paging_state` - paging state from the previous query or None pub async fn execute_paged( diff --git a/scylla/src/transport/session_builder.rs b/scylla/src/session/session_builder.rs similarity index 98% rename from scylla/src/transport/session_builder.rs rename to scylla/src/session/session_builder.rs index 2a78c90b5c..017a4f6cae 100644 --- a/scylla/src/transport/session_builder.rs +++ b/scylla/src/session/session_builder.rs @@ -1,10 +1,10 @@ //! SessionBuilder provides an easy way to create new Sessions -use super::connection::AddressTranslator; -use super::errors::NewSessionError; -use super::execution_profile::ExecutionProfileHandle; -use super::session::{Session, SessionConfig}; -use super::Compression; +use crate::session::{Session, SessionConfig}; +use crate::transport::connection::AddressTranslator; +use crate::transport::errors::NewSessionError; +use crate::transport::execution_profile::ExecutionProfileHandle; +use crate::transport::Compression; #[cfg(feature = "cloud")] use crate::cloud::{CloudConfig, CloudConfigError}; @@ -254,7 +254,7 @@ impl GenericSessionBuilder { /// # use std::net::SocketAddr; /// # use std::sync::Arc; /// # use scylla::{Session, SessionBuilder}; - /// # use scylla::transport::session::{AddressTranslator, TranslationError}; + /// # use scylla::session::{AddressTranslator, TranslationError}; /// # use scylla::transport::metadata::UntranslatedPeer; /// struct IdentityTranslator; /// @@ -284,7 +284,7 @@ impl GenericSessionBuilder { /// # use std::collections::HashMap; /// # use std::str::FromStr; /// # use scylla::{Session, SessionBuilder}; - /// # use scylla::transport::session::{AddressTranslator, TranslationError}; + /// # use scylla::session::{AddressTranslator, TranslationError}; /// # /// # async fn example() -> Result<(), Box> { /// let mut translation_rules = HashMap::new(); @@ -559,7 +559,7 @@ impl GenericSessionBuilder { /// # use scylla::{Session, SessionBuilder}; /// # async fn example() -> Result<(), Box> { /// use std::num::NonZeroUsize; - /// use scylla::transport::session::PoolSize; + /// use scylla::session::PoolSize; /// /// // This session will establish 4 connections to each node. /// // For Scylla clusters, this number will be divided across shards @@ -772,7 +772,7 @@ impl GenericSessionBuilder { /// # use std::net::SocketAddr; /// # use std::sync::Arc; /// # use scylla::{Session, SessionBuilder}; - /// # use scylla::transport::session::{AddressTranslator, TranslationError}; + /// # use scylla::session::{AddressTranslator, TranslationError}; /// # use scylla::transport::host_filter::DcHostFilter; /// /// # async fn example() -> Result<(), Box> { diff --git a/scylla/src/transport/session_test.rs b/scylla/src/session/session_test.rs similarity index 100% rename from scylla/src/transport/session_test.rs rename to scylla/src/session/session_test.rs diff --git a/scylla/src/transport/connection.rs b/scylla/src/transport/connection.rs index d06bba0bcb..13a1021590 100644 --- a/scylla/src/transport/connection.rs +++ b/scylla/src/transport/connection.rs @@ -57,10 +57,10 @@ use crate::frame::{ FrameParams, SerializedRequest, }; use crate::query::Query; +use crate::session::IntoTypedRows; use crate::sharding::ShardInfo; use crate::statement::prepared_statement::PreparedStatement; use crate::statement::Consistency; -use crate::transport::session::IntoTypedRows; use crate::transport::Compression; use crate::QueryResult; diff --git a/scylla/src/transport/cql_types_test.rs b/scylla/src/transport/cql_types_test.rs index dbc4cf2537..7486ce0054 100644 --- a/scylla/src/transport/cql_types_test.rs +++ b/scylla/src/transport/cql_types_test.rs @@ -5,9 +5,9 @@ use crate::frame::value::Counter; use crate::frame::value::Value; use crate::frame::value::{Date, Time, Timestamp}; use crate::macros::{FromUserType, IntoUserType}; +use crate::session::IntoTypedRows; +use crate::session::Session; use crate::test_utils::create_new_session_builder; -use crate::transport::session::IntoTypedRows; -use crate::transport::session::Session; use crate::utils::test_utils::unique_keyspace_name; use bigdecimal::BigDecimal; use chrono::{Duration, NaiveDate}; diff --git a/scylla/src/transport/host_filter.rs b/scylla/src/transport/host_filter.rs index 9bce4a3dc0..103c164d96 100644 --- a/scylla/src/transport/host_filter.rs +++ b/scylla/src/transport/host_filter.rs @@ -2,7 +2,7 @@ //! //! Host filters are essentially just a predicate over //! [`Peer`](crate::transport::metadata::Peer)s. Currently, they are used -//! by the [`Session`](crate::transport::session::Session) to determine whether +//! by the [`Session`](crate::session::Session) to determine whether //! connections should be opened to a given node or not. use std::collections::HashSet; diff --git a/scylla/src/transport/iterator.rs b/scylla/src/transport/iterator.rs index a9f5a7ec5b..3945db1cfe 100644 --- a/scylla/src/transport/iterator.rs +++ b/scylla/src/transport/iterator.rs @@ -19,8 +19,8 @@ use tracing::instrument::WithSubscriber; use super::errors::QueryError; use super::execution_profile::ExecutionProfileInner; -use super::session::RequestSpan; use crate::cql_to_rust::{FromRow, FromRowError}; +use crate::session::RequestSpan; use crate::frame::{ response::{ diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs index c57e5bb496..438fbcf1fb 100644 --- a/scylla/src/transport/mod.rs +++ b/scylla/src/transport/mod.rs @@ -1,7 +1,7 @@ pub(crate) mod caching_session; -mod cluster; +pub(crate) mod cluster; pub(crate) mod connection; -mod connection_pool; +pub(crate) mod connection_pool; pub mod downgrading_consistency_retry_policy; pub mod execution_profile; pub mod host_filter; @@ -10,12 +10,10 @@ pub mod load_balancing; pub mod locator; pub mod metadata; pub(crate) mod metrics; -mod node; +pub(crate) mod node; pub mod partitioner; pub mod query_result; pub mod retry_policy; -pub mod session; -pub mod session_builder; pub mod speculative_execution; pub use crate::frame::{Authenticator, Compression}; @@ -26,8 +24,6 @@ pub use scylla_cql::errors; mod authenticate_test; #[cfg(test)] mod cql_collections_test; -#[cfg(test)] -mod session_test; #[cfg(test)] mod cql_types_test; diff --git a/scylla/src/transport/query_result.rs b/scylla/src/transport/query_result.rs index 98a623f01c..6773b254d6 100644 --- a/scylla/src/transport/query_result.rs +++ b/scylla/src/transport/query_result.rs @@ -1,7 +1,7 @@ use crate::frame::response::cql_to_rust::{FromRow, FromRowError}; use crate::frame::response::result::ColumnSpec; use crate::frame::response::result::Row; -use crate::transport::session::{IntoTypedRows, TypedRowIter}; +use crate::session::{IntoTypedRows, TypedRowIter}; use bytes::Bytes; use thiserror::Error; use uuid::Uuid; diff --git a/scylla/src/utils/test_utils.rs b/scylla/src/utils/test_utils.rs index 7d3f079c5d..11bb5485aa 100644 --- a/scylla/src/utils/test_utils.rs +++ b/scylla/src/utils/test_utils.rs @@ -1,5 +1,5 @@ #[cfg(test)] -use crate::transport::session_builder::{GenericSessionBuilder, SessionBuilderKind}; +use crate::session::session_builder::{GenericSessionBuilder, SessionBuilderKind}; #[cfg(test)] use crate::Session; #[cfg(test)] @@ -73,7 +73,7 @@ pub fn create_new_session_builder() -> GenericSessionBuilder Date: Wed, 30 Aug 2023 15:27:01 +0200 Subject: [PATCH 05/43] move caching_session.rs to new session mod --- scylla/src/lib.rs | 2 +- scylla/src/{transport => session}/caching_session.rs | 0 scylla/src/session/mod.rs | 2 ++ scylla/src/transport/mod.rs | 1 - 4 files changed, 3 insertions(+), 2 deletions(-) rename scylla/src/{transport => session}/caching_session.rs (100%) diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index f579e40a07..a8b3bee49f 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -126,9 +126,9 @@ pub use statement::query; pub use frame::response::cql_to_rust; pub use frame::response::cql_to_rust::FromRow; +pub use session::CachingSession; pub use session::SessionBuilder; pub use session::{IntoTypedRows, Session, SessionConfig}; -pub use transport::caching_session::CachingSession; pub use transport::execution_profile::ExecutionProfile; pub use transport::query_result::QueryResult; diff --git a/scylla/src/transport/caching_session.rs b/scylla/src/session/caching_session.rs similarity index 100% rename from scylla/src/transport/caching_session.rs rename to scylla/src/session/caching_session.rs diff --git a/scylla/src/session/mod.rs b/scylla/src/session/mod.rs index e2c89c49bc..d916d7b2b9 100644 --- a/scylla/src/session/mod.rs +++ b/scylla/src/session/mod.rs @@ -1,8 +1,10 @@ +mod caching_session; mod session; pub mod session_builder; #[cfg(test)] mod session_test; +pub use caching_session::CachingSession; pub use session::*; #[cfg(feature = "cloud")] pub use session_builder::CloudSessionBuilder; diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs index 438fbcf1fb..95890eefb6 100644 --- a/scylla/src/transport/mod.rs +++ b/scylla/src/transport/mod.rs @@ -1,4 +1,3 @@ -pub(crate) mod caching_session; pub(crate) mod cluster; pub(crate) mod connection; pub(crate) mod connection_pool; From 2fb76e97da9067b4e86ed8a7c981ef117e6563f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Wed, 30 Aug 2023 14:41:07 +0200 Subject: [PATCH 06/43] extract connection module --- scylla/src/cloud/mod.rs | 2 +- .../{transport => connection}/connection.rs | 12 +++++----- .../connection_pool.rs | 22 +++++++++---------- scylla/src/connection/mod.rs | 13 +++++++++++ scylla/src/lib.rs | 1 + scylla/src/session/session.rs | 15 +++++++------ scylla/src/session/session_builder.rs | 3 +-- scylla/src/transport/cluster.rs | 3 +-- scylla/src/transport/iterator.rs | 2 +- scylla/src/transport/locator/test.rs | 2 +- scylla/src/transport/metadata.rs | 3 +-- scylla/src/transport/mod.rs | 2 -- scylla/src/transport/node.rs | 6 ++--- 13 files changed, 47 insertions(+), 39 deletions(-) rename scylla/src/{transport => connection}/connection.rs (99%) rename scylla/src/{transport => connection}/connection_pool.rs (98%) create mode 100644 scylla/src/connection/mod.rs diff --git a/scylla/src/cloud/mod.rs b/scylla/src/cloud/mod.rs index 2b9bf23aae..11943bae9f 100644 --- a/scylla/src/cloud/mod.rs +++ b/scylla/src/cloud/mod.rs @@ -11,7 +11,7 @@ use openssl::{ use tracing::warn; use uuid::Uuid; -use crate::transport::connection::{ConnectionConfig, SslConfig}; +use crate::connection::{ConnectionConfig, SslConfig}; pub(crate) fn set_ssl_config_for_scylla_cloud_host( host_id: Option, diff --git a/scylla/src/transport/connection.rs b/scylla/src/connection/connection.rs similarity index 99% rename from scylla/src/transport/connection.rs rename to scylla/src/connection/connection.rs index 13a1021590..fc4223f547 100644 --- a/scylla/src/transport/connection.rs +++ b/scylla/src/connection/connection.rs @@ -39,12 +39,12 @@ use std::{ net::{Ipv4Addr, Ipv6Addr}, }; -use super::errors::{BadKeyspaceName, DbError, QueryError}; -use super::iterator::RowIterator; -use super::metadata::{PeerEndpoint, UntranslatedEndpoint, UntranslatedPeer}; -use super::NodeAddr; #[cfg(feature = "cloud")] use crate::cloud::CloudConfig; +use crate::transport::errors::{BadKeyspaceName, DbError, QueryError}; +use crate::transport::iterator::RowIterator; +use crate::transport::metadata::{PeerEndpoint, UntranslatedEndpoint, UntranslatedPeer}; +use crate::transport::NodeAddr; use crate::batch::{Batch, BatchStatement}; use crate::frame::protocol_features::ProtocolFeatures; @@ -408,7 +408,7 @@ impl ConnectionConfig { } // Used to listen for fatal error in connection -pub(crate) type ErrorReceiver = tokio::sync::oneshot::Receiver; +pub(super) type ErrorReceiver = tokio::sync::oneshot::Receiver; impl Connection { // Returns new connection and ErrorReceiver which can be used to wait for a fatal error @@ -1820,9 +1820,9 @@ mod tests { use tokio::select; use tokio::sync::mpsc; + use super::open_connection; use super::ConnectionConfig; use crate::query::Query; - use crate::transport::connection::open_connection; use crate::transport::metadata::UntranslatedEndpoint; use crate::transport::node::ResolvedContactPoint; use crate::utils::test_utils::unique_keyspace_name; diff --git a/scylla/src/transport/connection_pool.rs b/scylla/src/connection/connection_pool.rs similarity index 98% rename from scylla/src/transport/connection_pool.rs rename to scylla/src/connection/connection_pool.rs index 7c5ba4138c..347574b75d 100644 --- a/scylla/src/transport/connection_pool.rs +++ b/scylla/src/connection/connection_pool.rs @@ -1,20 +1,17 @@ #[cfg(feature = "cloud")] use crate::cloud::set_ssl_config_for_scylla_cloud_host; +use crate::connection::{Connection, ConnectionConfig, ErrorReceiver, VerifiedKeyspaceName}; use crate::sharding::{Shard, ShardCount, Sharder, Token}; use crate::transport::errors::QueryError; -use crate::transport::{ - connection, - connection::{Connection, ConnectionConfig, ErrorReceiver, VerifiedKeyspaceName}, -}; #[cfg(feature = "cloud")] -use super::node::resolve_hostname; +use crate::transport::node::resolve_hostname; -use super::metadata::{PeerEndpoint, UntranslatedEndpoint}; +use crate::transport::metadata::{PeerEndpoint, UntranslatedEndpoint}; #[cfg(feature = "cloud")] -use super::node::ResolvedContactPoint; -use super::NodeAddr; +use crate::transport::node::ResolvedContactPoint; +use crate::transport::NodeAddr; use arc_swap::ArcSwap; use futures::{future::RemoteHandle, stream::FuturesUnordered, Future, FutureExt, StreamExt}; @@ -30,6 +27,8 @@ use tokio::sync::{broadcast, mpsc, Notify}; use tracing::instrument::WithSubscriber; use tracing::{debug, trace, warn}; +use super::connection::open_connection; + /// The target size of a per-node connection pool. #[derive(Debug, Clone, Copy)] pub enum PoolSize { @@ -947,7 +946,7 @@ impl PoolRefiller { .boxed(), _ => async move { let non_shard_aware_endpoint = endpoint_fut.await; - let result = connection::open_connection(non_shard_aware_endpoint, None, cfg).await; + let result = open_connection(non_shard_aware_endpoint, None, cfg).await; OpenedConnectionEvent { result, requested_shard: None, @@ -1239,8 +1238,7 @@ async fn open_connection_to_shard_aware_port( for port in source_port_iter { let connect_result = - connection::open_connection(endpoint.clone(), Some(port), connection_config.clone()) - .await; + open_connection(endpoint.clone(), Some(port), connection_config.clone()).await; match connect_result { Err(err) if err.is_address_unavailable_for_use() => continue, // If we can't use this port, try the next one @@ -1258,8 +1256,8 @@ async fn open_connection_to_shard_aware_port( #[cfg(test)] mod tests { use super::open_connection_to_shard_aware_port; + use crate::connection::ConnectionConfig; use crate::sharding::{ShardCount, Sharder}; - use crate::transport::connection::ConnectionConfig; use crate::transport::metadata::UntranslatedEndpoint; use crate::transport::node::ResolvedContactPoint; use std::net::{SocketAddr, ToSocketAddrs}; diff --git a/scylla/src/connection/mod.rs b/scylla/src/connection/mod.rs new file mode 100644 index 0000000000..d43f17e977 --- /dev/null +++ b/scylla/src/connection/mod.rs @@ -0,0 +1,13 @@ +mod connection; +mod connection_pool; + +use connection::ErrorReceiver; +#[cfg(feature = "ssl")] +pub(crate) use connection::SslConfig; +pub use connection::{AddressTranslator, ConnectionConfig}; +pub(crate) use connection::{ + Connection, NonErrorQueryResponse, QueryResponse, VerifiedKeyspaceName, +}; + +pub use connection_pool::PoolSize; +pub(crate) use connection_pool::{NodeConnectionPool, PoolConfig}; diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index a8b3bee49f..13c52bd5d3 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -105,6 +105,7 @@ pub mod authentication; #[cfg(feature = "cloud")] pub mod cloud; +pub mod connection; pub mod history; pub mod session; pub mod sharding; diff --git a/scylla/src/session/session.rs b/scylla/src/session/session.rs index 7387c8c3e5..55b3567e2c 100644 --- a/scylla/src/session/session.rs +++ b/scylla/src/session/session.rs @@ -29,6 +29,13 @@ use tokio::time::timeout; use tracing::{debug, trace, trace_span, Instrument}; use uuid::Uuid; +use crate::connection::PoolConfig; +use crate::connection::QueryResponse; +#[cfg(feature = "ssl")] +use crate::connection::SslConfig; +use crate::connection::{ + AddressTranslator, Connection, ConnectionConfig, NonErrorQueryResponse, VerifiedKeyspaceName, +}; use crate::cql_to_rust::FromRow; use crate::frame::response::cql_to_rust::FromRowError; use crate::frame::response::result; @@ -41,12 +48,6 @@ use crate::sharding::Token; use crate::statement::Consistency; use crate::tracing::{TracingEvent, TracingInfo}; use crate::transport::cluster::{Cluster, ClusterData, ClusterNeatDebug}; -use crate::transport::connection::QueryResponse; -#[cfg(feature = "ssl")] -use crate::transport::connection::SslConfig; -use crate::transport::connection::{AddressTranslator, NonErrorQueryResponse}; -use crate::transport::connection::{Connection, ConnectionConfig, VerifiedKeyspaceName}; -use crate::transport::connection_pool::PoolConfig; use crate::transport::errors::{NewSessionError, QueryError}; use crate::transport::execution_profile::{ ExecutionProfile, ExecutionProfileHandle, ExecutionProfileInner, @@ -69,7 +70,7 @@ use crate::{ statement::StatementConfig, }; -use crate::transport::connection_pool::PoolSize; +use crate::connection::PoolSize; use crate::authentication::AuthenticatorProvider; #[cfg(feature = "ssl")] diff --git a/scylla/src/session/session_builder.rs b/scylla/src/session/session_builder.rs index 017a4f6cae..b08f737c91 100644 --- a/scylla/src/session/session_builder.rs +++ b/scylla/src/session/session_builder.rs @@ -1,7 +1,7 @@ //! SessionBuilder provides an easy way to create new Sessions +use crate::connection::{AddressTranslator, PoolSize}; use crate::session::{Session, SessionConfig}; -use crate::transport::connection::AddressTranslator; use crate::transport::errors::NewSessionError; use crate::transport::execution_profile::ExecutionProfileHandle; use crate::transport::Compression; @@ -12,7 +12,6 @@ use crate::cloud::{CloudConfig, CloudConfigError}; use crate::ExecutionProfile; use crate::statement::Consistency; -use crate::transport::connection_pool::PoolSize; use crate::transport::host_filter::HostFilter; use std::borrow::Borrow; use std::marker::PhantomData; diff --git a/scylla/src/transport/cluster.rs b/scylla/src/transport/cluster.rs index 57c6e9f216..cf844e3a89 100644 --- a/scylla/src/transport/cluster.rs +++ b/scylla/src/transport/cluster.rs @@ -1,3 +1,4 @@ +use crate::connection::{Connection, PoolConfig, VerifiedKeyspaceName}; /// Cluster manages up to date information and connections to database nodes use crate::frame::response::event::{Event, StatusChangeEvent}; use crate::frame::value::ValueList; @@ -5,8 +6,6 @@ use crate::prepared_statement::TokenCalculationError; use crate::sharding::Token; use crate::transport::host_filter::HostFilter; use crate::transport::{ - connection::{Connection, VerifiedKeyspaceName}, - connection_pool::PoolConfig, errors::QueryError, metadata::{Keyspace, Metadata, MetadataReader}, node::Node, diff --git a/scylla/src/transport/iterator.rs b/scylla/src/transport/iterator.rs index 3945db1cfe..9f4ae3c06a 100644 --- a/scylla/src/transport/iterator.rs +++ b/scylla/src/transport/iterator.rs @@ -22,6 +22,7 @@ use super::execution_profile::ExecutionProfileInner; use crate::cql_to_rust::{FromRow, FromRowError}; use crate::session::RequestSpan; +use crate::connection::{Connection, NonErrorQueryResponse, QueryResponse}; use crate::frame::{ response::{ result, @@ -33,7 +34,6 @@ use crate::history::{self, HistoryListener}; use crate::statement::Consistency; use crate::statement::{prepared_statement::PreparedStatement, query::Query}; use crate::transport::cluster::ClusterData; -use crate::transport::connection::{Connection, NonErrorQueryResponse, QueryResponse}; use crate::transport::load_balancing::{self, RoutingInfo}; use crate::transport::metrics::Metrics; use crate::transport::retry_policy::{QueryInfo, RetryDecision, RetrySession}; diff --git a/scylla/src/transport/locator/test.rs b/scylla/src/transport/locator/test.rs index d981348d3e..6077515074 100644 --- a/scylla/src/transport/locator/test.rs +++ b/scylla/src/transport/locator/test.rs @@ -3,9 +3,9 @@ use rand_chacha::ChaCha8Rng; use uuid::Uuid; use super::{ReplicaLocator, ReplicaSet}; +use crate::connection::PoolConfig; use crate::sharding::Token; use crate::transport::{ - connection_pool::PoolConfig, metadata::{Keyspace, Metadata, Peer, Strategy}, Node, }; diff --git a/scylla/src/transport/metadata.rs b/scylla/src/transport/metadata.rs index e0bc07a24b..19af2c7b7c 100644 --- a/scylla/src/transport/metadata.rs +++ b/scylla/src/transport/metadata.rs @@ -1,8 +1,7 @@ +use crate::connection::{Connection, ConnectionConfig, NodeConnectionPool, PoolConfig, PoolSize}; use crate::frame::response::event::Event; use crate::sharding::Token; use crate::statement::query::Query; -use crate::transport::connection::{Connection, ConnectionConfig}; -use crate::transport::connection_pool::{NodeConnectionPool, PoolConfig, PoolSize}; use crate::transport::errors::{DbError, QueryError}; use crate::transport::host_filter::HostFilter; use crate::transport::node::resolve_contact_points; diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs index 95890eefb6..82def7be2a 100644 --- a/scylla/src/transport/mod.rs +++ b/scylla/src/transport/mod.rs @@ -1,6 +1,4 @@ pub(crate) mod cluster; -pub(crate) mod connection; -pub(crate) mod connection_pool; pub mod downgrading_consistency_retry_policy; pub mod execution_profile; pub mod host_filter; diff --git a/scylla/src/transport/node.rs b/scylla/src/transport/node.rs index 96ac0e0d46..9de32bac0f 100644 --- a/scylla/src/transport/node.rs +++ b/scylla/src/transport/node.rs @@ -2,11 +2,11 @@ use tokio::net::lookup_host; use tracing::warn; use uuid::Uuid; +use crate::connection::Connection; +use crate::connection::VerifiedKeyspaceName; +use crate::connection::{NodeConnectionPool, PoolConfig}; /// Node represents a cluster node along with it's data and connections use crate::sharding::{Sharder, Token}; -use crate::transport::connection::Connection; -use crate::transport::connection::VerifiedKeyspaceName; -use crate::transport::connection_pool::{NodeConnectionPool, PoolConfig}; use crate::transport::errors::QueryError; use std::fmt::Display; From 6e7e3c6271c44664e98c3535051222581052927f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Wed, 30 Aug 2023 14:46:56 +0200 Subject: [PATCH 07/43] move open_connection_to_shard_aware_port() to connection --- scylla/src/connection/connection.rs | 84 +++++++++++++++++++++- scylla/src/connection/connection_pool.rs | 89 +----------------------- 2 files changed, 84 insertions(+), 89 deletions(-) diff --git a/scylla/src/connection/connection.rs b/scylla/src/connection/connection.rs index fc4223f547..c64d47d669 100644 --- a/scylla/src/connection/connection.rs +++ b/scylla/src/connection/connection.rs @@ -58,7 +58,7 @@ use crate::frame::{ }; use crate::query::Query; use crate::session::IntoTypedRows; -use crate::sharding::ShardInfo; +use crate::sharding::{Shard, ShardInfo, Sharder}; use crate::statement::prepared_statement::PreparedStatement; use crate::statement::Consistency; use crate::transport::Compression; @@ -1510,6 +1510,32 @@ pub(crate) async fn open_named_connection( Ok((connection, error_receiver)) } +pub(crate) async fn open_connection_to_shard_aware_port( + endpoint: UntranslatedEndpoint, + shard: Shard, + sharder: Sharder, + connection_config: &ConnectionConfig, +) -> Result<(Connection, ErrorReceiver), QueryError> { + // Create iterator over all possible source ports for this shard + let source_port_iter = sharder.iter_source_ports_for_shard(shard); + + for port in source_port_iter { + let connect_result = + open_connection(endpoint.clone(), Some(port), connection_config.clone()).await; + + match connect_result { + Err(err) if err.is_address_unavailable_for_use() => continue, // If we can't use this port, try the next one + result => return result, + } + } + + // Tried all source ports for that shard, give up + Err(QueryError::IoError(Arc::new(std::io::Error::new( + std::io::ErrorKind::AddrInUse, + "Could not find free source port for shard", + )))) +} + async fn perform_authenticate( connection: &mut Connection, authenticate: &Authenticate, @@ -2209,4 +2235,60 @@ mod tests { let _ = proxy.finish().await; } + + use crate::sharding::{ShardCount, Sharder}; + use std::net::ToSocketAddrs; + + // Open many connections to a node + // Port collision should occur + // If they are not handled this test will most likely fail + #[tokio::test] + #[cfg(not(scylla_cloud_tests))] + async fn many_connections() { + use super::open_connection_to_shard_aware_port; + + let connections_number = 512; + + let connect_address: SocketAddr = std::env::var("SCYLLA_URI") + .unwrap_or_else(|_| "127.0.0.1:9042".to_string()) + .to_socket_addrs() + .unwrap() + .next() + .unwrap(); + + let connection_config = ConnectionConfig { + compression: None, + tcp_nodelay: true, + #[cfg(feature = "ssl")] + ssl_config: None, + ..Default::default() + }; + + // This does not have to be the real sharder, + // the test is only about port collisions, not connecting + // to the right shard + let sharder = Sharder::new(ShardCount::new(3).unwrap(), 12); + + // Open the connections + let mut conns = Vec::new(); + + for _ in 0..connections_number { + conns.push(open_connection_to_shard_aware_port( + UntranslatedEndpoint::ContactPoint(ResolvedContactPoint { + address: connect_address, + datacenter: None, + }), + 0, + sharder.clone(), + &connection_config, + )); + } + + let joined = futures::future::join_all(conns).await; + + // Check that each connection managed to connect successfully + for res in joined { + res.unwrap(); + } + } } diff --git a/scylla/src/connection/connection_pool.rs b/scylla/src/connection/connection_pool.rs index 347574b75d..a717c3589b 100644 --- a/scylla/src/connection/connection_pool.rs +++ b/scylla/src/connection/connection_pool.rs @@ -27,7 +27,7 @@ use tokio::sync::{broadcast, mpsc, Notify}; use tracing::instrument::WithSubscriber; use tracing::{debug, trace, warn}; -use super::connection::open_connection; +use super::connection::{open_connection, open_connection_to_shard_aware_port}; /// The target size of a per-node connection pool. #[derive(Debug, Clone, Copy)] @@ -1226,90 +1226,3 @@ struct OpenedConnectionEvent { requested_shard: Option, keyspace_name: Option, } - -async fn open_connection_to_shard_aware_port( - endpoint: UntranslatedEndpoint, - shard: Shard, - sharder: Sharder, - connection_config: &ConnectionConfig, -) -> Result<(Connection, ErrorReceiver), QueryError> { - // Create iterator over all possible source ports for this shard - let source_port_iter = sharder.iter_source_ports_for_shard(shard); - - for port in source_port_iter { - let connect_result = - open_connection(endpoint.clone(), Some(port), connection_config.clone()).await; - - match connect_result { - Err(err) if err.is_address_unavailable_for_use() => continue, // If we can't use this port, try the next one - result => return result, - } - } - - // Tried all source ports for that shard, give up - Err(QueryError::IoError(Arc::new(std::io::Error::new( - std::io::ErrorKind::AddrInUse, - "Could not find free source port for shard", - )))) -} - -#[cfg(test)] -mod tests { - use super::open_connection_to_shard_aware_port; - use crate::connection::ConnectionConfig; - use crate::sharding::{ShardCount, Sharder}; - use crate::transport::metadata::UntranslatedEndpoint; - use crate::transport::node::ResolvedContactPoint; - use std::net::{SocketAddr, ToSocketAddrs}; - - // Open many connections to a node - // Port collision should occur - // If they are not handled this test will most likely fail - #[tokio::test] - #[cfg(not(scylla_cloud_tests))] - async fn many_connections() { - let connections_number = 512; - - let connect_address: SocketAddr = std::env::var("SCYLLA_URI") - .unwrap_or_else(|_| "127.0.0.1:9042".to_string()) - .to_socket_addrs() - .unwrap() - .next() - .unwrap(); - - let connection_config = ConnectionConfig { - compression: None, - tcp_nodelay: true, - #[cfg(feature = "ssl")] - ssl_config: None, - ..Default::default() - }; - - // This does not have to be the real sharder, - // the test is only about port collisions, not connecting - // to the right shard - let sharder = Sharder::new(ShardCount::new(3).unwrap(), 12); - - // Open the connections - let mut conns = Vec::new(); - - for _ in 0..connections_number { - conns.push(open_connection_to_shard_aware_port( - UntranslatedEndpoint::ContactPoint(ResolvedContactPoint { - address: connect_address, - datacenter: None, - }), - 0, - sharder.clone(), - &connection_config, - )); - } - - let joined = futures::future::join_all(conns).await; - - // Check that each connection managed to connect successfully - for res in joined { - res.unwrap(); - } - } -} From 25c41cafe53bd80d0b67b3f58233e20b6abeaed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Wed, 30 Aug 2023 15:02:42 +0200 Subject: [PATCH 08/43] move metadata.rs to new cluster mod --- scylla/src/{transport => cluster}/metadata.rs | 2 +- scylla/src/cluster/mod.rs | 1 + scylla/src/connection/connection.rs | 4 ++-- scylla/src/connection/connection_pool.rs | 2 +- scylla/src/lib.rs | 1 + scylla/src/session/session_builder.rs | 2 +- scylla/src/session/session_test.rs | 6 ++---- scylla/src/transport/cluster.rs | 10 +++------- scylla/src/transport/host_filter.rs | 4 ++-- scylla/src/transport/load_balancing/default.rs | 5 +++-- scylla/src/transport/locator/mod.rs | 3 ++- scylla/src/transport/locator/precomputed_replicas.rs | 8 ++++---- scylla/src/transport/locator/test.rs | 6 ++---- scylla/src/transport/mod.rs | 1 - scylla/src/transport/node.rs | 2 +- 15 files changed, 26 insertions(+), 31 deletions(-) rename scylla/src/{transport => cluster}/metadata.rs (99%) create mode 100644 scylla/src/cluster/mod.rs diff --git a/scylla/src/transport/metadata.rs b/scylla/src/cluster/metadata.rs similarity index 99% rename from scylla/src/transport/metadata.rs rename to scylla/src/cluster/metadata.rs index 19af2c7b7c..a35945fc90 100644 --- a/scylla/src/transport/metadata.rs +++ b/scylla/src/cluster/metadata.rs @@ -31,7 +31,7 @@ use tokio::sync::{broadcast, mpsc}; use tracing::{debug, error, trace, warn}; use uuid::Uuid; -use super::node::{KnownNode, NodeAddr, ResolvedContactPoint}; +use crate::transport::node::{KnownNode, NodeAddr, ResolvedContactPoint}; /// Allows to read current metadata from the cluster pub(crate) struct MetadataReader { diff --git a/scylla/src/cluster/mod.rs b/scylla/src/cluster/mod.rs new file mode 100644 index 0000000000..de5643fda5 --- /dev/null +++ b/scylla/src/cluster/mod.rs @@ -0,0 +1 @@ +pub mod metadata; diff --git a/scylla/src/connection/connection.rs b/scylla/src/connection/connection.rs index c64d47d669..9928f2f760 100644 --- a/scylla/src/connection/connection.rs +++ b/scylla/src/connection/connection.rs @@ -41,9 +41,9 @@ use std::{ #[cfg(feature = "cloud")] use crate::cloud::CloudConfig; +use crate::cluster::metadata::{PeerEndpoint, UntranslatedEndpoint, UntranslatedPeer}; use crate::transport::errors::{BadKeyspaceName, DbError, QueryError}; use crate::transport::iterator::RowIterator; -use crate::transport::metadata::{PeerEndpoint, UntranslatedEndpoint, UntranslatedPeer}; use crate::transport::NodeAddr; use crate::batch::{Batch, BatchStatement}; @@ -1848,8 +1848,8 @@ mod tests { use super::open_connection; use super::ConnectionConfig; + use crate::cluster::metadata::UntranslatedEndpoint; use crate::query::Query; - use crate::transport::metadata::UntranslatedEndpoint; use crate::transport::node::ResolvedContactPoint; use crate::utils::test_utils::unique_keyspace_name; use crate::{IntoTypedRows, SessionBuilder}; diff --git a/scylla/src/connection/connection_pool.rs b/scylla/src/connection/connection_pool.rs index a717c3589b..451913a753 100644 --- a/scylla/src/connection/connection_pool.rs +++ b/scylla/src/connection/connection_pool.rs @@ -8,7 +8,7 @@ use crate::transport::errors::QueryError; #[cfg(feature = "cloud")] use crate::transport::node::resolve_hostname; -use crate::transport::metadata::{PeerEndpoint, UntranslatedEndpoint}; +use crate::cluster::metadata::{PeerEndpoint, UntranslatedEndpoint}; #[cfg(feature = "cloud")] use crate::transport::node::ResolvedContactPoint; use crate::transport::NodeAddr; diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index 13c52bd5d3..4324aa5f35 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -105,6 +105,7 @@ pub mod authentication; #[cfg(feature = "cloud")] pub mod cloud; +pub mod cluster; pub mod connection; pub mod history; pub mod session; diff --git a/scylla/src/session/session_builder.rs b/scylla/src/session/session_builder.rs index b08f737c91..9d9f4cf764 100644 --- a/scylla/src/session/session_builder.rs +++ b/scylla/src/session/session_builder.rs @@ -254,7 +254,7 @@ impl GenericSessionBuilder { /// # use std::sync::Arc; /// # use scylla::{Session, SessionBuilder}; /// # use scylla::session::{AddressTranslator, TranslationError}; - /// # use scylla::transport::metadata::UntranslatedPeer; + /// # use scylla::cluster::metadata::UntranslatedPeer; /// struct IdentityTranslator; /// /// #[async_trait] diff --git a/scylla/src/session/session_test.rs b/scylla/src/session/session_test.rs index 642b4474a4..898ab85555 100644 --- a/scylla/src/session/session_test.rs +++ b/scylla/src/session/session_test.rs @@ -1,5 +1,7 @@ use crate as scylla; use crate::batch::{Batch, BatchStatement}; +use crate::cluster::metadata::Strategy::NetworkTopologyStrategy; +use crate::cluster::metadata::{CollectionType, ColumnKind, CqlType, NativeType, UserDefinedType}; use crate::frame::response::result::Row; use crate::frame::value::ValueList; use crate::prepared_statement::PreparedStatement; @@ -10,10 +12,6 @@ use crate::statement::Consistency; use crate::tracing::TracingInfo; use crate::transport::cluster::Datacenter; use crate::transport::errors::{BadKeyspaceName, BadQuery, DbError, QueryError}; -use crate::transport::metadata::Strategy::NetworkTopologyStrategy; -use crate::transport::metadata::{ - CollectionType, ColumnKind, CqlType, NativeType, UserDefinedType, -}; use crate::transport::partitioner::{ calculate_token_for_partition_key, Murmur3Partitioner, Partitioner, PartitionerName, }; diff --git a/scylla/src/transport/cluster.rs b/scylla/src/transport/cluster.rs index cf844e3a89..2c03a18bc9 100644 --- a/scylla/src/transport/cluster.rs +++ b/scylla/src/transport/cluster.rs @@ -5,12 +5,7 @@ use crate::frame::value::ValueList; use crate::prepared_statement::TokenCalculationError; use crate::sharding::Token; use crate::transport::host_filter::HostFilter; -use crate::transport::{ - errors::QueryError, - metadata::{Keyspace, Metadata, MetadataReader}, - node::Node, - partitioner::PartitionerName, -}; +use crate::transport::{errors::QueryError, node::Node, partitioner::PartitionerName}; use arc_swap::ArcSwap; use futures::future::join_all; @@ -27,8 +22,9 @@ use uuid::Uuid; use super::node::{KnownNode, NodeAddr}; +use crate::cluster::metadata::{Keyspace, Metadata, MetadataReader, Strategy}; + use super::locator::ReplicaLocator; -use super::metadata::Strategy; use super::partitioner::calculate_token_for_partition_key; /// Cluster manages up to date information and connections to database nodes. diff --git a/scylla/src/transport/host_filter.rs b/scylla/src/transport/host_filter.rs index 103c164d96..9257678e6d 100644 --- a/scylla/src/transport/host_filter.rs +++ b/scylla/src/transport/host_filter.rs @@ -1,7 +1,7 @@ //! Host filters. //! //! Host filters are essentially just a predicate over -//! [`Peer`](crate::transport::metadata::Peer)s. Currently, they are used +//! [`Peer`](crate::cluster::metadata::Peer)s. Currently, they are used //! by the [`Session`](crate::session::Session) to determine whether //! connections should be opened to a given node or not. @@ -9,7 +9,7 @@ use std::collections::HashSet; use std::io::Error; use std::net::{SocketAddr, ToSocketAddrs}; -use crate::transport::metadata::Peer; +use crate::cluster::metadata::Peer; /// The `HostFilter` trait. pub trait HostFilter: Send + Sync { diff --git a/scylla/src/transport/load_balancing/default.rs b/scylla/src/transport/load_balancing/default.rs index f107bb48c4..2fdcdd4fe8 100644 --- a/scylla/src/transport/load_balancing/default.rs +++ b/scylla/src/transport/load_balancing/default.rs @@ -3,8 +3,9 @@ pub use self::latency_awareness::LatencyAwarenessBuilder; use super::{FallbackPlan, LoadBalancingPolicy, NodeRef, RoutingInfo}; use crate::{ + cluster::metadata::Strategy, sharding::Token, - transport::{cluster::ClusterData, locator::ReplicaSet, metadata::Strategy, node::Node}, + transport::{cluster::ClusterData, locator::ReplicaSet, node::Node}, }; use itertools::{Either, Itertools}; use rand::{prelude::SliceRandom, thread_rng, Rng}; @@ -892,11 +893,11 @@ mod tests { use uuid::Uuid; use crate::{ + cluster::metadata::{Metadata, Peer}, load_balancing::{LoadBalancingPolicy, Plan, RoutingInfo}, sharding::Token, transport::{ locator::test::{id_to_invalid_addr, mock_metadata_for_token_aware_tests}, - metadata::{Metadata, Peer}, ClusterData, }, }; diff --git a/scylla/src/transport/locator/mod.rs b/scylla/src/transport/locator/mod.rs index 59b884cc05..8e2e950487 100644 --- a/scylla/src/transport/locator/mod.rs +++ b/scylla/src/transport/locator/mod.rs @@ -8,7 +8,8 @@ mod token_ring; use rand::{seq::IteratorRandom, Rng}; pub use token_ring::TokenRing; -use super::{metadata::Strategy, Node, NodeRef}; +use super::{Node, NodeRef}; +use crate::cluster::metadata::Strategy; use crate::sharding::Token; use itertools::Itertools; use precomputed_replicas::PrecomputedReplicas; diff --git a/scylla/src/transport/locator/precomputed_replicas.rs b/scylla/src/transport/locator/precomputed_replicas.rs index 330b00d0cf..0ca1b17ef7 100644 --- a/scylla/src/transport/locator/precomputed_replicas.rs +++ b/scylla/src/transport/locator/precomputed_replicas.rs @@ -14,8 +14,8 @@ use super::replication_info::ReplicationInfo; use super::TokenRing; +use crate::cluster::metadata::Strategy; use crate::sharding::Token; -use crate::transport::metadata::Strategy; use crate::transport::node::Node; use std::cmp; @@ -215,10 +215,10 @@ mod tests { use std::collections::HashMap; use crate::{ + cluster::metadata::{Keyspace, Strategy}, sharding::Token, - transport::{ - locator::test::{create_ring, mock_metadata_for_token_aware_tests, A, C, D, E, F, G}, - metadata::{Keyspace, Strategy}, + transport::locator::test::{ + create_ring, mock_metadata_for_token_aware_tests, A, C, D, E, F, G, }, }; diff --git a/scylla/src/transport/locator/test.rs b/scylla/src/transport/locator/test.rs index 6077515074..39d34fabda 100644 --- a/scylla/src/transport/locator/test.rs +++ b/scylla/src/transport/locator/test.rs @@ -3,12 +3,10 @@ use rand_chacha::ChaCha8Rng; use uuid::Uuid; use super::{ReplicaLocator, ReplicaSet}; +use crate::cluster::metadata::{Keyspace, Metadata, Peer, Strategy}; use crate::connection::PoolConfig; use crate::sharding::Token; -use crate::transport::{ - metadata::{Keyspace, Metadata, Peer, Strategy}, - Node, -}; +use crate::transport::Node; use crate::transport::{NodeAddr, NodeRef}; use std::collections::HashSet; diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs index 82def7be2a..14b93a4c55 100644 --- a/scylla/src/transport/mod.rs +++ b/scylla/src/transport/mod.rs @@ -5,7 +5,6 @@ pub mod host_filter; pub mod iterator; pub mod load_balancing; pub mod locator; -pub mod metadata; pub(crate) mod metrics; pub(crate) mod node; pub mod partitioner; diff --git a/scylla/src/transport/node.rs b/scylla/src/transport/node.rs index 9de32bac0f..e18314c3ba 100644 --- a/scylla/src/transport/node.rs +++ b/scylla/src/transport/node.rs @@ -21,7 +21,7 @@ use std::{ }, }; -use super::metadata::{PeerEndpoint, UntranslatedEndpoint}; +use crate::cluster::metadata::{PeerEndpoint, UntranslatedEndpoint}; /// This enum is introduced to support address translation only upon opening a connection, /// as well as to cope with a bug present in older Cassandra and Scylla releases. From 59144ee869083a3e58466917dbdab98a3420a98e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Wed, 30 Aug 2023 15:07:30 +0200 Subject: [PATCH 09/43] move cluster.rs to new cluster mod --- examples/custom_load_balancing_policy.rs | 3 +- scylla/src/{transport => cluster}/cluster.rs | 7 ++--- scylla/src/cluster/mod.rs | 4 +++ scylla/src/session/session.rs | 2 +- scylla/src/session/session_test.rs | 2 +- scylla/src/transport/iterator.rs | 2 +- .../src/transport/load_balancing/default.rs | 28 +++++++++---------- scylla/src/transport/load_balancing/mod.rs | 3 +- scylla/src/transport/load_balancing/plan.rs | 2 +- scylla/src/transport/mod.rs | 2 -- scylla/tests/integration/consistency.rs | 4 +-- .../tests/integration/execution_profiles.rs | 2 +- scylla/tests/integration/utils.rs | 4 +-- 13 files changed, 34 insertions(+), 31 deletions(-) rename scylla/src/{transport => cluster}/cluster.rs (99%) diff --git a/examples/custom_load_balancing_policy.rs b/examples/custom_load_balancing_policy.rs index c4b2d32002..e119733ced 100644 --- a/examples/custom_load_balancing_policy.rs +++ b/examples/custom_load_balancing_policy.rs @@ -1,7 +1,8 @@ use anyhow::Result; use scylla::{ + cluster::ClusterData, load_balancing::{LoadBalancingPolicy, RoutingInfo}, - transport::{ClusterData, ExecutionProfile}, + transport::ExecutionProfile, Session, SessionBuilder, }; use std::{env, sync::Arc}; diff --git a/scylla/src/transport/cluster.rs b/scylla/src/cluster/cluster.rs similarity index 99% rename from scylla/src/transport/cluster.rs rename to scylla/src/cluster/cluster.rs index 2c03a18bc9..2ce1f53f01 100644 --- a/scylla/src/transport/cluster.rs +++ b/scylla/src/cluster/cluster.rs @@ -20,12 +20,11 @@ use tracing::instrument::WithSubscriber; use tracing::{debug, warn}; use uuid::Uuid; -use super::node::{KnownNode, NodeAddr}; - use crate::cluster::metadata::{Keyspace, Metadata, MetadataReader, Strategy}; -use super::locator::ReplicaLocator; -use super::partitioner::calculate_token_for_partition_key; +use crate::transport::locator::ReplicaLocator; +use crate::transport::node::{KnownNode, NodeAddr}; +use crate::transport::partitioner::calculate_token_for_partition_key; /// Cluster manages up to date information and connections to database nodes. /// All data can be accessed by cloning Arc in the `data` field diff --git a/scylla/src/cluster/mod.rs b/scylla/src/cluster/mod.rs index de5643fda5..2a780476d5 100644 --- a/scylla/src/cluster/mod.rs +++ b/scylla/src/cluster/mod.rs @@ -1 +1,5 @@ +mod cluster; pub mod metadata; + +pub(crate) use cluster::{Cluster, ClusterNeatDebug}; +pub use cluster::{ClusterData, Datacenter}; diff --git a/scylla/src/session/session.rs b/scylla/src/session/session.rs index 55b3567e2c..1289a34ed5 100644 --- a/scylla/src/session/session.rs +++ b/scylla/src/session/session.rs @@ -29,6 +29,7 @@ use tokio::time::timeout; use tracing::{debug, trace, trace_span, Instrument}; use uuid::Uuid; +use crate::cluster::{Cluster, ClusterData, ClusterNeatDebug}; use crate::connection::PoolConfig; use crate::connection::QueryResponse; #[cfg(feature = "ssl")] @@ -47,7 +48,6 @@ use crate::query::Query; use crate::sharding::Token; use crate::statement::Consistency; use crate::tracing::{TracingEvent, TracingInfo}; -use crate::transport::cluster::{Cluster, ClusterData, ClusterNeatDebug}; use crate::transport::errors::{NewSessionError, QueryError}; use crate::transport::execution_profile::{ ExecutionProfile, ExecutionProfileHandle, ExecutionProfileInner, diff --git a/scylla/src/session/session_test.rs b/scylla/src/session/session_test.rs index 898ab85555..17cb6e2a91 100644 --- a/scylla/src/session/session_test.rs +++ b/scylla/src/session/session_test.rs @@ -2,6 +2,7 @@ use crate as scylla; use crate::batch::{Batch, BatchStatement}; use crate::cluster::metadata::Strategy::NetworkTopologyStrategy; use crate::cluster::metadata::{CollectionType, ColumnKind, CqlType, NativeType, UserDefinedType}; +use crate::cluster::Datacenter; use crate::frame::response::result::Row; use crate::frame::value::ValueList; use crate::prepared_statement::PreparedStatement; @@ -10,7 +11,6 @@ use crate::retry_policy::{QueryInfo, RetryDecision, RetryPolicy, RetrySession}; use crate::sharding::Token; use crate::statement::Consistency; use crate::tracing::TracingInfo; -use crate::transport::cluster::Datacenter; use crate::transport::errors::{BadKeyspaceName, BadQuery, DbError, QueryError}; use crate::transport::partitioner::{ calculate_token_for_partition_key, Murmur3Partitioner, Partitioner, PartitionerName, diff --git a/scylla/src/transport/iterator.rs b/scylla/src/transport/iterator.rs index 9f4ae3c06a..fd33472e7e 100644 --- a/scylla/src/transport/iterator.rs +++ b/scylla/src/transport/iterator.rs @@ -22,6 +22,7 @@ use super::execution_profile::ExecutionProfileInner; use crate::cql_to_rust::{FromRow, FromRowError}; use crate::session::RequestSpan; +use crate::cluster::ClusterData; use crate::connection::{Connection, NonErrorQueryResponse, QueryResponse}; use crate::frame::{ response::{ @@ -33,7 +34,6 @@ use crate::frame::{ use crate::history::{self, HistoryListener}; use crate::statement::Consistency; use crate::statement::{prepared_statement::PreparedStatement, query::Query}; -use crate::transport::cluster::ClusterData; use crate::transport::load_balancing::{self, RoutingInfo}; use crate::transport::metrics::Metrics; use crate::transport::retry_policy::{QueryInfo, RetryDecision, RetrySession}; diff --git a/scylla/src/transport/load_balancing/default.rs b/scylla/src/transport/load_balancing/default.rs index 2fdcdd4fe8..c0ea23f6db 100644 --- a/scylla/src/transport/load_balancing/default.rs +++ b/scylla/src/transport/load_balancing/default.rs @@ -2,10 +2,11 @@ use self::latency_awareness::LatencyAwareness; pub use self::latency_awareness::LatencyAwarenessBuilder; use super::{FallbackPlan, LoadBalancingPolicy, NodeRef, RoutingInfo}; +use crate::cluster::ClusterData; use crate::{ cluster::metadata::Strategy, sharding::Token, - transport::{cluster::ClusterData, locator::ReplicaSet, node::Node}, + transport::{locator::ReplicaSet, node::Node}, }; use itertools::{Either, Itertools}; use rand::{prelude::SliceRandom, thread_rng, Rng}; @@ -875,14 +876,12 @@ mod tests { ExpectedGroups, ExpectedGroupsBuilder, }; use crate::{ + cluster::ClusterData, load_balancing::{ default::tests::framework::mock_cluster_data_for_token_aware_tests, RoutingInfo, }, sharding::Token, - transport::{ - locator::test::{KEYSPACE_NTS_RF_2, KEYSPACE_NTS_RF_3, KEYSPACE_SS_RF_2}, - ClusterData, - }, + transport::locator::test::{KEYSPACE_NTS_RF_2, KEYSPACE_NTS_RF_3, KEYSPACE_SS_RF_2}, }; use super::{DefaultPolicy, NodeLocationPreference}; @@ -893,13 +892,13 @@ mod tests { use uuid::Uuid; use crate::{ - cluster::metadata::{Metadata, Peer}, - load_balancing::{LoadBalancingPolicy, Plan, RoutingInfo}, - sharding::Token, - transport::{ - locator::test::{id_to_invalid_addr, mock_metadata_for_token_aware_tests}, + cluster::{ + metadata::{Metadata, Peer}, ClusterData, }, + load_balancing::{LoadBalancingPolicy, Plan, RoutingInfo}, + sharding::Token, + transport::locator::test::{id_to_invalid_addr, mock_metadata_for_token_aware_tests}, }; enum ExpectedGroup { @@ -2718,9 +2717,7 @@ mod latency_awareness { }; use crate::{ - load_balancing::default::NodeLocationPreference, test_utils::create_new_session_builder, - }; - use crate::{ + cluster::ClusterData, load_balancing::{ default::tests::test_default_policy_with_given_cluster_and_routing_info, RoutingInfo, @@ -2730,10 +2727,13 @@ mod latency_awareness { locator::test::{ id_to_invalid_addr, A, B, C, D, E, F, G, KEYSPACE_NTS_RF_2, KEYSPACE_NTS_RF_3, }, - ClusterData, NodeAddr, + NodeAddr, }, ExecutionProfile, }; + use crate::{ + load_balancing::default::NodeLocationPreference, test_utils::create_new_session_builder, + }; use std::time::Instant; trait DefaultPolicyTestExt { diff --git a/scylla/src/transport/load_balancing/mod.rs b/scylla/src/transport/load_balancing/mod.rs index 16c54d58f2..4e76f0b1d4 100644 --- a/scylla/src/transport/load_balancing/mod.rs +++ b/scylla/src/transport/load_balancing/mod.rs @@ -2,7 +2,8 @@ //! `Session` can use any load balancing policy which implements the `LoadBalancingPolicy` trait\ //! See [the book](https://rust-driver.docs.scylladb.com/stable/load-balancing/load-balancing.html) for more information -use super::{cluster::ClusterData, NodeRef}; +use super::NodeRef; +use crate::cluster::ClusterData; use crate::sharding::Token; use scylla_cql::{errors::QueryError, frame::types}; diff --git a/scylla/src/transport/load_balancing/plan.rs b/scylla/src/transport/load_balancing/plan.rs index e49d4cb012..93a4828638 100644 --- a/scylla/src/transport/load_balancing/plan.rs +++ b/scylla/src/transport/load_balancing/plan.rs @@ -1,7 +1,7 @@ use tracing::error; use super::{FallbackPlan, LoadBalancingPolicy, NodeRef, RoutingInfo}; -use crate::transport::ClusterData; +use crate::cluster::ClusterData; enum PlanState<'a> { Created, diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs index 14b93a4c55..faf0973ccf 100644 --- a/scylla/src/transport/mod.rs +++ b/scylla/src/transport/mod.rs @@ -1,4 +1,3 @@ -pub(crate) mod cluster; pub mod downgrading_consistency_retry_policy; pub mod execution_profile; pub mod host_filter; @@ -26,5 +25,4 @@ mod cql_types_test; #[cfg(test)] mod cql_value_test; -pub use cluster::ClusterData; pub use node::{KnownNode, Node, NodeAddr, NodeRef}; diff --git a/scylla/tests/integration/consistency.rs b/scylla/tests/integration/consistency.rs index 387d0936fd..4ffb34264e 100644 --- a/scylla/tests/integration/consistency.rs +++ b/scylla/tests/integration/consistency.rs @@ -373,7 +373,7 @@ impl LoadBalancingPolicy for RoutingInfoReportingWrapper { fn pick<'a>( &'a self, query: &'a RoutingInfo, - cluster: &'a scylla::transport::ClusterData, + cluster: &'a scylla::cluster::ClusterData, ) -> Option> { self.routing_info_tx .send(OwnedRoutingInfo::from(query.clone())) @@ -384,7 +384,7 @@ impl LoadBalancingPolicy for RoutingInfoReportingWrapper { fn fallback<'a>( &'a self, query: &'a RoutingInfo, - cluster: &'a scylla::transport::ClusterData, + cluster: &'a scylla::cluster::ClusterData, ) -> scylla::load_balancing::FallbackPlan<'a> { self.routing_info_tx .send(OwnedRoutingInfo::from(query.clone())) diff --git a/scylla/tests/integration/execution_profiles.rs b/scylla/tests/integration/execution_profiles.rs index 119487a609..8e49cba549 100644 --- a/scylla/tests/integration/execution_profiles.rs +++ b/scylla/tests/integration/execution_profiles.rs @@ -9,11 +9,11 @@ use scylla::query::Query; use scylla::statement::SerialConsistency; use scylla::transport::NodeRef; use scylla::{ + cluster::ClusterData, load_balancing::{LoadBalancingPolicy, RoutingInfo}, retry_policy::{RetryPolicy, RetrySession}, speculative_execution::SpeculativeExecutionPolicy, test_utils::unique_keyspace_name, - transport::ClusterData, ExecutionProfile, SessionBuilder, }; use scylla_cql::Consistency; diff --git a/scylla/tests/integration/utils.rs b/scylla/tests/integration/utils.rs index f32ffa2764..1baff486a3 100644 --- a/scylla/tests/integration/utils.rs +++ b/scylla/tests/integration/utils.rs @@ -22,7 +22,7 @@ impl LoadBalancingPolicy for FixedOrderLoadBalancer { fn pick<'a>( &'a self, _info: &'a scylla::load_balancing::RoutingInfo, - cluster: &'a scylla::transport::ClusterData, + cluster: &'a scylla::cluster::ClusterData, ) -> Option> { cluster .get_nodes_info() @@ -34,7 +34,7 @@ impl LoadBalancingPolicy for FixedOrderLoadBalancer { fn fallback<'a>( &'a self, _info: &'a scylla::load_balancing::RoutingInfo, - cluster: &'a scylla::transport::ClusterData, + cluster: &'a scylla::cluster::ClusterData, ) -> scylla::load_balancing::FallbackPlan<'a> { Box::new( cluster From 9c457bd484ab6501aaba9de8d838aa1bc4bb3a6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Wed, 30 Aug 2023 15:11:34 +0200 Subject: [PATCH 10/43] move locator to new cluster mod --- scylla/src/cluster/cluster.rs | 2 +- .../src/{transport => cluster}/locator/mod.rs | 4 +-- .../locator/precomputed_replicas.rs | 6 ++--- .../locator/replicas.rs | 0 .../locator/replication_info.rs | 4 +-- .../{transport => cluster}/locator/test.rs | 0 .../locator/token_ring.rs | 0 scylla/src/cluster/mod.rs | 1 + .../src/transport/load_balancing/default.rs | 27 +++++++++---------- scylla/src/transport/load_balancing/plan.rs | 6 ++--- scylla/src/transport/mod.rs | 1 - 11 files changed, 24 insertions(+), 27 deletions(-) rename scylla/src/{transport => cluster}/locator/mod.rs (99%) rename scylla/src/{transport => cluster}/locator/precomputed_replicas.rs (99%) rename scylla/src/{transport => cluster}/locator/replicas.rs (100%) rename scylla/src/{transport => cluster}/locator/replication_info.rs (99%) rename scylla/src/{transport => cluster}/locator/test.rs (100%) rename scylla/src/{transport => cluster}/locator/token_ring.rs (100%) diff --git a/scylla/src/cluster/cluster.rs b/scylla/src/cluster/cluster.rs index 2ce1f53f01..fb81372e89 100644 --- a/scylla/src/cluster/cluster.rs +++ b/scylla/src/cluster/cluster.rs @@ -20,9 +20,9 @@ use tracing::instrument::WithSubscriber; use tracing::{debug, warn}; use uuid::Uuid; +use crate::cluster::locator::ReplicaLocator; use crate::cluster::metadata::{Keyspace, Metadata, MetadataReader, Strategy}; -use crate::transport::locator::ReplicaLocator; use crate::transport::node::{KnownNode, NodeAddr}; use crate::transport::partitioner::calculate_token_for_partition_key; diff --git a/scylla/src/transport/locator/mod.rs b/scylla/src/cluster/locator/mod.rs similarity index 99% rename from scylla/src/transport/locator/mod.rs rename to scylla/src/cluster/locator/mod.rs index 8e2e950487..e54e32b7e6 100644 --- a/scylla/src/transport/locator/mod.rs +++ b/scylla/src/cluster/locator/mod.rs @@ -8,9 +8,9 @@ mod token_ring; use rand::{seq::IteratorRandom, Rng}; pub use token_ring::TokenRing; -use super::{Node, NodeRef}; use crate::cluster::metadata::Strategy; use crate::sharding::Token; +use crate::transport::{Node, NodeRef}; use itertools::Itertools; use precomputed_replicas::PrecomputedReplicas; use replicas::{ReplicasArray, EMPTY_REPLICAS}; @@ -741,7 +741,7 @@ impl<'a> IntoIterator for ReplicasOrdered<'a> { #[cfg(test)] mod tests { - use crate::{sharding::Token, transport::locator::test::*}; + use crate::{cluster::locator::test::*, sharding::Token}; #[tokio::test] async fn test_replicas_ordered() { diff --git a/scylla/src/transport/locator/precomputed_replicas.rs b/scylla/src/cluster/locator/precomputed_replicas.rs similarity index 99% rename from scylla/src/transport/locator/precomputed_replicas.rs rename to scylla/src/cluster/locator/precomputed_replicas.rs index 0ca1b17ef7..7b637e970a 100644 --- a/scylla/src/transport/locator/precomputed_replicas.rs +++ b/scylla/src/cluster/locator/precomputed_replicas.rs @@ -215,11 +215,11 @@ mod tests { use std::collections::HashMap; use crate::{ - cluster::metadata::{Keyspace, Strategy}, - sharding::Token, - transport::locator::test::{ + cluster::locator::test::{ create_ring, mock_metadata_for_token_aware_tests, A, C, D, E, F, G, }, + cluster::metadata::{Keyspace, Strategy}, + sharding::Token, }; use super::{PrecomputedReplicas, ReplicationInfo}; diff --git a/scylla/src/transport/locator/replicas.rs b/scylla/src/cluster/locator/replicas.rs similarity index 100% rename from scylla/src/transport/locator/replicas.rs rename to scylla/src/cluster/locator/replicas.rs diff --git a/scylla/src/transport/locator/replication_info.rs b/scylla/src/cluster/locator/replication_info.rs similarity index 99% rename from scylla/src/transport/locator/replication_info.rs rename to scylla/src/cluster/locator/replication_info.rs index a4f1fab746..efa39dbd0b 100644 --- a/scylla/src/transport/locator/replication_info.rs +++ b/scylla/src/cluster/locator/replication_info.rs @@ -204,10 +204,10 @@ where #[cfg(test)] mod tests { use crate::{ - sharding::Token, - transport::locator::test::{ + cluster::locator::test::{ create_ring, mock_metadata_for_token_aware_tests, A, B, C, D, E, F, G, }, + sharding::Token, }; use super::ReplicationInfo; diff --git a/scylla/src/transport/locator/test.rs b/scylla/src/cluster/locator/test.rs similarity index 100% rename from scylla/src/transport/locator/test.rs rename to scylla/src/cluster/locator/test.rs diff --git a/scylla/src/transport/locator/token_ring.rs b/scylla/src/cluster/locator/token_ring.rs similarity index 100% rename from scylla/src/transport/locator/token_ring.rs rename to scylla/src/cluster/locator/token_ring.rs diff --git a/scylla/src/cluster/mod.rs b/scylla/src/cluster/mod.rs index 2a780476d5..3971036422 100644 --- a/scylla/src/cluster/mod.rs +++ b/scylla/src/cluster/mod.rs @@ -1,4 +1,5 @@ mod cluster; +pub mod locator; pub mod metadata; pub(crate) use cluster::{Cluster, ClusterNeatDebug}; diff --git a/scylla/src/transport/load_balancing/default.rs b/scylla/src/transport/load_balancing/default.rs index c0ea23f6db..3373f91ebc 100644 --- a/scylla/src/transport/load_balancing/default.rs +++ b/scylla/src/transport/load_balancing/default.rs @@ -4,9 +4,8 @@ pub use self::latency_awareness::LatencyAwarenessBuilder; use super::{FallbackPlan, LoadBalancingPolicy, NodeRef, RoutingInfo}; use crate::cluster::ClusterData; use crate::{ - cluster::metadata::Strategy, - sharding::Token, - transport::{locator::ReplicaSet, node::Node}, + cluster::locator::ReplicaSet, cluster::metadata::Strategy, sharding::Token, + transport::node::Node, }; use itertools::{Either, Itertools}; use rand::{prelude::SliceRandom, thread_rng, Rng}; @@ -876,12 +875,12 @@ mod tests { ExpectedGroups, ExpectedGroupsBuilder, }; use crate::{ + cluster::locator::test::{KEYSPACE_NTS_RF_2, KEYSPACE_NTS_RF_3, KEYSPACE_SS_RF_2}, cluster::ClusterData, load_balancing::{ default::tests::framework::mock_cluster_data_for_token_aware_tests, RoutingInfo, }, sharding::Token, - transport::locator::test::{KEYSPACE_NTS_RF_2, KEYSPACE_NTS_RF_3, KEYSPACE_SS_RF_2}, }; use super::{DefaultPolicy, NodeLocationPreference}; @@ -892,13 +891,13 @@ mod tests { use uuid::Uuid; use crate::{ + cluster::locator::test::{id_to_invalid_addr, mock_metadata_for_token_aware_tests}, cluster::{ metadata::{Metadata, Peer}, ClusterData, }, load_balancing::{LoadBalancingPolicy, Plan, RoutingInfo}, sharding::Token, - transport::locator::test::{id_to_invalid_addr, mock_metadata_for_token_aware_tests}, }; enum ExpectedGroup { @@ -1199,7 +1198,7 @@ mod tests { #[tokio::test] async fn test_default_policy_with_token_aware_statements() { - use crate::transport::locator::test::{A, B, C, D, E, F, G}; + use crate::cluster::locator::test::{A, B, C, D, E, F, G}; let cluster = mock_cluster_data_for_token_aware_tests().await; struct Test<'a> { @@ -1669,7 +1668,7 @@ mod tests { #[tokio::test] async fn test_default_policy_with_lwt_statements() { - use crate::transport::locator::test::{A, B, C, D, E, F, G}; + use crate::cluster::locator::test::{A, B, C, D, E, F, G}; let cluster = mock_cluster_data_for_token_aware_tests().await; struct Test<'a> { @@ -2717,18 +2716,18 @@ mod latency_awareness { }; use crate::{ - cluster::ClusterData, + cluster::{ + locator::test::{ + id_to_invalid_addr, A, B, C, D, E, F, G, KEYSPACE_NTS_RF_2, KEYSPACE_NTS_RF_3, + }, + ClusterData, + }, load_balancing::{ default::tests::test_default_policy_with_given_cluster_and_routing_info, RoutingInfo, }, sharding::Token, - transport::{ - locator::test::{ - id_to_invalid_addr, A, B, C, D, E, F, G, KEYSPACE_NTS_RF_2, KEYSPACE_NTS_RF_3, - }, - NodeAddr, - }, + transport::NodeAddr, ExecutionProfile, }; use crate::{ diff --git a/scylla/src/transport/load_balancing/plan.rs b/scylla/src/transport/load_balancing/plan.rs index 93a4828638..d5fe1b384f 100644 --- a/scylla/src/transport/load_balancing/plan.rs +++ b/scylla/src/transport/load_balancing/plan.rs @@ -105,10 +105,8 @@ impl<'a> Iterator for Plan<'a> { mod tests { use std::{net::SocketAddr, str::FromStr, sync::Arc}; - use crate::transport::{ - locator::test::{create_locator, mock_metadata_for_token_aware_tests}, - Node, NodeAddr, - }; + use crate::cluster::locator::test::{create_locator, mock_metadata_for_token_aware_tests}; + use crate::transport::{Node, NodeAddr}; use super::*; diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs index faf0973ccf..3f11058391 100644 --- a/scylla/src/transport/mod.rs +++ b/scylla/src/transport/mod.rs @@ -3,7 +3,6 @@ pub mod execution_profile; pub mod host_filter; pub mod iterator; pub mod load_balancing; -pub mod locator; pub(crate) mod metrics; pub(crate) mod node; pub mod partitioner; From 33c94e2af171d9a4a677712dc74aaab38cf833bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Wed, 30 Aug 2023 15:21:38 +0200 Subject: [PATCH 11/43] move node.rs to new cluster module --- examples/compare-tokens.rs | 2 +- examples/custom_load_balancing_policy.rs | 2 +- scylla/src/cluster/cluster.rs | 5 +++-- scylla/src/cluster/locator/mod.rs | 2 +- scylla/src/cluster/locator/precomputed_replicas.rs | 2 +- scylla/src/cluster/locator/replicas.rs | 2 +- scylla/src/cluster/locator/replication_info.rs | 2 +- scylla/src/cluster/locator/test.rs | 3 +-- scylla/src/cluster/metadata.rs | 4 ++-- scylla/src/cluster/mod.rs | 7 +++++++ scylla/src/{transport => cluster}/node.rs | 0 scylla/src/connection/connection.rs | 4 ++-- scylla/src/connection/connection_pool.rs | 6 +++--- scylla/src/session/session.rs | 9 ++++----- scylla/src/session/session_builder.rs | 2 +- scylla/src/transport/host_filter.rs | 5 +++-- scylla/src/transport/iterator.rs | 2 +- scylla/src/transport/load_balancing/default.rs | 8 +++----- scylla/src/transport/load_balancing/mod.rs | 3 +-- scylla/src/transport/load_balancing/plan.rs | 2 +- scylla/src/transport/mod.rs | 3 --- scylla/tests/integration/consistency.rs | 2 +- scylla/tests/integration/execution_profiles.rs | 2 +- scylla/tests/integration/utils.rs | 6 +++--- 24 files changed, 43 insertions(+), 42 deletions(-) rename scylla/src/{transport => cluster}/node.rs (100%) diff --git a/examples/compare-tokens.rs b/examples/compare-tokens.rs index 76cca047e6..99feb3efc8 100644 --- a/examples/compare-tokens.rs +++ b/examples/compare-tokens.rs @@ -1,7 +1,7 @@ use anyhow::Result; +use scylla::cluster::NodeAddr; use scylla::frame::value::ValueList; use scylla::sharding::Token; -use scylla::transport::NodeAddr; use scylla::{Session, SessionBuilder}; use std::env; diff --git a/examples/custom_load_balancing_policy.rs b/examples/custom_load_balancing_policy.rs index e119733ced..5582ae2a5c 100644 --- a/examples/custom_load_balancing_policy.rs +++ b/examples/custom_load_balancing_policy.rs @@ -18,7 +18,7 @@ impl LoadBalancingPolicy for CustomLoadBalancingPolicy { &'a self, _info: &'a RoutingInfo, cluster: &'a ClusterData, - ) -> Option> { + ) -> Option> { self.fallback(_info, cluster).next() } diff --git a/scylla/src/cluster/cluster.rs b/scylla/src/cluster/cluster.rs index fb81372e89..07c82b5947 100644 --- a/scylla/src/cluster/cluster.rs +++ b/scylla/src/cluster/cluster.rs @@ -1,3 +1,4 @@ +use crate::cluster::Node; use crate::connection::{Connection, PoolConfig, VerifiedKeyspaceName}; /// Cluster manages up to date information and connections to database nodes use crate::frame::response::event::{Event, StatusChangeEvent}; @@ -5,7 +6,7 @@ use crate::frame::value::ValueList; use crate::prepared_statement::TokenCalculationError; use crate::sharding::Token; use crate::transport::host_filter::HostFilter; -use crate::transport::{errors::QueryError, node::Node, partitioner::PartitionerName}; +use crate::transport::{errors::QueryError, partitioner::PartitionerName}; use arc_swap::ArcSwap; use futures::future::join_all; @@ -23,7 +24,7 @@ use uuid::Uuid; use crate::cluster::locator::ReplicaLocator; use crate::cluster::metadata::{Keyspace, Metadata, MetadataReader, Strategy}; -use crate::transport::node::{KnownNode, NodeAddr}; +use crate::cluster::{KnownNode, NodeAddr}; use crate::transport::partitioner::calculate_token_for_partition_key; /// Cluster manages up to date information and connections to database nodes. diff --git a/scylla/src/cluster/locator/mod.rs b/scylla/src/cluster/locator/mod.rs index e54e32b7e6..bef7699d00 100644 --- a/scylla/src/cluster/locator/mod.rs +++ b/scylla/src/cluster/locator/mod.rs @@ -9,8 +9,8 @@ use rand::{seq::IteratorRandom, Rng}; pub use token_ring::TokenRing; use crate::cluster::metadata::Strategy; +use crate::cluster::{Node, NodeRef}; use crate::sharding::Token; -use crate::transport::{Node, NodeRef}; use itertools::Itertools; use precomputed_replicas::PrecomputedReplicas; use replicas::{ReplicasArray, EMPTY_REPLICAS}; diff --git a/scylla/src/cluster/locator/precomputed_replicas.rs b/scylla/src/cluster/locator/precomputed_replicas.rs index 7b637e970a..4249e2f077 100644 --- a/scylla/src/cluster/locator/precomputed_replicas.rs +++ b/scylla/src/cluster/locator/precomputed_replicas.rs @@ -15,8 +15,8 @@ use super::replication_info::ReplicationInfo; use super::TokenRing; use crate::cluster::metadata::Strategy; +use crate::cluster::Node; use crate::sharding::Token; -use crate::transport::node::Node; use std::cmp; use std::collections::BTreeSet; diff --git a/scylla/src/cluster/locator/replicas.rs b/scylla/src/cluster/locator/replicas.rs index 30df602695..9cae8496a9 100644 --- a/scylla/src/cluster/locator/replicas.rs +++ b/scylla/src/cluster/locator/replicas.rs @@ -1,6 +1,6 @@ use itertools::Either; -use crate::transport::{Node, NodeRef}; +use crate::cluster::{Node, NodeRef}; use std::{ops::Index, sync::Arc}; /// Container holding replicas, enabling unified use of both borrowed and owned `Node` sequences. diff --git a/scylla/src/cluster/locator/replication_info.rs b/scylla/src/cluster/locator/replication_info.rs index efa39dbd0b..d586506da2 100644 --- a/scylla/src/cluster/locator/replication_info.rs +++ b/scylla/src/cluster/locator/replication_info.rs @@ -1,8 +1,8 @@ use itertools::Itertools; use super::TokenRing; +use crate::cluster::Node; use crate::sharding::Token; -use crate::transport::node::Node; use std::cmp; use std::collections::{BTreeSet, HashMap}; diff --git a/scylla/src/cluster/locator/test.rs b/scylla/src/cluster/locator/test.rs index 39d34fabda..4f42375cac 100644 --- a/scylla/src/cluster/locator/test.rs +++ b/scylla/src/cluster/locator/test.rs @@ -4,10 +4,9 @@ use uuid::Uuid; use super::{ReplicaLocator, ReplicaSet}; use crate::cluster::metadata::{Keyspace, Metadata, Peer, Strategy}; +use crate::cluster::{Node, NodeAddr, NodeRef}; use crate::connection::PoolConfig; use crate::sharding::Token; -use crate::transport::Node; -use crate::transport::{NodeAddr, NodeRef}; use std::collections::HashSet; use std::sync::Arc; diff --git a/scylla/src/cluster/metadata.rs b/scylla/src/cluster/metadata.rs index a35945fc90..f34b3b424f 100644 --- a/scylla/src/cluster/metadata.rs +++ b/scylla/src/cluster/metadata.rs @@ -1,10 +1,10 @@ +use crate::cluster::resolve_contact_points; use crate::connection::{Connection, ConnectionConfig, NodeConnectionPool, PoolConfig, PoolSize}; use crate::frame::response::event::Event; use crate::sharding::Token; use crate::statement::query::Query; use crate::transport::errors::{DbError, QueryError}; use crate::transport::host_filter::HostFilter; -use crate::transport::node::resolve_contact_points; use crate::utils::parse::{ParseErrorCause, ParseResult, ParserState}; use futures::future::{self, FutureExt}; @@ -31,7 +31,7 @@ use tokio::sync::{broadcast, mpsc}; use tracing::{debug, error, trace, warn}; use uuid::Uuid; -use crate::transport::node::{KnownNode, NodeAddr, ResolvedContactPoint}; +use crate::cluster::{KnownNode, NodeAddr, ResolvedContactPoint}; /// Allows to read current metadata from the cluster pub(crate) struct MetadataReader { diff --git a/scylla/src/cluster/mod.rs b/scylla/src/cluster/mod.rs index 3971036422..35b35147b2 100644 --- a/scylla/src/cluster/mod.rs +++ b/scylla/src/cluster/mod.rs @@ -1,6 +1,13 @@ mod cluster; pub mod locator; pub mod metadata; +mod node; pub(crate) use cluster::{Cluster, ClusterNeatDebug}; pub use cluster::{ClusterData, Datacenter}; + +pub(crate) use node::{resolve_contact_points, resolve_hostname, ResolvedContactPoint}; +pub use node::{KnownNode, Node, NodeAddr, NodeRef}; + +#[cfg(feature = "cloud")] +pub(crate) use node::CloudEndpoint; diff --git a/scylla/src/transport/node.rs b/scylla/src/cluster/node.rs similarity index 100% rename from scylla/src/transport/node.rs rename to scylla/src/cluster/node.rs diff --git a/scylla/src/connection/connection.rs b/scylla/src/connection/connection.rs index 9928f2f760..aadfe95a65 100644 --- a/scylla/src/connection/connection.rs +++ b/scylla/src/connection/connection.rs @@ -42,9 +42,9 @@ use std::{ #[cfg(feature = "cloud")] use crate::cloud::CloudConfig; use crate::cluster::metadata::{PeerEndpoint, UntranslatedEndpoint, UntranslatedPeer}; +use crate::cluster::NodeAddr; use crate::transport::errors::{BadKeyspaceName, DbError, QueryError}; use crate::transport::iterator::RowIterator; -use crate::transport::NodeAddr; use crate::batch::{Batch, BatchStatement}; use crate::frame::protocol_features::ProtocolFeatures; @@ -1849,8 +1849,8 @@ mod tests { use super::open_connection; use super::ConnectionConfig; use crate::cluster::metadata::UntranslatedEndpoint; + use crate::cluster::ResolvedContactPoint; use crate::query::Query; - use crate::transport::node::ResolvedContactPoint; use crate::utils::test_utils::unique_keyspace_name; use crate::{IntoTypedRows, SessionBuilder}; use futures::{StreamExt, TryStreamExt}; diff --git a/scylla/src/connection/connection_pool.rs b/scylla/src/connection/connection_pool.rs index 451913a753..28a5c05958 100644 --- a/scylla/src/connection/connection_pool.rs +++ b/scylla/src/connection/connection_pool.rs @@ -6,12 +6,12 @@ use crate::sharding::{Shard, ShardCount, Sharder, Token}; use crate::transport::errors::QueryError; #[cfg(feature = "cloud")] -use crate::transport::node::resolve_hostname; +use crate::cluster::resolve_hostname; use crate::cluster::metadata::{PeerEndpoint, UntranslatedEndpoint}; +use crate::cluster::NodeAddr; #[cfg(feature = "cloud")] -use crate::transport::node::ResolvedContactPoint; -use crate::transport::NodeAddr; +use crate::cluster::ResolvedContactPoint; use arc_swap::ArcSwap; use futures::{future::RemoteHandle, stream::FuturesUnordered, Future, FutureExt, StreamExt}; diff --git a/scylla/src/session/session.rs b/scylla/src/session/session.rs index 1289a34ed5..0d75fb05d5 100644 --- a/scylla/src/session/session.rs +++ b/scylla/src/session/session.rs @@ -29,7 +29,10 @@ use tokio::time::timeout; use tracing::{debug, trace, trace_span, Instrument}; use uuid::Uuid; +#[cfg(feature = "cloud")] +use crate::cluster::CloudEndpoint; use crate::cluster::{Cluster, ClusterData, ClusterNeatDebug}; +use crate::cluster::{KnownNode, Node, NodeRef}; use crate::connection::PoolConfig; use crate::connection::QueryResponse; #[cfg(feature = "ssl")] @@ -56,15 +59,11 @@ use crate::transport::host_filter::HostFilter; use crate::transport::iterator::{PreparedIteratorConfig, RowIterator}; use crate::transport::load_balancing::{self, RoutingInfo}; use crate::transport::metrics::Metrics; -#[cfg(feature = "cloud")] -use crate::transport::node::CloudEndpoint; -use crate::transport::node::Node; use crate::transport::partitioner::PartitionerName; use crate::transport::query_result::QueryResult; use crate::transport::retry_policy::{QueryInfo, RetryDecision, RetrySession}; use crate::transport::speculative_execution; use crate::transport::Compression; -use crate::transport::{KnownNode, NodeRef}; use crate::{ batch::{Batch, BatchStatement}, statement::StatementConfig, @@ -398,7 +397,7 @@ impl Session { /// # use std::error::Error; /// # async fn check_only_compiles() -> Result<(), Box> { /// use scylla::{Session, SessionConfig}; - /// use scylla::transport::KnownNode; + /// use scylla::cluster::KnownNode; /// /// let mut config = SessionConfig::new(); /// config.known_nodes.push(KnownNode::Hostname("127.0.0.1:9042".to_string())); diff --git a/scylla/src/session/session_builder.rs b/scylla/src/session/session_builder.rs index 9d9f4cf764..b334a66737 100644 --- a/scylla/src/session/session_builder.rs +++ b/scylla/src/session/session_builder.rs @@ -949,8 +949,8 @@ mod tests { use scylla_cql::Consistency; use super::SessionBuilder; + use crate::cluster::KnownNode; use crate::transport::execution_profile::{defaults, ExecutionProfile}; - use crate::transport::node::KnownNode; use crate::transport::Compression; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::time::Duration; diff --git a/scylla/src/transport/host_filter.rs b/scylla/src/transport/host_filter.rs index 9257678e6d..b224924726 100644 --- a/scylla/src/transport/host_filter.rs +++ b/scylla/src/transport/host_filter.rs @@ -10,6 +10,7 @@ use std::io::Error; use std::net::{SocketAddr, ToSocketAddrs}; use crate::cluster::metadata::Peer; +use crate::cluster::NodeAddr; /// The `HostFilter` trait. pub trait HostFilter: Send + Sync { @@ -55,11 +56,11 @@ impl AllowListHostFilter { impl HostFilter for AllowListHostFilter { fn accept(&self, peer: &Peer) -> bool { match peer.address { - super::NodeAddr::Translatable(addr) => self.allowed.contains(&addr), + NodeAddr::Translatable(addr) => self.allowed.contains(&addr), // If the address is Untranslatable, then the node either was originally // an ContactPoint, or a Translatable node for which the host filter // returned true. - super::NodeAddr::Untranslatable(_) => true, + NodeAddr::Untranslatable(_) => true, } } } diff --git a/scylla/src/transport/iterator.rs b/scylla/src/transport/iterator.rs index fd33472e7e..37e5f22114 100644 --- a/scylla/src/transport/iterator.rs +++ b/scylla/src/transport/iterator.rs @@ -23,6 +23,7 @@ use crate::cql_to_rust::{FromRow, FromRowError}; use crate::session::RequestSpan; use crate::cluster::ClusterData; +use crate::cluster::{Node, NodeRef}; use crate::connection::{Connection, NonErrorQueryResponse, QueryResponse}; use crate::frame::{ response::{ @@ -37,7 +38,6 @@ use crate::statement::{prepared_statement::PreparedStatement, query::Query}; use crate::transport::load_balancing::{self, RoutingInfo}; use crate::transport::metrics::Metrics; use crate::transport::retry_policy::{QueryInfo, RetryDecision, RetrySession}; -use crate::transport::{Node, NodeRef}; use crate::utils::unzip_option; use tracing::{trace, trace_span, warn, Instrument}; use uuid::Uuid; diff --git a/scylla/src/transport/load_balancing/default.rs b/scylla/src/transport/load_balancing/default.rs index 3373f91ebc..ca3e755f76 100644 --- a/scylla/src/transport/load_balancing/default.rs +++ b/scylla/src/transport/load_balancing/default.rs @@ -4,8 +4,7 @@ pub use self::latency_awareness::LatencyAwarenessBuilder; use super::{FallbackPlan, LoadBalancingPolicy, NodeRef, RoutingInfo}; use crate::cluster::ClusterData; use crate::{ - cluster::locator::ReplicaSet, cluster::metadata::Strategy, sharding::Token, - transport::node::Node, + cluster::locator::ReplicaSet, cluster::metadata::Strategy, cluster::Node, sharding::Token, }; use itertools::{Either, Itertools}; use rand::{prelude::SliceRandom, thread_rng, Rng}; @@ -2134,7 +2133,7 @@ mod latency_awareness { use tracing::{instrument::WithSubscriber, trace}; use uuid::Uuid; - use crate::{load_balancing::NodeRef, transport::node::Node}; + use crate::{cluster::Node, load_balancing::NodeRef}; use std::{ collections::HashMap, ops::Deref, @@ -2720,14 +2719,13 @@ mod latency_awareness { locator::test::{ id_to_invalid_addr, A, B, C, D, E, F, G, KEYSPACE_NTS_RF_2, KEYSPACE_NTS_RF_3, }, - ClusterData, + ClusterData, NodeAddr, }, load_balancing::{ default::tests::test_default_policy_with_given_cluster_and_routing_info, RoutingInfo, }, sharding::Token, - transport::NodeAddr, ExecutionProfile, }; use crate::{ diff --git a/scylla/src/transport/load_balancing/mod.rs b/scylla/src/transport/load_balancing/mod.rs index 4e76f0b1d4..247ea5f640 100644 --- a/scylla/src/transport/load_balancing/mod.rs +++ b/scylla/src/transport/load_balancing/mod.rs @@ -2,8 +2,7 @@ //! `Session` can use any load balancing policy which implements the `LoadBalancingPolicy` trait\ //! See [the book](https://rust-driver.docs.scylladb.com/stable/load-balancing/load-balancing.html) for more information -use super::NodeRef; -use crate::cluster::ClusterData; +use crate::cluster::{ClusterData, NodeRef}; use crate::sharding::Token; use scylla_cql::{errors::QueryError, frame::types}; diff --git a/scylla/src/transport/load_balancing/plan.rs b/scylla/src/transport/load_balancing/plan.rs index d5fe1b384f..83c797178f 100644 --- a/scylla/src/transport/load_balancing/plan.rs +++ b/scylla/src/transport/load_balancing/plan.rs @@ -106,7 +106,7 @@ mod tests { use std::{net::SocketAddr, str::FromStr, sync::Arc}; use crate::cluster::locator::test::{create_locator, mock_metadata_for_token_aware_tests}; - use crate::transport::{Node, NodeAddr}; + use crate::cluster::{Node, NodeAddr}; use super::*; diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs index 3f11058391..dc2064923b 100644 --- a/scylla/src/transport/mod.rs +++ b/scylla/src/transport/mod.rs @@ -4,7 +4,6 @@ pub mod host_filter; pub mod iterator; pub mod load_balancing; pub(crate) mod metrics; -pub(crate) mod node; pub mod partitioner; pub mod query_result; pub mod retry_policy; @@ -23,5 +22,3 @@ mod cql_collections_test; mod cql_types_test; #[cfg(test)] mod cql_value_test; - -pub use node::{KnownNode, Node, NodeAddr, NodeRef}; diff --git a/scylla/tests/integration/consistency.rs b/scylla/tests/integration/consistency.rs index 4ffb34264e..8f3ec10e2a 100644 --- a/scylla/tests/integration/consistency.rs +++ b/scylla/tests/integration/consistency.rs @@ -374,7 +374,7 @@ impl LoadBalancingPolicy for RoutingInfoReportingWrapper { &'a self, query: &'a RoutingInfo, cluster: &'a scylla::cluster::ClusterData, - ) -> Option> { + ) -> Option> { self.routing_info_tx .send(OwnedRoutingInfo::from(query.clone())) .unwrap(); diff --git a/scylla/tests/integration/execution_profiles.rs b/scylla/tests/integration/execution_profiles.rs index 8e49cba549..50d1a029eb 100644 --- a/scylla/tests/integration/execution_profiles.rs +++ b/scylla/tests/integration/execution_profiles.rs @@ -5,9 +5,9 @@ use crate::utils::test_with_3_node_cluster; use assert_matches::assert_matches; use scylla::batch::BatchStatement; use scylla::batch::{Batch, BatchType}; +use scylla::cluster::NodeRef; use scylla::query::Query; use scylla::statement::SerialConsistency; -use scylla::transport::NodeRef; use scylla::{ cluster::ClusterData, load_balancing::{LoadBalancingPolicy, RoutingInfo}, diff --git a/scylla/tests/integration/utils.rs b/scylla/tests/integration/utils.rs index 1baff486a3..5baaba0327 100644 --- a/scylla/tests/integration/utils.rs +++ b/scylla/tests/integration/utils.rs @@ -23,7 +23,7 @@ impl LoadBalancingPolicy for FixedOrderLoadBalancer { &'a self, _info: &'a scylla::load_balancing::RoutingInfo, cluster: &'a scylla::cluster::ClusterData, - ) -> Option> { + ) -> Option> { cluster .get_nodes_info() .iter() @@ -48,7 +48,7 @@ impl LoadBalancingPolicy for FixedOrderLoadBalancer { &self, _: &scylla::load_balancing::RoutingInfo, _: std::time::Duration, - _: scylla::transport::NodeRef<'_>, + _: scylla::cluster::NodeRef<'_>, ) { } @@ -56,7 +56,7 @@ impl LoadBalancingPolicy for FixedOrderLoadBalancer { &self, _: &scylla::load_balancing::RoutingInfo, _: std::time::Duration, - _: scylla::transport::NodeRef<'_>, + _: scylla::cluster::NodeRef<'_>, _: &scylla_cql::errors::QueryError, ) { } From f673b447d560013e15976a227d6d81f4009b8796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Wed, 30 Aug 2023 15:24:52 +0200 Subject: [PATCH 12/43] move host_filter.rs to new cluster module --- scylla/src/cluster/cluster.rs | 2 +- scylla/src/{transport => cluster}/host_filter.rs | 0 scylla/src/cluster/metadata.rs | 2 +- scylla/src/cluster/mod.rs | 1 + scylla/src/lib.rs | 2 +- scylla/src/session/session.rs | 2 +- scylla/src/session/session_builder.rs | 6 +++--- scylla/src/transport/mod.rs | 1 - 8 files changed, 8 insertions(+), 8 deletions(-) rename scylla/src/{transport => cluster}/host_filter.rs (100%) diff --git a/scylla/src/cluster/cluster.rs b/scylla/src/cluster/cluster.rs index 07c82b5947..8d9aaca899 100644 --- a/scylla/src/cluster/cluster.rs +++ b/scylla/src/cluster/cluster.rs @@ -1,3 +1,4 @@ +use crate::cluster::host_filter::HostFilter; use crate::cluster::Node; use crate::connection::{Connection, PoolConfig, VerifiedKeyspaceName}; /// Cluster manages up to date information and connections to database nodes @@ -5,7 +6,6 @@ use crate::frame::response::event::{Event, StatusChangeEvent}; use crate::frame::value::ValueList; use crate::prepared_statement::TokenCalculationError; use crate::sharding::Token; -use crate::transport::host_filter::HostFilter; use crate::transport::{errors::QueryError, partitioner::PartitionerName}; use arc_swap::ArcSwap; diff --git a/scylla/src/transport/host_filter.rs b/scylla/src/cluster/host_filter.rs similarity index 100% rename from scylla/src/transport/host_filter.rs rename to scylla/src/cluster/host_filter.rs diff --git a/scylla/src/cluster/metadata.rs b/scylla/src/cluster/metadata.rs index f34b3b424f..b2cc065d3a 100644 --- a/scylla/src/cluster/metadata.rs +++ b/scylla/src/cluster/metadata.rs @@ -1,10 +1,10 @@ +use crate::cluster::host_filter::HostFilter; use crate::cluster::resolve_contact_points; use crate::connection::{Connection, ConnectionConfig, NodeConnectionPool, PoolConfig, PoolSize}; use crate::frame::response::event::Event; use crate::sharding::Token; use crate::statement::query::Query; use crate::transport::errors::{DbError, QueryError}; -use crate::transport::host_filter::HostFilter; use crate::utils::parse::{ParseErrorCause, ParseResult, ParserState}; use futures::future::{self, FutureExt}; diff --git a/scylla/src/cluster/mod.rs b/scylla/src/cluster/mod.rs index 35b35147b2..13aff71ebf 100644 --- a/scylla/src/cluster/mod.rs +++ b/scylla/src/cluster/mod.rs @@ -1,4 +1,5 @@ mod cluster; +pub mod host_filter; pub mod locator; pub mod metadata; mod node; diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index 4324aa5f35..741f88f141 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -137,8 +137,8 @@ pub use transport::query_result::QueryResult; #[cfg(feature = "cloud")] pub use session::CloudSessionBuilder; +pub use cluster::host_filter; pub use transport::execution_profile; -pub use transport::host_filter; pub use transport::load_balancing; pub use transport::retry_policy; pub use transport::speculative_execution; diff --git a/scylla/src/session/session.rs b/scylla/src/session/session.rs index 0d75fb05d5..fd37dc559f 100644 --- a/scylla/src/session/session.rs +++ b/scylla/src/session/session.rs @@ -29,6 +29,7 @@ use tokio::time::timeout; use tracing::{debug, trace, trace_span, Instrument}; use uuid::Uuid; +use crate::cluster::host_filter::HostFilter; #[cfg(feature = "cloud")] use crate::cluster::CloudEndpoint; use crate::cluster::{Cluster, ClusterData, ClusterNeatDebug}; @@ -55,7 +56,6 @@ use crate::transport::errors::{NewSessionError, QueryError}; use crate::transport::execution_profile::{ ExecutionProfile, ExecutionProfileHandle, ExecutionProfileInner, }; -use crate::transport::host_filter::HostFilter; use crate::transport::iterator::{PreparedIteratorConfig, RowIterator}; use crate::transport::load_balancing::{self, RoutingInfo}; use crate::transport::metrics::Metrics; diff --git a/scylla/src/session/session_builder.rs b/scylla/src/session/session_builder.rs index b334a66737..411893f8ed 100644 --- a/scylla/src/session/session_builder.rs +++ b/scylla/src/session/session_builder.rs @@ -11,8 +11,8 @@ use crate::cloud::{CloudConfig, CloudConfigError}; #[cfg(feature = "cloud")] use crate::ExecutionProfile; +use crate::cluster::host_filter::HostFilter; use crate::statement::Consistency; -use crate::transport::host_filter::HostFilter; use std::borrow::Borrow; use std::marker::PhantomData; use std::net::SocketAddr; @@ -761,7 +761,7 @@ impl GenericSessionBuilder { /// should be opened to the node or not. The driver will also avoid /// those nodes when re-establishing the control connection. /// - /// See the [host filter](crate::transport::host_filter) module for a list + /// See the [host filter](crate::cluster::host_filter) module for a list /// of pre-defined filters. It is also possible to provide a custom filter /// by implementing the HostFilter trait. /// @@ -772,7 +772,7 @@ impl GenericSessionBuilder { /// # use std::sync::Arc; /// # use scylla::{Session, SessionBuilder}; /// # use scylla::session::{AddressTranslator, TranslationError}; - /// # use scylla::transport::host_filter::DcHostFilter; + /// # use scylla::cluster::host_filter::DcHostFilter; /// /// # async fn example() -> Result<(), Box> { /// // The session will only connect to nodes from "my-local-dc" diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs index dc2064923b..ca78049797 100644 --- a/scylla/src/transport/mod.rs +++ b/scylla/src/transport/mod.rs @@ -1,6 +1,5 @@ pub mod downgrading_consistency_retry_policy; pub mod execution_profile; -pub mod host_filter; pub mod iterator; pub mod load_balancing; pub(crate) mod metrics; From f2b63dbfa11c64046c398c23d652478e7d9f0db2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Wed, 30 Aug 2023 15:32:53 +0200 Subject: [PATCH 13/43] move load_balancing to new execution mod --- scylla/src/{transport => execution}/load_balancing/default.rs | 0 scylla/src/{transport => execution}/load_balancing/mod.rs | 0 scylla/src/{transport => execution}/load_balancing/plan.rs | 0 scylla/src/execution/mod.rs | 1 + scylla/src/lib.rs | 3 ++- scylla/src/session/session.rs | 2 +- scylla/src/transport/iterator.rs | 2 +- scylla/src/transport/mod.rs | 1 - 8 files changed, 5 insertions(+), 4 deletions(-) rename scylla/src/{transport => execution}/load_balancing/default.rs (100%) rename scylla/src/{transport => execution}/load_balancing/mod.rs (100%) rename scylla/src/{transport => execution}/load_balancing/plan.rs (100%) create mode 100644 scylla/src/execution/mod.rs diff --git a/scylla/src/transport/load_balancing/default.rs b/scylla/src/execution/load_balancing/default.rs similarity index 100% rename from scylla/src/transport/load_balancing/default.rs rename to scylla/src/execution/load_balancing/default.rs diff --git a/scylla/src/transport/load_balancing/mod.rs b/scylla/src/execution/load_balancing/mod.rs similarity index 100% rename from scylla/src/transport/load_balancing/mod.rs rename to scylla/src/execution/load_balancing/mod.rs diff --git a/scylla/src/transport/load_balancing/plan.rs b/scylla/src/execution/load_balancing/plan.rs similarity index 100% rename from scylla/src/transport/load_balancing/plan.rs rename to scylla/src/execution/load_balancing/plan.rs diff --git a/scylla/src/execution/mod.rs b/scylla/src/execution/mod.rs new file mode 100644 index 0000000000..21cf8a0002 --- /dev/null +++ b/scylla/src/execution/mod.rs @@ -0,0 +1 @@ +pub mod load_balancing; diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index 741f88f141..7e26a5fcd5 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -107,6 +107,7 @@ pub mod cloud; pub mod cluster; pub mod connection; +pub mod execution; pub mod history; pub mod session; pub mod sharding; @@ -138,8 +139,8 @@ pub use transport::query_result::QueryResult; pub use session::CloudSessionBuilder; pub use cluster::host_filter; +pub use execution::load_balancing; pub use transport::execution_profile; -pub use transport::load_balancing; pub use transport::retry_policy; pub use transport::speculative_execution; diff --git a/scylla/src/session/session.rs b/scylla/src/session/session.rs index fd37dc559f..cd280779ea 100644 --- a/scylla/src/session/session.rs +++ b/scylla/src/session/session.rs @@ -42,6 +42,7 @@ use crate::connection::{ AddressTranslator, Connection, ConnectionConfig, NonErrorQueryResponse, VerifiedKeyspaceName, }; use crate::cql_to_rust::FromRow; +use crate::execution::load_balancing::{self, RoutingInfo}; use crate::frame::response::cql_to_rust::FromRowError; use crate::frame::response::result; use crate::frame::value::{ @@ -57,7 +58,6 @@ use crate::transport::execution_profile::{ ExecutionProfile, ExecutionProfileHandle, ExecutionProfileInner, }; use crate::transport::iterator::{PreparedIteratorConfig, RowIterator}; -use crate::transport::load_balancing::{self, RoutingInfo}; use crate::transport::metrics::Metrics; use crate::transport::partitioner::PartitionerName; use crate::transport::query_result::QueryResult; diff --git a/scylla/src/transport/iterator.rs b/scylla/src/transport/iterator.rs index 37e5f22114..6091280db2 100644 --- a/scylla/src/transport/iterator.rs +++ b/scylla/src/transport/iterator.rs @@ -25,6 +25,7 @@ use crate::session::RequestSpan; use crate::cluster::ClusterData; use crate::cluster::{Node, NodeRef}; use crate::connection::{Connection, NonErrorQueryResponse, QueryResponse}; +use crate::execution::load_balancing::{self, RoutingInfo}; use crate::frame::{ response::{ result, @@ -35,7 +36,6 @@ use crate::frame::{ use crate::history::{self, HistoryListener}; use crate::statement::Consistency; use crate::statement::{prepared_statement::PreparedStatement, query::Query}; -use crate::transport::load_balancing::{self, RoutingInfo}; use crate::transport::metrics::Metrics; use crate::transport::retry_policy::{QueryInfo, RetryDecision, RetrySession}; use crate::utils::unzip_option; diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs index ca78049797..badf5f4402 100644 --- a/scylla/src/transport/mod.rs +++ b/scylla/src/transport/mod.rs @@ -1,7 +1,6 @@ pub mod downgrading_consistency_retry_policy; pub mod execution_profile; pub mod iterator; -pub mod load_balancing; pub(crate) mod metrics; pub mod partitioner; pub mod query_result; From 34c765fea6bc353d20d39415a35d66bb0ad16e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 09:56:21 +0200 Subject: [PATCH 14/43] move execution_profile.rs to new execution mod --- .../speculative-execution/percentile.md | 2 +- docs/source/speculative-execution/simple.md | 2 +- examples/custom_load_balancing_policy.rs | 2 +- examples/execution_profile.rs | 2 +- examples/speculative-execution.rs | 4 +-- .../execution_profile.rs | 30 +++++++++---------- scylla/src/execution/mod.rs | 7 +++++ scylla/src/lib.rs | 3 +- scylla/src/session/session.rs | 4 +-- scylla/src/session/session_builder.rs | 4 +-- scylla/src/statement/batch.rs | 2 +- scylla/src/statement/mod.rs | 2 +- scylla/src/statement/prepared_statement.rs | 2 +- scylla/src/statement/query.rs | 2 +- scylla/src/transport/iterator.rs | 2 +- scylla/src/transport/mod.rs | 2 -- scylla/tests/integration/consistency.rs | 2 +- 17 files changed, 38 insertions(+), 36 deletions(-) rename scylla/src/{transport => execution}/execution_profile.rs (95%) diff --git a/docs/source/speculative-execution/percentile.md b/docs/source/speculative-execution/percentile.md index 243429d97f..9082b50f11 100644 --- a/docs/source/speculative-execution/percentile.md +++ b/docs/source/speculative-execution/percentile.md @@ -17,7 +17,7 @@ use scylla::{ Session, SessionBuilder, speculative_execution::PercentileSpeculativeExecutionPolicy, - transport::execution_profile::ExecutionProfile, + execution::ExecutionProfile, }; let policy = PercentileSpeculativeExecutionPolicy { diff --git a/docs/source/speculative-execution/simple.md b/docs/source/speculative-execution/simple.md index ad7720e664..ce2bec7b9b 100644 --- a/docs/source/speculative-execution/simple.md +++ b/docs/source/speculative-execution/simple.md @@ -17,7 +17,7 @@ use scylla::{ Session, SessionBuilder, speculative_execution::SimpleSpeculativeExecutionPolicy, - transport::execution_profile::ExecutionProfile, + execution::ExecutionProfile, }; let policy = SimpleSpeculativeExecutionPolicy { diff --git a/examples/custom_load_balancing_policy.rs b/examples/custom_load_balancing_policy.rs index 5582ae2a5c..2e33cd106d 100644 --- a/examples/custom_load_balancing_policy.rs +++ b/examples/custom_load_balancing_policy.rs @@ -1,8 +1,8 @@ use anyhow::Result; use scylla::{ cluster::ClusterData, + execution::ExecutionProfile, load_balancing::{LoadBalancingPolicy, RoutingInfo}, - transport::ExecutionProfile, Session, SessionBuilder, }; use std::{env, sync::Arc}; diff --git a/examples/execution_profile.rs b/examples/execution_profile.rs index 24843f76ed..b61b69d0a7 100644 --- a/examples/execution_profile.rs +++ b/examples/execution_profile.rs @@ -1,11 +1,11 @@ use anyhow::Result; +use scylla::execution::ExecutionProfile; use scylla::load_balancing; use scylla::query::Query; use scylla::retry_policy::{DefaultRetryPolicy, FallthroughRetryPolicy}; use scylla::session::Session; use scylla::speculative_execution::PercentileSpeculativeExecutionPolicy; use scylla::statement::{Consistency, SerialConsistency}; -use scylla::transport::ExecutionProfile; use scylla::{SessionBuilder, SessionConfig}; use std::env; use std::sync::Arc; diff --git a/examples/speculative-execution.rs b/examples/speculative-execution.rs index 4f0b3445f9..c7a35743fa 100644 --- a/examples/speculative-execution.rs +++ b/examples/speculative-execution.rs @@ -1,6 +1,6 @@ use scylla::{ - speculative_execution::PercentileSpeculativeExecutionPolicy, - transport::execution_profile::ExecutionProfile, Session, SessionBuilder, + execution::ExecutionProfile, speculative_execution::PercentileSpeculativeExecutionPolicy, + Session, SessionBuilder, }; use anyhow::Result; diff --git a/scylla/src/transport/execution_profile.rs b/scylla/src/execution/execution_profile.rs similarity index 95% rename from scylla/src/transport/execution_profile.rs rename to scylla/src/execution/execution_profile.rs index 245beffab9..aa3dbc9778 100644 --- a/scylla/src/transport/execution_profile.rs +++ b/scylla/src/execution/execution_profile.rs @@ -18,7 +18,7 @@ //! # async fn check_only_compiles() -> Result<(), Box> { //! use scylla::{Session, SessionBuilder}; //! use scylla::statement::Consistency; -//! use scylla::transport::ExecutionProfile; +//! use scylla::execution::ExecutionProfile; //! //! let profile = ExecutionProfile::builder() //! .consistency(Consistency::LocalOne) @@ -44,7 +44,7 @@ //! # async fn check_only_compiles() -> Result<(), Box> { //! use scylla::query::Query; //! use scylla::statement::Consistency; -//! use scylla::transport::ExecutionProfile; +//! use scylla::execution::ExecutionProfile; //! use std::time::Duration; //! //! let profile = ExecutionProfile::builder() @@ -71,7 +71,7 @@ //! # use std::error::Error; //! # async fn check_only_compiles() -> Result<(), Box> { //! use scylla::statement::Consistency; -//! use scylla::transport::ExecutionProfile; +//! use scylla::execution::ExecutionProfile; //! use std::time::Duration; //! //! let base_profile = ExecutionProfile::builder() @@ -112,7 +112,7 @@ //! use scylla::{Session, SessionBuilder}; //! use scylla::query::Query; //! use scylla::statement::Consistency; -//! use scylla::transport::ExecutionProfile; +//! use scylla::execution::ExecutionProfile; //! //! let profile1 = ExecutionProfile::builder() //! .consistency(Consistency::One) @@ -171,10 +171,10 @@ use crate::{ }; pub(crate) mod defaults { + use crate::execution::ExecutionProfileInner; use crate::load_balancing::{self, LoadBalancingPolicy}; use crate::retry_policy::{DefaultRetryPolicy, RetryPolicy}; use crate::speculative_execution::SpeculativeExecutionPolicy; - use crate::transport::execution_profile::ExecutionProfileInner; use scylla_cql::frame::types::SerialConsistency; use scylla_cql::Consistency; use std::sync::Arc; @@ -216,7 +216,7 @@ pub(crate) mod defaults { /// # Example /// /// ``` -/// # use scylla::transport::{ExecutionProfile, retry_policy::FallthroughRetryPolicy}; +/// # use scylla::execution::{ExecutionProfile, retries::FallthroughRetryPolicy}; /// # use scylla::statement::Consistency; /// # fn example() -> Result<(), Box> { /// let profile: ExecutionProfile = ExecutionProfile::builder() @@ -242,7 +242,7 @@ impl ExecutionProfileBuilder { /// /// # Example /// ``` - /// # use scylla::transport::ExecutionProfile; + /// # use scylla::execution::ExecutionProfile; /// # use std::time::Duration; /// # fn example() -> Result<(), Box> { /// let profile: ExecutionProfile = ExecutionProfile::builder() @@ -276,8 +276,8 @@ impl ExecutionProfileBuilder { /// /// # Example /// ``` - /// # use scylla::transport::ExecutionProfile; - /// # use scylla::transport::load_balancing::DefaultPolicy; + /// # use scylla::execution::ExecutionProfile; + /// # use scylla::execution::load_balancing::DefaultPolicy; /// # use std::sync::Arc; /// # fn example() -> Result<(), Box> { /// let profile: ExecutionProfile = ExecutionProfile::builder() @@ -300,8 +300,8 @@ impl ExecutionProfileBuilder { /// /// # Example /// ``` - /// use scylla::transport::retry_policy::DefaultRetryPolicy; - /// # use scylla::transport::ExecutionProfile; + /// use scylla::execution::retries::DefaultRetryPolicy; + /// # use scylla::execution::ExecutionProfile; /// # fn example() -> Result<(), Box> { /// let profile: ExecutionProfile = ExecutionProfile::builder() /// .retry_policy(Box::new(DefaultRetryPolicy::new())) @@ -323,8 +323,8 @@ impl ExecutionProfileBuilder { /// # fn check_only_compiles() -> Result<(), Box> { /// use std::{sync::Arc, time::Duration}; /// use scylla::{ - /// transport::ExecutionProfile, - /// transport::speculative_execution::SimpleSpeculativeExecutionPolicy, + /// execution::ExecutionProfile, + /// execution::speculative_execution::SimpleSpeculativeExecutionPolicy, /// }; /// /// let policy = SimpleSpeculativeExecutionPolicy { @@ -350,8 +350,8 @@ impl ExecutionProfileBuilder { /// /// # Example /// ``` - /// use scylla::transport::retry_policy::DefaultRetryPolicy; - /// # use scylla::transport::ExecutionProfile; + /// use scylla::execution::retries::DefaultRetryPolicy; + /// # use scylla::execution::ExecutionProfile; /// # fn example() -> Result<(), Box> { /// let profile: ExecutionProfile = ExecutionProfile::builder() /// .retry_policy(Box::new(DefaultRetryPolicy::new())) diff --git a/scylla/src/execution/mod.rs b/scylla/src/execution/mod.rs index 21cf8a0002..13dac1eb70 100644 --- a/scylla/src/execution/mod.rs +++ b/scylla/src/execution/mod.rs @@ -1 +1,8 @@ +mod execution_profile; pub mod load_balancing; + +pub(crate) use execution_profile::ExecutionProfileInner; +pub use execution_profile::{ExecutionProfile, ExecutionProfileBuilder, ExecutionProfileHandle}; + +#[cfg(test)] +pub(crate) use execution_profile::defaults; diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index 7e26a5fcd5..6695e20899 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -129,10 +129,10 @@ pub use statement::query; pub use frame::response::cql_to_rust; pub use frame::response::cql_to_rust::FromRow; +pub use execution::ExecutionProfile; pub use session::CachingSession; pub use session::SessionBuilder; pub use session::{IntoTypedRows, Session, SessionConfig}; -pub use transport::execution_profile::ExecutionProfile; pub use transport::query_result::QueryResult; #[cfg(feature = "cloud")] @@ -140,7 +140,6 @@ pub use session::CloudSessionBuilder; pub use cluster::host_filter; pub use execution::load_balancing; -pub use transport::execution_profile; pub use transport::retry_policy; pub use transport::speculative_execution; diff --git a/scylla/src/session/session.rs b/scylla/src/session/session.rs index cd280779ea..e4a1f368da 100644 --- a/scylla/src/session/session.rs +++ b/scylla/src/session/session.rs @@ -43,6 +43,7 @@ use crate::connection::{ }; use crate::cql_to_rust::FromRow; use crate::execution::load_balancing::{self, RoutingInfo}; +use crate::execution::{ExecutionProfile, ExecutionProfileHandle, ExecutionProfileInner}; use crate::frame::response::cql_to_rust::FromRowError; use crate::frame::response::result; use crate::frame::value::{ @@ -54,9 +55,6 @@ use crate::sharding::Token; use crate::statement::Consistency; use crate::tracing::{TracingEvent, TracingInfo}; use crate::transport::errors::{NewSessionError, QueryError}; -use crate::transport::execution_profile::{ - ExecutionProfile, ExecutionProfileHandle, ExecutionProfileInner, -}; use crate::transport::iterator::{PreparedIteratorConfig, RowIterator}; use crate::transport::metrics::Metrics; use crate::transport::partitioner::PartitionerName; diff --git a/scylla/src/session/session_builder.rs b/scylla/src/session/session_builder.rs index 411893f8ed..ef0affe7a4 100644 --- a/scylla/src/session/session_builder.rs +++ b/scylla/src/session/session_builder.rs @@ -1,9 +1,9 @@ //! SessionBuilder provides an easy way to create new Sessions use crate::connection::{AddressTranslator, PoolSize}; +use crate::execution::ExecutionProfileHandle; use crate::session::{Session, SessionConfig}; use crate::transport::errors::NewSessionError; -use crate::transport::execution_profile::ExecutionProfileHandle; use crate::transport::Compression; #[cfg(feature = "cloud")] @@ -950,7 +950,7 @@ mod tests { use super::SessionBuilder; use crate::cluster::KnownNode; - use crate::transport::execution_profile::{defaults, ExecutionProfile}; + use crate::execution::{defaults, ExecutionProfile}; use crate::transport::Compression; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::time::Duration; diff --git a/scylla/src/statement/batch.rs b/scylla/src/statement/batch.rs index 58d8ce411b..cb739a400e 100644 --- a/scylla/src/statement/batch.rs +++ b/scylla/src/statement/batch.rs @@ -1,10 +1,10 @@ use std::borrow::Cow; use std::sync::Arc; +use crate::execution::ExecutionProfileHandle; use crate::history::HistoryListener; use crate::retry_policy::RetryPolicy; use crate::statement::{prepared_statement::PreparedStatement, query::Query}; -use crate::transport::execution_profile::ExecutionProfileHandle; use super::StatementConfig; use super::{Consistency, SerialConsistency}; diff --git a/scylla/src/statement/mod.rs b/scylla/src/statement/mod.rs index a8d034615d..8dd418d3c0 100644 --- a/scylla/src/statement/mod.rs +++ b/scylla/src/statement/mod.rs @@ -1,6 +1,6 @@ use std::{sync::Arc, time::Duration}; -use crate::transport::execution_profile::ExecutionProfileHandle; +use crate::execution::ExecutionProfileHandle; use crate::{history::HistoryListener, retry_policy::RetryPolicy}; pub mod batch; diff --git a/scylla/src/statement/prepared_statement.rs b/scylla/src/statement/prepared_statement.rs index 88a100284d..9069be19d6 100644 --- a/scylla/src/statement/prepared_statement.rs +++ b/scylla/src/statement/prepared_statement.rs @@ -10,13 +10,13 @@ use uuid::Uuid; use scylla_cql::frame::response::result::ColumnSpec; use super::StatementConfig; +use crate::execution::ExecutionProfileHandle; use crate::frame::response::result::PreparedMetadata; use crate::frame::types::{Consistency, SerialConsistency}; use crate::frame::value::SerializedValues; use crate::history::HistoryListener; use crate::retry_policy::RetryPolicy; use crate::sharding::Token; -use crate::transport::execution_profile::ExecutionProfileHandle; use crate::transport::partitioner::{Partitioner, PartitionerHasher, PartitionerName}; /// Represents a statement prepared on the server. diff --git a/scylla/src/statement/query.rs b/scylla/src/statement/query.rs index 956b645833..188aaae801 100644 --- a/scylla/src/statement/query.rs +++ b/scylla/src/statement/query.rs @@ -1,8 +1,8 @@ use super::StatementConfig; +use crate::execution::ExecutionProfileHandle; use crate::frame::types::{Consistency, SerialConsistency}; use crate::history::HistoryListener; use crate::retry_policy::RetryPolicy; -use crate::transport::execution_profile::ExecutionProfileHandle; use std::sync::Arc; use std::time::Duration; diff --git a/scylla/src/transport/iterator.rs b/scylla/src/transport/iterator.rs index 6091280db2..4cd256b5ee 100644 --- a/scylla/src/transport/iterator.rs +++ b/scylla/src/transport/iterator.rs @@ -18,8 +18,8 @@ use tokio::sync::mpsc; use tracing::instrument::WithSubscriber; use super::errors::QueryError; -use super::execution_profile::ExecutionProfileInner; use crate::cql_to_rust::{FromRow, FromRowError}; +use crate::execution::ExecutionProfileInner; use crate::session::RequestSpan; use crate::cluster::ClusterData; diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs index badf5f4402..8e82581846 100644 --- a/scylla/src/transport/mod.rs +++ b/scylla/src/transport/mod.rs @@ -1,5 +1,4 @@ pub mod downgrading_consistency_retry_policy; -pub mod execution_profile; pub mod iterator; pub(crate) mod metrics; pub mod partitioner; @@ -8,7 +7,6 @@ pub mod retry_policy; pub mod speculative_execution; pub use crate::frame::{Authenticator, Compression}; -pub use execution_profile::ExecutionProfile; pub use scylla_cql::errors; #[cfg(test)] diff --git a/scylla/tests/integration/consistency.rs b/scylla/tests/integration/consistency.rs index 8f3ec10e2a..947dc7e0bb 100644 --- a/scylla/tests/integration/consistency.rs +++ b/scylla/tests/integration/consistency.rs @@ -1,6 +1,6 @@ use crate::utils::test_with_3_node_cluster; -use scylla::execution_profile::{ExecutionProfileBuilder, ExecutionProfileHandle}; +use scylla::execution::{ExecutionProfileBuilder, ExecutionProfileHandle}; use scylla::load_balancing::{DefaultPolicy, LoadBalancingPolicy, RoutingInfo}; use scylla::prepared_statement::PreparedStatement; use scylla::retry_policy::FallthroughRetryPolicy; From 5607cbed759567bf4e9d2981dd55c928a1a01737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 09:56:56 +0200 Subject: [PATCH 15/43] unpub fns in execution_profile.rs (private anyway) --- scylla/src/execution/execution_profile.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scylla/src/execution/execution_profile.rs b/scylla/src/execution/execution_profile.rs index aa3dbc9778..dc99ad20c9 100644 --- a/scylla/src/execution/execution_profile.rs +++ b/scylla/src/execution/execution_profile.rs @@ -179,22 +179,22 @@ pub(crate) mod defaults { use scylla_cql::Consistency; use std::sync::Arc; use std::time::Duration; - pub fn consistency() -> Consistency { + pub(crate) fn consistency() -> Consistency { Consistency::LocalQuorum } - pub fn serial_consistency() -> Option { + pub(crate) fn serial_consistency() -> Option { Some(SerialConsistency::LocalSerial) } - pub fn request_timeout() -> Option { + pub(crate) fn request_timeout() -> Option { Some(Duration::from_secs(30)) } - pub fn load_balancing_policy() -> Arc { + pub(crate) fn load_balancing_policy() -> Arc { Arc::new(load_balancing::DefaultPolicy::default()) } - pub fn retry_policy() -> Box { + pub(crate) fn retry_policy() -> Box { Box::new(DefaultRetryPolicy::new()) } - pub fn speculative_execution_policy() -> Option> { + pub(crate) fn speculative_execution_policy() -> Option> { None } From d27ae2d8207e2d3a6c533d99b525b12b72909611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 09:59:56 +0200 Subject: [PATCH 16/43] move speculative_execution.rs to new execution mod --- scylla/src/execution/mod.rs | 1 + scylla/src/{transport => execution}/speculative_execution.rs | 2 +- scylla/src/lib.rs | 3 +-- scylla/src/session/session.rs | 5 +++-- scylla/src/transport/mod.rs | 1 - 5 files changed, 6 insertions(+), 6 deletions(-) rename scylla/src/{transport => execution}/speculative_execution.rs (98%) diff --git a/scylla/src/execution/mod.rs b/scylla/src/execution/mod.rs index 13dac1eb70..053f42ad6e 100644 --- a/scylla/src/execution/mod.rs +++ b/scylla/src/execution/mod.rs @@ -1,5 +1,6 @@ mod execution_profile; pub mod load_balancing; +pub mod speculative_execution; pub(crate) use execution_profile::ExecutionProfileInner; pub use execution_profile::{ExecutionProfile, ExecutionProfileBuilder, ExecutionProfileHandle}; diff --git a/scylla/src/transport/speculative_execution.rs b/scylla/src/execution/speculative_execution.rs similarity index 98% rename from scylla/src/transport/speculative_execution.rs rename to scylla/src/execution/speculative_execution.rs index 516ba8cd01..e4c9eced9d 100644 --- a/scylla/src/transport/speculative_execution.rs +++ b/scylla/src/execution/speculative_execution.rs @@ -5,7 +5,7 @@ use futures::{ use std::{future::Future, sync::Arc, time::Duration}; use tracing::{trace_span, warn, Instrument}; -use super::{errors::QueryError, metrics::Metrics}; +use crate::transport::{errors::QueryError, metrics::Metrics}; /// Context is passed as an argument to `SpeculativeExecutionPolicy` methods pub struct Context { diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index 6695e20899..232695254f 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -139,8 +139,7 @@ pub use transport::query_result::QueryResult; pub use session::CloudSessionBuilder; pub use cluster::host_filter; -pub use execution::load_balancing; +pub use execution::{load_balancing, speculative_execution}; pub use transport::retry_policy; -pub use transport::speculative_execution; pub use transport::metrics::Metrics; diff --git a/scylla/src/session/session.rs b/scylla/src/session/session.rs index e4a1f368da..401fe3ff4f 100644 --- a/scylla/src/session/session.rs +++ b/scylla/src/session/session.rs @@ -43,7 +43,9 @@ use crate::connection::{ }; use crate::cql_to_rust::FromRow; use crate::execution::load_balancing::{self, RoutingInfo}; -use crate::execution::{ExecutionProfile, ExecutionProfileHandle, ExecutionProfileInner}; +use crate::execution::{ + speculative_execution, ExecutionProfile, ExecutionProfileHandle, ExecutionProfileInner, +}; use crate::frame::response::cql_to_rust::FromRowError; use crate::frame::response::result; use crate::frame::value::{ @@ -60,7 +62,6 @@ use crate::transport::metrics::Metrics; use crate::transport::partitioner::PartitionerName; use crate::transport::query_result::QueryResult; use crate::transport::retry_policy::{QueryInfo, RetryDecision, RetrySession}; -use crate::transport::speculative_execution; use crate::transport::Compression; use crate::{ batch::{Batch, BatchStatement}, diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs index 8e82581846..7a1a7fb7c7 100644 --- a/scylla/src/transport/mod.rs +++ b/scylla/src/transport/mod.rs @@ -4,7 +4,6 @@ pub(crate) mod metrics; pub mod partitioner; pub mod query_result; pub mod retry_policy; -pub mod speculative_execution; pub use crate::frame::{Authenticator, Compression}; pub use scylla_cql::errors; From bbd4751590e97130cf3114999e91dd078a54cf07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 10:11:01 +0200 Subject: [PATCH 17/43] extract retries module into execution mod --- .../execution-profiles/maximal-example.md | 2 +- docs/source/retry-policy/default.md | 6 +- docs/source/retry-policy/fallthrough.md | 6 +- examples/execution_profile.rs | 2 +- scylla/src/execution/execution_profile.rs | 6 +- scylla/src/execution/mod.rs | 1 + .../retries/default_rp.rs} | 85 +------------------ .../retries/downgrading_consistency_rp.rs} | 4 +- .../src/execution/retries/fallthrough_rp.rs | 36 ++++++++ scylla/src/execution/retries/mod.rs | 11 +++ scylla/src/execution/retries/retry_policy.rs | 51 +++++++++++ scylla/src/history.rs | 4 +- scylla/src/lib.rs | 1 - scylla/src/session/session.rs | 2 +- scylla/src/session/session_test.rs | 2 +- scylla/src/statement/batch.rs | 4 +- scylla/src/statement/mod.rs | 2 +- scylla/src/statement/prepared_statement.rs | 4 +- scylla/src/statement/query.rs | 4 +- scylla/src/transport/iterator.rs | 2 +- scylla/src/transport/mod.rs | 2 - scylla/tests/integration/consistency.rs | 2 +- .../tests/integration/execution_profiles.rs | 10 +-- scylla/tests/integration/lwt_optimisation.rs | 2 +- scylla/tests/integration/retries.rs | 2 +- 25 files changed, 133 insertions(+), 120 deletions(-) rename scylla/src/{transport/retry_policy.rs => execution/retries/default_rp.rs} (85%) rename scylla/src/{transport/downgrading_consistency_retry_policy.rs => execution/retries/downgrading_consistency_rp.rs} (99%) create mode 100644 scylla/src/execution/retries/fallthrough_rp.rs create mode 100644 scylla/src/execution/retries/mod.rs create mode 100644 scylla/src/execution/retries/retry_policy.rs diff --git a/docs/source/execution-profiles/maximal-example.md b/docs/source/execution-profiles/maximal-example.md index 8209b926a1..c1212a979b 100644 --- a/docs/source/execution-profiles/maximal-example.md +++ b/docs/source/execution-profiles/maximal-example.md @@ -11,7 +11,7 @@ use scylla::speculative_execution::SimpleSpeculativeExecutionPolicy; use scylla::statement::{Consistency, SerialConsistency}; use scylla::transport::ExecutionProfile; use scylla::transport::load_balancing::DefaultPolicy; -use scylla::transport::retry_policy::FallthroughRetryPolicy; +use scylla::execution::retries::FallthroughRetryPolicy; use std::{sync::Arc, time::Duration}; let profile = ExecutionProfile::builder() diff --git a/docs/source/retry-policy/default.md b/docs/source/retry-policy/default.md index e1f8514ed4..684adc1de6 100644 --- a/docs/source/retry-policy/default.md +++ b/docs/source/retry-policy/default.md @@ -12,7 +12,7 @@ To use in `Session`: # async fn check_only_compiles() -> Result<(), Box> { use scylla::{Session, SessionBuilder}; use scylla::transport::ExecutionProfile; -use scylla::transport::retry_policy::DefaultRetryPolicy; +use scylla::execution::retries::DefaultRetryPolicy; let handle = ExecutionProfile::builder() .retry_policy(Box::new(DefaultRetryPolicy::new())) @@ -37,7 +37,7 @@ To use in a [simple query](../queries/simple.md): # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::query::Query; use scylla::transport::ExecutionProfile; -use scylla::transport::retry_policy::DefaultRetryPolicy; +use scylla::execution::retries::DefaultRetryPolicy; // Create a Query manually and set the retry policy let mut my_query: Query = Query::new("INSERT INTO ks.tab (a) VALUES(?)"); @@ -66,7 +66,7 @@ To use in a [prepared query](../queries/prepared.md): # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::prepared_statement::PreparedStatement; use scylla::transport::ExecutionProfile; -use scylla::transport::retry_policy::DefaultRetryPolicy; +use scylla::execution::retries::DefaultRetryPolicy; // Create PreparedStatement manually and set the retry policy let mut prepared: PreparedStatement = session diff --git a/docs/source/retry-policy/fallthrough.md b/docs/source/retry-policy/fallthrough.md index 0f6ab59388..9b3833be93 100644 --- a/docs/source/retry-policy/fallthrough.md +++ b/docs/source/retry-policy/fallthrough.md @@ -11,7 +11,7 @@ To use in `Session`: # async fn check_only_compiles() -> Result<(), Box> { use scylla::{Session, SessionBuilder}; use scylla::transport::ExecutionProfile; -use scylla::transport::retry_policy::FallthroughRetryPolicy; +use scylla::execution::retries::FallthroughRetryPolicy; let handle = ExecutionProfile::builder() .retry_policy(Box::new(FallthroughRetryPolicy::new())) @@ -35,7 +35,7 @@ To use in a [simple query](../queries/simple.md): # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::query::Query; use scylla::transport::ExecutionProfile; -use scylla::transport::retry_policy::FallthroughRetryPolicy; +use scylla::execution::retries::FallthroughRetryPolicy; let handle = ExecutionProfile::builder() .retry_policy(Box::new(FallthroughRetryPolicy::new())) @@ -61,7 +61,7 @@ To use in a [prepared query](../queries/prepared.md): # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::prepared_statement::PreparedStatement; use scylla::transport::ExecutionProfile; -use scylla::transport::retry_policy::FallthroughRetryPolicy; +use scylla::execution::retries::FallthroughRetryPolicy; let handle = ExecutionProfile::builder() .retry_policy(Box::new(FallthroughRetryPolicy::new())) diff --git a/examples/execution_profile.rs b/examples/execution_profile.rs index b61b69d0a7..3473357f5e 100644 --- a/examples/execution_profile.rs +++ b/examples/execution_profile.rs @@ -1,8 +1,8 @@ use anyhow::Result; +use scylla::execution::retries::{DefaultRetryPolicy, FallthroughRetryPolicy}; use scylla::execution::ExecutionProfile; use scylla::load_balancing; use scylla::query::Query; -use scylla::retry_policy::{DefaultRetryPolicy, FallthroughRetryPolicy}; use scylla::session::Session; use scylla::speculative_execution::PercentileSpeculativeExecutionPolicy; use scylla::statement::{Consistency, SerialConsistency}; diff --git a/scylla/src/execution/execution_profile.rs b/scylla/src/execution/execution_profile.rs index dc99ad20c9..ebe531d7fc 100644 --- a/scylla/src/execution/execution_profile.rs +++ b/scylla/src/execution/execution_profile.rs @@ -166,14 +166,14 @@ use arc_swap::ArcSwap; use scylla_cql::{frame::types::SerialConsistency, Consistency}; use crate::{ - load_balancing::LoadBalancingPolicy, retry_policy::RetryPolicy, + execution::retries::RetryPolicy, load_balancing::LoadBalancingPolicy, speculative_execution::SpeculativeExecutionPolicy, }; pub(crate) mod defaults { + use crate::execution::retries::{DefaultRetryPolicy, RetryPolicy}; use crate::execution::ExecutionProfileInner; use crate::load_balancing::{self, LoadBalancingPolicy}; - use crate::retry_policy::{DefaultRetryPolicy, RetryPolicy}; use crate::speculative_execution::SpeculativeExecutionPolicy; use scylla_cql::frame::types::SerialConsistency; use scylla_cql::Consistency; @@ -295,7 +295,7 @@ impl ExecutionProfileBuilder { } /// Sets the [`RetryPolicy`] to use by default on queries. - /// The default is [DefaultRetryPolicy](crate::transport::retry_policy::DefaultRetryPolicy). + /// The default is [DefaultRetryPolicy](crate::execution::retries::DefaultRetryPolicy). /// It is possible to implement a custom retry policy by implementing the trait [`RetryPolicy`]. /// /// # Example diff --git a/scylla/src/execution/mod.rs b/scylla/src/execution/mod.rs index 053f42ad6e..ffa2713216 100644 --- a/scylla/src/execution/mod.rs +++ b/scylla/src/execution/mod.rs @@ -1,5 +1,6 @@ mod execution_profile; pub mod load_balancing; +pub mod retries; pub mod speculative_execution; pub(crate) use execution_profile::ExecutionProfileInner; diff --git a/scylla/src/transport/retry_policy.rs b/scylla/src/execution/retries/default_rp.rs similarity index 85% rename from scylla/src/transport/retry_policy.rs rename to scylla/src/execution/retries/default_rp.rs index ee0c50aac2..123b9c2bf7 100644 --- a/scylla/src/transport/retry_policy.rs +++ b/scylla/src/execution/retries/default_rp.rs @@ -1,89 +1,6 @@ -//! Query retries configurations\ -//! To decide when to retry a query the `Session` can use any object which implements -//! the `RetryPolicy` trait - -use crate::frame::types::Consistency; use crate::transport::errors::{DbError, QueryError, WriteType}; -/// Information about a failed query -pub struct QueryInfo<'a> { - /// The error with which the query failed - pub error: &'a QueryError, - /// A query is idempotent if it can be applied multiple times without changing the result of the initial application\ - /// If set to `true` we can be sure that it is idempotent\ - /// If set to `false` it is unknown whether it is idempotent - pub is_idempotent: bool, - /// Consistency with which the query failed - pub consistency: Consistency, -} - -#[derive(Clone, Debug, PartialEq, Eq)] -pub enum RetryDecision { - RetrySameNode(Option), // None means that the same consistency should be used as before - RetryNextNode(Option), // ditto - DontRetry, - IgnoreWriteError, -} - -/// Specifies a policy used to decide when to retry a query -pub trait RetryPolicy: std::fmt::Debug + Send + Sync { - /// Called for each new query, starts a session of deciding about retries - fn new_session(&self) -> Box; - - /// Used to clone this RetryPolicy - fn clone_boxed(&self) -> Box; -} - -impl Clone for Box { - fn clone(&self) -> Box { - self.clone_boxed() - } -} - -/// Used throughout a single query to decide when to retry it -/// After this query is finished it is destroyed or reset -pub trait RetrySession: Send + Sync { - /// Called after the query failed - decide what to do next - fn decide_should_retry(&mut self, query_info: QueryInfo) -> RetryDecision; - - /// Reset before using for a new query - fn reset(&mut self); -} - -/// Forwards all errors directly to the user, never retries -#[derive(Debug)] -pub struct FallthroughRetryPolicy; -pub struct FallthroughRetrySession; - -impl FallthroughRetryPolicy { - pub fn new() -> FallthroughRetryPolicy { - FallthroughRetryPolicy - } -} - -impl Default for FallthroughRetryPolicy { - fn default() -> FallthroughRetryPolicy { - FallthroughRetryPolicy - } -} - -impl RetryPolicy for FallthroughRetryPolicy { - fn new_session(&self) -> Box { - Box::new(FallthroughRetrySession) - } - - fn clone_boxed(&self) -> Box { - Box::new(FallthroughRetryPolicy) - } -} - -impl RetrySession for FallthroughRetrySession { - fn decide_should_retry(&mut self, _query_info: QueryInfo) -> RetryDecision { - RetryDecision::DontRetry - } - - fn reset(&mut self) {} -} +use super::{QueryInfo, RetryDecision, RetryPolicy, RetrySession}; /// Default retry policy - retries when there is a high chance that a retry might help.\ /// Behaviour based on [DataStax Java Driver](https://docs.datastax.com/en/developer/java-driver/4.10/manual/core/retries/) diff --git a/scylla/src/transport/downgrading_consistency_retry_policy.rs b/scylla/src/execution/retries/downgrading_consistency_rp.rs similarity index 99% rename from scylla/src/transport/downgrading_consistency_retry_policy.rs rename to scylla/src/execution/retries/downgrading_consistency_rp.rs index f55c25bcbf..37ee05e7ed 100644 --- a/scylla/src/transport/downgrading_consistency_retry_policy.rs +++ b/scylla/src/execution/retries/downgrading_consistency_rp.rs @@ -4,10 +4,10 @@ use scylla_cql::{ }; use tracing::debug; -use crate::retry_policy::{QueryInfo, RetryDecision, RetryPolicy, RetrySession}; +use super::{QueryInfo, RetryDecision, RetryPolicy, RetrySession}; /// Downgrading consistency retry policy - retries with lower consistency level if it knows\ -/// that the initial CL is unreachable. Also, it behaves as [DefaultRetryPolicy](crate::retry_policy::DefaultRetryPolicy) +/// that the initial CL is unreachable. Also, it behaves as [DefaultRetryPolicy](crate::execution::retries::DefaultRetryPolicy) /// when it believes that the initial CL is reachable. /// Behaviour based on [DataStax Java Driver]\ ///() diff --git a/scylla/src/execution/retries/fallthrough_rp.rs b/scylla/src/execution/retries/fallthrough_rp.rs new file mode 100644 index 0000000000..63d7fca23f --- /dev/null +++ b/scylla/src/execution/retries/fallthrough_rp.rs @@ -0,0 +1,36 @@ +use super::{QueryInfo, RetryDecision, RetryPolicy, RetrySession}; + +/// Forwards all errors directly to the user, never retries +#[derive(Debug)] +pub struct FallthroughRetryPolicy; +pub struct FallthroughRetrySession; + +impl FallthroughRetryPolicy { + pub fn new() -> FallthroughRetryPolicy { + FallthroughRetryPolicy + } +} + +impl Default for FallthroughRetryPolicy { + fn default() -> FallthroughRetryPolicy { + FallthroughRetryPolicy + } +} + +impl RetryPolicy for FallthroughRetryPolicy { + fn new_session(&self) -> Box { + Box::new(FallthroughRetrySession) + } + + fn clone_boxed(&self) -> Box { + Box::new(FallthroughRetryPolicy) + } +} + +impl RetrySession for FallthroughRetrySession { + fn decide_should_retry(&mut self, _query_info: QueryInfo) -> RetryDecision { + RetryDecision::DontRetry + } + + fn reset(&mut self) {} +} diff --git a/scylla/src/execution/retries/mod.rs b/scylla/src/execution/retries/mod.rs new file mode 100644 index 0000000000..d4a95a5645 --- /dev/null +++ b/scylla/src/execution/retries/mod.rs @@ -0,0 +1,11 @@ +mod default_rp; +mod downgrading_consistency_rp; +mod fallthrough_rp; +mod retry_policy; + +pub use default_rp::{DefaultRetryPolicy, DefaultRetrySession}; +pub use downgrading_consistency_rp::{ + DowngradingConsistencyRetryPolicy, DowngradingConsistencyRetrySession, +}; +pub use fallthrough_rp::{FallthroughRetryPolicy, FallthroughRetrySession}; +pub use retry_policy::{QueryInfo, RetryDecision, RetryPolicy, RetrySession}; diff --git a/scylla/src/execution/retries/retry_policy.rs b/scylla/src/execution/retries/retry_policy.rs new file mode 100644 index 0000000000..333b8faf7c --- /dev/null +++ b/scylla/src/execution/retries/retry_policy.rs @@ -0,0 +1,51 @@ +//! Query retries configurations\ +//! To decide when to retry a query the `Session` can use any object which implements +//! the `RetryPolicy` trait + +use crate::frame::types::Consistency; +use crate::transport::errors::QueryError; + +/// Information about a failed query +pub struct QueryInfo<'a> { + /// The error with which the query failed + pub error: &'a QueryError, + /// A query is idempotent if it can be applied multiple times without changing the result of the initial application\ + /// If set to `true` we can be sure that it is idempotent\ + /// If set to `false` it is unknown whether it is idempotent + pub is_idempotent: bool, + /// Consistency with which the query failed + pub consistency: Consistency, +} + +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum RetryDecision { + RetrySameNode(Option), // None means that the same consistency should be used as before + RetryNextNode(Option), // ditto + DontRetry, + IgnoreWriteError, +} + +/// Specifies a policy used to decide when to retry a query +pub trait RetryPolicy: std::fmt::Debug + Send + Sync { + /// Called for each new query, starts a session of deciding about retries + fn new_session(&self) -> Box; + + /// Used to clone this RetryPolicy + fn clone_boxed(&self) -> Box; +} + +impl Clone for Box { + fn clone(&self) -> Box { + self.clone_boxed() + } +} + +/// Used throughout a single query to decide when to retry it +/// After this query is finished it is destroyed or reset +pub trait RetrySession: Send + Sync { + /// Called after the query failed - decide what to do next + fn decide_should_retry(&mut self, query_info: QueryInfo) -> RetryDecision; + + /// Reset before using for a new query + fn reset(&mut self); +} diff --git a/scylla/src/history.rs b/scylla/src/history.rs index 6b1bd1a98f..7971afe4de 100644 --- a/scylla/src/history.rs +++ b/scylla/src/history.rs @@ -7,7 +7,7 @@ use std::{ time::SystemTime, }; -use crate::retry_policy::RetryDecision; +use crate::execution::retries::RetryDecision; use chrono::{DateTime, Utc}; use scylla_cql::errors::QueryError; @@ -456,7 +456,7 @@ mod tests { }; use crate::{ - query::Query, retry_policy::RetryDecision, utils::test_utils::unique_keyspace_name, + execution::retries::RetryDecision, query::Query, utils::test_utils::unique_keyspace_name, }; use super::{ diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index 232695254f..0300b43bef 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -140,6 +140,5 @@ pub use session::CloudSessionBuilder; pub use cluster::host_filter; pub use execution::{load_balancing, speculative_execution}; -pub use transport::retry_policy; pub use transport::metrics::Metrics; diff --git a/scylla/src/session/session.rs b/scylla/src/session/session.rs index 401fe3ff4f..2be4b5c92b 100644 --- a/scylla/src/session/session.rs +++ b/scylla/src/session/session.rs @@ -43,6 +43,7 @@ use crate::connection::{ }; use crate::cql_to_rust::FromRow; use crate::execution::load_balancing::{self, RoutingInfo}; +use crate::execution::retries::{QueryInfo, RetryDecision, RetrySession}; use crate::execution::{ speculative_execution, ExecutionProfile, ExecutionProfileHandle, ExecutionProfileInner, }; @@ -61,7 +62,6 @@ use crate::transport::iterator::{PreparedIteratorConfig, RowIterator}; use crate::transport::metrics::Metrics; use crate::transport::partitioner::PartitionerName; use crate::transport::query_result::QueryResult; -use crate::transport::retry_policy::{QueryInfo, RetryDecision, RetrySession}; use crate::transport::Compression; use crate::{ batch::{Batch, BatchStatement}, diff --git a/scylla/src/session/session_test.rs b/scylla/src/session/session_test.rs index 17cb6e2a91..a1ad2e8630 100644 --- a/scylla/src/session/session_test.rs +++ b/scylla/src/session/session_test.rs @@ -3,11 +3,11 @@ use crate::batch::{Batch, BatchStatement}; use crate::cluster::metadata::Strategy::NetworkTopologyStrategy; use crate::cluster::metadata::{CollectionType, ColumnKind, CqlType, NativeType, UserDefinedType}; use crate::cluster::Datacenter; +use crate::execution::retries::{QueryInfo, RetryDecision, RetryPolicy, RetrySession}; use crate::frame::response::result::Row; use crate::frame::value::ValueList; use crate::prepared_statement::PreparedStatement; use crate::query::Query; -use crate::retry_policy::{QueryInfo, RetryDecision, RetryPolicy, RetrySession}; use crate::sharding::Token; use crate::statement::Consistency; use crate::tracing::TracingInfo; diff --git a/scylla/src/statement/batch.rs b/scylla/src/statement/batch.rs index cb739a400e..6ce8453dd4 100644 --- a/scylla/src/statement/batch.rs +++ b/scylla/src/statement/batch.rs @@ -1,9 +1,9 @@ use std::borrow::Cow; use std::sync::Arc; +use crate::execution::retries::RetryPolicy; use crate::execution::ExecutionProfileHandle; use crate::history::HistoryListener; -use crate::retry_policy::RetryPolicy; use crate::statement::{prepared_statement::PreparedStatement, query::Query}; use super::StatementConfig; @@ -76,7 +76,7 @@ impl Batch { /// A query is idempotent if it can be applied multiple times without changing the result of the initial application /// If set to `true` we can be sure that it is idempotent /// If set to `false` it is unknown whether it is idempotent - /// This is used in [`RetryPolicy`](crate::retry_policy::RetryPolicy) to decide if retrying a query is safe + /// This is used in [`RetryPolicy`](crate::execution::retries::RetryPolicy) to decide if retrying a query is safe pub fn set_is_idempotent(&mut self, is_idempotent: bool) { self.config.is_idempotent = is_idempotent; } diff --git a/scylla/src/statement/mod.rs b/scylla/src/statement/mod.rs index 8dd418d3c0..2c137a0219 100644 --- a/scylla/src/statement/mod.rs +++ b/scylla/src/statement/mod.rs @@ -1,7 +1,7 @@ use std::{sync::Arc, time::Duration}; use crate::execution::ExecutionProfileHandle; -use crate::{history::HistoryListener, retry_policy::RetryPolicy}; +use crate::{execution::retries::RetryPolicy, history::HistoryListener}; pub mod batch; pub mod prepared_statement; diff --git a/scylla/src/statement/prepared_statement.rs b/scylla/src/statement/prepared_statement.rs index 9069be19d6..6fd31e2f1e 100644 --- a/scylla/src/statement/prepared_statement.rs +++ b/scylla/src/statement/prepared_statement.rs @@ -10,12 +10,12 @@ use uuid::Uuid; use scylla_cql::frame::response::result::ColumnSpec; use super::StatementConfig; +use crate::execution::retries::RetryPolicy; use crate::execution::ExecutionProfileHandle; use crate::frame::response::result::PreparedMetadata; use crate::frame::types::{Consistency, SerialConsistency}; use crate::frame::value::SerializedValues; use crate::history::HistoryListener; -use crate::retry_policy::RetryPolicy; use crate::sharding::Token; use crate::transport::partitioner::{Partitioner, PartitionerHasher, PartitionerName}; @@ -239,7 +239,7 @@ impl PreparedStatement { /// A query is idempotent if it can be applied multiple times without changing the result of the initial application /// If set to `true` we can be sure that it is idempotent /// If set to `false` it is unknown whether it is idempotent - /// This is used in [`RetryPolicy`](crate::retry_policy::RetryPolicy) to decide if retrying a query is safe + /// This is used in [`RetryPolicy`](crate::execution::retries::RetryPolicy) to decide if retrying a query is safe pub fn set_is_idempotent(&mut self, is_idempotent: bool) { self.config.is_idempotent = is_idempotent; } diff --git a/scylla/src/statement/query.rs b/scylla/src/statement/query.rs index 188aaae801..f11e240a27 100644 --- a/scylla/src/statement/query.rs +++ b/scylla/src/statement/query.rs @@ -1,8 +1,8 @@ use super::StatementConfig; +use crate::execution::retries::RetryPolicy; use crate::execution::ExecutionProfileHandle; use crate::frame::types::{Consistency, SerialConsistency}; use crate::history::HistoryListener; -use crate::retry_policy::RetryPolicy; use std::sync::Arc; use std::time::Duration; @@ -76,7 +76,7 @@ impl Query { /// A query is idempotent if it can be applied multiple times without changing the result of the initial application /// If set to `true` we can be sure that it is idempotent /// If set to `false` it is unknown whether it is idempotent - /// This is used in [`RetryPolicy`](crate::retry_policy::RetryPolicy) to decide if retrying a query is safe + /// This is used in [`RetryPolicy`](crate::execution::retries::RetryPolicy) to decide if retrying a query is safe pub fn set_is_idempotent(&mut self, is_idempotent: bool) { self.config.is_idempotent = is_idempotent; } diff --git a/scylla/src/transport/iterator.rs b/scylla/src/transport/iterator.rs index 4cd256b5ee..71cb1bf278 100644 --- a/scylla/src/transport/iterator.rs +++ b/scylla/src/transport/iterator.rs @@ -26,6 +26,7 @@ use crate::cluster::ClusterData; use crate::cluster::{Node, NodeRef}; use crate::connection::{Connection, NonErrorQueryResponse, QueryResponse}; use crate::execution::load_balancing::{self, RoutingInfo}; +use crate::execution::retries::{QueryInfo, RetryDecision, RetrySession}; use crate::frame::{ response::{ result, @@ -37,7 +38,6 @@ use crate::history::{self, HistoryListener}; use crate::statement::Consistency; use crate::statement::{prepared_statement::PreparedStatement, query::Query}; use crate::transport::metrics::Metrics; -use crate::transport::retry_policy::{QueryInfo, RetryDecision, RetrySession}; use crate::utils::unzip_option; use tracing::{trace, trace_span, warn, Instrument}; use uuid::Uuid; diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs index 7a1a7fb7c7..aad7475e39 100644 --- a/scylla/src/transport/mod.rs +++ b/scylla/src/transport/mod.rs @@ -1,9 +1,7 @@ -pub mod downgrading_consistency_retry_policy; pub mod iterator; pub(crate) mod metrics; pub mod partitioner; pub mod query_result; -pub mod retry_policy; pub use crate::frame::{Authenticator, Compression}; pub use scylla_cql::errors; diff --git a/scylla/tests/integration/consistency.rs b/scylla/tests/integration/consistency.rs index 947dc7e0bb..0f2ced0850 100644 --- a/scylla/tests/integration/consistency.rs +++ b/scylla/tests/integration/consistency.rs @@ -1,9 +1,9 @@ use crate::utils::test_with_3_node_cluster; +use scylla::execution::retries::FallthroughRetryPolicy; use scylla::execution::{ExecutionProfileBuilder, ExecutionProfileHandle}; use scylla::load_balancing::{DefaultPolicy, LoadBalancingPolicy, RoutingInfo}; use scylla::prepared_statement::PreparedStatement; -use scylla::retry_policy::FallthroughRetryPolicy; use scylla::session::Session; use scylla::sharding::Token; use scylla::test_utils::unique_keyspace_name; diff --git a/scylla/tests/integration/execution_profiles.rs b/scylla/tests/integration/execution_profiles.rs index 50d1a029eb..9b52fc5b7a 100644 --- a/scylla/tests/integration/execution_profiles.rs +++ b/scylla/tests/integration/execution_profiles.rs @@ -10,8 +10,8 @@ use scylla::query::Query; use scylla::statement::SerialConsistency; use scylla::{ cluster::ClusterData, + execution::retries::{RetryPolicy, RetrySession}, load_balancing::{LoadBalancingPolicy, RoutingInfo}, - retry_policy::{RetryPolicy, RetrySession}, speculative_execution::SpeculativeExecutionPolicy, test_utils::unique_keyspace_name, ExecutionProfile, SessionBuilder, @@ -82,7 +82,7 @@ impl LoadBalancingPolicy for BoundToPredefinedNodePolicy { } impl RetryPolicy for BoundToPredefinedNodePolicy { - fn new_session(&self) -> Box { + fn new_session(&self) -> Box { self.report_node(Report::RetryPolicy); Box::new(self.clone()) } @@ -95,10 +95,10 @@ impl RetryPolicy for BoundToPredefinedNodePolicy { impl RetrySession for BoundToPredefinedNodePolicy { fn decide_should_retry( &mut self, - query_info: scylla::retry_policy::QueryInfo, - ) -> scylla::retry_policy::RetryDecision { + query_info: scylla::execution::retries::QueryInfo, + ) -> scylla::execution::retries::RetryDecision { self.report_consistency(query_info.consistency); - scylla::retry_policy::RetryDecision::DontRetry + scylla::execution::retries::RetryDecision::DontRetry } fn reset(&mut self) {} diff --git a/scylla/tests/integration/lwt_optimisation.rs b/scylla/tests/integration/lwt_optimisation.rs index 7036757a4b..df7da30b88 100644 --- a/scylla/tests/integration/lwt_optimisation.rs +++ b/scylla/tests/integration/lwt_optimisation.rs @@ -1,6 +1,6 @@ use crate::utils::test_with_3_node_cluster; +use scylla::execution::retries::FallthroughRetryPolicy; use scylla::frame::types; -use scylla::retry_policy::FallthroughRetryPolicy; use scylla::session::Session; use scylla::{frame::protocol_features::ProtocolFeatures, test_utils::unique_keyspace_name}; use scylla::{ExecutionProfile, SessionBuilder}; diff --git a/scylla/tests/integration/retries.rs b/scylla/tests/integration/retries.rs index a3ace178b8..974c71473d 100644 --- a/scylla/tests/integration/retries.rs +++ b/scylla/tests/integration/retries.rs @@ -1,5 +1,5 @@ use crate::utils::test_with_3_node_cluster; -use scylla::retry_policy::FallthroughRetryPolicy; +use scylla::execution::retries::FallthroughRetryPolicy; use scylla::session::Session; use scylla::speculative_execution::SimpleSpeculativeExecutionPolicy; use scylla::ExecutionProfile; From ddae8cb8dd0f3d3d54aa641ae884a1d3a48871be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 10:13:14 +0200 Subject: [PATCH 18/43] move iterator.rs to execution mod --- docs/source/tracing/paged.md | 4 ++-- examples/tracing.rs | 2 +- scylla/src/connection/connection.rs | 2 +- scylla/src/{transport => execution}/iterator.rs | 2 +- scylla/src/execution/mod.rs | 1 + scylla/src/session/caching_session.rs | 2 +- scylla/src/session/session.rs | 2 +- scylla/src/transport/mod.rs | 1 - 8 files changed, 8 insertions(+), 8 deletions(-) rename scylla/src/{transport => execution}/iterator.rs (99%) diff --git a/docs/source/tracing/paged.md b/docs/source/tracing/paged.md index e69d4f3361..df3a056871 100644 --- a/docs/source/tracing/paged.md +++ b/docs/source/tracing/paged.md @@ -13,7 +13,7 @@ If tracing is enabled the row iterator will contain a list of tracing ids for al # use std::error::Error; # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::query::Query; -use scylla::transport::iterator::RowIterator; +use scylla::execution::iterator::RowIterator; use scylla::tracing::TracingInfo; use futures::StreamExt; use uuid::Uuid; @@ -49,7 +49,7 @@ for id in tracing_ids { # use std::error::Error; # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::prepared_statement::PreparedStatement; -use scylla::transport::iterator::RowIterator; +use scylla::execution::iterator::RowIterator; use scylla::tracing::TracingInfo; use futures::StreamExt; use uuid::Uuid; diff --git a/examples/tracing.rs b/examples/tracing.rs index bff0bca94a..3f03ceedd2 100644 --- a/examples/tracing.rs +++ b/examples/tracing.rs @@ -4,11 +4,11 @@ use anyhow::{anyhow, Result}; use futures::StreamExt; use scylla::batch::Batch; +use scylla::execution::iterator::RowIterator; use scylla::statement::{ prepared_statement::PreparedStatement, query::Query, Consistency, SerialConsistency, }; use scylla::tracing::TracingInfo; -use scylla::transport::iterator::RowIterator; use scylla::QueryResult; use scylla::{Session, SessionBuilder}; use std::env; diff --git a/scylla/src/connection/connection.rs b/scylla/src/connection/connection.rs index aadfe95a65..a9de847d60 100644 --- a/scylla/src/connection/connection.rs +++ b/scylla/src/connection/connection.rs @@ -43,8 +43,8 @@ use std::{ use crate::cloud::CloudConfig; use crate::cluster::metadata::{PeerEndpoint, UntranslatedEndpoint, UntranslatedPeer}; use crate::cluster::NodeAddr; +use crate::execution::iterator::RowIterator; use crate::transport::errors::{BadKeyspaceName, DbError, QueryError}; -use crate::transport::iterator::RowIterator; use crate::batch::{Batch, BatchStatement}; use crate::frame::protocol_features::ProtocolFeatures; diff --git a/scylla/src/transport/iterator.rs b/scylla/src/execution/iterator.rs similarity index 99% rename from scylla/src/transport/iterator.rs rename to scylla/src/execution/iterator.rs index 71cb1bf278..b61ea5ed14 100644 --- a/scylla/src/transport/iterator.rs +++ b/scylla/src/execution/iterator.rs @@ -17,10 +17,10 @@ use thiserror::Error; use tokio::sync::mpsc; use tracing::instrument::WithSubscriber; -use super::errors::QueryError; use crate::cql_to_rust::{FromRow, FromRowError}; use crate::execution::ExecutionProfileInner; use crate::session::RequestSpan; +use crate::transport::errors::QueryError; use crate::cluster::ClusterData; use crate::cluster::{Node, NodeRef}; diff --git a/scylla/src/execution/mod.rs b/scylla/src/execution/mod.rs index ffa2713216..be7a45cc8a 100644 --- a/scylla/src/execution/mod.rs +++ b/scylla/src/execution/mod.rs @@ -1,4 +1,5 @@ mod execution_profile; +pub mod iterator; pub mod load_balancing; pub mod retries; pub mod speculative_execution; diff --git a/scylla/src/session/caching_session.rs b/scylla/src/session/caching_session.rs index 82e12b1ab2..6a819bdc12 100644 --- a/scylla/src/session/caching_session.rs +++ b/scylla/src/session/caching_session.rs @@ -1,9 +1,9 @@ use crate::batch::{Batch, BatchStatement}; +use crate::execution::iterator::RowIterator; use crate::frame::value::{BatchValues, ValueList}; use crate::prepared_statement::PreparedStatement; use crate::query::Query; use crate::transport::errors::QueryError; -use crate::transport::iterator::RowIterator; use crate::transport::partitioner::PartitionerName; use crate::{QueryResult, Session}; use bytes::Bytes; diff --git a/scylla/src/session/session.rs b/scylla/src/session/session.rs index 2be4b5c92b..d26555cab3 100644 --- a/scylla/src/session/session.rs +++ b/scylla/src/session/session.rs @@ -42,6 +42,7 @@ use crate::connection::{ AddressTranslator, Connection, ConnectionConfig, NonErrorQueryResponse, VerifiedKeyspaceName, }; use crate::cql_to_rust::FromRow; +use crate::execution::iterator::{PreparedIteratorConfig, RowIterator}; use crate::execution::load_balancing::{self, RoutingInfo}; use crate::execution::retries::{QueryInfo, RetryDecision, RetrySession}; use crate::execution::{ @@ -58,7 +59,6 @@ use crate::sharding::Token; use crate::statement::Consistency; use crate::tracing::{TracingEvent, TracingInfo}; use crate::transport::errors::{NewSessionError, QueryError}; -use crate::transport::iterator::{PreparedIteratorConfig, RowIterator}; use crate::transport::metrics::Metrics; use crate::transport::partitioner::PartitionerName; use crate::transport::query_result::QueryResult; diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs index aad7475e39..eb26e2ce7b 100644 --- a/scylla/src/transport/mod.rs +++ b/scylla/src/transport/mod.rs @@ -1,4 +1,3 @@ -pub mod iterator; pub(crate) mod metrics; pub mod partitioner; pub mod query_result; From a9c809a4355efc31c7753008579b71ad169b43a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 10:20:14 +0200 Subject: [PATCH 19/43] move history.rs to execution mod --- examples/query_history.rs | 2 +- scylla/src/{ => execution}/history.rs | 0 scylla/src/execution/iterator.rs | 2 +- scylla/src/execution/mod.rs | 1 + scylla/src/lib.rs | 1 - scylla/src/session/session.rs | 3 +-- scylla/src/statement/batch.rs | 2 +- scylla/src/statement/mod.rs | 3 +-- scylla/src/statement/prepared_statement.rs | 2 +- scylla/src/statement/query.rs | 2 +- 10 files changed, 8 insertions(+), 10 deletions(-) rename scylla/src/{ => execution}/history.rs (100%) diff --git a/examples/query_history.rs b/examples/query_history.rs index 3782d03ec5..3df429ba1f 100644 --- a/examples/query_history.rs +++ b/examples/query_history.rs @@ -2,7 +2,7 @@ use anyhow::Result; use futures::StreamExt; -use scylla::history::{HistoryCollector, StructuredHistory}; +use scylla::execution::history::{HistoryCollector, StructuredHistory}; use scylla::query::Query; use scylla::session::Session; use scylla::SessionBuilder; diff --git a/scylla/src/history.rs b/scylla/src/execution/history.rs similarity index 100% rename from scylla/src/history.rs rename to scylla/src/execution/history.rs diff --git a/scylla/src/execution/iterator.rs b/scylla/src/execution/iterator.rs index b61ea5ed14..5ef91afbd3 100644 --- a/scylla/src/execution/iterator.rs +++ b/scylla/src/execution/iterator.rs @@ -25,6 +25,7 @@ use crate::transport::errors::QueryError; use crate::cluster::ClusterData; use crate::cluster::{Node, NodeRef}; use crate::connection::{Connection, NonErrorQueryResponse, QueryResponse}; +use crate::execution::history::{self, HistoryListener}; use crate::execution::load_balancing::{self, RoutingInfo}; use crate::execution::retries::{QueryInfo, RetryDecision, RetrySession}; use crate::frame::{ @@ -34,7 +35,6 @@ use crate::frame::{ }, value::SerializedValues, }; -use crate::history::{self, HistoryListener}; use crate::statement::Consistency; use crate::statement::{prepared_statement::PreparedStatement, query::Query}; use crate::transport::metrics::Metrics; diff --git a/scylla/src/execution/mod.rs b/scylla/src/execution/mod.rs index be7a45cc8a..c074fc0bcf 100644 --- a/scylla/src/execution/mod.rs +++ b/scylla/src/execution/mod.rs @@ -1,4 +1,5 @@ mod execution_profile; +pub mod history; pub mod iterator; pub mod load_balancing; pub mod retries; diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index 0300b43bef..27140c4c0e 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -108,7 +108,6 @@ pub mod cloud; pub mod cluster; pub mod connection; pub mod execution; -pub mod history; pub mod session; pub mod sharding; pub mod statement; diff --git a/scylla/src/session/session.rs b/scylla/src/session/session.rs index d26555cab3..2506627ccb 100644 --- a/scylla/src/session/session.rs +++ b/scylla/src/session/session.rs @@ -4,8 +4,7 @@ #[cfg(feature = "cloud")] use crate::cloud::CloudConfig; -use crate::history; -use crate::history::HistoryListener; +use crate::execution::history::{self, HistoryListener}; use crate::utils::pretty::{CommaSeparatedDisplayer, CqlValueDisplayer}; use crate::utils::unzip_option; use arc_swap::ArcSwapOption; diff --git a/scylla/src/statement/batch.rs b/scylla/src/statement/batch.rs index 6ce8453dd4..04de6a5da8 100644 --- a/scylla/src/statement/batch.rs +++ b/scylla/src/statement/batch.rs @@ -1,9 +1,9 @@ use std::borrow::Cow; use std::sync::Arc; +use crate::execution::history::HistoryListener; use crate::execution::retries::RetryPolicy; use crate::execution::ExecutionProfileHandle; -use crate::history::HistoryListener; use crate::statement::{prepared_statement::PreparedStatement, query::Query}; use super::StatementConfig; diff --git a/scylla/src/statement/mod.rs b/scylla/src/statement/mod.rs index 2c137a0219..e8c06e84d1 100644 --- a/scylla/src/statement/mod.rs +++ b/scylla/src/statement/mod.rs @@ -1,7 +1,6 @@ use std::{sync::Arc, time::Duration}; -use crate::execution::ExecutionProfileHandle; -use crate::{execution::retries::RetryPolicy, history::HistoryListener}; +use crate::execution::{history::HistoryListener, retries::RetryPolicy, ExecutionProfileHandle}; pub mod batch; pub mod prepared_statement; diff --git a/scylla/src/statement/prepared_statement.rs b/scylla/src/statement/prepared_statement.rs index 6fd31e2f1e..0e3941056b 100644 --- a/scylla/src/statement/prepared_statement.rs +++ b/scylla/src/statement/prepared_statement.rs @@ -10,12 +10,12 @@ use uuid::Uuid; use scylla_cql::frame::response::result::ColumnSpec; use super::StatementConfig; +use crate::execution::history::HistoryListener; use crate::execution::retries::RetryPolicy; use crate::execution::ExecutionProfileHandle; use crate::frame::response::result::PreparedMetadata; use crate::frame::types::{Consistency, SerialConsistency}; use crate::frame::value::SerializedValues; -use crate::history::HistoryListener; use crate::sharding::Token; use crate::transport::partitioner::{Partitioner, PartitionerHasher, PartitionerName}; diff --git a/scylla/src/statement/query.rs b/scylla/src/statement/query.rs index f11e240a27..cb79a95b35 100644 --- a/scylla/src/statement/query.rs +++ b/scylla/src/statement/query.rs @@ -1,8 +1,8 @@ use super::StatementConfig; +use crate::execution::history::HistoryListener; use crate::execution::retries::RetryPolicy; use crate::execution::ExecutionProfileHandle; use crate::frame::types::{Consistency, SerialConsistency}; -use crate::history::HistoryListener; use std::sync::Arc; use std::time::Duration; From e599114c906673dec1b0908e473ef6092025915e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 10:21:57 +0200 Subject: [PATCH 20/43] move tracing.rs to execution mod --- examples/tracing.rs | 2 +- scylla/src/execution/mod.rs | 1 + scylla/src/{ => execution}/tracing.rs | 0 scylla/src/lib.rs | 1 - scylla/src/session/session.rs | 8 +++++--- scylla/src/session/session_test.rs | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) rename scylla/src/{ => execution}/tracing.rs (100%) diff --git a/examples/tracing.rs b/examples/tracing.rs index 3f03ceedd2..192fa6453d 100644 --- a/examples/tracing.rs +++ b/examples/tracing.rs @@ -5,10 +5,10 @@ use anyhow::{anyhow, Result}; use futures::StreamExt; use scylla::batch::Batch; use scylla::execution::iterator::RowIterator; +use scylla::execution::tracing::TracingInfo; use scylla::statement::{ prepared_statement::PreparedStatement, query::Query, Consistency, SerialConsistency, }; -use scylla::tracing::TracingInfo; use scylla::QueryResult; use scylla::{Session, SessionBuilder}; use std::env; diff --git a/scylla/src/execution/mod.rs b/scylla/src/execution/mod.rs index c074fc0bcf..ea3c250398 100644 --- a/scylla/src/execution/mod.rs +++ b/scylla/src/execution/mod.rs @@ -4,6 +4,7 @@ pub mod iterator; pub mod load_balancing; pub mod retries; pub mod speculative_execution; +pub mod tracing; pub(crate) use execution_profile::ExecutionProfileInner; pub use execution_profile::{ExecutionProfile, ExecutionProfileBuilder, ExecutionProfileHandle}; diff --git a/scylla/src/tracing.rs b/scylla/src/execution/tracing.rs similarity index 100% rename from scylla/src/tracing.rs rename to scylla/src/execution/tracing.rs diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index 27140c4c0e..2e9bfec1a5 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -111,7 +111,6 @@ pub mod execution; pub mod session; pub mod sharding; pub mod statement; -pub mod tracing; pub mod transport; pub(crate) mod utils; diff --git a/scylla/src/session/session.rs b/scylla/src/session/session.rs index 2506627ccb..c078ebdaa4 100644 --- a/scylla/src/session/session.rs +++ b/scylla/src/session/session.rs @@ -44,6 +44,9 @@ use crate::cql_to_rust::FromRow; use crate::execution::iterator::{PreparedIteratorConfig, RowIterator}; use crate::execution::load_balancing::{self, RoutingInfo}; use crate::execution::retries::{QueryInfo, RetryDecision, RetrySession}; +use crate::execution::tracing::{ + TracingEvent, TracingInfo, TRACES_EVENTS_QUERY_STR, TRACES_SESSION_QUERY_STR, +}; use crate::execution::{ speculative_execution, ExecutionProfile, ExecutionProfileHandle, ExecutionProfileInner, }; @@ -56,7 +59,6 @@ use crate::prepared_statement::PreparedStatement; use crate::query::Query; use crate::sharding::Token; use crate::statement::Consistency; -use crate::tracing::{TracingEvent, TracingInfo}; use crate::transport::errors::{NewSessionError, QueryError}; use crate::transport::metrics::Metrics; use crate::transport::partitioner::PartitionerName; @@ -1343,12 +1345,12 @@ impl Session { consistency: Option, ) -> Result, QueryError> { // Query system_traces.sessions for TracingInfo - let mut traces_session_query = Query::new(crate::tracing::TRACES_SESSION_QUERY_STR); + let mut traces_session_query = Query::new(TRACES_SESSION_QUERY_STR); traces_session_query.config.consistency = consistency; traces_session_query.set_page_size(1024); // Query system_traces.events for TracingEvents - let mut traces_events_query = Query::new(crate::tracing::TRACES_EVENTS_QUERY_STR); + let mut traces_events_query = Query::new(TRACES_EVENTS_QUERY_STR); traces_events_query.config.consistency = consistency; traces_events_query.set_page_size(1024); diff --git a/scylla/src/session/session_test.rs b/scylla/src/session/session_test.rs index a1ad2e8630..c4e52dc6fd 100644 --- a/scylla/src/session/session_test.rs +++ b/scylla/src/session/session_test.rs @@ -4,13 +4,13 @@ use crate::cluster::metadata::Strategy::NetworkTopologyStrategy; use crate::cluster::metadata::{CollectionType, ColumnKind, CqlType, NativeType, UserDefinedType}; use crate::cluster::Datacenter; use crate::execution::retries::{QueryInfo, RetryDecision, RetryPolicy, RetrySession}; +use crate::execution::tracing::TracingInfo; use crate::frame::response::result::Row; use crate::frame::value::ValueList; use crate::prepared_statement::PreparedStatement; use crate::query::Query; use crate::sharding::Token; use crate::statement::Consistency; -use crate::tracing::TracingInfo; use crate::transport::errors::{BadKeyspaceName, BadQuery, DbError, QueryError}; use crate::transport::partitioner::{ calculate_token_for_partition_key, Murmur3Partitioner, Partitioner, PartitionerName, From 675d8746eeb40281030e39aea77a210dfbe8aad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 10:24:18 +0200 Subject: [PATCH 21/43] move metrics.rs to execution mod --- scylla/src/execution/iterator.rs | 2 +- scylla/src/{transport => execution}/metrics.rs | 0 scylla/src/execution/mod.rs | 3 +++ scylla/src/execution/speculative_execution.rs | 3 ++- scylla/src/lib.rs | 2 -- scylla/src/session/session.rs | 2 +- scylla/src/transport/mod.rs | 1 - 7 files changed, 7 insertions(+), 6 deletions(-) rename scylla/src/{transport => execution}/metrics.rs (100%) diff --git a/scylla/src/execution/iterator.rs b/scylla/src/execution/iterator.rs index 5ef91afbd3..130f0bd240 100644 --- a/scylla/src/execution/iterator.rs +++ b/scylla/src/execution/iterator.rs @@ -28,6 +28,7 @@ use crate::connection::{Connection, NonErrorQueryResponse, QueryResponse}; use crate::execution::history::{self, HistoryListener}; use crate::execution::load_balancing::{self, RoutingInfo}; use crate::execution::retries::{QueryInfo, RetryDecision, RetrySession}; +use crate::execution::Metrics; use crate::frame::{ response::{ result, @@ -37,7 +38,6 @@ use crate::frame::{ }; use crate::statement::Consistency; use crate::statement::{prepared_statement::PreparedStatement, query::Query}; -use crate::transport::metrics::Metrics; use crate::utils::unzip_option; use tracing::{trace, trace_span, warn, Instrument}; use uuid::Uuid; diff --git a/scylla/src/transport/metrics.rs b/scylla/src/execution/metrics.rs similarity index 100% rename from scylla/src/transport/metrics.rs rename to scylla/src/execution/metrics.rs diff --git a/scylla/src/execution/mod.rs b/scylla/src/execution/mod.rs index ea3c250398..1323d666e7 100644 --- a/scylla/src/execution/mod.rs +++ b/scylla/src/execution/mod.rs @@ -2,6 +2,7 @@ mod execution_profile; pub mod history; pub mod iterator; pub mod load_balancing; +pub(crate) mod metrics; pub mod retries; pub mod speculative_execution; pub mod tracing; @@ -11,3 +12,5 @@ pub use execution_profile::{ExecutionProfile, ExecutionProfileBuilder, Execution #[cfg(test)] pub(crate) use execution_profile::defaults; + +pub use metrics::Metrics; diff --git a/scylla/src/execution/speculative_execution.rs b/scylla/src/execution/speculative_execution.rs index e4c9eced9d..07ec3ff78c 100644 --- a/scylla/src/execution/speculative_execution.rs +++ b/scylla/src/execution/speculative_execution.rs @@ -5,7 +5,8 @@ use futures::{ use std::{future::Future, sync::Arc, time::Duration}; use tracing::{trace_span, warn, Instrument}; -use crate::transport::{errors::QueryError, metrics::Metrics}; +use crate::execution::Metrics; +use crate::transport::errors::QueryError; /// Context is passed as an argument to `SpeculativeExecutionPolicy` methods pub struct Context { diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index 2e9bfec1a5..897919df95 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -138,5 +138,3 @@ pub use session::CloudSessionBuilder; pub use cluster::host_filter; pub use execution::{load_balancing, speculative_execution}; - -pub use transport::metrics::Metrics; diff --git a/scylla/src/session/session.rs b/scylla/src/session/session.rs index c078ebdaa4..b70991351a 100644 --- a/scylla/src/session/session.rs +++ b/scylla/src/session/session.rs @@ -47,6 +47,7 @@ use crate::execution::retries::{QueryInfo, RetryDecision, RetrySession}; use crate::execution::tracing::{ TracingEvent, TracingInfo, TRACES_EVENTS_QUERY_STR, TRACES_SESSION_QUERY_STR, }; +use crate::execution::Metrics; use crate::execution::{ speculative_execution, ExecutionProfile, ExecutionProfileHandle, ExecutionProfileInner, }; @@ -60,7 +61,6 @@ use crate::query::Query; use crate::sharding::Token; use crate::statement::Consistency; use crate::transport::errors::{NewSessionError, QueryError}; -use crate::transport::metrics::Metrics; use crate::transport::partitioner::PartitionerName; use crate::transport::query_result::QueryResult; use crate::transport::Compression; diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs index eb26e2ce7b..16966d73c7 100644 --- a/scylla/src/transport/mod.rs +++ b/scylla/src/transport/mod.rs @@ -1,4 +1,3 @@ -pub(crate) mod metrics; pub mod partitioner; pub mod query_result; From c4062866d26898f6593b13b8e95aebd303d6b71c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 10:36:53 +0200 Subject: [PATCH 22/43] extract routing module --- examples/compare-tokens.rs | 2 +- scylla/benches/benchmark.rs | 2 +- scylla/src/cluster/cluster.rs | 6 +++--- scylla/src/cluster/locator/mod.rs | 4 ++-- scylla/src/cluster/locator/precomputed_replicas.rs | 4 ++-- scylla/src/cluster/locator/replication_info.rs | 4 ++-- scylla/src/cluster/locator/test.rs | 2 +- scylla/src/cluster/locator/token_ring.rs | 4 ++-- scylla/src/cluster/metadata.rs | 2 +- scylla/src/cluster/node.rs | 2 +- scylla/src/connection/connection.rs | 4 ++-- scylla/src/connection/connection_pool.rs | 5 ++++- scylla/src/execution/load_balancing/default.rs | 8 ++++---- scylla/src/execution/load_balancing/mod.rs | 2 +- scylla/src/lib.rs | 2 +- scylla/src/routing/mod.rs | 7 +++++++ scylla/src/{transport => routing}/partitioner.rs | 6 ++---- scylla/src/{ => routing}/sharding.rs | 5 +---- scylla/src/session/caching_session.rs | 4 ++-- scylla/src/session/session.rs | 4 ++-- scylla/src/session/session_test.rs | 8 ++++---- scylla/src/statement/prepared_statement.rs | 4 ++-- scylla/src/transport/mod.rs | 1 - scylla/tests/integration/consistency.rs | 2 +- 24 files changed, 49 insertions(+), 45 deletions(-) create mode 100644 scylla/src/routing/mod.rs rename scylla/src/{transport => routing}/partitioner.rs (98%) rename scylla/src/{ => routing}/sharding.rs (98%) diff --git a/examples/compare-tokens.rs b/examples/compare-tokens.rs index 99feb3efc8..04a5340da0 100644 --- a/examples/compare-tokens.rs +++ b/examples/compare-tokens.rs @@ -1,7 +1,7 @@ use anyhow::Result; use scylla::cluster::NodeAddr; use scylla::frame::value::ValueList; -use scylla::sharding::Token; +use scylla::routing::Token; use scylla::{Session, SessionBuilder}; use std::env; diff --git a/scylla/benches/benchmark.rs b/scylla/benches/benchmark.rs index c6058923b6..d4b0146add 100644 --- a/scylla/benches/benchmark.rs +++ b/scylla/benches/benchmark.rs @@ -4,7 +4,7 @@ use bytes::BytesMut; use scylla::{ frame::types, frame::value::ValueList, - transport::partitioner::{calculate_token_for_partition_key, Murmur3Partitioner}, + routing::partitioner::{calculate_token_for_partition_key, Murmur3Partitioner}, }; fn types_benchmark(c: &mut Criterion) { diff --git a/scylla/src/cluster/cluster.rs b/scylla/src/cluster/cluster.rs index 8d9aaca899..a701e4e919 100644 --- a/scylla/src/cluster/cluster.rs +++ b/scylla/src/cluster/cluster.rs @@ -5,8 +5,8 @@ use crate::connection::{Connection, PoolConfig, VerifiedKeyspaceName}; use crate::frame::response::event::{Event, StatusChangeEvent}; use crate::frame::value::ValueList; use crate::prepared_statement::TokenCalculationError; -use crate::sharding::Token; -use crate::transport::{errors::QueryError, partitioner::PartitionerName}; +use crate::routing::{partitioner::PartitionerName, Token}; +use crate::transport::errors::QueryError; use arc_swap::ArcSwap; use futures::future::join_all; @@ -25,7 +25,7 @@ use crate::cluster::locator::ReplicaLocator; use crate::cluster::metadata::{Keyspace, Metadata, MetadataReader, Strategy}; use crate::cluster::{KnownNode, NodeAddr}; -use crate::transport::partitioner::calculate_token_for_partition_key; +use crate::routing::partitioner::calculate_token_for_partition_key; /// Cluster manages up to date information and connections to database nodes. /// All data can be accessed by cloning Arc in the `data` field diff --git a/scylla/src/cluster/locator/mod.rs b/scylla/src/cluster/locator/mod.rs index bef7699d00..996af07110 100644 --- a/scylla/src/cluster/locator/mod.rs +++ b/scylla/src/cluster/locator/mod.rs @@ -10,7 +10,7 @@ pub use token_ring::TokenRing; use crate::cluster::metadata::Strategy; use crate::cluster::{Node, NodeRef}; -use crate::sharding::Token; +use crate::routing::Token; use itertools::Itertools; use precomputed_replicas::PrecomputedReplicas; use replicas::{ReplicasArray, EMPTY_REPLICAS}; @@ -741,7 +741,7 @@ impl<'a> IntoIterator for ReplicasOrdered<'a> { #[cfg(test)] mod tests { - use crate::{cluster::locator::test::*, sharding::Token}; + use crate::{cluster::locator::test::*, routing::Token}; #[tokio::test] async fn test_replicas_ordered() { diff --git a/scylla/src/cluster/locator/precomputed_replicas.rs b/scylla/src/cluster/locator/precomputed_replicas.rs index 4249e2f077..9493496219 100644 --- a/scylla/src/cluster/locator/precomputed_replicas.rs +++ b/scylla/src/cluster/locator/precomputed_replicas.rs @@ -16,7 +16,7 @@ use super::replication_info::ReplicationInfo; use super::TokenRing; use crate::cluster::metadata::Strategy; use crate::cluster::Node; -use crate::sharding::Token; +use crate::routing::Token; use std::cmp; use std::collections::BTreeSet; @@ -219,7 +219,7 @@ mod tests { create_ring, mock_metadata_for_token_aware_tests, A, C, D, E, F, G, }, cluster::metadata::{Keyspace, Strategy}, - sharding::Token, + routing::Token, }; use super::{PrecomputedReplicas, ReplicationInfo}; diff --git a/scylla/src/cluster/locator/replication_info.rs b/scylla/src/cluster/locator/replication_info.rs index d586506da2..52cddc2799 100644 --- a/scylla/src/cluster/locator/replication_info.rs +++ b/scylla/src/cluster/locator/replication_info.rs @@ -2,7 +2,7 @@ use itertools::Itertools; use super::TokenRing; use crate::cluster::Node; -use crate::sharding::Token; +use crate::routing::Token; use std::cmp; use std::collections::{BTreeSet, HashMap}; @@ -207,7 +207,7 @@ mod tests { cluster::locator::test::{ create_ring, mock_metadata_for_token_aware_tests, A, B, C, D, E, F, G, }, - sharding::Token, + routing::Token, }; use super::ReplicationInfo; diff --git a/scylla/src/cluster/locator/test.rs b/scylla/src/cluster/locator/test.rs index 4f42375cac..f56acb7a3c 100644 --- a/scylla/src/cluster/locator/test.rs +++ b/scylla/src/cluster/locator/test.rs @@ -6,7 +6,7 @@ use super::{ReplicaLocator, ReplicaSet}; use crate::cluster::metadata::{Keyspace, Metadata, Peer, Strategy}; use crate::cluster::{Node, NodeAddr, NodeRef}; use crate::connection::PoolConfig; -use crate::sharding::Token; +use crate::routing::Token; use std::collections::HashSet; use std::sync::Arc; diff --git a/scylla/src/cluster/locator/token_ring.rs b/scylla/src/cluster/locator/token_ring.rs index ff2a9ef840..686d8e0a90 100644 --- a/scylla/src/cluster/locator/token_ring.rs +++ b/scylla/src/cluster/locator/token_ring.rs @@ -1,4 +1,4 @@ -use crate::sharding::Token; +use crate::routing::Token; /// A token ring is a continuous hash ring. It defines association by hashing a key /// onto the ring and then walking the ring in one direction. @@ -72,7 +72,7 @@ impl TokenRing { #[cfg(test)] mod tests { use super::TokenRing; - use crate::sharding::Token; + use crate::routing::Token; #[test] fn test_token_ring() { diff --git a/scylla/src/cluster/metadata.rs b/scylla/src/cluster/metadata.rs index b2cc065d3a..e20dac8e9e 100644 --- a/scylla/src/cluster/metadata.rs +++ b/scylla/src/cluster/metadata.rs @@ -2,7 +2,7 @@ use crate::cluster::host_filter::HostFilter; use crate::cluster::resolve_contact_points; use crate::connection::{Connection, ConnectionConfig, NodeConnectionPool, PoolConfig, PoolSize}; use crate::frame::response::event::Event; -use crate::sharding::Token; +use crate::routing::Token; use crate::statement::query::Query; use crate::transport::errors::{DbError, QueryError}; use crate::utils::parse::{ParseErrorCause, ParseResult, ParserState}; diff --git a/scylla/src/cluster/node.rs b/scylla/src/cluster/node.rs index e18314c3ba..9427203104 100644 --- a/scylla/src/cluster/node.rs +++ b/scylla/src/cluster/node.rs @@ -6,7 +6,7 @@ use crate::connection::Connection; use crate::connection::VerifiedKeyspaceName; use crate::connection::{NodeConnectionPool, PoolConfig}; /// Node represents a cluster node along with it's data and connections -use crate::sharding::{Sharder, Token}; +use crate::routing::{sharding::Sharder, Token}; use crate::transport::errors::QueryError; use std::fmt::Display; diff --git a/scylla/src/connection/connection.rs b/scylla/src/connection/connection.rs index a9de847d60..95c0ef867b 100644 --- a/scylla/src/connection/connection.rs +++ b/scylla/src/connection/connection.rs @@ -57,8 +57,8 @@ use crate::frame::{ FrameParams, SerializedRequest, }; use crate::query::Query; +use crate::routing::sharding::{Shard, ShardInfo, Sharder}; use crate::session::IntoTypedRows; -use crate::sharding::{Shard, ShardInfo, Sharder}; use crate::statement::prepared_statement::PreparedStatement; use crate::statement::Consistency; use crate::transport::Compression; @@ -2236,7 +2236,7 @@ mod tests { let _ = proxy.finish().await; } - use crate::sharding::{ShardCount, Sharder}; + use crate::routing::sharding::{ShardCount, Sharder}; use std::net::ToSocketAddrs; // Open many connections to a node diff --git a/scylla/src/connection/connection_pool.rs b/scylla/src/connection/connection_pool.rs index 28a5c05958..a8f64641ea 100644 --- a/scylla/src/connection/connection_pool.rs +++ b/scylla/src/connection/connection_pool.rs @@ -2,7 +2,10 @@ use crate::cloud::set_ssl_config_for_scylla_cloud_host; use crate::connection::{Connection, ConnectionConfig, ErrorReceiver, VerifiedKeyspaceName}; -use crate::sharding::{Shard, ShardCount, Sharder, Token}; +use crate::routing::{ + sharding::{Shard, ShardCount, Sharder}, + Token, +}; use crate::transport::errors::QueryError; #[cfg(feature = "cloud")] diff --git a/scylla/src/execution/load_balancing/default.rs b/scylla/src/execution/load_balancing/default.rs index ca3e755f76..8c6fd618dd 100644 --- a/scylla/src/execution/load_balancing/default.rs +++ b/scylla/src/execution/load_balancing/default.rs @@ -4,7 +4,7 @@ pub use self::latency_awareness::LatencyAwarenessBuilder; use super::{FallbackPlan, LoadBalancingPolicy, NodeRef, RoutingInfo}; use crate::cluster::ClusterData; use crate::{ - cluster::locator::ReplicaSet, cluster::metadata::Strategy, cluster::Node, sharding::Token, + cluster::locator::ReplicaSet, cluster::metadata::Strategy, cluster::Node, routing::Token, }; use itertools::{Either, Itertools}; use rand::{prelude::SliceRandom, thread_rng, Rng}; @@ -879,7 +879,7 @@ mod tests { load_balancing::{ default::tests::framework::mock_cluster_data_for_token_aware_tests, RoutingInfo, }, - sharding::Token, + routing::Token, }; use super::{DefaultPolicy, NodeLocationPreference}; @@ -896,7 +896,7 @@ mod tests { ClusterData, }, load_balancing::{LoadBalancingPolicy, Plan, RoutingInfo}, - sharding::Token, + routing::Token, }; enum ExpectedGroup { @@ -2725,7 +2725,7 @@ mod latency_awareness { default::tests::test_default_policy_with_given_cluster_and_routing_info, RoutingInfo, }, - sharding::Token, + routing::Token, ExecutionProfile, }; use crate::{ diff --git a/scylla/src/execution/load_balancing/mod.rs b/scylla/src/execution/load_balancing/mod.rs index 247ea5f640..92221b10b3 100644 --- a/scylla/src/execution/load_balancing/mod.rs +++ b/scylla/src/execution/load_balancing/mod.rs @@ -3,7 +3,7 @@ //! See [the book](https://rust-driver.docs.scylladb.com/stable/load-balancing/load-balancing.html) for more information use crate::cluster::{ClusterData, NodeRef}; -use crate::sharding::Token; +use crate::routing::Token; use scylla_cql::{errors::QueryError, frame::types}; use std::time::Duration; diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index 897919df95..170363a024 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -108,8 +108,8 @@ pub mod cloud; pub mod cluster; pub mod connection; pub mod execution; +pub mod routing; pub mod session; -pub mod sharding; pub mod statement; pub mod transport; diff --git a/scylla/src/routing/mod.rs b/scylla/src/routing/mod.rs new file mode 100644 index 0000000000..e48d6afaa2 --- /dev/null +++ b/scylla/src/routing/mod.rs @@ -0,0 +1,7 @@ +pub mod partitioner; +pub mod sharding; + +#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug)] +pub struct Token { + pub value: i64, +} diff --git a/scylla/src/transport/partitioner.rs b/scylla/src/routing/partitioner.rs similarity index 98% rename from scylla/src/transport/partitioner.rs rename to scylla/src/routing/partitioner.rs index 95624e9db1..b2d2debbb8 100644 --- a/scylla/src/transport/partitioner.rs +++ b/scylla/src/routing/partitioner.rs @@ -2,7 +2,7 @@ use bytes::Buf; use std::num::Wrapping; use crate::{ - frame::value::SerializedValues, prepared_statement::TokenCalculationError, sharding::Token, + frame::value::SerializedValues, prepared_statement::TokenCalculationError, routing::Token, }; #[allow(clippy::upper_case_acronyms)] @@ -366,9 +366,7 @@ mod tests { use rand::Rng; use rand_pcg::Pcg32; - use crate::transport::partitioner::PartitionerHasher; - - use super::{CDCPartitioner, Murmur3Partitioner, Partitioner}; + use super::{CDCPartitioner, Murmur3Partitioner, Partitioner, PartitionerHasher}; fn assert_correct_murmur3_hash(pk: &'static str, expected_hash: i64) { let hash = Murmur3Partitioner.hash_one(pk.as_bytes()).value; diff --git a/scylla/src/sharding.rs b/scylla/src/routing/sharding.rs similarity index 98% rename from scylla/src/sharding.rs rename to scylla/src/routing/sharding.rs index d6fff76466..8486466fcf 100644 --- a/scylla/src/sharding.rs +++ b/scylla/src/routing/sharding.rs @@ -4,10 +4,7 @@ use std::convert::TryFrom; use std::num::NonZeroU16; use thiserror::Error; -#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug)] -pub struct Token { - pub value: i64, -} +use super::Token; pub type Shard = u32; pub type ShardCount = NonZeroU16; diff --git a/scylla/src/session/caching_session.rs b/scylla/src/session/caching_session.rs index 6a819bdc12..7b0554da6d 100644 --- a/scylla/src/session/caching_session.rs +++ b/scylla/src/session/caching_session.rs @@ -3,8 +3,8 @@ use crate::execution::iterator::RowIterator; use crate::frame::value::{BatchValues, ValueList}; use crate::prepared_statement::PreparedStatement; use crate::query::Query; +use crate::routing::partitioner::PartitionerName; use crate::transport::errors::QueryError; -use crate::transport::partitioner::PartitionerName; use crate::{QueryResult, Session}; use bytes::Bytes; use dashmap::DashMap; @@ -217,8 +217,8 @@ where #[cfg(test)] mod tests { use crate::query::Query; + use crate::routing::partitioner::PartitionerName; use crate::test_utils::create_new_session_builder; - use crate::transport::partitioner::PartitionerName; use crate::utils::test_utils::unique_keyspace_name; use crate::{ batch::{Batch, BatchStatement}, diff --git a/scylla/src/session/session.rs b/scylla/src/session/session.rs index b70991351a..bfadb58fe5 100644 --- a/scylla/src/session/session.rs +++ b/scylla/src/session/session.rs @@ -58,10 +58,10 @@ use crate::frame::value::{ }; use crate::prepared_statement::PreparedStatement; use crate::query::Query; -use crate::sharding::Token; +use crate::routing::partitioner::PartitionerName; +use crate::routing::Token; use crate::statement::Consistency; use crate::transport::errors::{NewSessionError, QueryError}; -use crate::transport::partitioner::PartitionerName; use crate::transport::query_result::QueryResult; use crate::transport::Compression; use crate::{ diff --git a/scylla/src/session/session_test.rs b/scylla/src/session/session_test.rs index c4e52dc6fd..eb6663c341 100644 --- a/scylla/src/session/session_test.rs +++ b/scylla/src/session/session_test.rs @@ -9,12 +9,12 @@ use crate::frame::response::result::Row; use crate::frame::value::ValueList; use crate::prepared_statement::PreparedStatement; use crate::query::Query; -use crate::sharding::Token; -use crate::statement::Consistency; -use crate::transport::errors::{BadKeyspaceName, BadQuery, DbError, QueryError}; -use crate::transport::partitioner::{ +use crate::routing::partitioner::{ calculate_token_for_partition_key, Murmur3Partitioner, Partitioner, PartitionerName, }; +use crate::routing::Token; +use crate::statement::Consistency; +use crate::transport::errors::{BadKeyspaceName, BadQuery, DbError, QueryError}; use crate::utils::test_utils::{ create_new_session_builder, supports_feature, unique_keyspace_name, }; diff --git a/scylla/src/statement/prepared_statement.rs b/scylla/src/statement/prepared_statement.rs index 0e3941056b..0b30db4332 100644 --- a/scylla/src/statement/prepared_statement.rs +++ b/scylla/src/statement/prepared_statement.rs @@ -16,8 +16,8 @@ use crate::execution::ExecutionProfileHandle; use crate::frame::response::result::PreparedMetadata; use crate::frame::types::{Consistency, SerialConsistency}; use crate::frame::value::SerializedValues; -use crate::sharding::Token; -use crate::transport::partitioner::{Partitioner, PartitionerHasher, PartitionerName}; +use crate::routing::partitioner::{Partitioner, PartitionerHasher, PartitionerName}; +use crate::routing::Token; /// Represents a statement prepared on the server. #[derive(Debug)] diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs index 16966d73c7..6818c47b33 100644 --- a/scylla/src/transport/mod.rs +++ b/scylla/src/transport/mod.rs @@ -1,4 +1,3 @@ -pub mod partitioner; pub mod query_result; pub use crate::frame::{Authenticator, Compression}; diff --git a/scylla/tests/integration/consistency.rs b/scylla/tests/integration/consistency.rs index 0f2ced0850..545c89bc47 100644 --- a/scylla/tests/integration/consistency.rs +++ b/scylla/tests/integration/consistency.rs @@ -4,8 +4,8 @@ use scylla::execution::retries::FallthroughRetryPolicy; use scylla::execution::{ExecutionProfileBuilder, ExecutionProfileHandle}; use scylla::load_balancing::{DefaultPolicy, LoadBalancingPolicy, RoutingInfo}; use scylla::prepared_statement::PreparedStatement; +use scylla::routing::Token; use scylla::session::Session; -use scylla::sharding::Token; use scylla::test_utils::unique_keyspace_name; use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; From 6273f6a44cd6392779fbe47f5d50f5a505ca9272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 10:45:06 +0200 Subject: [PATCH 23/43] extract tests module from transport tests --- scylla/src/lib.rs | 3 +++ scylla/src/session/mod.rs | 2 -- .../src/{transport => tests}/cql_collections_test.rs | 0 scylla/src/{transport => tests}/cql_types_test.rs | 0 scylla/src/{transport => tests}/cql_value_test.rs | 0 scylla/src/tests/mod.rs | 4 ++++ scylla/src/{session => tests}/session_test.rs | 0 scylla/src/transport/mod.rs | 10 ---------- 8 files changed, 7 insertions(+), 12 deletions(-) rename scylla/src/{transport => tests}/cql_collections_test.rs (100%) rename scylla/src/{transport => tests}/cql_types_test.rs (100%) rename scylla/src/{transport => tests}/cql_value_test.rs (100%) create mode 100644 scylla/src/tests/mod.rs rename scylla/src/{session => tests}/session_test.rs (100%) diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index 170363a024..c1c0cc304b 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -113,6 +113,9 @@ pub mod session; pub mod statement; pub mod transport; +#[cfg(test)] +mod tests; + pub(crate) mod utils; /// This module is NOT part of the public API (it is `pub` only for internal use of integration tests). diff --git a/scylla/src/session/mod.rs b/scylla/src/session/mod.rs index d916d7b2b9..2c3a129a73 100644 --- a/scylla/src/session/mod.rs +++ b/scylla/src/session/mod.rs @@ -1,8 +1,6 @@ mod caching_session; mod session; pub mod session_builder; -#[cfg(test)] -mod session_test; pub use caching_session::CachingSession; pub use session::*; diff --git a/scylla/src/transport/cql_collections_test.rs b/scylla/src/tests/cql_collections_test.rs similarity index 100% rename from scylla/src/transport/cql_collections_test.rs rename to scylla/src/tests/cql_collections_test.rs diff --git a/scylla/src/transport/cql_types_test.rs b/scylla/src/tests/cql_types_test.rs similarity index 100% rename from scylla/src/transport/cql_types_test.rs rename to scylla/src/tests/cql_types_test.rs diff --git a/scylla/src/transport/cql_value_test.rs b/scylla/src/tests/cql_value_test.rs similarity index 100% rename from scylla/src/transport/cql_value_test.rs rename to scylla/src/tests/cql_value_test.rs diff --git a/scylla/src/tests/mod.rs b/scylla/src/tests/mod.rs new file mode 100644 index 0000000000..671402d945 --- /dev/null +++ b/scylla/src/tests/mod.rs @@ -0,0 +1,4 @@ +mod cql_collections_test; +mod cql_types_test; +mod cql_value_test; +mod session_test; diff --git a/scylla/src/session/session_test.rs b/scylla/src/tests/session_test.rs similarity index 100% rename from scylla/src/session/session_test.rs rename to scylla/src/tests/session_test.rs diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs index 6818c47b33..4eb60ccb60 100644 --- a/scylla/src/transport/mod.rs +++ b/scylla/src/transport/mod.rs @@ -2,13 +2,3 @@ pub mod query_result; pub use crate::frame::{Authenticator, Compression}; pub use scylla_cql::errors; - -#[cfg(test)] -mod authenticate_test; -#[cfg(test)] -mod cql_collections_test; - -#[cfg(test)] -mod cql_types_test; -#[cfg(test)] -mod cql_value_test; From 2c6b923be874e6491448b2c77da67b1f6e360594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 10:48:32 +0200 Subject: [PATCH 24/43] re-export errors mod from execution, not transport --- examples/schema_agreement.rs | 2 +- examples/tower.rs | 2 +- scylla/src/cluster/cluster.rs | 2 +- scylla/src/cluster/metadata.rs | 2 +- scylla/src/cluster/node.rs | 2 +- scylla/src/connection/connection.rs | 2 +- scylla/src/connection/connection_pool.rs | 2 +- scylla/src/execution/errors.rs | 3 +++ scylla/src/execution/iterator.rs | 2 +- scylla/src/execution/mod.rs | 1 + scylla/src/execution/retries/default_rp.rs | 4 ++-- scylla/src/execution/retries/retry_policy.rs | 2 +- scylla/src/execution/speculative_execution.rs | 2 +- scylla/src/session/caching_session.rs | 2 +- scylla/src/session/session.rs | 2 +- scylla/src/session/session_builder.rs | 2 +- scylla/src/tests/session_test.rs | 2 +- scylla/src/transport/mod.rs | 1 - 18 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 scylla/src/execution/errors.rs diff --git a/examples/schema_agreement.rs b/examples/schema_agreement.rs index 2393e33aae..1868b8e7b8 100644 --- a/examples/schema_agreement.rs +++ b/examples/schema_agreement.rs @@ -1,6 +1,6 @@ use anyhow::{bail, Result}; +use scylla::execution::errors::QueryError; use scylla::session::{IntoTypedRows, Session}; -use scylla::transport::errors::QueryError; use scylla::SessionBuilder; use std::env; use std::time::Duration; diff --git a/examples/tower.rs b/examples/tower.rs index 1c3bb2112a..0d346ccf2f 100644 --- a/examples/tower.rs +++ b/examples/tower.rs @@ -13,7 +13,7 @@ struct SessionService { // A trivial service implementation for sending parameterless simple string requests to Scylla. impl Service for SessionService { type Response = scylla::QueryResult; - type Error = scylla::transport::errors::QueryError; + type Error = scylla::execution::errors::QueryError; type Future = Pin>>>; fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll> { diff --git a/scylla/src/cluster/cluster.rs b/scylla/src/cluster/cluster.rs index a701e4e919..61a0b424e7 100644 --- a/scylla/src/cluster/cluster.rs +++ b/scylla/src/cluster/cluster.rs @@ -1,12 +1,12 @@ use crate::cluster::host_filter::HostFilter; use crate::cluster::Node; use crate::connection::{Connection, PoolConfig, VerifiedKeyspaceName}; +use crate::execution::errors::QueryError; /// Cluster manages up to date information and connections to database nodes use crate::frame::response::event::{Event, StatusChangeEvent}; use crate::frame::value::ValueList; use crate::prepared_statement::TokenCalculationError; use crate::routing::{partitioner::PartitionerName, Token}; -use crate::transport::errors::QueryError; use arc_swap::ArcSwap; use futures::future::join_all; diff --git a/scylla/src/cluster/metadata.rs b/scylla/src/cluster/metadata.rs index e20dac8e9e..be0a196b90 100644 --- a/scylla/src/cluster/metadata.rs +++ b/scylla/src/cluster/metadata.rs @@ -1,10 +1,10 @@ use crate::cluster::host_filter::HostFilter; use crate::cluster::resolve_contact_points; use crate::connection::{Connection, ConnectionConfig, NodeConnectionPool, PoolConfig, PoolSize}; +use crate::execution::errors::{DbError, QueryError}; use crate::frame::response::event::Event; use crate::routing::Token; use crate::statement::query::Query; -use crate::transport::errors::{DbError, QueryError}; use crate::utils::parse::{ParseErrorCause, ParseResult, ParserState}; use futures::future::{self, FutureExt}; diff --git a/scylla/src/cluster/node.rs b/scylla/src/cluster/node.rs index 9427203104..3e3000e982 100644 --- a/scylla/src/cluster/node.rs +++ b/scylla/src/cluster/node.rs @@ -5,9 +5,9 @@ use uuid::Uuid; use crate::connection::Connection; use crate::connection::VerifiedKeyspaceName; use crate::connection::{NodeConnectionPool, PoolConfig}; +use crate::execution::errors::QueryError; /// Node represents a cluster node along with it's data and connections use crate::routing::{sharding::Sharder, Token}; -use crate::transport::errors::QueryError; use std::fmt::Display; use std::io; diff --git a/scylla/src/connection/connection.rs b/scylla/src/connection/connection.rs index 95c0ef867b..20dcba0d2d 100644 --- a/scylla/src/connection/connection.rs +++ b/scylla/src/connection/connection.rs @@ -43,8 +43,8 @@ use std::{ use crate::cloud::CloudConfig; use crate::cluster::metadata::{PeerEndpoint, UntranslatedEndpoint, UntranslatedPeer}; use crate::cluster::NodeAddr; +use crate::execution::errors::{BadKeyspaceName, DbError, QueryError}; use crate::execution::iterator::RowIterator; -use crate::transport::errors::{BadKeyspaceName, DbError, QueryError}; use crate::batch::{Batch, BatchStatement}; use crate::frame::protocol_features::ProtocolFeatures; diff --git a/scylla/src/connection/connection_pool.rs b/scylla/src/connection/connection_pool.rs index a8f64641ea..0500c17e38 100644 --- a/scylla/src/connection/connection_pool.rs +++ b/scylla/src/connection/connection_pool.rs @@ -2,11 +2,11 @@ use crate::cloud::set_ssl_config_for_scylla_cloud_host; use crate::connection::{Connection, ConnectionConfig, ErrorReceiver, VerifiedKeyspaceName}; +use crate::execution::errors::QueryError; use crate::routing::{ sharding::{Shard, ShardCount, Sharder}, Token, }; -use crate::transport::errors::QueryError; #[cfg(feature = "cloud")] use crate::cluster::resolve_hostname; diff --git a/scylla/src/execution/errors.rs b/scylla/src/execution/errors.rs new file mode 100644 index 0000000000..999bab1395 --- /dev/null +++ b/scylla/src/execution/errors.rs @@ -0,0 +1,3 @@ +pub use scylla_cql::errors::{ + BadKeyspaceName, BadQuery, DbError, NewSessionError, QueryError, WriteType, +}; diff --git a/scylla/src/execution/iterator.rs b/scylla/src/execution/iterator.rs index 130f0bd240..f8d1e4cf04 100644 --- a/scylla/src/execution/iterator.rs +++ b/scylla/src/execution/iterator.rs @@ -18,9 +18,9 @@ use tokio::sync::mpsc; use tracing::instrument::WithSubscriber; use crate::cql_to_rust::{FromRow, FromRowError}; +use crate::execution::errors::QueryError; use crate::execution::ExecutionProfileInner; use crate::session::RequestSpan; -use crate::transport::errors::QueryError; use crate::cluster::ClusterData; use crate::cluster::{Node, NodeRef}; diff --git a/scylla/src/execution/mod.rs b/scylla/src/execution/mod.rs index 1323d666e7..c0b1458eec 100644 --- a/scylla/src/execution/mod.rs +++ b/scylla/src/execution/mod.rs @@ -1,3 +1,4 @@ +pub mod errors; mod execution_profile; pub mod history; pub mod iterator; diff --git a/scylla/src/execution/retries/default_rp.rs b/scylla/src/execution/retries/default_rp.rs index 123b9c2bf7..05b6a2084d 100644 --- a/scylla/src/execution/retries/default_rp.rs +++ b/scylla/src/execution/retries/default_rp.rs @@ -1,4 +1,4 @@ -use crate::transport::errors::{DbError, QueryError, WriteType}; +use crate::execution::errors::{DbError, QueryError, WriteType}; use super::{QueryInfo, RetryDecision, RetryPolicy, RetrySession}; @@ -136,8 +136,8 @@ impl RetrySession for DefaultRetrySession { #[cfg(test)] mod tests { use super::{DefaultRetryPolicy, QueryInfo, RetryDecision, RetryPolicy}; + use crate::execution::errors::{BadQuery, DbError, QueryError, WriteType}; use crate::statement::Consistency; - use crate::transport::errors::{BadQuery, DbError, QueryError, WriteType}; use bytes::Bytes; use std::io::ErrorKind; use std::sync::Arc; diff --git a/scylla/src/execution/retries/retry_policy.rs b/scylla/src/execution/retries/retry_policy.rs index 333b8faf7c..7562666882 100644 --- a/scylla/src/execution/retries/retry_policy.rs +++ b/scylla/src/execution/retries/retry_policy.rs @@ -2,8 +2,8 @@ //! To decide when to retry a query the `Session` can use any object which implements //! the `RetryPolicy` trait +use crate::execution::errors::QueryError; use crate::frame::types::Consistency; -use crate::transport::errors::QueryError; /// Information about a failed query pub struct QueryInfo<'a> { diff --git a/scylla/src/execution/speculative_execution.rs b/scylla/src/execution/speculative_execution.rs index 07ec3ff78c..da10f25eb3 100644 --- a/scylla/src/execution/speculative_execution.rs +++ b/scylla/src/execution/speculative_execution.rs @@ -5,8 +5,8 @@ use futures::{ use std::{future::Future, sync::Arc, time::Duration}; use tracing::{trace_span, warn, Instrument}; +use crate::execution::errors::QueryError; use crate::execution::Metrics; -use crate::transport::errors::QueryError; /// Context is passed as an argument to `SpeculativeExecutionPolicy` methods pub struct Context { diff --git a/scylla/src/session/caching_session.rs b/scylla/src/session/caching_session.rs index 7b0554da6d..1134b14f5c 100644 --- a/scylla/src/session/caching_session.rs +++ b/scylla/src/session/caching_session.rs @@ -1,10 +1,10 @@ use crate::batch::{Batch, BatchStatement}; +use crate::execution::errors::QueryError; use crate::execution::iterator::RowIterator; use crate::frame::value::{BatchValues, ValueList}; use crate::prepared_statement::PreparedStatement; use crate::query::Query; use crate::routing::partitioner::PartitionerName; -use crate::transport::errors::QueryError; use crate::{QueryResult, Session}; use bytes::Bytes; use dashmap::DashMap; diff --git a/scylla/src/session/session.rs b/scylla/src/session/session.rs index bfadb58fe5..dd05c411cf 100644 --- a/scylla/src/session/session.rs +++ b/scylla/src/session/session.rs @@ -41,6 +41,7 @@ use crate::connection::{ AddressTranslator, Connection, ConnectionConfig, NonErrorQueryResponse, VerifiedKeyspaceName, }; use crate::cql_to_rust::FromRow; +use crate::execution::errors::{NewSessionError, QueryError}; use crate::execution::iterator::{PreparedIteratorConfig, RowIterator}; use crate::execution::load_balancing::{self, RoutingInfo}; use crate::execution::retries::{QueryInfo, RetryDecision, RetrySession}; @@ -61,7 +62,6 @@ use crate::query::Query; use crate::routing::partitioner::PartitionerName; use crate::routing::Token; use crate::statement::Consistency; -use crate::transport::errors::{NewSessionError, QueryError}; use crate::transport::query_result::QueryResult; use crate::transport::Compression; use crate::{ diff --git a/scylla/src/session/session_builder.rs b/scylla/src/session/session_builder.rs index ef0affe7a4..7b90bff00f 100644 --- a/scylla/src/session/session_builder.rs +++ b/scylla/src/session/session_builder.rs @@ -1,9 +1,9 @@ //! SessionBuilder provides an easy way to create new Sessions use crate::connection::{AddressTranslator, PoolSize}; +use crate::execution::errors::NewSessionError; use crate::execution::ExecutionProfileHandle; use crate::session::{Session, SessionConfig}; -use crate::transport::errors::NewSessionError; use crate::transport::Compression; #[cfg(feature = "cloud")] diff --git a/scylla/src/tests/session_test.rs b/scylla/src/tests/session_test.rs index eb6663c341..075920dd8f 100644 --- a/scylla/src/tests/session_test.rs +++ b/scylla/src/tests/session_test.rs @@ -3,6 +3,7 @@ use crate::batch::{Batch, BatchStatement}; use crate::cluster::metadata::Strategy::NetworkTopologyStrategy; use crate::cluster::metadata::{CollectionType, ColumnKind, CqlType, NativeType, UserDefinedType}; use crate::cluster::Datacenter; +use crate::execution::errors::{BadKeyspaceName, BadQuery, DbError, QueryError}; use crate::execution::retries::{QueryInfo, RetryDecision, RetryPolicy, RetrySession}; use crate::execution::tracing::TracingInfo; use crate::frame::response::result::Row; @@ -14,7 +15,6 @@ use crate::routing::partitioner::{ }; use crate::routing::Token; use crate::statement::Consistency; -use crate::transport::errors::{BadKeyspaceName, BadQuery, DbError, QueryError}; use crate::utils::test_utils::{ create_new_session_builder, supports_feature, unique_keyspace_name, }; diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs index 4eb60ccb60..6293d2ca7e 100644 --- a/scylla/src/transport/mod.rs +++ b/scylla/src/transport/mod.rs @@ -1,4 +1,3 @@ pub mod query_result; pub use crate::frame::{Authenticator, Compression}; -pub use scylla_cql::errors; From e3c311afa708b4d9da8f7ae13200c0afc4e9e573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 11:02:10 +0200 Subject: [PATCH 25/43] move some errors from scylla_cql to scylla --- scylla-cql/src/errors.rs | 262 +--------------- scylla-cql/src/frame/response/error.rs | 8 +- scylla-cql/src/frame/response/mod.rs | 6 +- scylla/src/cluster/cluster.rs | 2 +- scylla/src/cluster/metadata.rs | 2 +- scylla/src/connection/connection.rs | 4 +- scylla/src/execution/errors.rs | 280 +++++++++++++++++- scylla/src/execution/history.rs | 10 +- scylla/src/execution/iterator.rs | 3 +- .../src/execution/load_balancing/default.rs | 5 +- scylla/src/execution/load_balancing/mod.rs | 3 +- .../retries/downgrading_consistency_rp.rs | 8 +- scylla/src/session/session.rs | 1 - scylla/src/statement/prepared_statement.rs | 2 +- scylla/src/tests/session_test.rs | 2 +- .../tests/integration/execution_profiles.rs | 2 +- scylla/tests/integration/new_session.rs | 2 +- scylla/tests/integration/utils.rs | 2 +- 18 files changed, 309 insertions(+), 295 deletions(-) diff --git a/scylla-cql/src/errors.rs b/scylla-cql/src/errors.rs index 40587cfef6..f9452f9f6d 100644 --- a/scylla-cql/src/errors.rs +++ b/scylla-cql/src/errors.rs @@ -1,56 +1,11 @@ -//! This module contains various errors which can be returned by `scylla::Session` +//! This module contains various errors which can be returned +//! while working with CQL frames. -use crate::frame::frame_errors::{FrameError, ParseError}; use crate::frame::protocol_features::ProtocolFeatures; -use crate::frame::value::SerializeValuesError; use crate::Consistency; use bytes::Bytes; -use std::io::ErrorKind; -use std::sync::Arc; use thiserror::Error; -/// Error that occurred during query execution -#[derive(Error, Debug, Clone)] -pub enum QueryError { - /// Database sent a response containing some error with a message - #[error("Database returned an error: {0}, Error message: {1}")] - DbError(DbError, String), - - /// Caller passed an invalid query - #[error(transparent)] - BadQuery(#[from] BadQuery), - - /// Input/Output error has occurred, connection broken etc. - #[error("IO Error: {0}")] - IoError(Arc), - - /// Unexpected message received - #[error("Protocol Error: {0}")] - ProtocolError(&'static str), - - /// Invalid message received - #[error("Invalid message: {0}")] - InvalidMessage(String), - - /// Timeout error has occurred, function didn't complete in time. - #[error("Timeout Error")] - TimeoutError, - - #[error("Too many orphaned stream ids: {0}")] - TooManyOrphanedStreamIds(u16), - - #[error("Unable to allocate stream id")] - UnableToAllocStreamId, - - /// Client timeout occurred before any response arrived - #[error("Request timeout: {0}")] - RequestTimeout(String), - - /// Address translation failed - #[error("Address translation failed: {0}")] - TranslationError(#[from] TranslationError), -} - /// An error sent from the database in response to a query /// as described in the [specification](https://github.com/apache/cassandra/blob/5ed5e84613ef0e9664a774493db7d2604e3596e0/doc/native_protocol_v4.spec#L1029)\ #[derive(Error, Debug, Clone, PartialEq, Eq)] @@ -291,15 +246,6 @@ impl DbError { } } -/// Error caused by failed address translation done before establishing connection -#[derive(Debug, Copy, Clone, Error)] -pub enum TranslationError { - #[error("No rule for address")] - NoRuleForAddress, - #[error("Invalid address in rule")] - InvalidAddressInRule, -} - /// Type of the operation rejected by rate limiting #[derive(Debug, Clone, PartialEq, Eq)] pub enum OperationType { @@ -332,179 +278,12 @@ pub enum WriteType { Other(String), } -/// Error caused by caller creating an invalid query -#[derive(Error, Debug, Clone)] -#[error("Invalid query passed to Session")] -pub enum BadQuery { - /// Failed to serialize values passed to a query - values too big - #[error("Serializing values failed: {0} ")] - SerializeValuesError(#[from] SerializeValuesError), - - /// Serialized values are too long to compute partition key - #[error("Serialized values are too long to compute partition key! Length: {0}, Max allowed length: {1}")] - ValuesTooLongForKey(usize, usize), - - /// Passed invalid keyspace name to use - #[error("Passed invalid keyspace name to use: {0}")] - BadKeyspaceName(#[from] BadKeyspaceName), - - /// Other reasons of bad query - #[error("{0}")] - Other(String), -} - -/// Error that occurred during session creation -#[derive(Error, Debug, Clone)] -pub enum NewSessionError { - /// Failed to resolve hostname passed in Session creation - #[error("Couldn't resolve any hostname: {0:?}")] - FailedToResolveAnyHostname(Vec), - - /// List of known nodes passed to Session constructor is empty - /// There needs to be at least one node to connect to - #[error("Empty known nodes list")] - EmptyKnownNodesList, - - /// Database sent a response containing some error with a message - #[error("Database returned an error: {0}, Error message: {1}")] - DbError(DbError, String), - - /// Caller passed an invalid query - #[error(transparent)] - BadQuery(#[from] BadQuery), - - /// Input/Output error has occurred, connection broken etc. - #[error("IO Error: {0}")] - IoError(Arc), - - /// Unexpected message received - #[error("Protocol Error: {0}")] - ProtocolError(&'static str), - - /// Invalid message received - #[error("Invalid message: {0}")] - InvalidMessage(String), - - /// Timeout error has occurred, couldn't connect to node in time. - #[error("Timeout Error")] - TimeoutError, - - #[error("Too many orphaned stream ids: {0}")] - TooManyOrphanedStreamIds(u16), - - #[error("Unable to allocate stream id")] - UnableToAllocStreamId, - - /// Client timeout occurred before a response arrived for some query - /// during `Session` creation. - #[error("Client timeout: {0}")] - RequestTimeout(String), - - /// Address translation failed - #[error("Address translation failed: {0}")] - TranslationError(#[from] TranslationError), -} - -/// Invalid keyspace name given to `Session::use_keyspace()` -#[derive(Debug, Error, Clone)] -pub enum BadKeyspaceName { - /// Keyspace name is empty - #[error("Keyspace name is empty")] - Empty, - - /// Keyspace name too long, must be up to 48 characters - #[error("Keyspace name too long, must be up to 48 characters, found {1} characters. Bad keyspace name: '{0}'")] - TooLong(String, usize), - - /// Illegal character - only alphanumeric and underscores allowed. - #[error("Illegal character found: '{1}', only alphanumeric and underscores allowed. Bad keyspace name: '{0}'")] - IllegalCharacter(String, char), -} - impl std::fmt::Display for WriteType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{:?}", self) } } -impl From for QueryError { - fn from(io_error: std::io::Error) -> QueryError { - QueryError::IoError(Arc::new(io_error)) - } -} - -impl From for QueryError { - fn from(serialized_err: SerializeValuesError) -> QueryError { - QueryError::BadQuery(BadQuery::SerializeValuesError(serialized_err)) - } -} - -impl From for QueryError { - fn from(parse_error: ParseError) -> QueryError { - QueryError::InvalidMessage(format!("Error parsing message: {}", parse_error)) - } -} - -impl From for QueryError { - fn from(frame_error: FrameError) -> QueryError { - QueryError::InvalidMessage(format!("Frame error: {}", frame_error)) - } -} - -impl From for QueryError { - fn from(timer_error: tokio::time::error::Elapsed) -> QueryError { - QueryError::RequestTimeout(format!("{}", timer_error)) - } -} - -impl From for NewSessionError { - fn from(io_error: std::io::Error) -> NewSessionError { - NewSessionError::IoError(Arc::new(io_error)) - } -} - -impl From for NewSessionError { - fn from(query_error: QueryError) -> NewSessionError { - match query_error { - QueryError::DbError(e, msg) => NewSessionError::DbError(e, msg), - QueryError::BadQuery(e) => NewSessionError::BadQuery(e), - QueryError::IoError(e) => NewSessionError::IoError(e), - QueryError::ProtocolError(m) => NewSessionError::ProtocolError(m), - QueryError::InvalidMessage(m) => NewSessionError::InvalidMessage(m), - QueryError::TimeoutError => NewSessionError::TimeoutError, - QueryError::TooManyOrphanedStreamIds(ids) => { - NewSessionError::TooManyOrphanedStreamIds(ids) - } - QueryError::UnableToAllocStreamId => NewSessionError::UnableToAllocStreamId, - QueryError::RequestTimeout(msg) => NewSessionError::RequestTimeout(msg), - QueryError::TranslationError(e) => NewSessionError::TranslationError(e), - } - } -} - -impl From for QueryError { - fn from(keyspace_err: BadKeyspaceName) -> QueryError { - QueryError::BadQuery(BadQuery::BadKeyspaceName(keyspace_err)) - } -} - -impl QueryError { - /// Checks if this error indicates that a chosen source port/address cannot be bound. - /// This is caused by one of the following: - /// - The source address is already used by another socket, - /// - The source address is reserved and the process does not have sufficient privileges to use it. - pub fn is_address_unavailable_for_use(&self) -> bool { - if let QueryError::IoError(io_error) = self { - match io_error.kind() { - ErrorKind::AddrInUse | ErrorKind::PermissionDenied => return true, - _ => {} - } - } - - false - } -} - impl From for OperationType { fn from(operation_type: u8) -> OperationType { match operation_type { @@ -549,8 +328,7 @@ impl WriteType { #[cfg(test)] mod tests { - use super::{DbError, QueryError, WriteType}; - use crate::frame::types::Consistency; + use super::WriteType; #[test] fn write_type_from_str() { @@ -571,38 +349,4 @@ mod tests { assert_eq!(write_type, *expected_write_type); } } - - // A test to check that displaying DbError and QueryError::DbError works as expected - // - displays error description - // - displays error parameters - // - displays error message - // - indented multiline strings don't cause whitespace gaps - #[test] - fn dberror_full_info() { - // Test that DbError::Unavailable is displayed correctly - let db_error = DbError::Unavailable { - consistency: Consistency::Three, - required: 3, - alive: 2, - }; - - let db_error_displayed: String = format!("{}", db_error); - - let mut expected_dberr_msg = - "Not enough nodes are alive to satisfy required consistency level ".to_string(); - expected_dberr_msg += "(consistency: Three, required: 3, alive: 2)"; - - assert_eq!(db_error_displayed, expected_dberr_msg); - - // Test that QueryError::DbError::(DbError::Unavailable) is displayed correctly - let query_error = - QueryError::DbError(db_error, "a message about unavailable error".to_string()); - let query_error_displayed: String = format!("{}", query_error); - - let mut expected_querr_msg = "Database returned an error: ".to_string(); - expected_querr_msg += &expected_dberr_msg; - expected_querr_msg += ", Error message: a message about unavailable error"; - - assert_eq!(query_error_displayed, expected_querr_msg); - } } diff --git a/scylla-cql/src/frame/response/error.rs b/scylla-cql/src/frame/response/error.rs index e99d5686d5..95b1f875d0 100644 --- a/scylla-cql/src/frame/response/error.rs +++ b/scylla-cql/src/frame/response/error.rs @@ -1,4 +1,4 @@ -use crate::errors::{DbError, OperationType, QueryError, WriteType}; +use crate::errors::{DbError, OperationType, WriteType}; use crate::frame::frame_errors::ParseError; use crate::frame::protocol_features::ProtocolFeatures; use crate::frame::types; @@ -81,12 +81,6 @@ impl Error { } } -impl From for QueryError { - fn from(error: Error) -> QueryError { - QueryError::DbError(error.error, error.reason) - } -} - #[cfg(test)] mod tests { use super::Error; diff --git a/scylla-cql/src/frame/response/mod.rs b/scylla-cql/src/frame/response/mod.rs index c8c4ec104d..923707d67e 100644 --- a/scylla-cql/src/frame/response/mod.rs +++ b/scylla-cql/src/frame/response/mod.rs @@ -5,7 +5,7 @@ pub mod event; pub mod result; pub mod supported; -use crate::{errors::QueryError, frame::frame_errors::ParseError}; +use crate::frame::frame_errors::ParseError; use num_enum::TryFromPrimitive; use crate::frame::protocol_features::ProtocolFeatures; @@ -63,9 +63,9 @@ impl Response { Ok(response) } - pub fn into_non_error_response(self) -> Result { + pub fn into_non_error_response(self) -> Result { Ok(match self { - Response::Error(err) => return Err(QueryError::from(err)), + Response::Error(err) => return Err(err), Response::Ready => NonErrorResponse::Ready, Response::Result(res) => NonErrorResponse::Result(res), Response::Authenticate(auth) => NonErrorResponse::Authenticate(auth), diff --git a/scylla/src/cluster/cluster.rs b/scylla/src/cluster/cluster.rs index 61a0b424e7..90411660e9 100644 --- a/scylla/src/cluster/cluster.rs +++ b/scylla/src/cluster/cluster.rs @@ -8,11 +8,11 @@ use crate::frame::value::ValueList; use crate::prepared_statement::TokenCalculationError; use crate::routing::{partitioner::PartitionerName, Token}; +use crate::execution::errors::{BadQuery, NewSessionError}; use arc_swap::ArcSwap; use futures::future::join_all; use futures::{future::RemoteHandle, FutureExt}; use itertools::Itertools; -use scylla_cql::errors::{BadQuery, NewSessionError}; use std::collections::HashMap; use std::net::SocketAddr; use std::sync::Arc; diff --git a/scylla/src/cluster/metadata.rs b/scylla/src/cluster/metadata.rs index be0a196b90..177c8c0372 100644 --- a/scylla/src/cluster/metadata.rs +++ b/scylla/src/cluster/metadata.rs @@ -7,12 +7,12 @@ use crate::routing::Token; use crate::statement::query::Query; use crate::utils::parse::{ParseErrorCause, ParseResult, ParserState}; +use crate::execution::errors::NewSessionError; use futures::future::{self, FutureExt}; use futures::stream::{self, StreamExt, TryStreamExt}; use futures::Stream; use rand::seq::SliceRandom; use rand::{thread_rng, Rng}; -use scylla_cql::errors::NewSessionError; use scylla_cql::frame::response::result::Row; use scylla_cql::frame::value::ValueList; use scylla_macros::FromRow; diff --git a/scylla/src/connection/connection.rs b/scylla/src/connection/connection.rs index 20dcba0d2d..51ceba30a2 100644 --- a/scylla/src/connection/connection.rs +++ b/scylla/src/connection/connection.rs @@ -1,7 +1,7 @@ +use crate::execution::errors::TranslationError; use async_trait::async_trait; use bytes::Bytes; use futures::{future::RemoteHandle, FutureExt}; -use scylla_cql::errors::TranslationError; use scylla_cql::frame::request::options::Options; use scylla_cql::frame::response::Error; use scylla_cql::frame::types::SerialConsistency; @@ -1832,8 +1832,8 @@ impl VerifiedKeyspaceName { #[cfg(test)] mod tests { + use crate::execution::errors::QueryError; use assert_matches::assert_matches; - use scylla_cql::errors::QueryError; use scylla_cql::frame::protocol_features::{ LWT_OPTIMIZATION_META_BIT_MASK_KEY, SCYLLA_LWT_ADD_METADATA_MARK_EXTENSION, }; diff --git a/scylla/src/execution/errors.rs b/scylla/src/execution/errors.rs index 999bab1395..196f74a8d5 100644 --- a/scylla/src/execution/errors.rs +++ b/scylla/src/execution/errors.rs @@ -1,3 +1,277 @@ -pub use scylla_cql::errors::{ - BadKeyspaceName, BadQuery, DbError, NewSessionError, QueryError, WriteType, -}; +//! This module contains various errors which can be returned by `scylla::Session` + +use std::io::ErrorKind; +use std::sync::Arc; + +pub use scylla_cql::errors::{DbError, OperationType, WriteType}; + +use scylla_cql::frame::frame_errors::{FrameError, ParseError}; +use scylla_cql::frame::response::Error as CqlError; +use scylla_cql::frame::value::SerializeValuesError; +use thiserror::Error; + +/// Error that occurred during query execution +#[derive(Error, Debug, Clone)] +pub enum QueryError { + /// Database sent a response containing some error with a message + #[error("Database returned an error: {0}, Error message: {1}")] + DbError(DbError, String), + + /// Caller passed an invalid query + #[error(transparent)] + BadQuery(#[from] BadQuery), + + /// Input/Output error has occurred, connection broken etc. + #[error("IO Error: {0}")] + IoError(Arc), + + /// Unexpected message received + #[error("Protocol Error: {0}")] + ProtocolError(&'static str), + + /// Invalid message received + #[error("Invalid message: {0}")] + InvalidMessage(String), + + /// Timeout error has occurred, function didn't complete in time. + #[error("Timeout Error")] + TimeoutError, + + #[error("Too many orphaned stream ids: {0}")] + TooManyOrphanedStreamIds(u16), + + #[error("Unable to allocate stream id")] + UnableToAllocStreamId, + + /// Client timeout occurred before any response arrived + #[error("Request timeout: {0}")] + RequestTimeout(String), + + /// Address translation failed + #[error("Address translation failed: {0}")] + TranslationError(#[from] TranslationError), +} + +/// Error that occurred during session creation +#[derive(Error, Debug, Clone)] +pub enum NewSessionError { + /// Failed to resolve hostname passed in Session creation + #[error("Couldn't resolve any hostname: {0:?}")] + FailedToResolveAnyHostname(Vec), + + /// List of known nodes passed to Session constructor is empty + /// There needs to be at least one node to connect to + #[error("Empty known nodes list")] + EmptyKnownNodesList, + + /// Database sent a response containing some error with a message + #[error("Database returned an error: {0}, Error message: {1}")] + DbError(DbError, String), + + /// Caller passed an invalid query + #[error(transparent)] + BadQuery(#[from] BadQuery), + + /// Input/Output error has occurred, connection broken etc. + #[error("IO Error: {0}")] + IoError(Arc), + + /// Unexpected message received + #[error("Protocol Error: {0}")] + ProtocolError(&'static str), + + /// Invalid message received + #[error("Invalid message: {0}")] + InvalidMessage(String), + + /// Timeout error has occurred, couldn't connect to node in time. + #[error("Timeout Error")] + TimeoutError, + + #[error("Too many orphaned stream ids: {0}")] + TooManyOrphanedStreamIds(u16), + + #[error("Unable to allocate stream id")] + UnableToAllocStreamId, + + /// Client timeout occurred before a response arrived for some query + /// during `Session` creation. + #[error("Client timeout: {0}")] + RequestTimeout(String), + + /// Address translation failed + #[error("Address translation failed: {0}")] + TranslationError(#[from] TranslationError), +} + +/// Error caused by failed address translation done before establishing connection +#[derive(Debug, Copy, Clone, Error)] +pub enum TranslationError { + #[error("No rule for address")] + NoRuleForAddress, + #[error("Invalid address in rule")] + InvalidAddressInRule, +} + +/// Error caused by caller creating an invalid query +#[derive(Error, Debug, Clone)] +#[error("Invalid query passed to Session")] +pub enum BadQuery { + /// Failed to serialize values passed to a query - values too big + #[error("Serializing values failed: {0} ")] + SerializeValuesError(#[from] SerializeValuesError), + + /// Serialized values are too long to compute partition key + #[error("Serialized values are too long to compute partition key! Length: {0}, Max allowed length: {1}")] + ValuesTooLongForKey(usize, usize), + + /// Passed invalid keyspace name to use + #[error("Passed invalid keyspace name to use: {0}")] + BadKeyspaceName(#[from] BadKeyspaceName), + + /// Other reasons of bad query + #[error("{0}")] + Other(String), +} + +/// Invalid keyspace name given to `Session::use_keyspace()` +#[derive(Debug, Error, Clone)] +pub enum BadKeyspaceName { + /// Keyspace name is empty + #[error("Keyspace name is empty")] + Empty, + + /// Keyspace name too long, must be up to 48 characters + #[error("Keyspace name too long, must be up to 48 characters, found {1} characters. Bad keyspace name: '{0}'")] + TooLong(String, usize), + + /// Illegal character - only alphanumeric and underscores allowed. + #[error("Illegal character found: '{1}', only alphanumeric and underscores allowed. Bad keyspace name: '{0}'")] + IllegalCharacter(String, char), +} + +impl From for QueryError { + fn from(io_error: std::io::Error) -> QueryError { + QueryError::IoError(Arc::new(io_error)) + } +} + +impl From for QueryError { + fn from(serialized_err: SerializeValuesError) -> QueryError { + QueryError::BadQuery(BadQuery::SerializeValuesError(serialized_err)) + } +} + +impl From for QueryError { + fn from(parse_error: ParseError) -> QueryError { + QueryError::InvalidMessage(format!("Error parsing message: {}", parse_error)) + } +} + +impl From for QueryError { + fn from(frame_error: FrameError) -> QueryError { + QueryError::InvalidMessage(format!("Frame error: {}", frame_error)) + } +} + +impl From for QueryError { + fn from(timer_error: tokio::time::error::Elapsed) -> QueryError { + QueryError::RequestTimeout(format!("{}", timer_error)) + } +} + +impl From for NewSessionError { + fn from(io_error: std::io::Error) -> NewSessionError { + NewSessionError::IoError(Arc::new(io_error)) + } +} + +impl From for NewSessionError { + fn from(query_error: QueryError) -> NewSessionError { + match query_error { + QueryError::DbError(e, msg) => NewSessionError::DbError(e, msg), + QueryError::BadQuery(e) => NewSessionError::BadQuery(e), + QueryError::IoError(e) => NewSessionError::IoError(e), + QueryError::ProtocolError(m) => NewSessionError::ProtocolError(m), + QueryError::InvalidMessage(m) => NewSessionError::InvalidMessage(m), + QueryError::TimeoutError => NewSessionError::TimeoutError, + QueryError::TooManyOrphanedStreamIds(ids) => { + NewSessionError::TooManyOrphanedStreamIds(ids) + } + QueryError::UnableToAllocStreamId => NewSessionError::UnableToAllocStreamId, + QueryError::RequestTimeout(msg) => NewSessionError::RequestTimeout(msg), + QueryError::TranslationError(e) => NewSessionError::TranslationError(e), + } + } +} + +impl From for QueryError { + fn from(keyspace_err: BadKeyspaceName) -> QueryError { + QueryError::BadQuery(BadQuery::BadKeyspaceName(keyspace_err)) + } +} + +impl QueryError { + /// Checks if this error indicates that a chosen source port/address cannot be bound. + /// This is caused by one of the following: + /// - The source address is already used by another socket, + /// - The source address is reserved and the process does not have sufficient privileges to use it. + pub fn is_address_unavailable_for_use(&self) -> bool { + if let QueryError::IoError(io_error) = self { + match io_error.kind() { + ErrorKind::AddrInUse | ErrorKind::PermissionDenied => return true, + _ => {} + } + } + + false + } +} + +impl From for QueryError { + fn from(error: CqlError) -> QueryError { + QueryError::DbError(error.error, error.reason) + } +} + +#[cfg(test)] +mod tests { + use super::DbError; + use crate::statement::Consistency; + + use super::QueryError; + + // A test to check that displaying DbError and QueryError::DbError works as expected + // - displays error description + // - displays error parameters + // - displays error message + // - indented multiline strings don't cause whitespace gaps + #[test] + fn dberror_full_info() { + // Test that DbError::Unavailable is displayed correctly + let db_error = DbError::Unavailable { + consistency: Consistency::Three, + required: 3, + alive: 2, + }; + + let db_error_displayed: String = format!("{}", db_error); + + let mut expected_dberr_msg = + "Not enough nodes are alive to satisfy required consistency level ".to_string(); + expected_dberr_msg += "(consistency: Three, required: 3, alive: 2)"; + + assert_eq!(db_error_displayed, expected_dberr_msg); + + // Test that QueryError::DbError::(DbError::Unavailable) is displayed correctly + let query_error = + QueryError::DbError(db_error, "a message about unavailable error".to_string()); + let query_error_displayed: String = format!("{}", query_error); + + let mut expected_querr_msg = "Database returned an error: ".to_string(); + expected_querr_msg += &expected_dberr_msg; + expected_querr_msg += ", Error message: a message about unavailable error"; + + assert_eq!(query_error_displayed, expected_querr_msg); + } +} diff --git a/scylla/src/execution/history.rs b/scylla/src/execution/history.rs index 7971afe4de..955f4f23cf 100644 --- a/scylla/src/execution/history.rs +++ b/scylla/src/execution/history.rs @@ -10,7 +10,7 @@ use std::{ use crate::execution::retries::RetryDecision; use chrono::{DateTime, Utc}; -use scylla_cql::errors::QueryError; +use crate::execution::errors::QueryError; use tracing::warn; /// Id of a single query, i.e. a single call to Session::query/execute/etc. @@ -464,12 +464,12 @@ mod tests { SpeculativeId, StructuredHistory, TimePoint, }; use crate::test_utils::create_new_session_builder; + use crate::{ + execution::errors::{DbError, QueryError}, + statement::Consistency, + }; use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, Utc}; use futures::StreamExt; - use scylla_cql::{ - errors::{DbError, QueryError}, - Consistency, - }; // Set a single time for all timestamps within StructuredHistory. // HistoryCollector sets the timestamp to current time which changes with each test. diff --git a/scylla/src/execution/iterator.rs b/scylla/src/execution/iterator.rs index f8d1e4cf04..33c8cd03ad 100644 --- a/scylla/src/execution/iterator.rs +++ b/scylla/src/execution/iterator.rs @@ -409,7 +409,8 @@ impl RowIterator { // A separate module is used here so that the parent module cannot construct // SendAttemptedProof directly. mod checked_channel_sender { - use scylla_cql::{errors::QueryError, frame::response::result::Rows}; + use crate::execution::errors::QueryError; + use scylla_cql::frame::response::result::Rows; use std::marker::PhantomData; use tokio::sync::mpsc; use uuid::Uuid; diff --git a/scylla/src/execution/load_balancing/default.rs b/scylla/src/execution/load_balancing/default.rs index 8c6fd618dd..cadd1b4321 100644 --- a/scylla/src/execution/load_balancing/default.rs +++ b/scylla/src/execution/load_balancing/default.rs @@ -3,13 +3,14 @@ pub use self::latency_awareness::LatencyAwarenessBuilder; use super::{FallbackPlan, LoadBalancingPolicy, NodeRef, RoutingInfo}; use crate::cluster::ClusterData; +use crate::execution::errors::QueryError; +use crate::statement::{Consistency, SerialConsistency}; use crate::{ cluster::locator::ReplicaSet, cluster::metadata::Strategy, cluster::Node, routing::Token, }; use itertools::{Either, Itertools}; use rand::{prelude::SliceRandom, thread_rng, Rng}; use rand_pcg::Pcg32; -use scylla_cql::{errors::QueryError, frame::types::SerialConsistency, Consistency}; use std::{fmt, sync::Arc, time::Duration}; use tracing::warn; @@ -2127,9 +2128,9 @@ mod tests { } mod latency_awareness { + use crate::execution::errors::{DbError, QueryError}; use futures::{future::RemoteHandle, FutureExt}; use itertools::Either; - use scylla_cql::errors::{DbError, QueryError}; use tracing::{instrument::WithSubscriber, trace}; use uuid::Uuid; diff --git a/scylla/src/execution/load_balancing/mod.rs b/scylla/src/execution/load_balancing/mod.rs index 92221b10b3..a21d4f8588 100644 --- a/scylla/src/execution/load_balancing/mod.rs +++ b/scylla/src/execution/load_balancing/mod.rs @@ -3,8 +3,9 @@ //! See [the book](https://rust-driver.docs.scylladb.com/stable/load-balancing/load-balancing.html) for more information use crate::cluster::{ClusterData, NodeRef}; +use crate::execution::errors::QueryError; use crate::routing::Token; -use scylla_cql::{errors::QueryError, frame::types}; +use scylla_cql::frame::types; use std::time::Duration; diff --git a/scylla/src/execution/retries/downgrading_consistency_rp.rs b/scylla/src/execution/retries/downgrading_consistency_rp.rs index 37ee05e7ed..a94343a21a 100644 --- a/scylla/src/execution/retries/downgrading_consistency_rp.rs +++ b/scylla/src/execution/retries/downgrading_consistency_rp.rs @@ -1,6 +1,6 @@ -use scylla_cql::{ - errors::{DbError, QueryError, WriteType}, - Consistency, +use crate::{ + execution::errors::{DbError, QueryError, WriteType}, + statement::Consistency, }; use tracing::debug; @@ -183,8 +183,8 @@ impl RetrySession for DowngradingConsistencyRetrySession { mod tests { use std::{io::ErrorKind, sync::Arc}; + use crate::execution::errors::BadQuery; use bytes::Bytes; - use scylla_cql::errors::BadQuery; use super::*; diff --git a/scylla/src/session/session.rs b/scylla/src/session/session.rs index dd05c411cf..664c9968eb 100644 --- a/scylla/src/session/session.rs +++ b/scylla/src/session/session.rs @@ -12,7 +12,6 @@ use bytes::Bytes; use futures::future::join_all; use futures::future::try_join_all; use itertools::{Either, Itertools}; -pub use scylla_cql::errors::TranslationError; use scylla_cql::frame::response::result::{deser_cql_value, ColumnSpec, Rows}; use scylla_cql::frame::response::NonErrorResponse; use std::borrow::Borrow; diff --git a/scylla/src/statement/prepared_statement.rs b/scylla/src/statement/prepared_statement.rs index 0b30db4332..1d828d7537 100644 --- a/scylla/src/statement/prepared_statement.rs +++ b/scylla/src/statement/prepared_statement.rs @@ -1,5 +1,5 @@ +use crate::execution::errors::{BadQuery, QueryError}; use bytes::{Bytes, BytesMut}; -use scylla_cql::errors::{BadQuery, QueryError}; use smallvec::{smallvec, SmallVec}; use std::convert::TryInto; use std::sync::Arc; diff --git a/scylla/src/tests/session_test.rs b/scylla/src/tests/session_test.rs index 075920dd8f..00af58e3fc 100644 --- a/scylla/src/tests/session_test.rs +++ b/scylla/src/tests/session_test.rs @@ -2398,7 +2398,7 @@ async fn test_rate_limit_exceeded_exception() { } } - use scylla_cql::errors::OperationType; + use crate::execution::errors::OperationType; match maybe_err.expect("Rate limit error didn't occur") { QueryError::DbError(DbError::RateLimitReached { op_type, .. }, _) => { diff --git a/scylla/tests/integration/execution_profiles.rs b/scylla/tests/integration/execution_profiles.rs index 9b52fc5b7a..3fe66b8fea 100644 --- a/scylla/tests/integration/execution_profiles.rs +++ b/scylla/tests/integration/execution_profiles.rs @@ -72,7 +72,7 @@ impl LoadBalancingPolicy for BoundToPredefinedNodePolicy { _query: &RoutingInfo, _latency: std::time::Duration, _node: NodeRef<'_>, - _error: &scylla_cql::errors::QueryError, + _error: &scylla::execution::errors::QueryError, ) { } diff --git a/scylla/tests/integration/new_session.rs b/scylla/tests/integration/new_session.rs index fc6490bb07..269ffb4200 100644 --- a/scylla/tests/integration/new_session.rs +++ b/scylla/tests/integration/new_session.rs @@ -1,6 +1,6 @@ use assert_matches::assert_matches; +use scylla::execution::errors::NewSessionError; use scylla::SessionBuilder; -use scylla_cql::errors::NewSessionError; #[cfg(not(scylla_cloud_tests))] #[tokio::test] diff --git a/scylla/tests/integration/utils.rs b/scylla/tests/integration/utils.rs index 5baaba0327..43bb9677e9 100644 --- a/scylla/tests/integration/utils.rs +++ b/scylla/tests/integration/utils.rs @@ -57,7 +57,7 @@ impl LoadBalancingPolicy for FixedOrderLoadBalancer { _: &scylla::load_balancing::RoutingInfo, _: std::time::Duration, _: scylla::cluster::NodeRef<'_>, - _: &scylla_cql::errors::QueryError, + _: &scylla::execution::errors::QueryError, ) { } From 58cd7ed485cf85d0cf4676f2d494cfe9d9b9adf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 11:13:42 +0200 Subject: [PATCH 26/43] extract driver_tracing.rs with RequestSpan --- scylla/src/execution/driver_tracing.rs | 182 +++++++++++++++++++++++++ scylla/src/execution/iterator.rs | 2 +- scylla/src/execution/mod.rs | 1 + scylla/src/session/session.rs | 171 +---------------------- 4 files changed, 186 insertions(+), 170 deletions(-) create mode 100644 scylla/src/execution/driver_tracing.rs diff --git a/scylla/src/execution/driver_tracing.rs b/scylla/src/execution/driver_tracing.rs new file mode 100644 index 0000000000..4144b2a05c --- /dev/null +++ b/scylla/src/execution/driver_tracing.rs @@ -0,0 +1,182 @@ +use std::{ + borrow::Borrow, + fmt::Display, + sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }, +}; + +use itertools::Either; +use scylla_cql::frame::response::result::{deser_cql_value, ColumnSpec, Rows}; +use tracing::trace_span; + +use crate::{ + cluster::Node, + connection::Connection, + routing::Token, + utils::pretty::{CommaSeparatedDisplayer, CqlValueDisplayer}, + QueryResult, +}; + +pub(crate) struct RequestSpan { + span: tracing::Span, + speculative_executions: AtomicUsize, +} + +impl RequestSpan { + pub(crate) fn new_query(contents: &str, request_size: usize) -> Self { + use tracing::field::Empty; + + let span = trace_span!( + "Request", + kind = "unprepared", + contents = contents, + // + request_size = request_size, + result_size = Empty, + result_rows = Empty, + replicas = Empty, + shard = Empty, + speculative_executions = Empty, + ); + + Self { + span, + speculative_executions: 0.into(), + } + } + + pub(crate) fn new_prepared<'ps>( + partition_key: Option + Clone>, + token: Option, + request_size: usize, + ) -> Self { + use tracing::field::Empty; + + let span = trace_span!( + "Request", + kind = "prepared", + partition_key = Empty, + token = Empty, + // + request_size = request_size, + result_size = Empty, + result_rows = Empty, + replicas = Empty, + shard = Empty, + speculative_executions = Empty, + ); + + if let Some(partition_key) = partition_key { + span.record( + "partition_key", + tracing::field::display( + format_args!("{}", partition_key_displayer(partition_key),), + ), + ); + } + if let Some(token) = token { + span.record("token", token.value); + } + + Self { + span, + speculative_executions: 0.into(), + } + } + + pub(crate) fn new_batch() -> Self { + use tracing::field::Empty; + + let span = trace_span!( + "Request", + kind = "batch", + // + request_size = Empty, + result_size = Empty, + result_rows = Empty, + replicas = Empty, + shard = Empty, + speculative_executions = Empty, + ); + + Self { + span, + speculative_executions: 0.into(), + } + } + + pub(crate) fn record_shard_id(&self, conn: &Connection) { + if let Some(info) = conn.get_shard_info() { + self.span.record("shard", info.shard); + } + } + + pub(crate) fn record_result_fields(&self, result: &QueryResult) { + self.span.record("result_size", result.serialized_size); + if let Some(rows) = result.rows.as_ref() { + self.span.record("result_rows", rows.len()); + } + } + + pub(crate) fn record_rows_fields(&self, rows: &Rows) { + self.span.record("result_size", rows.serialized_size); + self.span.record("result_rows", rows.rows.len()); + } + + pub(crate) fn record_replicas<'a>(&'a self, replicas: &'a [impl Borrow>]) { + struct ReplicaIps<'a, N>(&'a [N]); + impl<'a, N> Display for ReplicaIps<'a, N> + where + N: Borrow>, + { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let mut nodes = self.0.iter(); + if let Some(node) = nodes.next() { + write!(f, "{}", node.borrow().address.ip())?; + + for node in nodes { + write!(f, ",{}", node.borrow().address.ip())?; + } + } + Ok(()) + } + } + self.span + .record("replicas", tracing::field::display(&ReplicaIps(replicas))); + } + + pub(crate) fn inc_speculative_executions(&self) { + self.speculative_executions.fetch_add(1, Ordering::Relaxed); + } + + pub(crate) fn span(&self) -> &tracing::Span { + &self.span + } +} + +impl Drop for RequestSpan { + fn drop(&mut self) { + self.span.record( + "speculative_executions", + self.speculative_executions.load(Ordering::Relaxed), + ); + } +} + +fn partition_key_displayer<'ps, 'res>( + mut pk_values_iter: impl Iterator + 'res + Clone, +) -> impl Display + 'res { + CommaSeparatedDisplayer( + std::iter::from_fn(move || { + pk_values_iter + .next() + .map(|(mut cell, spec)| deser_cql_value(&spec.typ, &mut cell)) + }) + .map(|c| match c { + Ok(c) => Either::Left(CqlValueDisplayer(c)), + Err(_) => Either::Right(""), + }), + ) +} diff --git a/scylla/src/execution/iterator.rs b/scylla/src/execution/iterator.rs index 33c8cd03ad..64026c7063 100644 --- a/scylla/src/execution/iterator.rs +++ b/scylla/src/execution/iterator.rs @@ -18,9 +18,9 @@ use tokio::sync::mpsc; use tracing::instrument::WithSubscriber; use crate::cql_to_rust::{FromRow, FromRowError}; +use crate::execution::driver_tracing::RequestSpan; use crate::execution::errors::QueryError; use crate::execution::ExecutionProfileInner; -use crate::session::RequestSpan; use crate::cluster::ClusterData; use crate::cluster::{Node, NodeRef}; diff --git a/scylla/src/execution/mod.rs b/scylla/src/execution/mod.rs index c0b1458eec..5435b959fe 100644 --- a/scylla/src/execution/mod.rs +++ b/scylla/src/execution/mod.rs @@ -1,3 +1,4 @@ +pub(crate) mod driver_tracing; pub mod errors; mod execution_profile; pub mod history; diff --git a/scylla/src/session/session.rs b/scylla/src/session/session.rs index 664c9968eb..7e84274e05 100644 --- a/scylla/src/session/session.rs +++ b/scylla/src/session/session.rs @@ -4,23 +4,19 @@ #[cfg(feature = "cloud")] use crate::cloud::CloudConfig; +use crate::execution::driver_tracing::RequestSpan; use crate::execution::history::{self, HistoryListener}; -use crate::utils::pretty::{CommaSeparatedDisplayer, CqlValueDisplayer}; use crate::utils::unzip_option; use arc_swap::ArcSwapOption; use bytes::Bytes; use futures::future::join_all; use futures::future::try_join_all; -use itertools::{Either, Itertools}; -use scylla_cql::frame::response::result::{deser_cql_value, ColumnSpec, Rows}; +use itertools::Itertools; use scylla_cql::frame::response::NonErrorResponse; use std::borrow::Borrow; -use std::fmt::Display; use std::future::Future; use std::net::SocketAddr; use std::num::NonZeroU32; -use std::sync::atomic::AtomicUsize; -use std::sync::atomic::Ordering; use std::sync::Arc; use std::time::Duration; use tokio::time::timeout; @@ -59,7 +55,6 @@ use crate::frame::value::{ use crate::prepared_statement::PreparedStatement; use crate::query::Query; use crate::routing::partitioner::PartitionerName; -use crate::routing::Token; use crate::statement::Consistency; use crate::transport::query_result::QueryResult; use crate::transport::Compression; @@ -1815,165 +1810,3 @@ impl<'a> ExecuteQueryContext<'a> { .log_attempt_error(*attempt_id, error, retry_decision); } } - -pub(crate) struct RequestSpan { - span: tracing::Span, - speculative_executions: AtomicUsize, -} - -impl RequestSpan { - pub(crate) fn new_query(contents: &str, request_size: usize) -> Self { - use tracing::field::Empty; - - let span = trace_span!( - "Request", - kind = "unprepared", - contents = contents, - // - request_size = request_size, - result_size = Empty, - result_rows = Empty, - replicas = Empty, - shard = Empty, - speculative_executions = Empty, - ); - - Self { - span, - speculative_executions: 0.into(), - } - } - - pub(crate) fn new_prepared<'ps>( - partition_key: Option + Clone>, - token: Option, - request_size: usize, - ) -> Self { - use tracing::field::Empty; - - let span = trace_span!( - "Request", - kind = "prepared", - partition_key = Empty, - token = Empty, - // - request_size = request_size, - result_size = Empty, - result_rows = Empty, - replicas = Empty, - shard = Empty, - speculative_executions = Empty, - ); - - if let Some(partition_key) = partition_key { - span.record( - "partition_key", - tracing::field::display( - format_args!("{}", partition_key_displayer(partition_key),), - ), - ); - } - if let Some(token) = token { - span.record("token", token.value); - } - - Self { - span, - speculative_executions: 0.into(), - } - } - - pub(crate) fn new_batch() -> Self { - use tracing::field::Empty; - - let span = trace_span!( - "Request", - kind = "batch", - // - request_size = Empty, - result_size = Empty, - result_rows = Empty, - replicas = Empty, - shard = Empty, - speculative_executions = Empty, - ); - - Self { - span, - speculative_executions: 0.into(), - } - } - - pub(crate) fn record_shard_id(&self, conn: &Connection) { - if let Some(info) = conn.get_shard_info() { - self.span.record("shard", info.shard); - } - } - - pub(crate) fn record_result_fields(&self, result: &QueryResult) { - self.span.record("result_size", result.serialized_size); - if let Some(rows) = result.rows.as_ref() { - self.span.record("result_rows", rows.len()); - } - } - - pub(crate) fn record_rows_fields(&self, rows: &Rows) { - self.span.record("result_size", rows.serialized_size); - self.span.record("result_rows", rows.rows.len()); - } - - pub(crate) fn record_replicas<'a>(&'a self, replicas: &'a [impl Borrow>]) { - struct ReplicaIps<'a, N>(&'a [N]); - impl<'a, N> Display for ReplicaIps<'a, N> - where - N: Borrow>, - { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let mut nodes = self.0.iter(); - if let Some(node) = nodes.next() { - write!(f, "{}", node.borrow().address.ip())?; - - for node in nodes { - write!(f, ",{}", node.borrow().address.ip())?; - } - } - Ok(()) - } - } - self.span - .record("replicas", tracing::field::display(&ReplicaIps(replicas))); - } - - pub(crate) fn inc_speculative_executions(&self) { - self.speculative_executions.fetch_add(1, Ordering::Relaxed); - } - - pub(crate) fn span(&self) -> &tracing::Span { - &self.span - } -} - -impl Drop for RequestSpan { - fn drop(&mut self) { - self.span.record( - "speculative_executions", - self.speculative_executions.load(Ordering::Relaxed), - ); - } -} - -fn partition_key_displayer<'ps, 'res>( - mut pk_values_iter: impl Iterator + 'res + Clone, -) -> impl Display + 'res { - CommaSeparatedDisplayer( - std::iter::from_fn(move || { - pk_values_iter - .next() - .map(|(mut cell, spec)| deser_cql_value(&spec.typ, &mut cell)) - }) - .map(|c| match c { - Ok(c) => Either::Left(CqlValueDisplayer(c)), - Err(_) => Either::Right(""), - }), - ) -} From fc9f57fdd4c788fcbd8305953aeabdbb15c4f358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 11:18:42 +0200 Subject: [PATCH 27/43] move IntoTypedRows & TypedRowsIter to query_result --- examples/basic.rs | 2 +- examples/cql-time-types.rs | 2 +- examples/schema_agreement.rs | 2 +- examples/tls.rs | 2 +- scylla/src/connection/connection.rs | 2 +- scylla/src/lib.rs | 4 +-- scylla/src/session/session.rs | 36 ++---------------------- scylla/src/tests/cql_collections_test.rs | 3 +- scylla/src/tests/cql_types_test.rs | 2 +- scylla/src/tests/session_test.rs | 3 +- scylla/src/transport/query_result.rs | 35 ++++++++++++++++++++++- 11 files changed, 48 insertions(+), 45 deletions(-) diff --git a/examples/basic.rs b/examples/basic.rs index ea5fb277f5..848153fdfa 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -1,7 +1,7 @@ use anyhow::Result; use scylla::macros::FromRow; -use scylla::session::{IntoTypedRows, Session}; use scylla::SessionBuilder; +use scylla::{session::Session, IntoTypedRows}; use std::env; #[tokio::main] diff --git a/examples/cql-time-types.rs b/examples/cql-time-types.rs index 9d705f49ac..eb68838d00 100644 --- a/examples/cql-time-types.rs +++ b/examples/cql-time-types.rs @@ -5,8 +5,8 @@ use anyhow::Result; use chrono::{Duration, NaiveDate}; use scylla::frame::response::result::CqlValue; use scylla::frame::value::{Date, Time, Timestamp}; -use scylla::session::{IntoTypedRows, Session}; use scylla::SessionBuilder; +use scylla::{IntoTypedRows, Session}; use std::env; #[tokio::main] diff --git a/examples/schema_agreement.rs b/examples/schema_agreement.rs index 1868b8e7b8..cfa17f451e 100644 --- a/examples/schema_agreement.rs +++ b/examples/schema_agreement.rs @@ -1,7 +1,7 @@ use anyhow::{bail, Result}; use scylla::execution::errors::QueryError; -use scylla::session::{IntoTypedRows, Session}; use scylla::SessionBuilder; +use scylla::{IntoTypedRows, Session}; use std::env; use std::time::Duration; diff --git a/examples/tls.rs b/examples/tls.rs index 1f9b49ce90..b7e0c1b7b7 100644 --- a/examples/tls.rs +++ b/examples/tls.rs @@ -1,6 +1,6 @@ use anyhow::Result; -use scylla::session::{IntoTypedRows, Session}; use scylla::SessionBuilder; +use scylla::{IntoTypedRows, Session}; use std::env; use std::fs; use std::path::PathBuf; diff --git a/scylla/src/connection/connection.rs b/scylla/src/connection/connection.rs index 51ceba30a2..2fe2fd5fc2 100644 --- a/scylla/src/connection/connection.rs +++ b/scylla/src/connection/connection.rs @@ -58,9 +58,9 @@ use crate::frame::{ }; use crate::query::Query; use crate::routing::sharding::{Shard, ShardInfo, Sharder}; -use crate::session::IntoTypedRows; use crate::statement::prepared_statement::PreparedStatement; use crate::statement::Consistency; +use crate::transport::query_result::IntoTypedRows; use crate::transport::Compression; use crate::QueryResult; diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index c1c0cc304b..8b1c10faf4 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -133,8 +133,8 @@ pub use frame::response::cql_to_rust::FromRow; pub use execution::ExecutionProfile; pub use session::CachingSession; pub use session::SessionBuilder; -pub use session::{IntoTypedRows, Session, SessionConfig}; -pub use transport::query_result::QueryResult; +pub use session::{Session, SessionConfig}; +pub use transport::query_result::{IntoTypedRows, QueryResult}; #[cfg(feature = "cloud")] pub use session::CloudSessionBuilder; diff --git a/scylla/src/session/session.rs b/scylla/src/session/session.rs index 7e84274e05..bbc2275997 100644 --- a/scylla/src/session/session.rs +++ b/scylla/src/session/session.rs @@ -3,6 +3,7 @@ #[cfg(feature = "cloud")] use crate::cloud::CloudConfig; +use crate::IntoTypedRows; use crate::execution::driver_tracing::RequestSpan; use crate::execution::history::{self, HistoryListener}; @@ -35,7 +36,7 @@ use crate::connection::SslConfig; use crate::connection::{ AddressTranslator, Connection, ConnectionConfig, NonErrorQueryResponse, VerifiedKeyspaceName, }; -use crate::cql_to_rust::FromRow; + use crate::execution::errors::{NewSessionError, QueryError}; use crate::execution::iterator::{PreparedIteratorConfig, RowIterator}; use crate::execution::load_balancing::{self, RoutingInfo}; @@ -47,7 +48,6 @@ use crate::execution::Metrics; use crate::execution::{ speculative_execution, ExecutionProfile, ExecutionProfileHandle, ExecutionProfileInner, }; -use crate::frame::response::cql_to_rust::FromRowError; use crate::frame::response::result; use crate::frame::value::{ BatchValues, BatchValuesFirstSerialized, BatchValuesIterator, ValueList, @@ -338,38 +338,6 @@ impl Default for SessionConfig { } } -/// Trait used to implement `Vec::into_typed` -// This is the only way to add custom method to Vec -pub trait IntoTypedRows { - fn into_typed(self) -> TypedRowIter; -} - -// Adds method Vec::into_typed(self) -// It transforms the Vec into iterator mapping to custom row type -impl IntoTypedRows for Vec { - fn into_typed(self) -> TypedRowIter { - TypedRowIter { - row_iter: self.into_iter(), - phantom_data: Default::default(), - } - } -} - -/// Iterator over rows parsed as the given type\ -/// Returned by `rows.into_typed::<(...)>()` -pub struct TypedRowIter { - row_iter: std::vec::IntoIter, - phantom_data: std::marker::PhantomData, -} - -impl Iterator for TypedRowIter { - type Item = Result; - - fn next(&mut self) -> Option { - self.row_iter.next().map(RowT::from_row) - } -} - pub(crate) enum RunQueryResult { IgnoredWriteError, Completed(ResT), diff --git a/scylla/src/tests/cql_collections_test.rs b/scylla/src/tests/cql_collections_test.rs index cd89443271..a70da29d38 100644 --- a/scylla/src/tests/cql_collections_test.rs +++ b/scylla/src/tests/cql_collections_test.rs @@ -2,7 +2,8 @@ use crate::cql_to_rust::FromCqlVal; use crate::frame::value::Value; use crate::test_utils::create_new_session_builder; use crate::utils::test_utils::unique_keyspace_name; -use crate::{frame::response::result::CqlValue, IntoTypedRows, Session}; +use crate::IntoTypedRows; +use crate::{frame::response::result::CqlValue, Session}; use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; async fn connect() -> Session { diff --git a/scylla/src/tests/cql_types_test.rs b/scylla/src/tests/cql_types_test.rs index 7486ce0054..1816ad2d9e 100644 --- a/scylla/src/tests/cql_types_test.rs +++ b/scylla/src/tests/cql_types_test.rs @@ -5,9 +5,9 @@ use crate::frame::value::Counter; use crate::frame::value::Value; use crate::frame::value::{Date, Time, Timestamp}; use crate::macros::{FromUserType, IntoUserType}; -use crate::session::IntoTypedRows; use crate::session::Session; use crate::test_utils::create_new_session_builder; +use crate::transport::query_result::IntoTypedRows; use crate::utils::test_utils::unique_keyspace_name; use bigdecimal::BigDecimal; use chrono::{Duration, NaiveDate}; diff --git a/scylla/src/tests/session_test.rs b/scylla/src/tests/session_test.rs index 00af58e3fc..3fe9d4e4d7 100644 --- a/scylla/src/tests/session_test.rs +++ b/scylla/src/tests/session_test.rs @@ -15,13 +15,14 @@ use crate::routing::partitioner::{ }; use crate::routing::Token; use crate::statement::Consistency; +use crate::transport::query_result::IntoTypedRows; use crate::utils::test_utils::{ create_new_session_builder, supports_feature, unique_keyspace_name, }; use crate::CachingSession; use crate::ExecutionProfile; use crate::QueryResult; -use crate::{IntoTypedRows, Session, SessionBuilder}; +use crate::{Session, SessionBuilder}; use assert_matches::assert_matches; use bytes::Bytes; use futures::{FutureExt, StreamExt, TryStreamExt}; diff --git a/scylla/src/transport/query_result.rs b/scylla/src/transport/query_result.rs index 6773b254d6..0098d24fc7 100644 --- a/scylla/src/transport/query_result.rs +++ b/scylla/src/transport/query_result.rs @@ -1,8 +1,9 @@ use crate::frame::response::cql_to_rust::{FromRow, FromRowError}; use crate::frame::response::result::ColumnSpec; use crate::frame::response::result::Row; -use crate::session::{IntoTypedRows, TypedRowIter}; + use bytes::Bytes; +use scylla_cql::frame::response::result; use thiserror::Error; use uuid::Uuid; @@ -258,6 +259,38 @@ impl From for SingleRowTypedError { } } +/// Trait used to implement `Vec::into_typed` +// This is the only way to add custom method to Vec +pub trait IntoTypedRows { + fn into_typed(self) -> TypedRowIter; +} + +// Adds method Vec::into_typed(self) +// It transforms the Vec into iterator mapping to custom row type +impl IntoTypedRows for Vec { + fn into_typed(self) -> TypedRowIter { + TypedRowIter { + row_iter: self.into_iter(), + phantom_data: Default::default(), + } + } +} + +/// Iterator over rows parsed as the given type\ +/// Returned by `rows.into_typed::<(...)>()` +pub struct TypedRowIter { + row_iter: std::vec::IntoIter, + phantom_data: std::marker::PhantomData, +} + +impl Iterator for TypedRowIter { + type Item = Result; + + fn next(&mut self) -> Option { + self.row_iter.next().map(RowT::from_row) + } +} + #[cfg(test)] mod tests { use super::*; From 71efe6285cdfcb0c5aeb1f9d77c71ac884833052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 11:25:39 +0200 Subject: [PATCH 28/43] extract response mod, move QueryResponse there --- scylla/src/connection/connection.rs | 71 +------------------------- scylla/src/connection/mod.rs | 4 +- scylla/src/execution/iterator.rs | 3 +- scylla/src/lib.rs | 1 + scylla/src/response/mod.rs | 2 + scylla/src/response/query_response.rs | 73 +++++++++++++++++++++++++++ scylla/src/session/session.rs | 6 +-- 7 files changed, 83 insertions(+), 77 deletions(-) create mode 100644 scylla/src/response/mod.rs create mode 100644 scylla/src/response/query_response.rs diff --git a/scylla/src/connection/connection.rs b/scylla/src/connection/connection.rs index 2fe2fd5fc2..1137efb2af 100644 --- a/scylla/src/connection/connection.rs +++ b/scylla/src/connection/connection.rs @@ -1,4 +1,5 @@ use crate::execution::errors::TranslationError; +use crate::response::QueryResponse; use async_trait::async_trait; use bytes::Bytes; use futures::{future::RemoteHandle, FutureExt}; @@ -51,7 +52,7 @@ use crate::frame::protocol_features::ProtocolFeatures; use crate::frame::{ self, request::{self, batch, execute, query, register, SerializableRequest}, - response::{event::Event, result, NonErrorResponse, Response, ResponseOpcode}, + response::{event::Event, result, Response, ResponseOpcode}, server_event_type::EventType, value::{BatchValues, ValueList}, FrameParams, SerializedRequest, @@ -211,74 +212,6 @@ struct TaskResponse { body: Bytes, } -pub(crate) struct QueryResponse { - pub(crate) response: Response, - pub(crate) tracing_id: Option, - pub(crate) warnings: Vec, -} - -// A QueryResponse in which response can not be Response::Error -pub(crate) struct NonErrorQueryResponse { - pub(crate) response: NonErrorResponse, - pub(crate) tracing_id: Option, - pub(crate) warnings: Vec, -} - -impl QueryResponse { - pub(crate) fn into_non_error_query_response(self) -> Result { - Ok(NonErrorQueryResponse { - response: self.response.into_non_error_response()?, - tracing_id: self.tracing_id, - warnings: self.warnings, - }) - } - - pub(crate) fn into_query_result(self) -> Result { - self.into_non_error_query_response()?.into_query_result() - } -} - -impl NonErrorQueryResponse { - pub(crate) fn as_set_keyspace(&self) -> Option<&result::SetKeyspace> { - match &self.response { - NonErrorResponse::Result(result::Result::SetKeyspace(sk)) => Some(sk), - _ => None, - } - } - - pub(crate) fn as_schema_change(&self) -> Option<&result::SchemaChange> { - match &self.response { - NonErrorResponse::Result(result::Result::SchemaChange(sc)) => Some(sc), - _ => None, - } - } - - pub(crate) fn into_query_result(self) -> Result { - let (rows, paging_state, col_specs, serialized_size) = match self.response { - NonErrorResponse::Result(result::Result::Rows(rs)) => ( - Some(rs.rows), - rs.metadata.paging_state, - rs.metadata.col_specs, - rs.serialized_size, - ), - NonErrorResponse::Result(_) => (None, None, vec![], 0), - _ => { - return Err(QueryError::ProtocolError( - "Unexpected server response, expected Result or Error", - )) - } - }; - - Ok(QueryResult { - rows, - warnings: self.warnings, - tracing_id: self.tracing_id, - paging_state, - col_specs, - serialized_size, - }) - } -} #[cfg(feature = "ssl")] mod ssl_config { use openssl::{ diff --git a/scylla/src/connection/mod.rs b/scylla/src/connection/mod.rs index d43f17e977..583c069684 100644 --- a/scylla/src/connection/mod.rs +++ b/scylla/src/connection/mod.rs @@ -5,9 +5,7 @@ use connection::ErrorReceiver; #[cfg(feature = "ssl")] pub(crate) use connection::SslConfig; pub use connection::{AddressTranslator, ConnectionConfig}; -pub(crate) use connection::{ - Connection, NonErrorQueryResponse, QueryResponse, VerifiedKeyspaceName, -}; +pub(crate) use connection::{Connection, VerifiedKeyspaceName}; pub use connection_pool::PoolSize; pub(crate) use connection_pool::{NodeConnectionPool, PoolConfig}; diff --git a/scylla/src/execution/iterator.rs b/scylla/src/execution/iterator.rs index 64026c7063..8a26b7411d 100644 --- a/scylla/src/execution/iterator.rs +++ b/scylla/src/execution/iterator.rs @@ -24,7 +24,7 @@ use crate::execution::ExecutionProfileInner; use crate::cluster::ClusterData; use crate::cluster::{Node, NodeRef}; -use crate::connection::{Connection, NonErrorQueryResponse, QueryResponse}; +use crate::connection::Connection; use crate::execution::history::{self, HistoryListener}; use crate::execution::load_balancing::{self, RoutingInfo}; use crate::execution::retries::{QueryInfo, RetryDecision, RetrySession}; @@ -36,6 +36,7 @@ use crate::frame::{ }, value::SerializedValues, }; +use crate::response::{NonErrorQueryResponse, QueryResponse}; use crate::statement::Consistency; use crate::statement::{prepared_statement::PreparedStatement, query::Query}; use crate::utils::unzip_option; diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index 8b1c10faf4..fac3cd00a4 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -108,6 +108,7 @@ pub mod cloud; pub mod cluster; pub mod connection; pub mod execution; +pub mod response; pub mod routing; pub mod session; pub mod statement; diff --git a/scylla/src/response/mod.rs b/scylla/src/response/mod.rs new file mode 100644 index 0000000000..845151be93 --- /dev/null +++ b/scylla/src/response/mod.rs @@ -0,0 +1,2 @@ +mod query_response; +pub(crate) use query_response::{NonErrorQueryResponse, QueryResponse}; diff --git a/scylla/src/response/query_response.rs b/scylla/src/response/query_response.rs new file mode 100644 index 0000000000..fa0866eafa --- /dev/null +++ b/scylla/src/response/query_response.rs @@ -0,0 +1,73 @@ +use scylla_cql::frame::response::{result, NonErrorResponse, Response}; +use uuid::Uuid; + +use crate::{execution::errors::QueryError, QueryResult}; + +pub(crate) struct QueryResponse { + pub(crate) response: Response, + pub(crate) tracing_id: Option, + pub(crate) warnings: Vec, +} + +// A QueryResponse in which response can not be Response::Error +pub(crate) struct NonErrorQueryResponse { + pub(crate) response: NonErrorResponse, + pub(crate) tracing_id: Option, + pub(crate) warnings: Vec, +} + +impl QueryResponse { + pub(crate) fn into_non_error_query_response(self) -> Result { + Ok(NonErrorQueryResponse { + response: self.response.into_non_error_response()?, + tracing_id: self.tracing_id, + warnings: self.warnings, + }) + } + + pub(crate) fn into_query_result(self) -> Result { + self.into_non_error_query_response()?.into_query_result() + } +} + +impl NonErrorQueryResponse { + pub(crate) fn as_set_keyspace(&self) -> Option<&result::SetKeyspace> { + match &self.response { + NonErrorResponse::Result(result::Result::SetKeyspace(sk)) => Some(sk), + _ => None, + } + } + + pub(crate) fn as_schema_change(&self) -> Option<&result::SchemaChange> { + match &self.response { + NonErrorResponse::Result(result::Result::SchemaChange(sc)) => Some(sc), + _ => None, + } + } + + pub(crate) fn into_query_result(self) -> Result { + let (rows, paging_state, col_specs, serialized_size) = match self.response { + NonErrorResponse::Result(result::Result::Rows(rs)) => ( + Some(rs.rows), + rs.metadata.paging_state, + rs.metadata.col_specs, + rs.serialized_size, + ), + NonErrorResponse::Result(_) => (None, None, vec![], 0), + _ => { + return Err(QueryError::ProtocolError( + "Unexpected server response, expected Result or Error", + )) + } + }; + + Ok(QueryResult { + rows, + warnings: self.warnings, + tracing_id: self.tracing_id, + paging_state, + col_specs, + serialized_size, + }) + } +} diff --git a/scylla/src/session/session.rs b/scylla/src/session/session.rs index bbc2275997..ca6bb3799e 100644 --- a/scylla/src/session/session.rs +++ b/scylla/src/session/session.rs @@ -30,12 +30,10 @@ use crate::cluster::CloudEndpoint; use crate::cluster::{Cluster, ClusterData, ClusterNeatDebug}; use crate::cluster::{KnownNode, Node, NodeRef}; use crate::connection::PoolConfig; -use crate::connection::QueryResponse; #[cfg(feature = "ssl")] use crate::connection::SslConfig; -use crate::connection::{ - AddressTranslator, Connection, ConnectionConfig, NonErrorQueryResponse, VerifiedKeyspaceName, -}; +use crate::connection::{AddressTranslator, Connection, ConnectionConfig, VerifiedKeyspaceName}; +use crate::response::{NonErrorQueryResponse, QueryResponse}; use crate::execution::errors::{NewSessionError, QueryError}; use crate::execution::iterator::{PreparedIteratorConfig, RowIterator}; From 7c4ec68936fa212f1d2fbec66442fd91010fab8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 11:32:57 +0200 Subject: [PATCH 29/43] move query_result.rs to new response mod --- scylla/src/connection/connection.rs | 2 +- scylla/src/lib.rs | 2 +- scylla/src/response/mod.rs | 6 ++++++ scylla/src/{transport => response}/query_result.rs | 0 scylla/src/session/session.rs | 2 +- scylla/src/tests/cql_types_test.rs | 2 +- scylla/src/tests/session_test.rs | 2 +- scylla/src/transport/mod.rs | 2 -- 8 files changed, 11 insertions(+), 7 deletions(-) rename scylla/src/{transport => response}/query_result.rs (100%) diff --git a/scylla/src/connection/connection.rs b/scylla/src/connection/connection.rs index 1137efb2af..91a2e3a4b7 100644 --- a/scylla/src/connection/connection.rs +++ b/scylla/src/connection/connection.rs @@ -58,10 +58,10 @@ use crate::frame::{ FrameParams, SerializedRequest, }; use crate::query::Query; +use crate::response::IntoTypedRows; use crate::routing::sharding::{Shard, ShardInfo, Sharder}; use crate::statement::prepared_statement::PreparedStatement; use crate::statement::Consistency; -use crate::transport::query_result::IntoTypedRows; use crate::transport::Compression; use crate::QueryResult; diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index fac3cd00a4..a7426a0871 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -132,10 +132,10 @@ pub use frame::response::cql_to_rust; pub use frame::response::cql_to_rust::FromRow; pub use execution::ExecutionProfile; +pub use response::{IntoTypedRows, QueryResult}; pub use session::CachingSession; pub use session::SessionBuilder; pub use session::{Session, SessionConfig}; -pub use transport::query_result::{IntoTypedRows, QueryResult}; #[cfg(feature = "cloud")] pub use session::CloudSessionBuilder; diff --git a/scylla/src/response/mod.rs b/scylla/src/response/mod.rs index 845151be93..409109e030 100644 --- a/scylla/src/response/mod.rs +++ b/scylla/src/response/mod.rs @@ -1,2 +1,8 @@ mod query_response; +mod query_result; + pub(crate) use query_response::{NonErrorQueryResponse, QueryResponse}; +pub use query_result::{ + FirstRowError, FirstRowTypedError, IntoTypedRows, MaybeFirstRowTypedError, QueryResult, + RowsExpectedError, RowsNotExpectedError, SingleRowError, SingleRowTypedError, TypedRowIter, +}; diff --git a/scylla/src/transport/query_result.rs b/scylla/src/response/query_result.rs similarity index 100% rename from scylla/src/transport/query_result.rs rename to scylla/src/response/query_result.rs diff --git a/scylla/src/session/session.rs b/scylla/src/session/session.rs index ca6bb3799e..b3dfc3d516 100644 --- a/scylla/src/session/session.rs +++ b/scylla/src/session/session.rs @@ -52,9 +52,9 @@ use crate::frame::value::{ }; use crate::prepared_statement::PreparedStatement; use crate::query::Query; +use crate::response::QueryResult; use crate::routing::partitioner::PartitionerName; use crate::statement::Consistency; -use crate::transport::query_result::QueryResult; use crate::transport::Compression; use crate::{ batch::{Batch, BatchStatement}, diff --git a/scylla/src/tests/cql_types_test.rs b/scylla/src/tests/cql_types_test.rs index 1816ad2d9e..54b7ae30c9 100644 --- a/scylla/src/tests/cql_types_test.rs +++ b/scylla/src/tests/cql_types_test.rs @@ -5,9 +5,9 @@ use crate::frame::value::Counter; use crate::frame::value::Value; use crate::frame::value::{Date, Time, Timestamp}; use crate::macros::{FromUserType, IntoUserType}; +use crate::response::IntoTypedRows; use crate::session::Session; use crate::test_utils::create_new_session_builder; -use crate::transport::query_result::IntoTypedRows; use crate::utils::test_utils::unique_keyspace_name; use bigdecimal::BigDecimal; use chrono::{Duration, NaiveDate}; diff --git a/scylla/src/tests/session_test.rs b/scylla/src/tests/session_test.rs index 3fe9d4e4d7..f33365d25c 100644 --- a/scylla/src/tests/session_test.rs +++ b/scylla/src/tests/session_test.rs @@ -15,12 +15,12 @@ use crate::routing::partitioner::{ }; use crate::routing::Token; use crate::statement::Consistency; -use crate::transport::query_result::IntoTypedRows; use crate::utils::test_utils::{ create_new_session_builder, supports_feature, unique_keyspace_name, }; use crate::CachingSession; use crate::ExecutionProfile; +use crate::IntoTypedRows; use crate::QueryResult; use crate::{Session, SessionBuilder}; use assert_matches::assert_matches; diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs index 6293d2ca7e..70fde221b4 100644 --- a/scylla/src/transport/mod.rs +++ b/scylla/src/transport/mod.rs @@ -1,3 +1 @@ -pub mod query_result; - pub use crate::frame::{Authenticator, Compression}; From 4dbc401cf5a23fae984a930ae6827ac32bcf1c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 11:36:06 +0200 Subject: [PATCH 30/43] re-export Compression in connection mod --- docs/source/connecting/compression.md | 2 +- examples/cqlsh-rs.rs | 2 +- scylla/src/connection/connection.rs | 3 ++- scylla/src/connection/mod.rs | 3 +++ scylla/src/session/session.rs | 4 ++-- scylla/src/session/session_builder.rs | 18 +++++++++--------- scylla/src/transport/mod.rs | 2 +- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/docs/source/connecting/compression.md b/docs/source/connecting/compression.md index 018c4cffc2..85b8a2c646 100644 --- a/docs/source/connecting/compression.md +++ b/docs/source/connecting/compression.md @@ -13,7 +13,7 @@ An example enabling `Snappy` compression algorithm: # extern crate scylla; # extern crate tokio; use scylla::{Session, SessionBuilder}; -use scylla::transport::Compression; +use scylla::connection::Compression; use std::error::Error; #[tokio::main] diff --git a/examples/cqlsh-rs.rs b/examples/cqlsh-rs.rs index 877b4af596..fc7ceaebbf 100644 --- a/examples/cqlsh-rs.rs +++ b/examples/cqlsh-rs.rs @@ -3,7 +3,7 @@ use rustyline::completion::{Completer, Pair}; use rustyline::error::ReadlineError; use rustyline::{CompletionType, Config, Context, Editor}; use rustyline_derive::{Helper, Highlighter, Hinter, Validator}; -use scylla::transport::Compression; +use scylla::connection::Compression; use scylla::{QueryResult, Session, SessionBuilder}; use std::env; diff --git a/scylla/src/connection/connection.rs b/scylla/src/connection/connection.rs index 91a2e3a4b7..9a9b9087b6 100644 --- a/scylla/src/connection/connection.rs +++ b/scylla/src/connection/connection.rs @@ -62,9 +62,10 @@ use crate::response::IntoTypedRows; use crate::routing::sharding::{Shard, ShardInfo, Sharder}; use crate::statement::prepared_statement::PreparedStatement; use crate::statement::Consistency; -use crate::transport::Compression; use crate::QueryResult; +use super::Compression; + // Queries for schema agreement const LOCAL_VERSION: &str = "SELECT schema_version FROM system.local WHERE key='local'"; diff --git a/scylla/src/connection/mod.rs b/scylla/src/connection/mod.rs index 583c069684..13392629e1 100644 --- a/scylla/src/connection/mod.rs +++ b/scylla/src/connection/mod.rs @@ -2,6 +2,9 @@ mod connection; mod connection_pool; use connection::ErrorReceiver; + +pub use scylla_cql::frame::Compression; + #[cfg(feature = "ssl")] pub(crate) use connection::SslConfig; pub use connection::{AddressTranslator, ConnectionConfig}; diff --git a/scylla/src/session/session.rs b/scylla/src/session/session.rs index b3dfc3d516..c48637eed4 100644 --- a/scylla/src/session/session.rs +++ b/scylla/src/session/session.rs @@ -35,6 +35,7 @@ use crate::connection::SslConfig; use crate::connection::{AddressTranslator, Connection, ConnectionConfig, VerifiedKeyspaceName}; use crate::response::{NonErrorQueryResponse, QueryResponse}; +use crate::connection::Compression; use crate::execution::errors::{NewSessionError, QueryError}; use crate::execution::iterator::{PreparedIteratorConfig, RowIterator}; use crate::execution::load_balancing::{self, RoutingInfo}; @@ -55,7 +56,6 @@ use crate::query::Query; use crate::response::QueryResult; use crate::routing::partitioner::PartitionerName; use crate::statement::Consistency; -use crate::transport::Compression; use crate::{ batch::{Batch, BatchStatement}, statement::StatementConfig, @@ -1198,7 +1198,7 @@ impl Session { /// # Example /// ```rust /// # use scylla::{Session, SessionBuilder}; - /// # use scylla::transport::Compression; + /// # use scylla::connection::Compression; /// # async fn example() -> Result<(), Box> { /// # let session = SessionBuilder::new().known_node("127.0.0.1:9042").build().await?; /// session diff --git a/scylla/src/session/session_builder.rs b/scylla/src/session/session_builder.rs index 7b90bff00f..c44a9a6fc7 100644 --- a/scylla/src/session/session_builder.rs +++ b/scylla/src/session/session_builder.rs @@ -1,10 +1,10 @@ //! SessionBuilder provides an easy way to create new Sessions +use crate::connection::Compression; use crate::connection::{AddressTranslator, PoolSize}; use crate::execution::errors::NewSessionError; use crate::execution::ExecutionProfileHandle; use crate::session::{Session, SessionConfig}; -use crate::transport::Compression; #[cfg(feature = "cloud")] use crate::cloud::{CloudConfig, CloudConfigError}; @@ -55,7 +55,7 @@ pub type CloudSessionBuilder = GenericSessionBuilder; /// /// ``` /// # use scylla::{Session, SessionBuilder}; -/// # use scylla::transport::Compression; +/// # use scylla::connection::Compression; /// # async fn example() -> Result<(), Box> { /// let session: Session = SessionBuilder::new() /// .known_node("127.0.0.1:9042") @@ -173,7 +173,7 @@ impl GenericSessionBuilder { /// # Example /// ``` /// # use scylla::{Session, SessionBuilder}; - /// # use scylla::transport::Compression; + /// # use scylla::connection::Compression; /// # async fn example() -> Result<(), Box> { /// let session: Session = SessionBuilder::new() /// .known_node("127.0.0.1:9042") @@ -201,7 +201,7 @@ impl GenericSessionBuilder { /// use scylla::{Session, SessionBuilder}; /// use async_trait::async_trait; /// use scylla::authentication::{AuthenticatorProvider, AuthenticatorSession, AuthError}; - /// # use scylla::transport::Compression; + /// # use scylla::connection::Compression; /// /// struct CustomAuthenticator; /// @@ -373,7 +373,7 @@ impl GenericSessionBuilder { /// # Example /// ``` /// # use scylla::{Session, SessionBuilder}; - /// # use scylla::transport::Compression; + /// # use scylla::connection::Compression; /// # async fn example() -> Result<(), Box> { /// let session: Session = SessionBuilder::new() /// .known_node("127.0.0.1:9042") @@ -493,7 +493,7 @@ impl GenericSessionBuilder { /// # Example /// ``` /// # use scylla::{Session, SessionBuilder}; - /// # use scylla::transport::Compression; + /// # use scylla::connection::Compression; /// # async fn example() -> Result<(), Box> { /// let session: Session = SessionBuilder::new() /// .known_node("127.0.0.1:9042") @@ -514,7 +514,7 @@ impl GenericSessionBuilder { /// # Example /// ``` /// # use scylla::{Session, SessionBuilder}; - /// # use scylla::transport::Compression; + /// # use scylla::connection::Compression; /// # async fn example() -> Result<(), Box> { /// let session: Session = SessionBuilder::new() /// .known_node("127.0.0.1:9042") @@ -896,7 +896,7 @@ impl GenericSessionBuilder { /// # Example /// ``` /// # use scylla::{Session, SessionBuilder}; - /// # use scylla::transport::Compression; + /// # use scylla::connection::Compression; /// # async fn example() -> Result<(), Box> { /// let session: Session = SessionBuilder::new() /// .known_node("127.0.0.1:9042") @@ -950,8 +950,8 @@ mod tests { use super::SessionBuilder; use crate::cluster::KnownNode; + use crate::connection::Compression; use crate::execution::{defaults, ExecutionProfile}; - use crate::transport::Compression; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::time::Duration; diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs index 70fde221b4..8b13789179 100644 --- a/scylla/src/transport/mod.rs +++ b/scylla/src/transport/mod.rs @@ -1 +1 @@ -pub use crate::frame::{Authenticator, Compression}; + From 313b22aa6cfff376f1779baf7538aecfeccadc8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 11:36:49 +0200 Subject: [PATCH 31/43] finally! annihilate transport module --- scylla/src/lib.rs | 1 - scylla/src/transport/mod.rs | 1 - 2 files changed, 2 deletions(-) delete mode 100644 scylla/src/transport/mod.rs diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index a7426a0871..a87b6c2132 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -112,7 +112,6 @@ pub mod response; pub mod routing; pub mod session; pub mod statement; -pub mod transport; #[cfg(test)] mod tests; diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs deleted file mode 100644 index 8b13789179..0000000000 --- a/scylla/src/transport/mod.rs +++ /dev/null @@ -1 +0,0 @@ - From c38b5e031a26474d7815a87505fd7ff836028c41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 11:42:03 +0200 Subject: [PATCH 32/43] create cql mod for structured imports from scylla-cql --- scylla/src/cql/mod.rs | 2 ++ scylla/src/lib.rs | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 scylla/src/cql/mod.rs diff --git a/scylla/src/cql/mod.rs b/scylla/src/cql/mod.rs new file mode 100644 index 0000000000..c0da3c177a --- /dev/null +++ b/scylla/src/cql/mod.rs @@ -0,0 +1,2 @@ +//! This module re-exports entities from scylla-cql crate in a structured, +//! controlled way, so that only appropriate items are exposed for users. diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index a87b6c2132..7532e2e550 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -63,7 +63,7 @@ //! # Ok(()) //! # } //! ``` -//! But the driver will accept anything implementing the trait [ValueList](crate::frame::value::ValueList) +//! But the driver will accept anything implementing the trait [ValueList](crate::cql::ValueList) //! //! ### Receiving results //! The easiest way to read rows returned by a query is to cast each row to a tuple of values: @@ -107,6 +107,7 @@ pub mod cloud; pub mod cluster; pub mod connection; +pub mod cql; pub mod execution; pub mod response; pub mod routing; From 4967b4cec0b1aa58f522fcd3edb6f990c434b016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 12:19:05 +0200 Subject: [PATCH 33/43] move type benchmark to scylla-cql So that it can access its full types API. --- scylla-cql/benches/benchmark.rs | 36 ++++++++++++++++++++++++++++++++- scylla/benches/benchmark.rs | 36 +-------------------------------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/scylla-cql/benches/benchmark.rs b/scylla-cql/benches/benchmark.rs index 0aa6c89102..8789cd7a5c 100644 --- a/scylla-cql/benches/benchmark.rs +++ b/scylla-cql/benches/benchmark.rs @@ -1,8 +1,10 @@ use std::borrow::Cow; +use bytes::BytesMut; use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; use scylla_cql::frame::request::SerializableRequest; +use scylla_cql::frame::types; use scylla_cql::frame::value::SerializedValues; use scylla_cql::frame::value::ValueList; use scylla_cql::frame::{request::query, Compression, SerializedRequest}; @@ -51,5 +53,37 @@ fn serialized_request_make_bench(c: &mut Criterion) { } } -criterion_group!(benches, serialized_request_make_bench); +fn types_benchmark(c: &mut Criterion) { + let mut buf = BytesMut::with_capacity(64); + c.bench_function("short", |b| { + b.iter(|| { + buf.clear(); + types::write_short(-1, &mut buf); + types::read_short(&mut &buf[..]).unwrap(); + }) + }); + c.bench_function("int", |b| { + b.iter(|| { + buf.clear(); + types::write_int(-1, &mut buf); + types::read_int(&mut &buf[..]).unwrap(); + }) + }); + c.bench_function("long", |b| { + b.iter(|| { + buf.clear(); + types::write_long(-1, &mut buf); + types::read_long(&mut &buf[..]).unwrap(); + }) + }); + c.bench_function("string", |b| { + b.iter(|| { + buf.clear(); + types::write_string("hello, world", &mut buf).unwrap(); + types::read_string(&mut &buf[..]).unwrap(); + }) + }); +} + +criterion_group!(benches, serialized_request_make_bench, types_benchmark); criterion_main!(benches); diff --git a/scylla/benches/benchmark.rs b/scylla/benches/benchmark.rs index d4b0146add..95d4237b09 100644 --- a/scylla/benches/benchmark.rs +++ b/scylla/benches/benchmark.rs @@ -1,44 +1,10 @@ use criterion::{criterion_group, criterion_main, Criterion}; -use bytes::BytesMut; use scylla::{ - frame::types, frame::value::ValueList, routing::partitioner::{calculate_token_for_partition_key, Murmur3Partitioner}, }; -fn types_benchmark(c: &mut Criterion) { - let mut buf = BytesMut::with_capacity(64); - c.bench_function("short", |b| { - b.iter(|| { - buf.clear(); - types::write_short(-1, &mut buf); - types::read_short(&mut &buf[..]).unwrap(); - }) - }); - c.bench_function("int", |b| { - b.iter(|| { - buf.clear(); - types::write_int(-1, &mut buf); - types::read_int(&mut &buf[..]).unwrap(); - }) - }); - c.bench_function("long", |b| { - b.iter(|| { - buf.clear(); - types::write_long(-1, &mut buf); - types::read_long(&mut &buf[..]).unwrap(); - }) - }); - c.bench_function("string", |b| { - b.iter(|| { - buf.clear(); - types::write_string("hello, world", &mut buf).unwrap(); - types::read_string(&mut &buf[..]).unwrap(); - }) - }); -} - fn calculate_token_bench(c: &mut Criterion) { let simple_pk = ("I'm prepared!!!",); let serialized_simple_pk = simple_pk.serialized().unwrap().into_owned(); @@ -91,5 +57,5 @@ fn calculate_token_bench(c: &mut Criterion) { ); } -criterion_group!(benches, types_benchmark, calculate_token_bench); +criterion_group!(benches, calculate_token_bench); criterion_main!(benches); From ae499faa020a0f7107daff4fbca533e83013430c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 16:33:13 +0200 Subject: [PATCH 34/43] re-export value in cql mod --- scylla/src/cql/mod.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scylla/src/cql/mod.rs b/scylla/src/cql/mod.rs index c0da3c177a..90cc73b6f5 100644 --- a/scylla/src/cql/mod.rs +++ b/scylla/src/cql/mod.rs @@ -1,2 +1,11 @@ //! This module re-exports entities from scylla-cql crate in a structured, //! controlled way, so that only appropriate items are exposed for users. + +pub mod value { + pub use scylla_cql::frame::value::{ + Counter, CqlDuration, Date, MaybeUnset, SerializeValuesError, SerializedValues, Time, + Timestamp, Unset, Value, ValueList, + }; +} + +pub use value::{Value, ValueList}; From 934de127ae23e5941c78f4df7079e31975b786be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 16:31:08 +0200 Subject: [PATCH 35/43] re-export CqlValue in cql::value --- scylla/src/cql/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/scylla/src/cql/mod.rs b/scylla/src/cql/mod.rs index 90cc73b6f5..ef17302c35 100644 --- a/scylla/src/cql/mod.rs +++ b/scylla/src/cql/mod.rs @@ -2,6 +2,7 @@ //! controlled way, so that only appropriate items are exposed for users. pub mod value { + pub use scylla_cql::frame::response::result::CqlValue; pub use scylla_cql::frame::value::{ Counter, CqlDuration, Date, MaybeUnset, SerializeValuesError, SerializedValues, Time, Timestamp, Unset, Value, ValueList, From 80daa7c97dae88ae135169da65be034f197e7b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 16:28:59 +0200 Subject: [PATCH 36/43] re-export frame::response::result in cql mod --- scylla/src/cql/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scylla/src/cql/mod.rs b/scylla/src/cql/mod.rs index ef17302c35..f7f1d00f19 100644 --- a/scylla/src/cql/mod.rs +++ b/scylla/src/cql/mod.rs @@ -10,3 +10,13 @@ pub mod value { } pub use value::{Value, ValueList}; + +pub mod frame { + pub mod response { + pub mod result { + pub use scylla_cql::frame::response::result::{ + ColumnSpec, ColumnType, PartitionKeyIndex, PreparedMetadata, Row, TableSpec, + }; + } + } +} From a449c4bdaef7e977b3446f284999a3c125f987dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 16:22:45 +0200 Subject: [PATCH 37/43] re-export types and ProtocolFeatures in test_utils --- scylla/src/utils/test_utils.rs | 2 ++ scylla/tests/integration/lwt_optimisation.rs | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/scylla/src/utils/test_utils.rs b/scylla/src/utils/test_utils.rs index 11bb5485aa..f672d1fd5b 100644 --- a/scylla/src/utils/test_utils.rs +++ b/scylla/src/utils/test_utils.rs @@ -92,3 +92,5 @@ pub fn create_new_session_builder() -> GenericSessionBuilder Date: Thu, 31 Aug 2023 15:13:34 +0200 Subject: [PATCH 38/43] re-export cql_to_rust in cql mod --- scylla/src/cql/mod.rs | 6 ++++++ scylla/src/lib.rs | 4 ++-- scylla/src/response/query_result.rs | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/scylla/src/cql/mod.rs b/scylla/src/cql/mod.rs index f7f1d00f19..6a35123af2 100644 --- a/scylla/src/cql/mod.rs +++ b/scylla/src/cql/mod.rs @@ -20,3 +20,9 @@ pub mod frame { } } } + +pub mod cql_to_rust { + pub use scylla_cql::cql_to_rust::{ + CqlTypeError, FromCqlVal, FromCqlValError, FromRow, FromRowError, + }; +} diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index 7532e2e550..92a4dc4a23 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -128,8 +128,8 @@ pub use statement::batch; pub use statement::prepared_statement; pub use statement::query; -pub use frame::response::cql_to_rust; -pub use frame::response::cql_to_rust::FromRow; +pub use cql::cql_to_rust; +pub use cql::cql_to_rust::FromRow; pub use execution::ExecutionProfile; pub use response::{IntoTypedRows, QueryResult}; diff --git a/scylla/src/response/query_result.rs b/scylla/src/response/query_result.rs index 0098d24fc7..9de0689914 100644 --- a/scylla/src/response/query_result.rs +++ b/scylla/src/response/query_result.rs @@ -1,4 +1,4 @@ -use crate::frame::response::cql_to_rust::{FromRow, FromRowError}; +use crate::cql::cql_to_rust::{FromRow, FromRowError}; use crate::frame::response::result::ColumnSpec; use crate::frame::response::result::Row; From a6d9425f2ac383915f0c9aeb08b5ef8e7cc6a046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 16:46:35 +0200 Subject: [PATCH 39/43] no longer expose scylla_cql::frame in scylla --- examples/compare-tokens.rs | 2 +- examples/cql-time-types.rs | 3 +-- examples/custom_deserialization.rs | 2 +- examples/tower.rs | 6 ++---- examples/value_list.rs | 2 +- scylla/benches/benchmark.rs | 2 +- scylla/src/lib.rs | 2 +- scylla/tests/integration/hygiene.rs | 3 +-- 8 files changed, 9 insertions(+), 13 deletions(-) diff --git a/examples/compare-tokens.rs b/examples/compare-tokens.rs index 04a5340da0..a42572e560 100644 --- a/examples/compare-tokens.rs +++ b/examples/compare-tokens.rs @@ -1,6 +1,6 @@ use anyhow::Result; use scylla::cluster::NodeAddr; -use scylla::frame::value::ValueList; +use scylla::cql::ValueList; use scylla::routing::Token; use scylla::{Session, SessionBuilder}; use std::env; diff --git a/examples/cql-time-types.rs b/examples/cql-time-types.rs index eb68838d00..db5bbadc28 100644 --- a/examples/cql-time-types.rs +++ b/examples/cql-time-types.rs @@ -3,8 +3,7 @@ use anyhow::Result; use chrono::{Duration, NaiveDate}; -use scylla::frame::response::result::CqlValue; -use scylla::frame::value::{Date, Time, Timestamp}; +use scylla::cql::value::{CqlValue, Date, Time, Timestamp}; use scylla::SessionBuilder; use scylla::{IntoTypedRows, Session}; use std::env; diff --git a/examples/custom_deserialization.rs b/examples/custom_deserialization.rs index 122c842bb8..5aa6ac66ed 100644 --- a/examples/custom_deserialization.rs +++ b/examples/custom_deserialization.rs @@ -1,6 +1,6 @@ use anyhow::Result; +use scylla::cql::value::CqlValue; use scylla::cql_to_rust::{FromCqlVal, FromCqlValError}; -use scylla::frame::response::result::CqlValue; use scylla::macros::impl_from_cql_value_from_method; use scylla::{Session, SessionBuilder}; use std::env; diff --git a/examples/tower.rs b/examples/tower.rs index 0d346ccf2f..f93a70655c 100644 --- a/examples/tower.rs +++ b/examples/tower.rs @@ -44,11 +44,9 @@ async fn main() -> anyhow::Result<()> { .call("SELECT keyspace_name, table_name FROM system_schema.tables;".into()) .await?; - let print_text = |t: &Option| { + let print_text = |t: &Option| { t.as_ref() - .unwrap_or(&scylla::frame::response::result::CqlValue::Text( - "".to_string(), - )) + .unwrap_or(&scylla::cql::value::CqlValue::Text("".to_string())) .as_text() .unwrap_or(&"".to_string()) .clone() diff --git a/examples/value_list.rs b/examples/value_list.rs index 44b388dcbc..9fbef876ac 100644 --- a/examples/value_list.rs +++ b/examples/value_list.rs @@ -37,7 +37,7 @@ async fn main() { // You can also use type generics: #[derive(scylla::ValueList)] - struct MyTypeWithGenerics { + struct MyTypeWithGenerics { k: i32, my: Option, } diff --git a/scylla/benches/benchmark.rs b/scylla/benches/benchmark.rs index 95d4237b09..2f61726d90 100644 --- a/scylla/benches/benchmark.rs +++ b/scylla/benches/benchmark.rs @@ -1,7 +1,7 @@ use criterion::{criterion_group, criterion_main, Criterion}; use scylla::{ - frame::value::ValueList, + cql::ValueList, routing::partitioner::{calculate_token_for_partition_key, Murmur3Partitioner}, }; diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index 92a4dc4a23..9cefba3bd0 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -98,7 +98,7 @@ pub mod _macro_internal { pub use scylla_cql::_macro_internal::*; } -pub use scylla_cql::frame; +pub(crate) use scylla_cql::frame; pub use scylla_cql::macros::{self, *}; pub mod authentication; diff --git a/scylla/tests/integration/hygiene.rs b/scylla/tests/integration/hygiene.rs index 6195bb0256..c0f0c449f7 100644 --- a/scylla/tests/integration/hygiene.rs +++ b/scylla/tests/integration/hygiene.rs @@ -19,9 +19,8 @@ macro_rules! test_crate { } #[test] fn test_rename() { + use _scylla::_macro_internal::{CqlValue, Value, ValueList}; use _scylla::cql_to_rust::{FromCqlVal, FromRow}; - use _scylla::frame::response::result::CqlValue; - use _scylla::frame::value::{Value, ValueList}; pub fn derived() where From 06271ee5e1f666c54c60c03e43ace4f6234722a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 15:20:08 +0200 Subject: [PATCH 40/43] clippy-fixes --- scylla/src/cluster/mod.rs | 1 + scylla/src/connection/mod.rs | 1 + scylla/src/session/mod.rs | 1 + 3 files changed, 3 insertions(+) diff --git a/scylla/src/cluster/mod.rs b/scylla/src/cluster/mod.rs index 13aff71ebf..112ad2e022 100644 --- a/scylla/src/cluster/mod.rs +++ b/scylla/src/cluster/mod.rs @@ -1,3 +1,4 @@ +#[allow(clippy::module_inception)] mod cluster; pub mod host_filter; pub mod locator; diff --git a/scylla/src/connection/mod.rs b/scylla/src/connection/mod.rs index 13392629e1..ecd2432c05 100644 --- a/scylla/src/connection/mod.rs +++ b/scylla/src/connection/mod.rs @@ -1,3 +1,4 @@ +#[allow(clippy::module_inception)] mod connection; mod connection_pool; diff --git a/scylla/src/session/mod.rs b/scylla/src/session/mod.rs index 2c3a129a73..ae7338f017 100644 --- a/scylla/src/session/mod.rs +++ b/scylla/src/session/mod.rs @@ -1,4 +1,5 @@ mod caching_session; +#[allow(clippy::module_inception)] mod session; pub mod session_builder; From 9b6bbed2454b0ef82f73657f81bf8cd0ab8a3d20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 17:13:50 +0200 Subject: [PATCH 41/43] fixes for doc tests --- scylla/src/connection/mod.rs | 1 + scylla/src/session/session_builder.rs | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/scylla/src/connection/mod.rs b/scylla/src/connection/mod.rs index ecd2432c05..2f4814f1eb 100644 --- a/scylla/src/connection/mod.rs +++ b/scylla/src/connection/mod.rs @@ -6,6 +6,7 @@ use connection::ErrorReceiver; pub use scylla_cql::frame::Compression; +pub use crate::execution::errors::TranslationError; #[cfg(feature = "ssl")] pub(crate) use connection::SslConfig; pub use connection::{AddressTranslator, ConnectionConfig}; diff --git a/scylla/src/session/session_builder.rs b/scylla/src/session/session_builder.rs index c44a9a6fc7..643dd16253 100644 --- a/scylla/src/session/session_builder.rs +++ b/scylla/src/session/session_builder.rs @@ -253,7 +253,7 @@ impl GenericSessionBuilder { /// # use std::net::SocketAddr; /// # use std::sync::Arc; /// # use scylla::{Session, SessionBuilder}; - /// # use scylla::session::{AddressTranslator, TranslationError}; + /// # use scylla::connection::{AddressTranslator, TranslationError}; /// # use scylla::cluster::metadata::UntranslatedPeer; /// struct IdentityTranslator; /// @@ -283,7 +283,7 @@ impl GenericSessionBuilder { /// # use std::collections::HashMap; /// # use std::str::FromStr; /// # use scylla::{Session, SessionBuilder}; - /// # use scylla::session::{AddressTranslator, TranslationError}; + /// # use scylla::connection::{AddressTranslator, TranslationError}; /// # /// # async fn example() -> Result<(), Box> { /// let mut translation_rules = HashMap::new(); @@ -558,7 +558,7 @@ impl GenericSessionBuilder { /// # use scylla::{Session, SessionBuilder}; /// # async fn example() -> Result<(), Box> { /// use std::num::NonZeroUsize; - /// use scylla::session::PoolSize; + /// use scylla::connection::PoolSize; /// /// // This session will establish 4 connections to each node. /// // For Scylla clusters, this number will be divided across shards @@ -771,7 +771,7 @@ impl GenericSessionBuilder { /// # use std::net::SocketAddr; /// # use std::sync::Arc; /// # use scylla::{Session, SessionBuilder}; - /// # use scylla::session::{AddressTranslator, TranslationError}; + /// # use scylla::connection::{AddressTranslator, TranslationError}; /// # use scylla::cluster::host_filter::DcHostFilter; /// /// # async fn example() -> Result<(), Box> { From ae591155dabc39bc9e6961ae938b1e4c03f96d78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 17:26:51 +0200 Subject: [PATCH 42/43] adjust docs for new module structure --- docs/source/data-types/counter.md | 2 +- docs/source/data-types/date.md | 7 +++---- docs/source/data-types/duration.md | 4 ++-- docs/source/data-types/time.md | 4 ++-- docs/source/data-types/timestamp.md | 2 +- docs/source/execution-profiles/create-and-use.md | 6 +++--- docs/source/execution-profiles/maximal-example.md | 4 ++-- docs/source/execution-profiles/priority.md | 2 +- docs/source/execution-profiles/remap.md | 2 +- docs/source/load-balancing/load-balancing.md | 4 ++-- docs/source/queries/result.md | 4 ++-- docs/source/queries/timeouts.md | 2 +- docs/source/queries/values.md | 6 +++--- docs/source/retry-policy/default.md | 6 +++--- docs/source/retry-policy/downgrading-consistency.md | 12 ++++++------ docs/source/retry-policy/fallthrough.md | 6 +++--- docs/source/tracing/basic.md | 6 +++--- docs/source/tracing/paged.md | 4 ++-- docs/source/tracing/prepare.md | 2 +- docs/source/tracing/query-history.md | 2 +- 20 files changed, 43 insertions(+), 44 deletions(-) diff --git a/docs/source/data-types/counter.md b/docs/source/data-types/counter.md index 0f31b6cba7..654155ad4e 100644 --- a/docs/source/data-types/counter.md +++ b/docs/source/data-types/counter.md @@ -8,7 +8,7 @@ # use std::error::Error; # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::IntoTypedRows; -use scylla::frame::value::Counter; +use scylla::cql::value::Counter; // Read counter from the table if let Some(rows) = session.query("SELECT c FROM keyspace.table", &[]).await?.rows { diff --git a/docs/source/data-types/date.md b/docs/source/data-types/date.md index 6d3384c6af..23ec76be5c 100644 --- a/docs/source/data-types/date.md +++ b/docs/source/data-types/date.md @@ -1,6 +1,6 @@ # Date -For most use cases `Date` can be represented as +For most use cases `Date` can be represented as [`chrono::NaiveDate`](https://docs.rs/chrono/0.4.19/chrono/naive/struct.NaiveDate.html).\ `NaiveDate` supports dates from -262145-1-1 to 262143-12-31. @@ -40,11 +40,10 @@ Internally `Date` is represented as number of days since -5877641-06-23 i.e. 2^3 # use scylla::Session; # use std::error::Error; # async fn check_only_compiles(session: &Session) -> Result<(), Box> { -use scylla::frame::value::Date; -use scylla::frame::response::result::CqlValue; +use scylla::cql::value::{CqlValue, Date}; // Insert date using raw u32 representation -let to_insert: Date = Date(2_u32.pow(31)); // 1970-01-01 +let to_insert: Date = Date(2_u32.pow(31)); // 1970-01-01 session .query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,)) .await?; diff --git a/docs/source/data-types/duration.md b/docs/source/data-types/duration.md index 7526a478b3..9e473db60c 100644 --- a/docs/source/data-types/duration.md +++ b/docs/source/data-types/duration.md @@ -1,5 +1,5 @@ # Duration -`Duration` is represented as [`CqlDuration`](https://docs.rs/scylla/latest/scylla/frame/value/struct.CqlDuration.html)\ +`Duration` is represented as [`CqlDuration`](https://docs.rs/scylla/latest/scylla/cql/value/struct.CqlDuration.html)\ ```rust # extern crate scylla; @@ -7,7 +7,7 @@ # use std::error::Error; # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::IntoTypedRows; -use scylla::frame::value::CqlDuration; +use scylla::cql::value::CqlDuration; // Insert some ip address into the table let to_insert: CqlDuration = CqlDuration { months: 1, days: 2, nanoseconds: 3 }; diff --git a/docs/source/data-types/time.md b/docs/source/data-types/time.md index 6f46f9dae1..f7a73f4f6a 100644 --- a/docs/source/data-types/time.md +++ b/docs/source/data-types/time.md @@ -1,7 +1,7 @@ # Time `Time` is represented as [`chrono::Duration`](https://docs.rs/chrono/0.4.19/chrono/struct.Duration.html) -Internally `Time` is represented as number of nanoseconds since midnight. +Internally `Time` is represented as number of nanoseconds since midnight. It can't be negative or exceed `86399999999999` (24 hours). When sending in a query it needs to be wrapped in `value::Time` to differentiate from [`Timestamp`](timestamp.md) @@ -13,7 +13,7 @@ When sending in a query it needs to be wrapped in `value::Time` to differentiate # use std::error::Error; # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::IntoTypedRows; -use scylla::frame::value::Time; +use scylla::cql::value::Time; use chrono::Duration; // Insert some time into the table diff --git a/docs/source/data-types/timestamp.md b/docs/source/data-types/timestamp.md index d61aec2aec..5361aaec63 100644 --- a/docs/source/data-types/timestamp.md +++ b/docs/source/data-types/timestamp.md @@ -13,7 +13,7 @@ When sending in a query it needs to be wrapped in `value::Timestamp` to differen # use std::error::Error; # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::IntoTypedRows; -use scylla::frame::value::Timestamp; +use scylla::cql::value::Timestamp; use chrono::Duration; // Insert some timestamp into the table diff --git a/docs/source/execution-profiles/create-and-use.md b/docs/source/execution-profiles/create-and-use.md index 01bfa52d99..01dcd6c3c8 100644 --- a/docs/source/execution-profiles/create-and-use.md +++ b/docs/source/execution-profiles/create-and-use.md @@ -8,7 +8,7 @@ To create an `ExecutionProfile` and attach it as default for `Session`: # async fn check_only_compiles() -> Result<(), Box> { use scylla::{Session, SessionBuilder}; use scylla::statement::Consistency; -use scylla::transport::ExecutionProfile; +use scylla::execution::ExecutionProfile; let profile = ExecutionProfile::builder() .consistency(Consistency::LocalOne) @@ -34,7 +34,7 @@ To create an `ExecutionProfile` and attach it to a `Query`: # async fn check_only_compiles() -> Result<(), Box> { use scylla::query::Query; use scylla::statement::Consistency; -use scylla::transport::ExecutionProfile; +use scylla::execution::ExecutionProfile; use std::time::Duration; let profile = ExecutionProfile::builder() @@ -60,7 +60,7 @@ To create an `ExecutionProfile` based on another profile: # use std::error::Error; # async fn check_only_compiles() -> Result<(), Box> { use scylla::statement::Consistency; -use scylla::transport::ExecutionProfile; +use scylla::execution::ExecutionProfile; use std::time::Duration; let base_profile = ExecutionProfile::builder() diff --git a/docs/source/execution-profiles/maximal-example.md b/docs/source/execution-profiles/maximal-example.md index c1212a979b..0c5a50c930 100644 --- a/docs/source/execution-profiles/maximal-example.md +++ b/docs/source/execution-profiles/maximal-example.md @@ -9,8 +9,8 @@ use scylla::query::Query; use scylla::speculative_execution::SimpleSpeculativeExecutionPolicy; use scylla::statement::{Consistency, SerialConsistency}; -use scylla::transport::ExecutionProfile; -use scylla::transport::load_balancing::DefaultPolicy; +use scylla::execution::ExecutionProfile; +use scylla::execution::load_balancing::DefaultPolicy; use scylla::execution::retries::FallthroughRetryPolicy; use std::{sync::Arc, time::Duration}; diff --git a/docs/source/execution-profiles/priority.md b/docs/source/execution-profiles/priority.md index 92a46d50c4..25bd0f7656 100644 --- a/docs/source/execution-profiles/priority.md +++ b/docs/source/execution-profiles/priority.md @@ -16,7 +16,7 @@ Priorities of execution profiles and directly set options: use scylla::{Session, SessionBuilder}; use scylla::query::Query; use scylla::statement::Consistency; -use scylla::transport::ExecutionProfile; +use scylla::execution::ExecutionProfile; let session_profile = ExecutionProfile::builder() .consistency(Consistency::One) diff --git a/docs/source/execution-profiles/remap.md b/docs/source/execution-profiles/remap.md index a64aee3916..308cb2b483 100644 --- a/docs/source/execution-profiles/remap.md +++ b/docs/source/execution-profiles/remap.md @@ -26,7 +26,7 @@ Below, the remaps described above are followed in code. use scylla::{Session, SessionBuilder}; use scylla::query::Query; use scylla::statement::Consistency; -use scylla::transport::ExecutionProfile; +use scylla::execution::ExecutionProfile; let profile1 = ExecutionProfile::builder() .consistency(Consistency::One) diff --git a/docs/source/load-balancing/load-balancing.md b/docs/source/load-balancing/load-balancing.md index a1efebc403..db34a37439 100644 --- a/docs/source/load-balancing/load-balancing.md +++ b/docs/source/load-balancing/load-balancing.md @@ -9,7 +9,7 @@ balancing plan based on the query information and the state of the cluster. Load balancing policies do not influence to which nodes connections are being opened. For a node connection blacklist configuration refer to -`scylla::transport::host_filter::HostFilter`, which can be set session-wide +`scylla::cluster::host_filter::HostFilter`, which can be set session-wide using `SessionBuilder::host_filter` method. ## Plan @@ -49,7 +49,7 @@ The newly created execution profile is then converted to a handle using # async fn check_only_compiles(uri: &str) -> Result<(), Box> { use scylla::SessionBuilder; use scylla::load_balancing::DefaultPolicy; -use scylla::transport::ExecutionProfile; +use scylla::execution::ExecutionProfile; use scylla::session::Session; use std::sync::Arc; diff --git a/docs/source/queries/result.md b/docs/source/queries/result.md index 6350eab9ad..80a215d8bc 100644 --- a/docs/source/queries/result.md +++ b/docs/source/queries/result.md @@ -89,7 +89,7 @@ session.query("INSERT INTO ks.tab (a) VALUES (0)", &[]).await?.result_not_rows() For more see [`QueryResult`](https://docs.rs/scylla/latest/scylla/transport/query_result/struct.QueryResult.html) ### `NULL` values -`NULL` values will return an error when parsed as a Rust type. +`NULL` values will return an error when parsed as a Rust type. To properly handle `NULL` values parse column as an `Option<>`: ```rust # extern crate scylla; @@ -123,7 +123,7 @@ Field names don't need to match column names. # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::IntoTypedRows; use scylla::macros::FromRow; -use scylla::frame::response::cql_to_rust::FromRow; +use scylla::cql::cql_to_rust::FromRow; #[derive(FromRow)] struct MyRow { diff --git a/docs/source/queries/timeouts.md b/docs/source/queries/timeouts.md index 92c11dfd6a..bfbe87d8a6 100644 --- a/docs/source/queries/timeouts.md +++ b/docs/source/queries/timeouts.md @@ -18,7 +18,7 @@ However, setting per-statement timeout to `None` results in falling back to per- # use std::error::Error; # async fn timeouts() -> Result<(), Box> { use scylla::{Session, SessionBuilder, query::Query}; -use scylla::transport::ExecutionProfile; +use scylla::execution::ExecutionProfile; use std::time::Duration; let uri = std::env::var("SCYLLA_URI") diff --git a/docs/source/queries/values.md b/docs/source/queries/values.md index 09b369b689..7f5206ca12 100644 --- a/docs/source/queries/values.md +++ b/docs/source/queries/values.md @@ -1,7 +1,7 @@ # Query values Query text is constant, but the values might change. You can pass changing values to a query by specifying a list of variables as bound values.\ -Each `?` in query text will be filled with the matching value. +Each `?` in query text will be filled with the matching value. > **Never** pass values by adding strings, this could lead to [SQL Injection](https://en.wikipedia.org/wiki/SQL_injection) @@ -12,7 +12,7 @@ or a custom struct which derives from `ValueList`. A few examples: ```rust # extern crate scylla; -# use scylla::{Session, ValueList, frame::response::result::CqlValue}; +# use scylla::{Session, ValueList, cql::value::CqlValue}; # use std::error::Error; # use std::collections::HashMap; # async fn check_only_compiles(session: &Session) -> Result<(), Box> { @@ -94,7 +94,7 @@ Using `Unset` results in better performance: # use scylla::Session; # use std::error::Error; # async fn check_only_compiles(session: &Session) -> Result<(), Box> { -use scylla::frame::value::{MaybeUnset, Unset}; +use scylla::cql::value::{MaybeUnset, Unset}; // Inserting a null results in suboptimal performance let null_i32: Option = None; diff --git a/docs/source/retry-policy/default.md b/docs/source/retry-policy/default.md index 684adc1de6..b4b2835c01 100644 --- a/docs/source/retry-policy/default.md +++ b/docs/source/retry-policy/default.md @@ -11,7 +11,7 @@ To use in `Session`: # use std::error::Error; # async fn check_only_compiles() -> Result<(), Box> { use scylla::{Session, SessionBuilder}; -use scylla::transport::ExecutionProfile; +use scylla::execution::ExecutionProfile; use scylla::execution::retries::DefaultRetryPolicy; let handle = ExecutionProfile::builder() @@ -36,7 +36,7 @@ To use in a [simple query](../queries/simple.md): # use std::sync::Arc; # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::query::Query; -use scylla::transport::ExecutionProfile; +use scylla::execution::ExecutionProfile; use scylla::execution::retries::DefaultRetryPolicy; // Create a Query manually and set the retry policy @@ -65,7 +65,7 @@ To use in a [prepared query](../queries/prepared.md): # use std::sync::Arc; # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::prepared_statement::PreparedStatement; -use scylla::transport::ExecutionProfile; +use scylla::execution::ExecutionProfile; use scylla::execution::retries::DefaultRetryPolicy; // Create PreparedStatement manually and set the retry policy diff --git a/docs/source/retry-policy/downgrading-consistency.md b/docs/source/retry-policy/downgrading-consistency.md index 711329ec80..cd2c1edbce 100644 --- a/docs/source/retry-policy/downgrading-consistency.md +++ b/docs/source/retry-policy/downgrading-consistency.md @@ -52,8 +52,8 @@ To use in `Session`: # use std::error::Error; # async fn check_only_compiles() -> Result<(), Box> { use scylla::{Session, SessionBuilder}; -use scylla::transport::ExecutionProfile; -use scylla::transport::downgrading_consistency_retry_policy::DowngradingConsistencyRetryPolicy; +use scylla::execution::ExecutionProfile; +use scylla::execution::retries::DowngradingConsistencyRetryPolicy; let handle = ExecutionProfile::builder() .retry_policy(Box::new(DowngradingConsistencyRetryPolicy::new())) @@ -76,8 +76,8 @@ To use in a [simple query](../queries/simple.md): # use std::error::Error; # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::query::Query; -use scylla::transport::ExecutionProfile; -use scylla::transport::downgrading_consistency_retry_policy::DowngradingConsistencyRetryPolicy; +use scylla::execution::ExecutionProfile; +use scylla::execution::retries::DowngradingConsistencyRetryPolicy; let handle = ExecutionProfile::builder() .retry_policy(Box::new(DowngradingConsistencyRetryPolicy::new())) @@ -102,8 +102,8 @@ To use in a [prepared query](../queries/prepared.md): # use std::error::Error; # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::prepared_statement::PreparedStatement; -use scylla::transport::ExecutionProfile; -use scylla::transport::downgrading_consistency_retry_policy::DowngradingConsistencyRetryPolicy; +use scylla::execution::ExecutionProfile; +use scylla::execution::retries::DowngradingConsistencyRetryPolicy; let handle = ExecutionProfile::builder() .retry_policy(Box::new(DowngradingConsistencyRetryPolicy::new())) diff --git a/docs/source/retry-policy/fallthrough.md b/docs/source/retry-policy/fallthrough.md index 9b3833be93..8e7e2b4379 100644 --- a/docs/source/retry-policy/fallthrough.md +++ b/docs/source/retry-policy/fallthrough.md @@ -10,7 +10,7 @@ To use in `Session`: # use std::error::Error; # async fn check_only_compiles() -> Result<(), Box> { use scylla::{Session, SessionBuilder}; -use scylla::transport::ExecutionProfile; +use scylla::execution::ExecutionProfile; use scylla::execution::retries::FallthroughRetryPolicy; let handle = ExecutionProfile::builder() @@ -34,7 +34,7 @@ To use in a [simple query](../queries/simple.md): # use std::error::Error; # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::query::Query; -use scylla::transport::ExecutionProfile; +use scylla::execution::ExecutionProfile; use scylla::execution::retries::FallthroughRetryPolicy; let handle = ExecutionProfile::builder() @@ -60,7 +60,7 @@ To use in a [prepared query](../queries/prepared.md): # use std::error::Error; # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::prepared_statement::PreparedStatement; -use scylla::transport::ExecutionProfile; +use scylla::execution::ExecutionProfile; use scylla::execution::retries::FallthroughRetryPolicy; let handle = ExecutionProfile::builder() diff --git a/docs/source/tracing/basic.md b/docs/source/tracing/basic.md index 4ee5bc5737..c131fa5601 100644 --- a/docs/source/tracing/basic.md +++ b/docs/source/tracing/basic.md @@ -12,7 +12,7 @@ return a `QueryResult` which contains a `tracing_id` if tracing was enabled. # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::query::Query; use scylla::QueryResult; -use scylla::tracing::TracingInfo; +use scylla::execution::tracing::TracingInfo; use uuid::Uuid; // Create a Query manually and enable tracing @@ -40,7 +40,7 @@ if let Some(id) = tracing_id { # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::prepared_statement::PreparedStatement; use scylla::QueryResult; -use scylla::tracing::TracingInfo; +use scylla::execution::tracing::TracingInfo; use uuid::Uuid; // Prepare the query @@ -72,7 +72,7 @@ if let Some(id) = tracing_id { # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::batch::Batch; use scylla::QueryResult; -use scylla::tracing::TracingInfo; +use scylla::execution::tracing::TracingInfo; use uuid::Uuid; // Create a batch statement diff --git a/docs/source/tracing/paged.md b/docs/source/tracing/paged.md index df3a056871..aec6b024b3 100644 --- a/docs/source/tracing/paged.md +++ b/docs/source/tracing/paged.md @@ -14,7 +14,7 @@ If tracing is enabled the row iterator will contain a list of tracing ids for al # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::query::Query; use scylla::execution::iterator::RowIterator; -use scylla::tracing::TracingInfo; +use scylla::execution::tracing::TracingInfo; use futures::StreamExt; use uuid::Uuid; @@ -50,7 +50,7 @@ for id in tracing_ids { # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::prepared_statement::PreparedStatement; use scylla::execution::iterator::RowIterator; -use scylla::tracing::TracingInfo; +use scylla::execution::tracing::TracingInfo; use futures::StreamExt; use uuid::Uuid; diff --git a/docs/source/tracing/prepare.md b/docs/source/tracing/prepare.md index 2f3850cbde..cef6a48d1c 100644 --- a/docs/source/tracing/prepare.md +++ b/docs/source/tracing/prepare.md @@ -10,7 +10,7 @@ # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::query::Query; use scylla::prepared_statement::PreparedStatement; -use scylla::tracing::TracingInfo; +use scylla::execution::tracing::TracingInfo; use uuid::Uuid; // Prepare the query with tracing enabled diff --git a/docs/source/tracing/query-history.md b/docs/source/tracing/query-history.md index 1c0779259e..fd4cd086ff 100644 --- a/docs/source/tracing/query-history.md +++ b/docs/source/tracing/query-history.md @@ -12,7 +12,7 @@ This history includes all requests sent, decisions to retry and speculative exec # use std::error::Error; # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::query::Query; -use scylla::history::{HistoryCollector, StructuredHistory}; +use scylla::execution::history::{HistoryCollector, StructuredHistory}; use std::sync::Arc; // Create a query for which we would like to trace the history of its execution From b4cd5be2fa8825f6ac14d70d303d5e12afa2de68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Thu, 31 Aug 2023 17:37:55 +0200 Subject: [PATCH 43/43] cargo doc links fixes --- scylla/src/connection/connection.rs | 2 +- scylla/src/session/session.rs | 2 +- scylla/src/session/session_builder.rs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scylla/src/connection/connection.rs b/scylla/src/connection/connection.rs index 9a9b9087b6..597d6491b2 100644 --- a/scylla/src/connection/connection.rs +++ b/scylla/src/connection/connection.rs @@ -1251,7 +1251,7 @@ impl Connection { /// This interface allows to deal with such cases, by allowing to translate an address as sent /// by a ScyllaDB node to another address to be used by the driver for connection. /// -/// Please note that the "known nodes" addresses provided while creating the [`Session`] +/// Please note that the "known nodes" addresses provided while creating the [`crate::session::Session`] /// instance are not translated, only IP address retrieved from or sent by Cassandra nodes /// to the driver are. #[async_trait] diff --git a/scylla/src/session/session.rs b/scylla/src/session/session.rs index c48637eed4..fd5d64e1a3 100644 --- a/scylla/src/session/session.rs +++ b/scylla/src/session/session.rs @@ -346,7 +346,7 @@ pub(crate) enum RunQueryResult { impl Session { /// Estabilishes a CQL session with the database /// - /// Usually it's easier to use [SessionBuilder](crate::session_builder::SessionBuilder) + /// Usually it's easier to use [SessionBuilder](crate::session::SessionBuilder) /// instead of calling `Session::connect` directly, because it's more convenient. /// # Arguments /// * `config` - Connection configuration - known nodes, Compression, etc. diff --git a/scylla/src/session/session_builder.rs b/scylla/src/session/session_builder.rs index 643dd16253..71f9dbd72f 100644 --- a/scylla/src/session/session_builder.rs +++ b/scylla/src/session/session_builder.rs @@ -809,7 +809,7 @@ impl GenericSessionBuilder { self } - /// Set the number of attempts to fetch [TracingInfo](crate::tracing::TracingInfo) + /// Set the number of attempts to fetch [TracingInfo](crate::execution::tracing::TracingInfo) /// in [`Session::get_tracing_info`]. /// The default is 5 attempts. /// @@ -834,7 +834,7 @@ impl GenericSessionBuilder { self } - /// Set the delay between attempts to fetch [TracingInfo](crate::tracing::TracingInfo) + /// Set the delay between attempts to fetch [TracingInfo](crate::execution::tracing::TracingInfo) /// in [`Session::get_tracing_info`]. /// The default is 3 milliseconds. /// @@ -859,7 +859,7 @@ impl GenericSessionBuilder { self } - /// Set the consistency level of fetching [TracingInfo](crate::tracing::TracingInfo) + /// Set the consistency level of fetching [TracingInfo](crate::execution::tracing::TracingInfo) /// in [`Session::get_tracing_info`]. /// The default is [`Consistency::One`]. ///