Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions crates/storage-cassandra/src/admin_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

//! `AdminStore` implementation for `CassandraCatalogStore`.

use crate::cassandra_util::PolicySession as _;
use crate::cassandra_util::Stmt;
use cdrs_tokio::types::IntoRustByName;
use extenddb_storage::management_store::{AdminEntry, OpError, OpResult};
use futures::future::BoxFuture;
Expand Down Expand Up @@ -39,7 +41,8 @@ impl extenddb_storage::management_store::AdminStore for CassandraCatalogStore {
);

let result = session
.query_with_values(
.run(
Stmt::Lwt,
&query,
cdrs_tokio::query_values!(admin_name.as_str(), password_hash.as_str()),
)
Expand Down Expand Up @@ -119,7 +122,7 @@ impl extenddb_storage::management_store::AdminStore for CassandraCatalogStore {

// Quorum, so the console's quorum session check sees the deletion.
let query = format!("DELETE FROM {catalog_keyspace}.admin_users WHERE admin_name = ?");
crate::cassandra_util::execute_quorum(
crate::cassandra_util::execute(
&session,
&query,
cdrs_tokio::query_values!(admin_name.as_str()),
Expand Down Expand Up @@ -147,7 +150,7 @@ impl extenddb_storage::management_store::AdminStore for CassandraCatalogStore {
let query = format!(
"UPDATE {catalog_keyspace}.admin_users SET password_hash = ? WHERE admin_name = ?"
);
crate::cassandra_util::execute_quorum(
crate::cassandra_util::execute(
&session,
&query,
cdrs_tokio::query_values!(password_hash.as_str(), admin_name.as_str()),
Expand Down
25 changes: 17 additions & 8 deletions crates/storage-cassandra/src/authorization_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

//! `AuthorizationStore` implementation for `CassandraCatalogStore`.

use crate::cassandra_util::PolicySession as _;
use crate::cassandra_util::Stmt;
use cdrs_tokio::types::IntoRustByName;
use extenddb_storage::authorization_store::{AuthorizationStore, SessionData};
use extenddb_storage::management_store::{OpError, OpResult};
Expand All @@ -26,7 +28,8 @@ impl AuthorizationStore for CassandraCatalogStore {
WHERE account_id = ? AND principal_type = 'user' AND principal_name = ?"
);
let result = session
.query_with_values(
.run(
Stmt::Read,
&query,
cdrs_tokio::query_values!(account_id.as_str(), user_name.as_str()),
)
Expand Down Expand Up @@ -73,7 +76,8 @@ impl AuthorizationStore for CassandraCatalogStore {
WHERE account_id = ? AND user_name = ? ALLOW FILTERING"
);
let groups_result = session
.query_with_values(
.run(
Stmt::Read,
&groups_query,
cdrs_tokio::query_values!(account_id.as_str(), user_name.as_str()),
)
Expand Down Expand Up @@ -103,7 +107,8 @@ impl AuthorizationStore for CassandraCatalogStore {
WHERE account_id = ? AND principal_type = 'group' AND principal_name = ?"
);
let policy_result = session
.query_with_values(
.run(
Stmt::Read,
&policy_query,
cdrs_tokio::query_values!(account_id.as_str(), group_name.as_str()),
)
Expand Down Expand Up @@ -151,7 +156,8 @@ impl AuthorizationStore for CassandraCatalogStore {
WHERE account_id = ? AND principal_type = 'user' AND principal_name = ?"
);
let result = session
.query_with_values(
.run(
Stmt::Read,
&query,
cdrs_tokio::query_values!(account_id.as_str(), user_name.as_str()),
)
Expand Down Expand Up @@ -266,7 +272,8 @@ impl AuthorizationStore for CassandraCatalogStore {
);

let result = session
.query_with_values(
.run(
Stmt::Read,
&query,
cdrs_tokio::query_values!(
account_id.as_str(),
Expand Down Expand Up @@ -354,7 +361,8 @@ impl AuthorizationStore for CassandraCatalogStore {
);

let result = session
.query_with_values(
.run(
Stmt::Read,
&query,
cdrs_tokio::query_values!(account_id.as_str(), user_name.as_str()),
)
Expand Down Expand Up @@ -408,7 +416,8 @@ impl AuthorizationStore for CassandraCatalogStore {
);

let result = session
.query_with_values(
.run(
Stmt::Read,
&query,
cdrs_tokio::query_values!(account_id.as_str(), role_name.as_str()),
)
Expand Down Expand Up @@ -456,7 +465,7 @@ impl AuthorizationStore for CassandraCatalogStore {
);

let result = session
.query_with_values(&query, cdrs_tokio::query_values!(arn.as_str()))
.run(Stmt::Read, &query, cdrs_tokio::query_values!(arn.as_str()))
.await
.map_err(|e| {
tracing::error!("fetch_resource_tags query failed: {e}");
Expand Down
71 changes: 30 additions & 41 deletions crates/storage-cassandra/src/backup_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@
//! serial level is a local quorum with no Paxos read, so the scan reads at
//! quorum and the coordinator clock after it.

use crate::cassandra_util::PolicySession as _;
use crate::cassandra_util::Stmt;
use std::time::Duration;

use cdrs_tokio::consistency::Consistency;
use cdrs_tokio::error::Error as DriverError;
use cdrs_tokio::frame::message_error::ErrorType;
use cdrs_tokio::query::{BatchQueryBuilder, QueryValues};
use cdrs_tokio::statement::StatementParamsBuilder;
use cdrs_tokio::query::QueryValues;
use cdrs_tokio::types::IntoRustByName;
use cdrs_tokio::types::rows::Row;
use cdrs_tokio::types::value::Value;
Expand Down Expand Up @@ -184,7 +184,7 @@ fn seconds_to_millis(seconds: f64) -> i64 {
/// The coordinator's clock, in epoch milliseconds: the clock every heartbeat
/// is stamped with, so a stale window is measured on it.
pub(crate) async fn coordinator_now_millis(engine: &CassandraEngine) -> Result<i64, StorageError> {
let rows = crate::cassandra_util::query_rows::<StorageError>(
let rows = crate::cassandra_util::system_read::<StorageError>(
&engine.session,
"SELECT toTimestamp(now()) AS now FROM system.local",
cdrs_tokio::query_values!(),
Expand Down Expand Up @@ -242,12 +242,7 @@ pub(crate) async fn conditional_write(
query: &str,
values: QueryValues,
) -> Result<WriteOutcome, StorageError> {
let params = StatementParamsBuilder::new()
.with_consistency(Consistency::LocalQuorum)
.with_serial_consistency(Consistency::LocalSerial)
.with_values(values)
.build();
match session.query_with_params(query, params).await {
match session.run(Stmt::Lwt, query, values).await {
Ok(result) => Ok(if crate::cassandra_util::lwt_applied(&result)? {
WriteOutcome::Matched
} else {
Expand Down Expand Up @@ -463,7 +458,7 @@ impl JobClaim for CassandraBackupClaim {
FROM {}.backups_by_arn WHERE account_id = ? AND backup_arn = ?",
self.engine.catalog_keyspace()
);
let rows = crate::cassandra_util::query_rows_quorum::<StorageError>(
let rows = crate::cassandra_util::query_rows::<StorageError>(
&self.engine.session,
&query,
cdrs_tokio::query_values!(
Expand Down Expand Up @@ -502,8 +497,7 @@ impl CassandraEngine {
if let Some(error) = crate::test_hooks::index_entry_removal_error(&row.backup_arn) {
return Err(error);
}
let batch = BatchQueryBuilder::new()
.with_consistency(Consistency::LocalQuorum)
let batch = crate::cassandra_util::batch()
.add_query(
format!(
"DELETE FROM {catalog}.backup_index_by_status \
Expand Down Expand Up @@ -539,7 +533,7 @@ impl CassandraEngine {
),
);
self.session
.batch(
.run_batch(
batch
.build()
.map_err(|e| StorageError::Internal(e.to_string()))?,
Expand All @@ -564,8 +558,7 @@ impl CassandraEngine {
if let Some(error) = crate::test_hooks::index_entry_batch_error(&row.backup_arn) {
return Err(error);
}
let batch = BatchQueryBuilder::new()
.with_consistency(Consistency::LocalQuorum)
let batch = crate::cassandra_util::batch()
.add_query(
format!(
"INSERT INTO {catalog}.backups_by_account (account_id, created_at, \
Expand Down Expand Up @@ -616,7 +609,7 @@ impl CassandraEngine {
),
);
self.session
.batch(
.run_batch(
batch
.build()
.map_err(|e| StorageError::Internal(e.to_string()))?,
Expand Down Expand Up @@ -659,7 +652,7 @@ impl CassandraEngine {
"SELECT * FROM {}.backups_by_arn WHERE account_id = ? AND backup_arn = ?",
self.catalog_keyspace()
);
let rows = crate::cassandra_util::query_rows_quorum::<StorageError>(
let rows = crate::cassandra_util::query_rows::<StorageError>(
&self.session,
&query,
cdrs_tokio::query_values!(account_id, backup_arn),
Expand All @@ -686,8 +679,7 @@ impl CassandraEngine {
to: &str,
) {
let catalog = self.catalog_keyspace();
let batch = BatchQueryBuilder::new()
.with_consistency(Consistency::LocalQuorum)
let batch = crate::cassandra_util::batch()
.add_query(
format!(
"DELETE FROM {catalog}.backup_index_by_status \
Expand All @@ -711,7 +703,7 @@ impl CassandraEngine {
),
);
let sent = match batch.build() {
Ok(batch) => self.session.batch(batch).await.map(|_| ()),
Ok(batch) => self.session.run_batch(batch).await.map(|_| ()),
Err(error) => Err(error),
};
if let Err(error) = sent {
Expand Down Expand Up @@ -907,7 +899,7 @@ impl CassandraEngine {
WHERE store_root = ? AND backup_status = ?",
self.catalog_keyspace()
);
let rows = crate::cassandra_util::query_rows_quorum::<StorageError>(
let rows = crate::cassandra_util::query_rows::<StorageError>(
&self.session,
&query,
cdrs_tokio::query_values!(store_root, status.as_str()),
Expand Down Expand Up @@ -943,7 +935,7 @@ impl CassandraEngine {
) -> Result<(), StorageError> {
let catalog = self.catalog_keyspace();
if remove {
crate::cassandra_util::query_rows_quorum::<StorageError>(
crate::cassandra_util::execute::<StorageError>(
&self.session,
&format!(
"DELETE FROM {catalog}.backup_index_by_status \
Expand All @@ -958,7 +950,7 @@ impl CassandraEngine {
)
.await?;
} else {
crate::cassandra_util::query_rows_quorum::<StorageError>(
crate::cassandra_util::execute::<StorageError>(
&self.session,
&format!(
"INSERT INTO {catalog}.backup_index_by_status \
Expand Down Expand Up @@ -1236,7 +1228,7 @@ impl CassandraEngine {
FROM {}.tables WHERE account_id = ? AND table_name = ?",
self.catalog_keyspace()
);
let rows = crate::cassandra_util::query_rows_quorum::<StorageError>(
let rows = crate::cassandra_util::query_rows::<StorageError>(
&self.session,
&query,
cdrs_tokio::query_values!(account_id, table_name),
Expand Down Expand Up @@ -1429,7 +1421,7 @@ impl JobClaim for CassandraRestoreClaim {
restore_failure_reason FROM {}.tables WHERE account_id = ? AND table_name = ?",
self.engine.catalog_keyspace()
);
let rows = crate::cassandra_util::query_rows_quorum::<StorageError>(
let rows = crate::cassandra_util::query_rows::<StorageError>(
&self.engine.session,
&query,
cdrs_tokio::query_values!(
Expand Down Expand Up @@ -1472,7 +1464,7 @@ impl BackupCatalog for CassandraEngine {
"SELECT value FROM {}.settings WHERE key = 'catalog_id'",
self.catalog_keyspace()
);
let rows = crate::cassandra_util::query_rows_quorum::<StorageError>(
let rows = crate::cassandra_util::query_rows::<StorageError>(
&self.session,
&query,
cdrs_tokio::query_values!(),
Expand Down Expand Up @@ -1815,13 +1807,9 @@ impl BackupCatalog for CassandraEngine {
query.push_str(" AND created_at < ?");
values.push(Value::from((upper * 1_000.0).ceil() as i64));
}
let params = StatementParamsBuilder::new()
.with_consistency(Consistency::LocalQuorum)
.with_values(QueryValues::SimpleValues(values))
.build();
let listed = self
.session
.query_with_params(&query, params)
.run(Stmt::Read, &query, QueryValues::SimpleValues(values))
.await
.map_err(|e| StorageError::Internal(format!("List backup index: {e}")))?
.response_body()
Expand Down Expand Up @@ -2239,7 +2227,7 @@ impl BackupCatalog for CassandraEngine {
let scan = format!(
"SELECT account_id, backup_arn, active_restores FROM {catalog}.backups_by_arn"
);
let rows = crate::cassandra_util::query_rows_quorum::<StorageError>(
let rows = crate::cassandra_util::query_rows::<StorageError>(
&self.session,
&scan,
cdrs_tokio::query_values!(),
Expand Down Expand Up @@ -2418,7 +2406,7 @@ impl BackupCatalog for CassandraEngine {
ALLOW FILTERING",
self.catalog_keyspace()
);
let rows = crate::cassandra_util::query_rows_quorum::<StorageError>(
let rows = crate::cassandra_util::query_rows::<StorageError>(
&self.session,
&query,
cdrs_tokio::query_values!(status),
Expand Down Expand Up @@ -2502,7 +2490,7 @@ impl BackupCatalog for CassandraEngine {
ALLOW FILTERING",
self.catalog_keyspace()
);
let rows = crate::cassandra_util::query_rows_quorum::<StorageError>(
let rows = crate::cassandra_util::query_rows::<StorageError>(
&self.session,
&query,
cdrs_tokio::query_values!(),
Expand Down Expand Up @@ -2672,7 +2660,7 @@ impl BackupCatalog for CassandraEngine {
WHERE account_id = ? AND table_name = ?",
self.catalog_keyspace()
);
let rows = crate::cassandra_util::query_rows_quorum::<StorageError>(
let rows = crate::cassandra_util::query_rows::<StorageError>(
&self.session,
&query,
cdrs_tokio::query_values!(key.account_id.as_str(), key.table_name.as_str()),
Expand Down Expand Up @@ -2711,7 +2699,7 @@ impl BackupCatalog for CassandraEngine {
ALLOW FILTERING",
self.catalog_keyspace()
);
let rows = crate::cassandra_util::query_rows_quorum::<StorageError>(
let rows = crate::cassandra_util::query_rows::<StorageError>(
&self.session,
&query,
cdrs_tokio::query_values!(status.as_str()),
Expand Down Expand Up @@ -2788,7 +2776,7 @@ impl BackupCatalog for CassandraEngine {
BackupStatus::Deleted,
BackupStatus::Failed,
] {
let rows = crate::cassandra_util::query_rows_quorum::<StorageError>(
let rows = crate::cassandra_util::query_rows::<StorageError>(
&self.session,
&query,
cdrs_tokio::query_values!(store_root, status.as_str()),
Expand Down Expand Up @@ -2854,7 +2842,7 @@ impl BackupCatalog for CassandraEngine {
}
_ => sweep.removed += 1,
}
crate::cassandra_util::query_rows_quorum::<StorageError>(
crate::cassandra_util::execute::<StorageError>(
&self.session,
&delete,
cdrs_tokio::query_values!(store_root, status.as_str(), backup_arn.as_str()),
Expand All @@ -2874,7 +2862,7 @@ impl BackupCatalog for CassandraEngine {
// the kind and id they carry. Hints, not verified against the
// rows (the trait doc).
let catalog = self.catalog_keyspace();
let partitions = crate::cassandra_util::query_rows_quorum::<StorageError>(
let partitions = crate::cassandra_util::query_rows::<StorageError>(
&self.session,
&format!("SELECT DISTINCT store_root, backup_status FROM {catalog}.backup_index_by_status"),
cdrs_tokio::query_values!(),
Expand All @@ -2892,7 +2880,7 @@ impl BackupCatalog for CassandraEngine {
let status: String =
crate::cassandra_util::get_column(&partition, "backup_status", "status index")?;
let status = BackupStatus::parse(&status)?;
let rows = crate::cassandra_util::query_rows_quorum::<StorageError>(
let rows = crate::cassandra_util::query_rows::<StorageError>(
&self.session,
&entries_query,
cdrs_tokio::query_values!(root.as_str(), status.as_str()),
Expand Down Expand Up @@ -3431,6 +3419,7 @@ mod tests {

use std::net::{IpAddr, Ipv4Addr, SocketAddr};

use cdrs_tokio::consistency::Consistency;
use cdrs_tokio::frame::message_error::{ErrorBody, WriteTimeoutError, WriteType};

use super::*;
Expand Down
Loading
Loading