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

Update diesel, diesel_migrations, uuid, and rand #132

Merged
merged 5 commits into from
May 30, 2023

Conversation

primeos-work
Copy link
Member

@primeos-work primeos-work commented Jan 4, 2023

This updates the last four crates that were restricted to outdated versions (apart from the config create which we decided not to update for now). The details are described in the individual commit messages. We have to bump the MSRV as well for the last commit (updating all crates in Cargo.lock).

Not much to see yet - still very incomplete.
PoC (untested) is ready but we should certainly avoid the mutexes (replaced via r2d2 connection pools).
Will supersede #81, #66, and #62.
TODO: Probably update rand as well (s. comment in Cargo.toml). -> done
Reason for the MSRV bump:

error: package `time-core v0.1.1` cannot be built because it requires rustc 1.65.0 or newer, while the currently active rustc version is 1.64.0
$ cargo update
    Updating crates.io index
      Adding android-tzdata v0.1.1
    Updating aquamarine v0.3.1 -> v0.3.2
    Updating base64 v0.21.0 -> v0.21.2
      Adding bitflags v2.3.1
    Updating bumpalo v3.12.1 -> v3.13.0
    Updating chrono v0.4.24 -> v0.4.25
    Updating clap v4.2.5 -> v4.3.0
    Updating clap_builder v4.2.5 -> v4.3.0
    Updating clap_complete v4.2.1 -> v4.3.0
    Updating clap_lex v0.4.1 -> v0.5.0
    Removing codespan-reporting v0.11.1
    Updating console v0.15.5 -> v0.15.7
    Removing cxx v1.0.94
    Removing cxx-build v1.0.94
    Removing cxxbridge-flags v1.0.94
    Removing cxxbridge-macro v1.0.94
    Updating diesel v2.0.4 -> v2.1.0
    Updating diesel_derives v2.0.2 -> v2.1.0
    Updating diesel_migrations v2.0.0 -> v2.1.0
      Adding diesel_table_macro_syntax v0.1.0
    Updating digest v0.10.6 -> v0.10.7
    Updating git2 v0.17.1 -> v0.17.2
    Updating h2 v0.3.18 -> v0.3.19
    Updating handlebars v4.3.6 -> v4.3.7
    Updating iana-time-zone-haiku v0.1.1 -> v0.1.2
    Updating indicatif v0.17.3 -> v0.17.4
    Updating io-lifetimes v1.0.10 -> v1.0.11
    Updating js-sys v0.3.61 -> v0.3.63
    Updating libc v0.2.142 -> v0.2.144
    Updating libgit2-sys v0.15.1+1.6.4 -> v0.15.2+1.6.4
    Removing link-cplusplus v1.0.8
    Updating linux-raw-sys v0.3.6 -> v0.3.8
    Updating log v0.4.17 -> v0.4.18
    Updating migrations_internals v2.0.0 -> v2.1.0
    Updating migrations_macros v2.0.0 -> v2.1.0
    Updating mio v0.8.6 -> v0.8.7
    Removing num-integer v0.1.45
    Updating once_cell v1.17.1 -> v1.17.2
    Updating openssl v0.10.52 -> v0.10.53
    Updating openssl-sys v0.9.87 -> v0.9.88
    Updating pin-project v1.0.12 -> v1.1.0
    Updating pin-project-internal v1.0.12 -> v1.1.0
    Updating pkg-config v0.3.26 -> v0.3.27
    Updating portable-atomic v0.3.19 -> v1.3.2
    Updating proc-macro2 v1.0.56 -> v1.0.59
    Updating quote v1.0.26 -> v1.0.28
    Updating regex v1.8.1 -> v1.8.3
    Updating regex-syntax v0.7.1 -> v0.7.2
    Updating reqwest v0.11.17 -> v0.11.18
    Updating rustix v0.37.18 -> v0.37.19
    Removing scratch v1.0.5
    Updating security-framework v2.8.2 -> v2.9.1
    Updating security-framework-sys v2.8.0 -> v2.9.0
    Updating serde v1.0.160 -> v1.0.163
    Updating serde_derive v1.0.160 -> v1.0.163
    Updating serde_spanned v0.6.1 -> v0.6.2
    Updating syn v2.0.15 -> v2.0.18
    Removing termcolor v1.2.0
    Updating time v0.3.20 -> v0.3.21
    Updating time-core v0.1.0 -> v0.1.1
    Updating time-macros v0.2.8 -> v0.2.9
    Updating tokio v1.28.0 -> v1.28.2
    Updating toml v0.7.3 -> v0.7.4
    Updating toml_datetime v0.6.1 -> v0.6.2
    Updating toml_edit v0.19.8 -> v0.19.10
    Updating tracing-core v0.1.30 -> v0.1.31
    Updating unicode-ident v1.0.8 -> v1.0.9
    Updating uuid v1.3.2 -> v1.3.3
    Updating vergen v8.1.3 -> v8.2.1
    Updating wasm-bindgen v0.2.84 -> v0.2.86
    Updating wasm-bindgen-backend v0.2.84 -> v0.2.86
    Updating wasm-bindgen-futures v0.4.34 -> v0.4.36
    Updating wasm-bindgen-macro v0.2.84 -> v0.2.86
    Updating wasm-bindgen-macro-support v0.2.84 -> v0.2.86
    Updating wasm-bindgen-shared v0.2.84 -> v0.2.86
    Updating web-sys v0.3.61 -> v0.3.63
    Updating winnow v0.4.5 -> v0.4.6

This implements the major upgrade of the Diesel crate from version 1 to
version 2. The relevant changes are the following:
- Diesel now requires mutable access to the `Connection` to perform any
  database interaction [0].
- The Diesel derive attributes need to be wrapped by `diesel()` now [1].
- The diesel_migration crate has been completely rewritten and the
  `embed_migrations!()` macro had to be replaced [2].
- The `connection::Connection::transaction` closure now takes one
  argument (the database connection). See [3] vs. [4].
  - I also decided to rename `database_connection` to `conn` in these
    cases to better differentiate the two (we could keep/shadow the
    outer variable for a smaller diff but it seems cleaner that way).

Note: The `Arc<PgConnection> -> Arc<Mutex<PgConnection>>` change is only
intended as a PoC. It is not a good idea as the mutex locking makes some
of the async blocks/code completely pointless. This problem already
existed before though. The documentation sates that the requirement of
mutable connections is expected to be a "straightforward change as the
connection already can execute only one query at a time". So this change
should only make matters worse by moving the locking up and therefore
increasing the time for which locks are held. This should only make the
execution a bit slower (not sure if it would even be noticeable) but it
increases the risk of deadlocks which is the real danger.
To avoid this issue we should use a connection pool instead (e.g., via
r2d2) but there are alternatives like trying to move the locking further
down in the code again or rewriting the database logic.

[0]: https://diesel.rs/guides/migration_guide.html#2-0-0-mutable-connection
[1]: https://diesel.rs/guides/migration_guide.html#2-0-0-derive-attributes
[2]: https://diesel.rs/guides/migration_guide.html#2-0-0-upgrade-migrations
[3]: https://docs.diesel.rs/2.0.x/diesel/connection/trait.Connection.html#method.transaction
[4]: https://docs.diesel.rs/1.4.x/diesel/connection/trait.Connection.html#method.transaction

Signed-off-by: Michael Weiss <[email protected]>
The diesel+uuid part is resolved now (13bcbde) but the crate is also a
direct dependency since 8706494 as src/commands/build.rs uses it for
shuffling the endpoint configurations (it should be trivial to change
that code though).

Signed-off-by: Michael Weiss <[email protected]>
This replaces the mutex-based PoC of 13bcbde via the `r2d2` feature of
the `diesel` crate. Using `unwrap()` should be fine as `Pool::get()`
only errors if the code runs into a timeout (in which case there's
probably a network issue or the database is down so we could only return
a proper error message instead of panicking).

The `min_idle` setting defaults to `None` which causes the `max_idle`
value to be used (defaults to 10). The `build()` function "will block
until the pool has established its configured minimum number of
connections". Therefore, it seems best to lower the value to 1 since
butido is a CLI and not a service/daemon (so the pool will open
additional connections on demand for the async code instead of
establishing all connections at the beginning - we probably only need
few database connections in most cases).

Signed-off-by: Michael Weiss <[email protected]>
Now, we finally don't have any completely frozen dependencies anymore
and are only holding the `config` crate back (we could continue waiting
for the major rewrite of the crate that might happen or just update the
code now and then again after the "rewrite" is complete).

Signed-off-by: Michael Weiss <[email protected]>
@primeos-work primeos-work changed the title WIP: Diesel update Update diesel, diesel_migrations, uuid, and rand May 30, 2023
This is just the result of running `cargo update` without touching
Cargo.toml (since we currently only use dependabot to update direct
dependencies and not indirect/transitive dependencies).

Version 0.1.1 of the time-core crate requires rustc 1.65.0 or newer so
let's also bump the MSRV from 1.64.0 to 1.65.0.

Signed-off-by: Michael Weiss <[email protected]>
@primeos-work primeos-work marked this pull request as ready for review May 30, 2023 12:51
@primeos-work
Copy link
Member Author

We did just test this PR together (against the test DB, an empty DB, mixed with an old butido client, and finally against the production DB). We didn't notice any issues/regressions so we'll merge this now.

@primeos-work primeos-work added this pull request to the merge queue May 30, 2023
Merged via the queue into science-computing:master with commit d990131 May 30, 2023
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.

1 participant