Skip to content

Commit

Permalink
Avoid cloning prepared metadata fields (#982)
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai authored Jan 9, 2023
1 parent 0d813e0 commit c2dafcb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
14 changes: 12 additions & 2 deletions shotover-proxy/src/transforms/cassandra/sink_cluster/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use self::node_pool::PreparedMetadata;
use crate::error::ChainResponse;
use crate::frame::cassandra::{parse_statement_single, CassandraMetadata, Tracing};
use crate::frame::{CassandraFrame, CassandraOperation, CassandraResult, Frame};
Expand All @@ -11,7 +12,6 @@ use cassandra_protocol::events::ServerEvent;
use cassandra_protocol::frame::message_error::{ErrorBody, ErrorType, UnpreparedError};
use cassandra_protocol::frame::message_execute::BodyReqExecuteOwned;
use cassandra_protocol::frame::message_result::BodyResResultPrepared;
use cassandra_protocol::frame::message_result::PreparedMetadata;
use cassandra_protocol::frame::{Opcode, Version};
use cassandra_protocol::types::CBytesShort;
use cql3_parser::cassandra_statement::CassandraStatement;
Expand Down Expand Up @@ -1173,7 +1173,17 @@ fn get_prepared_result_message(message: &mut Message) -> Option<(CBytesShort, Pr
..
})) = message.frame()
{
return Some((prepared.id.clone(), prepared.metadata.clone()));
return Some((
prepared.id.clone(),
PreparedMetadata {
pk_indexes: prepared.metadata.pk_indexes.clone(),
keyspace: prepared
.metadata
.global_table_spec
.as_ref()
.map(|x| x.ks_name.clone()),
},
));
}

None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use super::token_map::TokenMap;
use super::KeyspaceChanRx;
use anyhow::{anyhow, Error, Result};
use cassandra_protocol::frame::message_execute::BodyReqExecuteOwned;
use cassandra_protocol::frame::message_result::PreparedMetadata;
use cassandra_protocol::frame::Version;
use cassandra_protocol::token::Murmur3Token;
use cassandra_protocol::types::CBytesShort;
Expand All @@ -14,6 +13,12 @@ use std::sync::Arc;
use std::{collections::HashMap, net::SocketAddr};
use tokio::sync::{watch, RwLock};

#[derive(Debug, Clone)]
pub struct PreparedMetadata {
pub pk_indexes: Vec<i16>,
pub keyspace: Option<String>,
}

#[derive(Debug)]
pub enum GetReplicaErr {
NoPreparedMetadata,
Expand Down Expand Up @@ -157,11 +162,10 @@ impl NodePool {
let keyspace = self
.keyspace_metadata
.get(
&metadata
.global_table_spec
metadata
.keyspace
.as_ref()
.ok_or(GetReplicaErr::NoKeyspaceMetadata)?
.ks_name,
.ok_or(GetReplicaErr::NoKeyspaceMetadata)?,
)
.ok_or(GetReplicaErr::NoKeyspaceMetadata)?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ mod test_token_aware_router {
use super::super::node_pool::{KeyspaceMetadata, NodePool};
use super::super::routing_key::calculate_routing_key;
use crate::transforms::cassandra::sink_cluster::node::CassandraNode;
use crate::transforms::cassandra::sink_cluster::node_pool::PreparedMetadata;
use crate::transforms::cassandra::sink_cluster::{KeyspaceChanRx, KeyspaceChanTx};
use cassandra_protocol::consistency::Consistency::One;
use cassandra_protocol::frame::message_execute::BodyReqExecuteOwned;
use cassandra_protocol::frame::message_result::PreparedMetadata;
use cassandra_protocol::frame::message_result::{
ColSpec, ColType::Varchar, ColTypeOption, TableSpec,
};
use cassandra_protocol::frame::Version;
use cassandra_protocol::query::QueryParams;
use cassandra_protocol::query::QueryValues::SimpleValues;
Expand Down Expand Up @@ -50,7 +47,7 @@ mod test_token_aware_router {
router.update_keyspaces(&mut keyspaces_rx).await;

router
.add_prepared_result(id.clone(), prepared_metadata().clone())
.add_prepared_result(id.clone(), prepared_metadata())
.await;

for (pk, test_token, rack_replicas, dc_replicas) in test_data() {
Expand Down Expand Up @@ -149,18 +146,7 @@ mod test_token_aware_router {
fn prepared_metadata() -> PreparedMetadata {
PreparedMetadata {
pk_indexes: vec![0],
global_table_spec: Some(TableSpec {
ks_name: "demo_ks".into(),
table_name: "books_by_author".into(),
}),
col_specs: vec![ColSpec {
table_spec: None,
name: "author".into(),
col_type: ColTypeOption {
id: Varchar,
value: None,
},
}],
keyspace: Some("demo_ks".into()),
}
}

Expand Down

0 comments on commit c2dafcb

Please sign in to comment.