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: semver check added for redis version #75

Merged
merged 4 commits into from
Dec 20, 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: 7 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ members = [
resolver = "2"

[workspace.package]
version = '0.8.3'
version = '0.8.4'
edition = "2021"
authors = ["Glenn Gore <[email protected]>"]
description = "Affinidi Messaging"
Expand Down Expand Up @@ -105,3 +105,4 @@ tui-logger = { version = "0.14", features = ["tracing-support"] }
url = "2.5"
uuid = { version = "1.11", features = ["v4", "fast-rng"] }
varint = "0.9"
semver = "1.0.24"
1 change: 1 addition & 0 deletions affinidi-messaging-mediator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ tower-http.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
uuid.workspace = true
semver.workspace = true

[dev-dependencies]
console.workspace = true
Expand Down
28 changes: 22 additions & 6 deletions affinidi-messaging-mediator/src/database/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use super::DatabaseHandler;
use crate::common::{config::Config, errors::MediatorError};
use deadpool_redis::Connection;
use redis::aio::PubSub;
use semver::{Version, VersionReq};
use std::{fs::read_to_string, thread::sleep, time::Duration};
use tracing::{error, event, info, Level};

const REDIS_VERSION: &str = "7.2"; // required Redis version
const REDIS_VERSION_REQ: &str = ">=7.1, <8.0";

impl DatabaseHandler {
pub async fn new(config: &Config) -> Result<Self, MediatorError> {
Expand Down Expand Up @@ -124,6 +125,11 @@ impl DatabaseHandler {

/// Helper function to check the version of the Redis Server
async fn _check_server_version(database: &DatabaseHandler) -> Result<String, MediatorError> {
let redis_version_req: VersionReq = match VersionReq::parse(REDIS_VERSION_REQ) {
Ok(result) => result,
Err(err) => panic!("Couldn't process required Redis version. Reason: {}", err),
};

let mut conn = database.get_async_connection().await?;
let server_info: String = match deadpool_redis::redis::cmd("INFO")
.arg("SERVER")
Expand Down Expand Up @@ -156,19 +162,29 @@ async fn _check_server_version(database: &DatabaseHandler) -> Result<String, Med
.next();

if let Some(version) = server_version {
if version.starts_with(REDIS_VERSION) {
let semver_version: Version = match Version::parse(&version) {
Ok(result) => result,
Err(err) => {
error!("Cannot parse Redis version ({}). Reason: {}", version, err);
return Err(MediatorError::DatabaseError(
"NA".into(),
format!("Cannot parse Redis version ({}). Reason: {}", version, err),
));
}
};
if redis_version_req.matches(&semver_version) {
info!("Redis version is compatible: {}", version);
Ok(version.to_owned())
} else {
error!(
"Redis version ({}) must be equal to major.minor: ({})",
version, REDIS_VERSION
"Redis version ({}) must match ({})",
version, REDIS_VERSION_REQ
);
Err(MediatorError::DatabaseError(
"NA".into(),
format!(
"Redis version ({}) must be equal to major.minor: ({})",
version, REDIS_VERSION
"Redis version ({}) must match ({})",
version, REDIS_VERSION_REQ
),
))
}
Expand Down
Loading