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

result: small cleanups before bump to 0.15 #205

Merged
merged 8 commits into from
Nov 21, 2024

Conversation

muzarski
Copy link
Collaborator

@muzarski muzarski commented Nov 20, 2024

Tracing id and paging state response

These were moved from CassResultData to CassResult.

CassResultData

AlterProperlyUpdatesColumnCount test

This test should not be enabled. It expects that prepared statement's result metadata was updated after table schema was altered. It worked only because of a driver bug described later. I disabled this test. It's expected to be working for CQL protocol v5 and above. I think it can be addressed later.

Driver bug

Before this PR, there was an inconsistency of metadata stored in CassResultData:

  • column_specs: Vec<ColumnSpec<'static>> was obtained from a query result
  • col_data_types: Arc<Vec<Arc<CassDataType>>> was obtained from the prepared statement's cached result metadata

Because of this, these vector could be of a different length when table schema was altered - query result provided the updated metadata, while prepared statement still held an outdated metadata.

Why was the aforementioned test working?
It's because cass_result_column_count would return the size of column_specs (i.e. updated metadata).

This PR fixes the issue by unifying these two vectors into a single one. CassColumnSpec was introduced to address it. It holds a column name (String) and a column data type (Arc<CassDataType).

AlterDoesntUpdateColumnCount

On the other hand, this test should be enabled. It expects, that for protocol version 4 or less, the prepared statement's metadata is not updated after table schema was altered. It's enabled at the end of PR, once the bug mentioned above is fixed.

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 implemented Rust unit tests for the features/changes introduced.
  • I have enabled appropriate tests in .github/workflows/build.yml in gtest_filter.
  • I have enabled appropriate tests in .github/workflows/cassandra.yml in gtest_filter.

CassResultData should represent a result metadata. Tracing id is not
a part of it.
Again, paging state response has nothing to do with the metadata
needed to deserialize the rows.
@muzarski muzarski self-assigned this Nov 20, 2024
@muzarski muzarski requested a review from Lorak-mmk November 20, 2024 16:57
@muzarski muzarski marked this pull request as draft November 20, 2024 17:20
This test should not be enabled!

See the description:
 * Verify that the column count of a bound statement's result metadata is
 * properly updated for newer protocol versions (v5 and greater) when a table's
 * schema is altered.

This test will not work after next commit, thus it's being disabled.

On the other hand, the test AlterDoesntUpdateColumnCount should be enabled.
 * Verify that the column count of a bound statement's result metadata doesn't
 * change for older protocol versions (v4 and less) when a table's schema is altered.

It will be enabled later in this PR, once following issue is addressed:
Currently, the `column_specs` and `col_data_types` may have different sizes
for prepared statements. This is because, `col_data_types` is created based
on prepared statement's cached metadata, and `column_specs` are taken from
the QueryResult.
Currently, we heavily depend on the fact that `QueryResult::col_specs()`
returns a  `&[ColumnSpec<'static>]`. This won't be true once we bump
rust-driver dependency to 0.15 - the lifetime of ColumnSpec will be tied
to the lifetime of `QueryRowsResult` object.

It looks like most of the information held by `col_spec` was reduntant.
It was only used to retrieve the name of the column. This is why, we will
only hold the information about the column names. The column types are
stored in `col_data_types`.

This also allows us to get rid of `'static` bound from `CassResultData::from_result_payload`.
It will be helpful when bumping to 0.15.

As a bonus, we can also replace the `Vec<>` with a slice `&[]` in
`from_result_payload`, since we do not need to own the column specs anymore.
@muzarski muzarski force-pushed the cass-result-cleanup branch from 2069df0 to 904a971 Compare November 20, 2024 17:38
@muzarski
Copy link
Collaborator Author

I found a bug in the driver. The fix will be part of this PR.

This structure will hold information about the column name
and the column data type.

Refactored the `CassResultData`, so now it holds one vector
of `CassColumnSpec` instead of two separate vectors for names and
data types. Previous version was buggy for prepared statements:
- data types came from cached metadata from the statement
- column names came from metadata provided by query result

Because of this, the vector could be of a different length, when someone
ALTERed the corresponding table.

Notice that after this commit, we don't reuse cached metadata from prepared
statement and reuse the metadata provided from the server. Next commits
will fix that.
It is now enabled in favor of AlterProperlyUpdatesColumnCount.

From now on, the metadata in `CassResultData` is consistent,
and the behaviour is that metadata is not updated after altering the table.

Original cpp-driver expects this behaviour for CQL v4 and less:
 * Verify that the column count of a bound statement's result metadata doesn't
 * change for older protocol versions (v4 and less) when a table's schema is altered.
@muzarski muzarski marked this pull request as ready for review November 20, 2024 19:02
@muzarski
Copy link
Collaborator Author

v2: addressed the bug and updated the cover letter. It's ready for review.

Copy link
Collaborator

@Lorak-mmk Lorak-mmk left a comment

Choose a reason for hiding this comment

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

Looks very good, I really like the introduction of CassColumnSpec - it both makes the code easier to understand, and prevents the bug you encountered on a type level!

scylla-rust-wrapper/src/query_result.rs Show resolved Hide resolved
@muzarski
Copy link
Collaborator Author

v2.1: Renamed CassResultData -> CassResultMetadata

@muzarski muzarski merged commit 739855a into scylladb:master Nov 21, 2024
11 checks passed
@muzarski muzarski mentioned this pull request Nov 27, 2024
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.

2 participants