Skip to content

Commit 64647f9

Browse files
authored
Merge pull request #1127 from Lorak-mmk/fix-concurrent-ddl
Fix concurrent DDL queries
2 parents be14812 + 019cf1f commit 64647f9

21 files changed

+473
-460
lines changed

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ The above commands will leave a running ScyllaDB cluster in the background.
4949
To stop it, use `make down`.\
5050
Starting a cluster without running any test is possible with `make up`.
5151

52+
### Writing tests that need to connect to Scylla
53+
54+
If you test requires connecting to Scylla, there are a few things you should consider.
55+
56+
1. Such tests are considered integration tests and should be placed in `scylla/tests/integration`.
57+
2. To avoid name conflicts while creating a keyspace use `unique_keyspace_name` function from `utils` module.
58+
3. This `utils` module (`scylla/tests/integration/utils.rs`) contains other functions that may be helpful for writing tests.
59+
For example `create_new_session_builder` or `test_with_3_node_cluster`.
60+
4. To perform DDL queries (creating / altering / dropping a keyspace / table /type) use `ddl` method from the utils module.
61+
To do this, import the `PerformDDL` trait (`use crate::utils::PerformDDL;`). Then you can call `ddl` method on a
62+
`Session`.
63+
5264
### Tracing in tests
5365

5466
By default cargo captures `print!` macro's output from tests and prints them for failed tests.

scylla/src/transport/caching_session.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,9 @@ where
329329
mod tests {
330330
use crate::query::Query;
331331
use crate::statement::PagingState;
332-
use crate::test_utils::{create_new_session_builder, scylla_supports_tablets, setup_tracing};
332+
use crate::test_utils::{
333+
create_new_session_builder, scylla_supports_tablets, setup_tracing, PerformDDL,
334+
};
333335
use crate::transport::partitioner::PartitionerName;
334336
use crate::transport::session::Session;
335337
use crate::utils::test_utils::unique_keyspace_name;
@@ -358,18 +360,15 @@ mod tests {
358360
}
359361

360362
session
361-
.query_unpaged(create_ks, &[])
363+
.ddl(create_ks)
362364
.await
363365
.expect("Could not create keyspace");
364366

365367
session
366-
.query_unpaged(
367-
format!(
368-
"CREATE TABLE IF NOT EXISTS {}.test_table (a int primary key, b int)",
369-
ks
370-
),
371-
&[],
372-
)
368+
.ddl(format!(
369+
"CREATE TABLE IF NOT EXISTS {}.test_table (a int primary key, b int)",
370+
ks
371+
))
373372
.await
374373
.expect("Could not create table");
375374

@@ -566,10 +565,7 @@ mod tests {
566565
let session: CachingSession = create_caching_session().await;
567566

568567
session
569-
.execute_unpaged(
570-
"CREATE TABLE IF NOT EXISTS test_batch_table (a int, b int, primary key (a, b))",
571-
(),
572-
)
568+
.ddl("CREATE TABLE IF NOT EXISTS test_batch_table (a int, b int, primary key (a, b))")
573569
.await
574570
.unwrap();
575571

@@ -689,7 +685,7 @@ mod tests {
689685
let session: CachingSession = CachingSession::from(new_for_test(true).await, 100);
690686

691687
session
692-
.execute_unpaged("CREATE TABLE tbl (a int PRIMARY KEY, b int)", ())
688+
.ddl("CREATE TABLE tbl (a int PRIMARY KEY, b int)")
693689
.await
694690
.unwrap();
695691

@@ -745,10 +741,7 @@ mod tests {
745741
let session: CachingSession = CachingSession::from(new_for_test(false).await, 100);
746742

747743
session
748-
.execute_unpaged(
749-
"CREATE TABLE tbl (a int PRIMARY KEY) with cdc = {'enabled': true}",
750-
&(),
751-
)
744+
.ddl("CREATE TABLE tbl (a int PRIMARY KEY) with cdc = {'enabled': true}")
752745
.await
753746
.unwrap();
754747

scylla/src/transport/connection.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,7 +2397,7 @@ mod tests {
23972397
use crate::transport::connection::open_connection;
23982398
use crate::transport::node::ResolvedContactPoint;
23992399
use crate::transport::topology::UntranslatedEndpoint;
2400-
use crate::utils::test_utils::unique_keyspace_name;
2400+
use crate::utils::test_utils::{unique_keyspace_name, PerformDDL};
24012401
use crate::SessionBuilder;
24022402
use futures::{StreamExt, TryStreamExt};
24032403
use std::collections::HashMap;
@@ -2452,17 +2452,14 @@ mod tests {
24522452
.build()
24532453
.await
24542454
.unwrap();
2455-
session.query_unpaged(format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks.clone()), &[]).await.unwrap();
2455+
session.ddl(format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks.clone())).await.unwrap();
24562456
session.use_keyspace(ks.clone(), false).await.unwrap();
24572457
session
2458-
.query_unpaged("DROP TABLE IF EXISTS connection_query_iter_tab", &[])
2458+
.ddl("DROP TABLE IF EXISTS connection_query_iter_tab")
24592459
.await
24602460
.unwrap();
24612461
session
2462-
.query_unpaged(
2463-
"CREATE TABLE IF NOT EXISTS connection_query_iter_tab (p int primary key)",
2464-
&[],
2465-
)
2462+
.ddl("CREATE TABLE IF NOT EXISTS connection_query_iter_tab (p int primary key)")
24662463
.await
24672464
.unwrap();
24682465
}
@@ -2548,13 +2545,10 @@ mod tests {
25482545
.build()
25492546
.await
25502547
.unwrap();
2551-
session.query_unpaged(format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks.clone()), &[]).await.unwrap();
2548+
session.ddl(format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks.clone())).await.unwrap();
25522549
session.use_keyspace(ks.clone(), false).await.unwrap();
25532550
session
2554-
.query_unpaged(
2555-
"CREATE TABLE IF NOT EXISTS t (p int primary key, v blob)",
2556-
&[],
2557-
)
2551+
.ddl("CREATE TABLE IF NOT EXISTS t (p int primary key, v blob)")
25582552
.await
25592553
.unwrap();
25602554
}
@@ -2580,7 +2574,7 @@ mod tests {
25802574
.await
25812575
.unwrap();
25822576

2583-
connection.query_unpaged("TRUNCATE t").await.unwrap();
2577+
connection.ddl("TRUNCATE t").await.unwrap();
25842578

25852579
let mut futs = Vec::new();
25862580

0 commit comments

Comments
 (0)