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

Aid in migration to the new deserialization API #1121

Merged
merged 4 commits into from
Nov 13, 2024

Conversation

wprzytula
Copy link
Collaborator

Motivation

Let's reduce friction when migrating to the new deserialization API.

What's done

Deprecations

Entities (traits and structs) belonging to the old deserialization API, which we plan to remove soon, are labeled with #[deprecated] attribute. This way they will trigger warnings when used, urging users to consider migration.

Convenient switching between the legacy & the new Session's API

There already are Session and LegacySession. However, a viable migration strategy involves incremental migration from the old API to the new API. In such case, it makes sense to have cheap conversions between Session APIs, using the same data underneath. This is done: LegacySession is convertible to Session and vice versa (and they share the same Cluster through an Arc).

Migration guide

A migration guide is added. It briefly describes the old and the new deserialization traits and compares them. Then, it summarises what changes are needed to adjust to the new deserialization framework entities.

Fixes: #965

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • I added relevant tests for new features and bug fixes.
  • All commits compile, pass static checks and pass test.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have provided docstrings for the public items that I want to introduce.
  • I have adjusted the documentation in ./docs/source/.
  • I added appropriate Fixes: annotations to PR description.

@wprzytula wprzytula force-pushed the deserialization-api-migration-aid branch from a747219 to 5a5298f Compare November 12, 2024 19:46
@wprzytula wprzytula force-pushed the deserialization-api-migration-aid branch from 5a5298f to dad84ac Compare November 12, 2024 19:50
@github-actions github-actions bot added the semver-checks-breaking cargo-semver-checks reports that this PR introduces breaking API changes label Nov 12, 2024
Copy link

github-actions bot commented Nov 12, 2024

cargo semver-checks detected some API incompatibilities in this PR.
Checked commit: b7d1dfe

See the following report for details:

cargo semver-checks output
./scripts/semver-checks.sh --baseline-rev 82536814e3341dd2ffdba7366d545474fc0338d7
+ cargo semver-checks -p scylla -p scylla-cql --baseline-rev 82536814e3341dd2ffdba7366d545474fc0338d7
     Cloning 82536814e3341dd2ffdba7366d545474fc0338d7
     Parsing scylla v0.14.0 (current)
      Parsed [  24.970s] (current)
     Parsing scylla v0.14.0 (baseline)
      Parsed [  23.456s] (baseline)
    Checking scylla v0.14.0 -> v0.14.0 (no change)
     Checked [   0.139s] 94 checks: 93 pass, 1 fail, 0 warn, 0 skip

--- failure type_marked_deprecated: #[deprecated] added on type ---

Description:
A type is now #[deprecated]. Downstream crates will get a compiler warning when using this type.
        ref: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.36.0/src/lints/type_marked_deprecated.ron

Failed in:
  Struct LegacyQueryResult in /home/runner/work/scylla-rust-driver/scylla-rust-driver/scylla/src/transport/legacy_query_result.rs:52
  Struct LegacyQueryResult in /home/runner/work/scylla-rust-driver/scylla-rust-driver/scylla/src/transport/legacy_query_result.rs:52
  Enum LegacyDeserializationApi in /home/runner/work/scylla-rust-driver/scylla-rust-driver/scylla/src/transport/session.rs:179
  Struct LegacyRowIterator in /home/runner/work/scylla-rust-driver/scylla-rust-driver/scylla/src/transport/iterator.rs:1084
  Struct LegacyTypedRowIterator in /home/runner/work/scylla-rust-driver/scylla-rust-driver/scylla/src/transport/iterator.rs:1137

     Summary semver requires new minor version: 0 major and 1 minor checks failed
    Finished [  48.624s] scylla
     Parsing scylla-cql v0.3.0 (current)
      Parsed [  11.259s] (current)
     Parsing scylla-cql v0.3.0 (baseline)
      Parsed [  11.304s] (baseline)
    Checking scylla-cql v0.3.0 -> v0.3.0 (no change)
     Checked [   0.114s] 94 checks: 94 pass, 0 skip
     Summary no semver update required
    Finished [  22.726s] scylla-cql
make: *** [Makefile:61: semver-rev] Error 1

@wprzytula wprzytula added this to the 0.15.0 milestone Nov 12, 2024
@wprzytula wprzytula self-assigned this Nov 12, 2024
Lorak-mmk
Lorak-mmk previously approved these changes Nov 13, 2024
scylla/src/transport/session.rs Show resolved Hide resolved
scylla/src/transport/iterator.rs Outdated Show resolved Hide resolved
scylla/src/lib.rs Show resolved Hide resolved
piodul and others added 2 commits November 13, 2024 16:41
The Cluster struct by itself only serves as a facade for the
ClusterWorker, i.e. it has channels that allow sending requests to the
worker, receives the ClusterData via the `data` field etc. Apart from
the `_worker_handle` field, all other fields are cloneable. Two tasks
working on two copies of the same Cluster object should behave the same
as if they shared and operated on a single Cluster object (e.g. via
Arc<Cluster>).

This commit makes the Cluster object cloneable - the `_worker_handle` is
shared via an Arc. This will be very useful in the next commit - we will
do a similar thing for the GenericSession object.

Co-authored-by: Wojciech Przytuła <[email protected]>
In order to make migration from the old API easier and allow doing it
gradually, some components of the client programs would probably like to
use the old API while the new components will use the new API. However,
in the current design, Session and LegacySession are two different
types and it's not possible to "cast" one to another - even though they
have nearly the same fields and implementations.

The previous commit made Cluster cloneable, based on the observation
that it's perfectly fine to clone Cluster's fields, construct a new one
and treat it as a shared facade, handle to the same "semantic" cluster.
The same applies to Session, actually - cloning a session would have
similar effect (though we encourage users to keep Session in an Arc so
that cloning is cheaper).

Instead of making GenericSession cloneable, we introduce methods which,
in reality, perform a clone but change the kind of session's API. This
allows to have two session objects which share the same resources but
have different APIs. This should be very useful when migrating large
projects to the new API - components that need to use the new API can
just "convert" the session to the new interface and use that.
As we want to phase out the legacy deserialization API, let's yell at
users still using it, by use of the amazing #[deprecated] annotation,
the greatest friend of a Rust lib maintainer.
@wprzytula
Copy link
Collaborator Author

Rebased on main after #1117 was merged.

Lorak-mmk
Lorak-mmk previously approved these changes Nov 13, 2024
Adds a document that should help adjust users to the new deserialization
API.

Co-authored-by: Wojciech Przytuła <[email protected]>
@wprzytula wprzytula merged commit 8ccc597 into scylladb:main Nov 13, 2024
12 checks passed
@wprzytula wprzytula deleted the deserialization-api-migration-aid branch November 13, 2024 20:40
@wprzytula wprzytula mentioned this pull request Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/deserialization semver-checks-breaking cargo-semver-checks reports that this PR introduces breaking API changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deserialization refactor: adjust docs and provide a migration guide
4 participants