Skip to content

Commit

Permalink
prepared: update result metadata after reprepare
Browse files Browse the repository at this point in the history
  • Loading branch information
muzarski committed Feb 7, 2024
1 parent a9a2a6c commit 746a6e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions scylla/src/statement/prepared_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ impl PreparedStatement {
self.shared.result_metadata.load_full()
}

pub(crate) fn set_result_metadata(&self, metadata: Arc<ResultMetadata>) {
self.shared.result_metadata.store(metadata)
}

/// Get the name of the partitioner used for this statement.
pub(crate) fn get_partitioner_name(&self) -> &PartitionerName {
&self.partitioner_name
Expand Down
11 changes: 11 additions & 0 deletions scylla/src/transport/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,8 @@ impl Connection {
"Prepared statement Id changed, md5 sum should stay the same",
))
} else {
// Update the result metadata.
previous_prepared.set_result_metadata(reprepared.get_result_metadata());
Ok(())
}
}
Expand Down Expand Up @@ -733,6 +735,15 @@ impl Connection {
// Repreparation of a statement is needed
self.reprepare(prepared_statement.get_statement(), prepared_statement)
.await?;

// Since we make use of `ArcSwap` for `ResultMetadata`,
// old `cached_metadata` variable points to old metadata before reprepare.
// We need to fetch updated metadata from the object.
let cached_metadata = self
.config
.skip_result_metadata
.then(|| prepared_statement.get_result_metadata());

self.send_request(
&execute_frame,
true,
Expand Down

0 comments on commit 746a6e1

Please sign in to comment.