-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #806 from sylwiaszunejko/prepare_query
Quietly prepare unprepared query
- Loading branch information
Showing
4 changed files
with
127 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ mod lwt_optimisation; | |
mod new_session; | ||
mod retries; | ||
mod shards; | ||
mod silent_prepare_query; | ||
pub(crate) mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
use crate::utils::test_with_3_node_cluster; | ||
use scylla::transport::session::Session; | ||
use scylla::SessionBuilder; | ||
use scylla::{query::Query, test_utils::unique_keyspace_name}; | ||
use scylla_proxy::{ | ||
Condition, ProxyError, Reaction, RequestOpcode, RequestReaction, RequestRule, ShardAwareness, | ||
WorkerError, | ||
}; | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
|
||
#[tokio::test] | ||
#[ntest::timeout(30000)] | ||
#[cfg(not(scylla_cloud_tests))] | ||
async fn test_prepare_query_with_values() { | ||
// unprepared query with non empty values should be prepared | ||
const TIMEOUT_PER_REQUEST: Duration = Duration::from_millis(1000); | ||
|
||
let res = test_with_3_node_cluster(ShardAwareness::QueryNode, |proxy_uris, translation_map, mut running_proxy| async move { | ||
// DB preparation phase | ||
let session: Session = SessionBuilder::new() | ||
.known_node(proxy_uris[0].as_str()) | ||
.address_translator(Arc::new(translation_map)) | ||
.build() | ||
.await | ||
.unwrap(); | ||
|
||
let ks = unique_keyspace_name(); | ||
session.query(format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 3}}", ks), &[]).await.unwrap(); | ||
session.use_keyspace(ks, false).await.unwrap(); | ||
session | ||
.query("CREATE TABLE t (a int primary key)", &[]) | ||
.await | ||
.unwrap(); | ||
|
||
let q = Query::from("INSERT INTO t (a) VALUES (?)"); | ||
|
||
let drop_unprepared_frame_rule = RequestRule( | ||
Condition::RequestOpcode(RequestOpcode::Query) | ||
.and(Condition::BodyContainsCaseSensitive(Box::new(*b"t"))), | ||
RequestReaction::drop_frame(), | ||
); | ||
|
||
running_proxy.running_nodes[2] | ||
.change_request_rules(Some(vec![drop_unprepared_frame_rule])); | ||
|
||
tokio::select! { | ||
_res = session.query(q, (0,)) => (), | ||
_ = tokio::time::sleep(TIMEOUT_PER_REQUEST) => panic!("Rules did not work: no received response"), | ||
}; | ||
|
||
running_proxy | ||
}).await; | ||
|
||
match res { | ||
Ok(()) => (), | ||
Err(ProxyError::Worker(WorkerError::DriverDisconnected(_))) => (), | ||
Err(err) => panic!("{}", err), | ||
} | ||
} | ||
|
||
#[tokio::test] | ||
#[ntest::timeout(30000)] | ||
#[cfg(not(scylla_cloud_tests))] | ||
async fn test_query_with_no_values() { | ||
// unprepared query with empty values should not be prepared | ||
const TIMEOUT_PER_REQUEST: Duration = Duration::from_millis(1000); | ||
|
||
let res = test_with_3_node_cluster(ShardAwareness::QueryNode, |proxy_uris, translation_map, mut running_proxy| async move { | ||
// DB preparation phase | ||
let session: Session = SessionBuilder::new() | ||
.known_node(proxy_uris[0].as_str()) | ||
.address_translator(Arc::new(translation_map)) | ||
.build() | ||
.await | ||
.unwrap(); | ||
|
||
let ks = unique_keyspace_name(); | ||
session.query(format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 3}}", ks), &[]).await.unwrap(); | ||
session.use_keyspace(ks, false).await.unwrap(); | ||
session | ||
.query("CREATE TABLE t (a int primary key)", &[]) | ||
.await | ||
.unwrap(); | ||
|
||
let q = Query::from("INSERT INTO t (a) VALUES (1)"); | ||
|
||
let drop_prepared_frame_rule = RequestRule( | ||
Condition::RequestOpcode(RequestOpcode::Prepare) | ||
.and(Condition::BodyContainsCaseSensitive(Box::new(*b"t"))), | ||
RequestReaction::drop_frame(), | ||
); | ||
|
||
running_proxy.running_nodes[2] | ||
.change_request_rules(Some(vec![drop_prepared_frame_rule])); | ||
|
||
tokio::select! { | ||
_res = session.query(q, ()) => (), | ||
_ = tokio::time::sleep(TIMEOUT_PER_REQUEST) => panic!("Rules did not work: no received response"), | ||
}; | ||
|
||
running_proxy | ||
}).await; | ||
|
||
match res { | ||
Ok(()) => (), | ||
Err(ProxyError::Worker(WorkerError::DriverDisconnected(_))) => (), | ||
Err(err) => panic!("{}", err), | ||
} | ||
} |