Skip to content

Commit 4664c82

Browse files
authored
Merge pull request #356 from NodeDB-Lab/fix/statement-command-tag
Report one real command tag per DML statement on every engine, protocol, and path
2 parents a89b56d + b891fc8 commit 4664c82

506 files changed

Lines changed: 32401 additions & 6761 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎nodedb-client/src/native/connection/response.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub(super) fn response_to_query_result(resp: NativeResponse) -> NodeDbResult<Que
5454
columns: resp.columns.unwrap_or_default(),
5555
rows: resp.rows.unwrap_or_default(),
5656
rows_affected: resp.rows_affected.unwrap_or(0),
57+
command: resp.command,
5758
})
5859
}
5960

@@ -69,6 +70,7 @@ mod tests {
6970
columns: vec!["x".into()],
7071
rows: vec![vec![nodedb_types::Value::Integer(42)]],
7172
rows_affected: 0,
73+
command: None,
7274
},
7375
0,
7476
);

‎nodedb-client/src/remote/client/sql_lifecycle.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ impl NodeDbRemote {
4949
columns,
5050
rows,
5151
rows_affected: 0,
52+
command: None,
5253
})
5354
}
5455

‎nodedb-cluster-tests/tests/common_suite/cases/calvin_cluster_pgwire_e2e.rs‎

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ use crate::common;
3030
use std::sync::atomic::Ordering;
3131
use std::time::Duration;
3232

33-
use nodedb::types::{DatabaseId, VShardId};
3433
use nodedb_cluster::calvin::SEQUENCER_GROUP_ID;
3534
use tokio_postgres::SimpleQueryMessage;
3635

36+
use super::vshard_names::distinct_vshard_collections;
3737
use common::cluster_harness::{TestClusterNode, wait_for};
3838

3939
/// Observed sequencer-group leader id from a node's local Raft status, or `0`
@@ -61,23 +61,6 @@ async fn value_of(client: &tokio_postgres::Client, coll: &str, id: &str) -> Opti
6161
})
6262
}
6363

64-
/// Find two collection names whose vShard ids differ.
65-
fn two_distinct_vshard_collections() -> (String, String) {
66-
let mut first: Option<(String, u32)> = None;
67-
for i in 0u32..512 {
68-
let name = format!("calvin_e2e_{i}");
69-
let vshard = VShardId::from_collection_in_database(DatabaseId::DEFAULT, &name).as_u32();
70-
if let Some((ref fname, fv)) = first {
71-
if fv != vshard {
72-
return (fname.clone(), name);
73-
}
74-
} else {
75-
first = Some((name, vshard));
76-
}
77-
}
78-
panic!("could not find two distinct-vshard collections in 512 tries");
79-
}
80-
8164
/// Calvin multi-shard batch via pgwire `simple_query` COMMITS when sent as an
8265
/// interactive `BEGIN ... COMMIT` block.
8366
///
@@ -124,7 +107,7 @@ async fn calvin_multishard_write_in_explicit_block_commits() {
124107
)
125108
.await;
126109

127-
let (col_a, col_b) = two_distinct_vshard_collections();
110+
let (col_a, col_b) = distinct_vshard_collections("calvin_e2e_0", "calvin_e2e");
128111

129112
// Create both collections on this (single) node.
130113
node.client

‎nodedb-cluster-tests/tests/common_suite/cases/calvin_multi_shard_bitemporal_best_effort_restart.rs‎

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
//!
1212
//! 1. Two `document_schemaless` collections, each created `WITH
1313
//! (bitemporal=true)`, are placed on DIFFERENT vShards
14-
//! (`distinct_vshard_bitemporal_collections`, same technique as
15-
//! `calvin_multi_shard_redo_restart.rs`).
14+
//! (`vshard_names::distinct_vshard_collections`).
1615
//! 2. `BEGIN; INSERT INTO <a>; INSERT INTO <b>; COMMIT` is sent as ONE
1716
//! `simple_query` call, so both writes are buffered inside the block and,
1817
//! on COMMIT, `classify_dispatch` sees writes on two vShards → MultiShard.
@@ -32,9 +31,9 @@ use crate::common;
3231
use std::sync::atomic::Ordering;
3332
use std::time::Duration;
3433

35-
use nodedb::types::{DatabaseId, VShardId};
3634
use tokio_postgres::SimpleQueryMessage;
3735

36+
use super::vshard_names::distinct_vshard_collections;
3837
use common::cluster_harness::{TestClusterNode, read_once_a_leader_exists, wait_for};
3938

4039
/// Observed sequencer-group leader id from a node's local Raft status, or `0`
@@ -61,26 +60,6 @@ fn admitted_total(node: &TestClusterNode) -> u64 {
6160
.unwrap_or(0)
6261
}
6362

64-
/// A `(coll_a, coll_b)` pair of bitemporal collection names whose vShard ids
65-
/// differ, so a transaction writing to both is genuinely multi-shard.
66-
/// Deterministic: `VShardId::from_collection_in_database` is a pure function
67-
/// of the database id + collection name bytes. Same technique as
68-
/// `calvin_multi_shard_redo_restart.rs::distinct_vshard_collections`.
69-
fn distinct_vshard_bitemporal_collections() -> (String, String) {
70-
let a_name = "bt_a".to_string();
71-
let va = VShardId::from_collection_in_database(DatabaseId::DEFAULT, &a_name).as_u32();
72-
for i in 0u32..512 {
73-
let b_name = format!("bt_b_{i}");
74-
if VShardId::from_collection_in_database(DatabaseId::DEFAULT, &b_name).as_u32() != va {
75-
return (a_name, b_name);
76-
}
77-
}
78-
panic!(
79-
"could not find a second bitemporal collection name on a distinct vShard \
80-
from the first in 512 tries"
81-
);
82-
}
83-
8463
/// Current `value` for `id` in a bitemporal document collection, or `None` if
8564
/// not visible.
8665
///
@@ -160,7 +139,7 @@ async fn calvin_multi_shard_bitemporal_best_effort_commit_survives_wal_only_rest
160139
)
161140
.await;
162141

163-
let (coll_a, coll_b) = distinct_vshard_bitemporal_collections();
142+
let (coll_a, coll_b) = distinct_vshard_collections("bt_a", "bt_b");
164143

165144
node.client
166145
.simple_query(&format!(

‎nodedb-cluster-tests/tests/common_suite/cases/calvin_multi_shard_bitemporal_restart.rs‎

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
//!
1010
//! 1. Two `document_schemaless` collections, each created `WITH
1111
//! (bitemporal=true)`, are placed on DIFFERENT vShards
12-
//! (`distinct_vshard_bitemporal_collections`, same technique as
13-
//! `calvin_multi_shard_redo_restart.rs`).
12+
//! (`vshard_names::distinct_vshard_collections`).
1413
//! 2. `BEGIN; INSERT INTO <a>; INSERT INTO <b>; COMMIT` is sent as ONE
1514
//! `simple_query` call, so both writes are buffered inside the block and,
1615
//! on COMMIT, `classify_dispatch` sees writes on two vShards → MultiShard
@@ -29,9 +28,9 @@ use crate::common;
2928
use std::sync::atomic::Ordering;
3029
use std::time::Duration;
3130

32-
use nodedb::types::{DatabaseId, VShardId};
3331
use tokio_postgres::SimpleQueryMessage;
3432

33+
use super::vshard_names::distinct_vshard_collections;
3534
use common::cluster_harness::{TestClusterNode, read_once_a_leader_exists, wait_for};
3635

3736
/// Observed sequencer-group leader id from a node's local Raft status, or `0`
@@ -58,26 +57,6 @@ fn admitted_total(node: &TestClusterNode) -> u64 {
5857
.unwrap_or(0)
5958
}
6059

61-
/// A `(coll_a, coll_b)` pair of bitemporal collection names whose vShard ids
62-
/// differ, so a transaction writing to both is genuinely multi-shard.
63-
/// Deterministic: `VShardId::from_collection_in_database` is a pure function
64-
/// of the database id + collection name bytes. Same technique as
65-
/// `calvin_multi_shard_redo_restart.rs::distinct_vshard_collections`.
66-
fn distinct_vshard_bitemporal_collections() -> (String, String) {
67-
let a_name = "bt_a".to_string();
68-
let va = VShardId::from_collection_in_database(DatabaseId::DEFAULT, &a_name).as_u32();
69-
for i in 0u32..512 {
70-
let b_name = format!("bt_b_{i}");
71-
if VShardId::from_collection_in_database(DatabaseId::DEFAULT, &b_name).as_u32() != va {
72-
return (a_name, b_name);
73-
}
74-
}
75-
panic!(
76-
"could not find a second bitemporal collection name on a distinct vShard \
77-
from the first in 512 tries"
78-
);
79-
}
80-
8160
/// Current `value` for `id` in a bitemporal document collection, or `None` if
8261
/// not visible.
8362
///
@@ -156,7 +135,7 @@ async fn calvin_multi_shard_bitemporal_commit_survives_wal_only_restart() {
156135
)
157136
.await;
158137

159-
let (coll_a, coll_b) = distinct_vshard_bitemporal_collections();
138+
let (coll_a, coll_b) = distinct_vshard_collections("bt_a", "bt_b");
160139

161140
node.client
162141
.simple_query(&format!(

‎nodedb-cluster-tests/tests/common_suite/cases/calvin_multi_shard_redo_restart.rs‎

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//! `vector_index_txn_restart.rs` for the single-shard analogue).
77
//!
88
//! 1. Two collections — a KV collection and a vector-indexed document
9-
//! collection — are created on DIFFERENT vShards (`distinct_vshard_
10-
//! collections`, same technique as `calvin_cluster_pgwire_e2e.rs`).
9+
//! collection — are created on DIFFERENT vShards
10+
//! (`vshard_names::distinct_vshard_collections`).
1111
//! 2. `BEGIN; INSERT INTO <kv>; INSERT INTO <vecdocs>; COMMIT` is sent as ONE
1212
//! `simple_query` call. tokio-postgres ships this as a single wire
1313
//! message; the server buffers the two INSERTs during the transaction and,
@@ -25,9 +25,9 @@ use crate::common;
2525
use std::sync::atomic::Ordering;
2626
use std::time::Duration;
2727

28-
use nodedb::types::{DatabaseId, VShardId};
2928
use tokio_postgres::SimpleQueryMessage;
3029

30+
use super::vshard_names::distinct_vshard_collections;
3131
use common::cluster_harness::{TestClusterNode, read_once_a_leader_exists, wait_for};
3232

3333
/// Observed sequencer-group leader id from a node's local Raft status, or `0`
@@ -54,26 +54,6 @@ fn admitted_total(node: &TestClusterNode) -> u64 {
5454
.unwrap_or(0)
5555
}
5656

57-
/// A `(kv_name, vec_name)` pair of collection names whose vShard ids differ,
58-
/// so a transaction writing to both is genuinely multi-shard. Deterministic:
59-
/// `VShardId::from_collection_in_database` is a pure function of the database
60-
/// id + collection name bytes. Same technique as
61-
/// `calvin_cluster_pgwire_e2e.rs::two_distinct_vshard_collections`.
62-
fn distinct_vshard_collections() -> (String, String) {
63-
let kv_name = "cmr_kv".to_string();
64-
let vkv = VShardId::from_collection_in_database(DatabaseId::DEFAULT, &kv_name).as_u32();
65-
for i in 0u32..512 {
66-
let vec_name = format!("cmr_vecdocs_{i}");
67-
if VShardId::from_collection_in_database(DatabaseId::DEFAULT, &vec_name).as_u32() != vkv {
68-
return (kv_name, vec_name);
69-
}
70-
}
71-
panic!(
72-
"could not find a vector-doc collection name on a distinct vShard from \
73-
the KV collection in 512 tries"
74-
);
75-
}
76-
7757
/// Single-row `col` value for `id` in a KV/document collection, or `None` if
7858
/// not visible.
7959
///
@@ -140,7 +120,7 @@ async fn calvin_multi_shard_write_in_explicit_block_commits_and_survives_restart
140120
)
141121
.await;
142122

143-
let (kv, vecdocs) = distinct_vshard_collections();
123+
let (kv, vecdocs) = distinct_vshard_collections("cmr_kv", "cmr_vecdocs");
144124

145125
node.client
146126
.simple_query(&format!(

0 commit comments

Comments
 (0)