Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepared tests #68

Merged
merged 3 commits into from
Aug 18, 2022
Merged

Prepared tests #68

merged 3 commits into from
Aug 18, 2022

Conversation

Gor027
Copy link
Contributor

@Gor027 Gor027 commented Jul 28, 2022

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have enabled appropriate tests in .github/workflows/build.yaml in gtest_filter.

This PR is dependent upon #65

Adds necessary implementations to pass all PreparedTests besides PreparedIDUnchangedDuringReprepare, which is also ignored in the C++ driver.
Certain validations in tests are commented out for now, as their corresponding implementations in Rust are not yet present.
Also, DowngradingConsistency retry policies in those tests are changed to be Default retry consistency, as DowngradingConsistency is deprecated and not supported by the Rust driver.

@Gor027 Gor027 force-pushed the prepared_tests branch 2 times, most recently from bba2e67 to 39f80c8 Compare August 2, 2022 09:22
@Gor027 Gor027 force-pushed the prepared_tests branch 2 times, most recently from 9729e7b to f2ccf44 Compare August 9, 2022 09:21
@Gor027 Gor027 mentioned this pull request Aug 9, 2022
4 tasks
Comment on lines 230 to 231
Statement::Simple(inner) => inner.set_timestamp(Some(timeout_ms as i64)),
Statement::Prepared(inner) => Arc::make_mut(inner).set_timestamp(Some(timeout_ms as i64)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Timestamp is a completely different thing than timeout.

  • A CQL timestamp defines the order in which writes are applied to the database.
  • Timeout (here, client-side timeout) means the time the driver will wait until response arrives from the database. If no response arrives within the timeout period, the driver is supposed to return an error.

Here, I think you have accidentally implemented cass_statement_set_timestamp.

Currently, the rust driver doesn't support client timeouts directly, but you can implement them yourself in the wrapper code. You need to keep the timeout in the CassStatement somewhere, wrap session.execute() etc. calls with tokio::time::timeout and handle the timeout error returned by the tokio::time::timeout call appropriately.

Comment on lines 142 to 143
let session_opt = ptr_to_ref(cass_session);
let statement_opt = ptr_to_ref(statement);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do those names have an _opt suffix? Those aren't Options?

Comment on lines 146 to 149
let query = match statement.clone() {
Statement::Simple(q) => q.contents,
Statement::Prepared(ps) => ps.get_statement().to_string(),
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By doing statement.clone(), you are cloning the whole statement, but then you only need a small part of it and you have unnecessarily cloned the whole statement.

Perhaps you can match on a reference (&statement) and move .clone() to the first match, like this:

let query = match &statement {
    Statement::Simple(q) => q.contents.clone(),
    Statement::Prepared(ps) => ps.get_statement().to_string(),
};


let query = match statement.clone() {
Statement::Simple(q) => q.contents,
Statement::Prepared(ps) => ps.get_statement().to_string(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes sense at all to prepare a prepared statement again. I think in this case it makes sense to just clone a prepared statement, put it into a box and immediately return it.

}
let session = session_guard.as_ref().unwrap();
let mut prepared = session
.prepare(query)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of passing a string, you can put a Query here. AFAIK the resulting PreparedStatement should inherit all properties of the original Query, so setting them manually later shouldn't be necessary.

@@ -134,6 +136,16 @@ fn create_cass_row_columns(row: Row, metadata: &Arc<CassResultData>) -> Vec<Cass
.collect()
}

fn create_col_index_mapping(col_specs: &[ColumnSpec]) -> HashMap<String, usize> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that constructing a hashmap to speed up lookup by name is an overkill. The number of columns is usually small, so linear lookup should be sufficient. Creating a hashmap allocates (at least one allocation for the hashmap itself + one allocation for each String), so it would be best to avoid it.

@Gor027 Gor027 force-pushed the prepared_tests branch 2 times, most recently from 0fd11f3 to f1e1cec Compare August 12, 2022 07:52
@Gor027 Gor027 requested review from piodul and avelanarius August 12, 2022 16:27
@@ -25,6 +27,7 @@ pub struct CassStatement {
pub statement: Statement,
pub bound_values: Vec<MaybeUnset<Option<CqlValue>>>,
pub paging_state: Option<Bytes>,
pub request_timeout_ms: cass_uint64_t,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe replace it with Option<cass_uint64_t> - if option is None then apply no timeout, instead of hardcoding 2 year timeout.

Gor027 added 3 commits August 18, 2022 10:44
Add implementation for:
  * cass_statement_set_serial_consistency
  * cass_statement_set_consistency
  * cass_statement_set_timestamp
  * cass_statement_set_request_timout
Added retry policy definition:
  * constructor for Default retry policy: cass_retry_policy_default_new
  * destructor for CassRetryPolicy: cass_retry_policy_free

Added implementation of cass_row_get_column_by_name.

Modified PrepareFromExistingSimpleStatement and
PrepareFromExistingBoundStatement tests to prepare statements with
Default retry policy instead of DowngradingConsistency as the latter is
deprecated and is not supported by rust driver.

Statement setters validations are commented out in tests as their
corresponding implementations in rust bindings are not
present(src/testing.cpp).

In FailFastWhenPreparedIDChangesDuringReprepare test, the result's error
message is changed according to the error message the rust driver
returns.

PreparedIDUnchangedDuringReprepare test is ignored, as it is also
ignored in cpp-driver.
@avelanarius avelanarius merged commit 2af2288 into scylladb:master Aug 18, 2022
avelanarius added a commit that referenced this pull request Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants