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

v2.23.1 #276

Merged
merged 2 commits into from
May 6, 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
3 changes: 3 additions & 0 deletions doc/releaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,3 +615,6 @@ This file describes the main feature changes for each readout.exe released versi

## v2.23.0 - 18/03/2024
- Added o2-readout-rawmerger: a utility to concatenate multiple raw files in a single one, e.g. to replay full detector data from a single FLP.

## v2.23.1 - 06/05/2024
- Fix MySQL 8.0.34 depracation warning for auto-reconnect feature. Functionnality re-implemented locally.
51 changes: 42 additions & 9 deletions src/ReadoutDatabase.cxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ReadoutDatabase.h"
#include <mysql.h>
#include <mysql/errmsg.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
Expand All @@ -8,18 +9,39 @@
#include <inttypes.h>
#include <string>
#include <map>
#include <time.h>

#if LIBMYSQL_VERSION_ID >= 80000
typedef bool my_bool;
#endif

int ReadoutDatabase::connect() {
time_t now = time(NULL);
if ((lastConnectTime != 0) && (now < lastConnectTime + reconnectTimeout)) return -2;
lastConnectTime = now;
if (db != nullptr) {
mysql_close(db);
db = nullptr;
}
db = mysql_init(nullptr);
if (db == nullptr) {
return -1;
}
if (mysql_real_connect(db,cxDbHost.c_str(),cxDbUser.c_str(),cxDbPwd.c_str(),cxDbName.c_str(),0,nullptr,0) == nullptr) {
log(std::string("DB connect error :") + mysql_error(db));
return -1;
}
log("DB connected");
lastConnectTime = 0;
return 0;
}

ReadoutDatabase::ReadoutDatabase(const char* cx, int v, const LogCallback& cb) {
verbose = v;
theLogCallback = cb;

char *db_db=nullptr, *db_user=nullptr, *db_pwd=nullptr, *db_host=nullptr;
char *p=nullptr,*ptr,*lptr;
my_bool reconnect = 1;

if (cx == nullptr) {
throw __LINE__;
Expand Down Expand Up @@ -50,6 +72,7 @@ ReadoutDatabase::ReadoutDatabase(const char* cx, int v, const LogCallback& cb) {
break;
}
}
cxDbUser = db_user;

// pwd
for (lptr=ptr;*ptr!=0;ptr++) {
Expand All @@ -60,6 +83,7 @@ ReadoutDatabase::ReadoutDatabase(const char* cx, int v, const LogCallback& cb) {
break;
}
}
cxDbPwd = db_pwd;

// host
for (lptr=ptr;*ptr!=0;ptr++) {
Expand All @@ -70,6 +94,7 @@ ReadoutDatabase::ReadoutDatabase(const char* cx, int v, const LogCallback& cb) {
break;
}
}
cxDbHost = db_host;

// db name
db_db=ptr;
Expand All @@ -82,12 +107,7 @@ ReadoutDatabase::ReadoutDatabase(const char* cx, int v, const LogCallback& cb) {
log("Using database " + std::string(db_db) + "@" + std::string(db_host));

// try to connect
if (mysql_real_connect(db,db_host,db_user,db_pwd,db_db,0,nullptr,0)==nullptr) {
goto open_failed;
}


if (mysql_options(db, MYSQL_OPT_RECONNECT, &reconnect)) {
if (this->connect()) {
goto open_failed;
}

Expand Down Expand Up @@ -167,14 +187,27 @@ int ReadoutDatabase::query(int maxRetry, const char *inQuery,...) {

int i;
for (i=1; i<=maxRetry; i++) {
if (mysql_query(db,query)==0) break;
if (mysql_query(db,query) == 0) break;
lastError = std::string("DB query error :") + mysql_error(db);
log("DB error: " + std::to_string(mysql_errno(db)) + " = " + lastError);
if (mysql_errno(db) == CR_SERVER_LOST) {
log("DB trying to reconnect");
int err = connect();
if (err == 0) {
continue;
} else {
if (err == -2) {
log("DB reconnect - need to wait a bit before retry");
}
return -1;
}
}
usleep(retryTimeout);
}
if (i > maxRetry) {
return -1;
}

log("DB query success");
return 0;
}

Expand Down
7 changes: 7 additions & 0 deletions src/ReadoutDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,20 @@ class ReadoutDatabase {
uint64_t vRun;
std::string vRole;
std::string cxDbName; // name of the database used
std::string cxDbUser;
std::string cxDbPwd;
std::string cxDbHost;
time_t lastConnectTime = 0;
int reconnectTimeout = 10;

int maxRetry = 20; // number of query retries
int retryTimeout = 50; // retry interval (milliseconds)

LogCallback theLogCallback;
void log(const std::string &log);

int connect();

std::string lastError = ""; // error string of last query, if any
std::string lastQuery = ""; // last query executed
};
2 changes: 1 addition & 1 deletion src/ReadoutVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#define READOUT_VERSION "2.23.0"
#define READOUT_VERSION "2.23.1"