Skip to content

Commit

Permalink
fix prepared results bug (#945)
Browse files Browse the repository at this point in the history
  • Loading branch information
conorbros authored Dec 7, 2022
1 parent 38698c3 commit d0a4e7b
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions shotover-proxy/src/transforms/cassandra/sink_cluster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use async_trait::async_trait;
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::query::QueryParams;
Expand Down Expand Up @@ -487,30 +488,30 @@ impl CassandraSinkCluster {
)
.await?;

if !prepare_responses.windows(2).all(|w| w[0] == w[1]) {
let err_str = prepare_responses
.iter_mut()
.filter_map(|response| {
if let Some(Frame::Cassandra(CassandraFrame {
operation:
CassandraOperation::Result(CassandraResult::Prepared(prepared)),
..
})) = response.frame()
{
Some(format!("\n{:?}", prepared))
} else {
None
}
})
let prepared_results: Vec<&mut Box<BodyResResultPrepared>> = prepare_responses
.iter_mut()
.filter_map(|message| {
if let Some(Frame::Cassandra(CassandraFrame {
operation: CassandraOperation::Result(CassandraResult::Prepared(prepared)),
..
})) = message.frame()
{
Some(prepared)
} else {
None
}
})
.collect();

if !prepared_results.windows(2).all(|w| w[0] == w[1]) {
let err_str = prepared_results
.iter()
.map(|p| format!("\n{:?}", p))
.collect::<String>();

if cfg!(test) {
panic!("{}", err_str);
} else {
tracing::error!(
"Nodes did not return the same response to PREPARE statement {err_str}"
);
}
tracing::error!(
"Nodes did not return the same response to PREPARE statement {err_str}"
);
}
}

Expand Down

0 comments on commit d0a4e7b

Please sign in to comment.