Skip to content

Commit

Permalink
Revert "Merge pull request #812 from sylwiaszunejko/prepare_batch"
Browse files Browse the repository at this point in the history
This reverts commit 07b262c, reversing
changes made to 1854c96.
  • Loading branch information
piodul committed Oct 6, 2023
1 parent 4d0283c commit a9241e6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 169 deletions.
60 changes: 3 additions & 57 deletions scylla/src/transport/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub(crate) use ssl_config::SslConfig;

use crate::authentication::AuthenticatorProvider;
use scylla_cql::frame::response::authenticate::Authenticate;
use std::collections::{BTreeSet, HashMap, HashSet};
use std::collections::{BTreeSet, HashMap};
use std::convert::TryFrom;
use std::io::ErrorKind;
use std::net::{IpAddr, SocketAddr};
Expand All @@ -52,7 +52,7 @@ use crate::frame::{
request::{self, batch, execute, query, register, SerializableRequest},
response::{event::Event, result, NonErrorResponse, Response, ResponseOpcode},
server_event_type::EventType,
value::{BatchValues, BatchValuesIterator, ValueList},
value::{BatchValues, ValueList},
FrameParams, SerializedRequest,
};
use crate::query::Query;
Expand Down Expand Up @@ -772,13 +772,11 @@ impl Connection {

pub(crate) async fn batch_with_consistency(
&self,
init_batch: &Batch,
batch: &Batch,
values: impl BatchValues,
consistency: Consistency,
serial_consistency: Option<SerialConsistency>,
) -> Result<QueryResult, QueryError> {
let batch = self.prepare_batch(init_batch, &values).await?;

let batch_frame = batch::Batch {
statements: Cow::Borrowed(&batch.statements),
values,
Expand Down Expand Up @@ -822,58 +820,6 @@ impl Connection {
}
}

async fn prepare_batch<'b>(
&self,
init_batch: &'b Batch,
values: impl BatchValues,
) -> Result<Cow<'b, Batch>, QueryError> {
let mut to_prepare = HashSet::<&str>::new();

{
let mut values_iter = values.batch_values_iter();
for stmt in &init_batch.statements {
if let BatchStatement::Query(query) = stmt {
let value = values_iter.next_serialized().transpose()?;
if let Some(v) = value {
if v.len() > 0 {
to_prepare.insert(&query.contents);
}
}
} else {
values_iter.skip_next();
}
}
}

if to_prepare.is_empty() {
return Ok(Cow::Borrowed(init_batch));
}

let mut prepared_queries = HashMap::<&str, PreparedStatement>::new();

for query in &to_prepare {
let prepared = self.prepare(&Query::new(query.to_string())).await?;
prepared_queries.insert(query, prepared);
}

let mut batch: Cow<Batch> = Cow::Owned(Default::default());
batch.to_mut().config = init_batch.config.clone();
for stmt in &init_batch.statements {
match stmt {
BatchStatement::Query(query) => match prepared_queries.get(query.contents.as_str())
{
Some(prepared) => batch.to_mut().append_statement(prepared.clone()),
None => batch.to_mut().append_statement(query.clone()),
},
BatchStatement::PreparedStatement(prepared) => {
batch.to_mut().append_statement(prepared.clone());
}
}
}

Ok(batch)
}

pub(crate) async fn use_keyspace(
&self,
keyspace_name: &VerifiedKeyspaceName,
Expand Down
2 changes: 0 additions & 2 deletions scylla/src/transport/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ mod authenticate_test;
mod cql_collections_test;
#[cfg(test)]
mod session_test;
#[cfg(test)]
mod silent_prepare_batch_test;

#[cfg(test)]
mod cql_types_test;
Expand Down
110 changes: 0 additions & 110 deletions scylla/src/transport/silent_prepare_batch_test.rs

This file was deleted.

0 comments on commit a9241e6

Please sign in to comment.