Skip to content

Commit

Permalink
prepared: wrap result metadata with ArcSwap
Browse files Browse the repository at this point in the history
In the following commit, the result metadata will be updated during
reprepare. We make use of `ArcSwap`, which is a mechanism used for
shared data which is rarely updated.
  • Loading branch information
muzarski committed Feb 7, 2024
1 parent c001c80 commit a9a2a6c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions scylla/src/statement/prepared_statement.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use arc_swap::ArcSwap;
use bytes::{Bytes, BytesMut};
use scylla_cql::errors::{BadQuery, QueryError};
use scylla_cql::frame::types::RawValue;
Expand Down Expand Up @@ -37,7 +38,7 @@ pub struct PreparedStatement {
#[derive(Debug)]
struct PreparedStatementSharedData {
metadata: PreparedMetadata,
result_metadata: ResultMetadata,
result_metadata: ArcSwap<ResultMetadata>,
statement: String,
}

Expand Down Expand Up @@ -69,7 +70,7 @@ impl PreparedStatement {
id,
shared: Arc::new(PreparedStatementSharedData {
metadata,
result_metadata,
result_metadata: ArcSwap::from_pointee(result_metadata),
statement,
}),
prepare_tracing_ids: Vec::new(),
Expand Down Expand Up @@ -310,8 +311,8 @@ impl PreparedStatement {
}

/// Access metadata about the result of prepared statement returned by the database
pub fn get_result_metadata(&self) -> &ResultMetadata {
&self.shared.result_metadata
pub fn get_result_metadata(&self) -> Arc<ResultMetadata> {
self.shared.result_metadata.load_full()
}

/// Get the name of the partitioner used for this statement.
Expand Down
2 changes: 1 addition & 1 deletion scylla/src/transport/caching_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ where
id: prepared.get_id().clone(),
is_confirmed_lwt: prepared.is_confirmed_lwt(),
metadata: prepared.get_prepared_metadata().clone(),
result_metadata: prepared.get_result_metadata().clone(),
result_metadata: prepared.get_result_metadata().as_ref().clone(),
partitioner_name: prepared.get_partitioner_name().clone(),
};
self.cache.insert(query_contents, raw);
Expand Down
4 changes: 2 additions & 2 deletions scylla/src/transport/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ impl Connection {
&execute_frame,
true,
prepared_statement.config.tracing,
cached_metadata,
cached_metadata.as_deref(),
)
.await?;

Expand All @@ -737,7 +737,7 @@ impl Connection {
&execute_frame,
true,
prepared_statement.config.tracing,
cached_metadata,
cached_metadata.as_deref(),
)
.await
}
Expand Down

0 comments on commit a9a2a6c

Please sign in to comment.