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

fix: Use Redis ConnectionManager to reconnect on failures #34

Merged
merged 4 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 9 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Changed
### Fixed
sbernauer marked this conversation as resolved.
Show resolved Hide resolved

- Bump Rust dependency versions ([#19]).
- Use redis [`ConnectionManager`](https://docs.rs/redis/latest/redis/aio/struct.ConnectionManager.html) to reconnect on
Redis connection failures. Previously trino-lb would stop working once the Redis Pod restarted. This change only
affects the single Redis instance connection, *not* the cluster mode connection, as a
[ClusterConnection](https://docs.rs/redis/latest/redis/cluster/struct.ClusterConnection.html) does not seem to support
a [`ConnectionManager`](https://docs.rs/redis/latest/redis/aio/struct.ConnectionManager.html) ([#34]).

[#19]: https://github.com/stackabletech/trino-lb/pull/19
[#34]: https://github.com/stackabletech/trino-lb/pull/34

## [0.2.0] - 2024-04-07

### Added

- BREAKING: Add support for single instance redis persistence (without Redis cluster mode).
This is breaking, because you need to set `trinoLb.persistence.redis.clusterMode: true` in your config to keep using the cluster mode ([#15]).
This is breaking, because you need to set `trinoLb.persistence.redis.clusterMode: true` in your config to keep using
the cluster mode ([#15]).

[#15]: https://github.com/stackabletech/trino-lb/pull/15

Expand Down
2 changes: 1 addition & 1 deletion trino-lb-persistence/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub trait Persistence {

#[enum_dispatch]
pub enum PersistenceImplementation {
Redis(redis::RedisPersistence<::redis::aio::MultiplexedConnection>),
Redis(redis::RedisPersistence<::redis::aio::ConnectionManager>),
RedisCluster(
redis::RedisPersistence<
::redis::cluster_async::ClusterConnection<::redis::aio::MultiplexedConnection>,
Expand Down
8 changes: 5 additions & 3 deletions trino-lb-persistence/src/redis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use std::{

use futures::{future::try_join_all, TryFutureExt};
use redis::{
aio::MultiplexedConnection, cluster::ClusterClientBuilder, cluster_async::ClusterConnection,
aio::{ConnectionManager, MultiplexedConnection},
cluster::ClusterClientBuilder,
cluster_async::ClusterConnection,
AsyncCommands, Client, RedisError, Script,
};
use snafu::{OptionExt, ResultExt, Snafu};
Expand Down Expand Up @@ -124,7 +126,7 @@ where
cluster_groups: Vec<String>,
}

impl RedisPersistence<MultiplexedConnection> {
impl RedisPersistence<ConnectionManager> {
pub async fn new(config: &RedisConfig, cluster_groups: Vec<String>) -> Result<Self, Error> {
let redis_host = config.endpoint.host_str().context(ExtractRedisHostSnafu {
endpoint: config.endpoint.clone(),
Expand All @@ -133,7 +135,7 @@ impl RedisPersistence<MultiplexedConnection> {

let client = Client::open(config.endpoint.as_str()).context(CreateClientSnafu)?;
let connection = client
.get_multiplexed_async_connection()
.get_connection_manager()
.await
.context(CreateClientSnafu)?;

Expand Down
2 changes: 1 addition & 1 deletion trino-lb/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async fn start() -> Result<(), MainError> {
.context(CreateRedisPersistenceClientSnafu)?
.into()
} else {
RedisPersistence::<::redis::aio::MultiplexedConnection>::new(
RedisPersistence::<::redis::aio::ConnectionManager>::new(
redis_config,
cluster_groups,
)
Expand Down