Skip to content

Commit 3e1fefa

Browse files
authored
Merge pull request #92 from sy-c/master
v2.7.2
2 parents 9cbe674 + 5ecadf7 commit 3e1fefa

File tree

8 files changed

+147
-37
lines changed

8 files changed

+147
-37
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ endif()
2222
# global compilation options
2323
enable_language(C)
2424
enable_language(CXX)
25-
set(CMAKE_CXX_STANDARD 14)
25+
set(CMAKE_CXX_STANDARD 17)
2626
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2727
set(CMAKE_CXX_EXTENSIONS OFF)
2828
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
@@ -65,7 +65,7 @@ endif()
6565
include(ExternalProject)
6666
externalproject_add (Common-standalone
6767
GIT_REPOSITORY "https://github.com/AliceO2Group/Common.git"
68-
GIT_TAG "v1.6.1"
68+
GIT_TAG "v1.6.3"
6969
LOG_DOWNLOAD 1
7070
UPDATE_COMMAND ""
7171
PATCH_COMMAND ""

doc/releaseNotes.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,12 @@ This file describes the main feature changes for each InfoLogger released versio
150150
- o2-infologger-adminDb:
151151
- added interactive confirmation prompt when clearing/deleting non-empty tables, unless option '-o noWarning' is set.
152152
- added command '-c status' to display status information about infoLogger database content (number of tables, number of rows, data size).
153+
154+
## v2.7.2 - 26/09/2024
155+
- o2-infologger-daemon: improved handling of large number of connections.
156+
- fixed message flood of "accept() failed" errors when reaching maximum number allowed file descriptors. A single message is now reported when condition occurs, and then when it is cleared. Reaching system limits of max number of descriptors is now handled gracefuly and recovers fine. NB: loop of accept() failures was still occuring even after remote process dead, because fds content are buffered to avoid message loss.
157+
- upgraded to o2-Common v1.6.3, which fixes unclosed file descriptor when rotating log files (which was contributing to trigger issue above, increasing number of fds in use).
158+
- added startup checks to verify compatibility of rxMaxConnections with max number of file descriptors allowed by system. If needed, tries to increase the limit. If it does not work, rxMaxConnections is automatically reduced to a lower value.
159+
- increased default value of rxMaxConnections from 1024 to 2048. This is the number of concurrent clients allowed to connect to o2-infologger-daemon. Can be changed in configuration file.
160+
- o2-infologger-server: improved logging per thread/database.
161+
- o2-infologger-newdb: added option to skip user creation

newMysql.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ FORCE_REDO=0
2727
# if set, SQL queries & output printed
2828
SQL_DEBUG=0
2929

30+
# if set, recreate user accounts unless access to db already ok (existing ones will be deleted, including their privileges)
31+
SQL_RECREATE_USER=1
32+
3033
# where are we running now
3134
HERE=`hostname -f`
3235

@@ -240,9 +243,11 @@ for CONFIG in "${EXTRA_CONFIG[@]}"; do
240243
fi
241244

242245
for QHOST in "%" "localhost" "${HERE}"; do
243-
mysqlExecute "drop user \"${EXTRA_USER[$CONFIG]}\"@\"${QHOST}\";"
244-
mysqlExecute "create user \"${EXTRA_USER[$CONFIG]}\"@\"${QHOST}\";"
245-
mysqlExecute "set password for \"${EXTRA_USER[$CONFIG]}\"@\"${QHOST}\" = PASSWORD(\"${EXTRA_PWD[$CONFIG]}\");"
246+
if [ "$SQL_RECREATE_USER" == "1" ]; then
247+
mysqlExecute "drop user \"${EXTRA_USER[$CONFIG]}\"@\"${QHOST}\";"
248+
mysqlExecute "create user \"${EXTRA_USER[$CONFIG]}\"@\"${QHOST}\";"
249+
mysqlExecute "set password for \"${EXTRA_USER[$CONFIG]}\"@\"${QHOST}\" = PASSWORD(\"${EXTRA_PWD[$CONFIG]}\");"
250+
fi
246251
mysqlExecute "grant ${EXTRA_PRIVILEGE[$CONFIG]} on $INFOLOGGER_DB_NAME.* to \"${EXTRA_USER[$CONFIG]}\"@\"${QHOST}\";"
247252
done
248253
done

src/InfoLoggerDispatch.cxx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
// class InfoLoggerDispatch implementation
1616
///////////////////////////////////////////
1717

18-
InfoLoggerDispatch::InfoLoggerDispatch(ConfigInfoLoggerServer* vConfig, SimpleLog* vLog)
18+
InfoLoggerDispatch::InfoLoggerDispatch(ConfigInfoLoggerServer* vConfig, SimpleLog* vLog, std::string vLogPrefix)
1919
{
20+
logPrefix = vLogPrefix;
2021
input = std::make_unique<AliceO2::Common::Fifo<std::shared_ptr<InfoLoggerMessageList>>>(vConfig->dbDispatchQueueSize);
2122
if (vLog != NULL) {
2223
theLog = vLog;
@@ -87,6 +88,33 @@ int InfoLoggerDispatchPrint::customMessageProcess(std::shared_ptr<InfoLoggerMess
8788
return 0;
8889
}
8990

91+
void InfoLoggerDispatch::logInfo(const char* message, ...) {
92+
char buffer[1024] = "";
93+
va_list ap;
94+
va_start(ap, message);
95+
vsnprintf(buffer,sizeof(buffer), message, ap);
96+
va_end(ap);
97+
theLog->info("%s%s", logPrefix.c_str(), buffer);
98+
}
99+
100+
void InfoLoggerDispatch::logError(const char* message, ...) {
101+
char buffer[1024] = "";
102+
va_list ap;
103+
va_start(ap, message);
104+
vsnprintf(buffer,sizeof(buffer), message, ap);
105+
va_end(ap);
106+
theLog->error("%s%s", logPrefix.c_str(), buffer);
107+
}
108+
109+
void InfoLoggerDispatch::logWarning(const char* message, ...) {
110+
char buffer[1024] = "";
111+
va_list ap;
112+
va_start(ap, message);
113+
vsnprintf(buffer,sizeof(buffer), message, ap);
114+
va_end(ap);
115+
theLog->warning("%s%s", logPrefix.c_str(), buffer);
116+
}
117+
90118
/////////////////////////////////////////////////
91119
// end of class InfoLoggerDispatch implementation
92120
/////////////////////////////////////////////////

src/InfoLoggerDispatch.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class InfoLoggerDispatch
3131
{
3232

3333
public:
34-
InfoLoggerDispatch(ConfigInfoLoggerServer* theConfig = NULL, SimpleLog* theLog = NULL);
34+
InfoLoggerDispatch(ConfigInfoLoggerServer* theConfig = NULL, SimpleLog* theLog = NULL, std::string theLogPrefix = "");
3535
virtual ~InfoLoggerDispatch();
3636

3737
// todo: define settings: non-blocking, etc
@@ -46,11 +46,16 @@ class InfoLoggerDispatch
4646

4747
// virtual customDispatch...
4848

49+
void logInfo(const char* message, ...) __attribute__((format(printf, 2, 3)));
50+
void logError(const char* message, ...) __attribute__((format(printf, 2, 3)));
51+
void logWarning(const char* message, ...) __attribute__((format(printf, 2, 3)));
52+
4953
protected:
5054
std::unique_ptr<AliceO2::Common::Fifo<std::shared_ptr<InfoLoggerMessageList>>> input;
5155
std::unique_ptr<AliceO2::Common::Thread> dispatchThread;
5256
SimpleLog* theLog;
5357
SimpleLog defaultLog;
58+
std::string logPrefix; // a string appended to each log
5459

5560
ConfigInfoLoggerServer* theConfig;
5661

@@ -82,7 +87,7 @@ class InfoLoggerDispatchSQLImpl;
8287
class InfoLoggerDispatchSQL : public InfoLoggerDispatch
8388
{
8489
public:
85-
InfoLoggerDispatchSQL(ConfigInfoLoggerServer* theConfig, SimpleLog* theLog);
90+
InfoLoggerDispatchSQL(ConfigInfoLoggerServer* theConfig, SimpleLog* theLog, std::string prefix);
8691
~InfoLoggerDispatchSQL();
8792
int customMessageProcess(std::shared_ptr<InfoLoggerMessageList> msg);
8893
int customLoop();

src/InfoLoggerDispatchSQL.cxx

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ typedef bool my_bool;
2828
class InfoLoggerDispatchSQLImpl
2929
{
3030
public:
31-
SimpleLog* theLog; // handle for logging
3231
ConfigInfoLoggerServer* theConfig; // struct with config parameters
32+
InfoLoggerDispatchSQL* parent;
3333

3434
void start();
3535
void stop();
@@ -67,7 +67,7 @@ void InfoLoggerDispatchSQLImpl::start()
6767
{
6868

6969
// log DB params
70-
theLog->info("Using DB %s@%s:%s", theConfig->dbUser.c_str(), theConfig->dbHost.c_str(), theConfig->dbName.c_str());
70+
parent->logInfo("Using DB %s@%s:%s", theConfig->dbUser.c_str(), theConfig->dbHost.c_str(), theConfig->dbName.c_str());
7171

7272
// prepare insert query from 1st protocol definition
7373
// e.g. INSERT INTO messages(severity,level,timestamp,hostname,rolename,pid,username,system,facility,detector,partition,run,errcode,errLine,errsource) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) */
@@ -101,20 +101,20 @@ void InfoLoggerDispatchSQLImpl::start()
101101
}
102102
}
103103
sql_insert += ")";
104-
theLog->info("insert query = %s", sql_insert.c_str());
104+
parent->logInfo("insert query = %s", sql_insert.c_str());
105105
if (errLine) {
106-
theLog->error("Failed to initialize db query: error %d", errLine);
106+
parent->logError("Failed to initialize db query: error %d", errLine);
107107
}
108108

109109
// try to connect DB
110110
// done automatically in customloop
111111
}
112112

113-
InfoLoggerDispatchSQL::InfoLoggerDispatchSQL(ConfigInfoLoggerServer* config, SimpleLog* log) : InfoLoggerDispatch(config, log)
113+
InfoLoggerDispatchSQL::InfoLoggerDispatchSQL(ConfigInfoLoggerServer* config, SimpleLog* log, std::string prefix) : InfoLoggerDispatch(config, log, prefix)
114114
{
115115
dPtr = std::make_unique<InfoLoggerDispatchSQLImpl>();
116-
dPtr->theLog = log;
117116
dPtr->theConfig = config;
117+
dPtr->parent = this;
118118
dPtr->start();
119119

120120
// enable customloop callback
@@ -124,7 +124,7 @@ InfoLoggerDispatchSQL::InfoLoggerDispatchSQL(ConfigInfoLoggerServer* config, Sim
124124
void InfoLoggerDispatchSQLImpl::stop()
125125
{
126126
disconnectDB();
127-
theLog->info("DB thread insert count = %llu, delayed msg count = %llu, dropped msg count = %llu", insertCount, msgDelayedCount, msgDroppedCount);
127+
parent->logInfo("DB thread insert count = %llu, delayed msg count = %llu, dropped msg count = %llu", insertCount, msgDelayedCount, msgDroppedCount);
128128
}
129129

130130
InfoLoggerDispatchSQL::~InfoLoggerDispatchSQL()
@@ -156,18 +156,18 @@ int InfoLoggerDispatchSQLImpl::connectDB()
156156
// init mysql handle
157157
db = mysql_init(db);
158158
if (db == NULL) {
159-
theLog->error("mysql_init() failed");
159+
parent->logError("mysql_init() failed");
160160
return 1;
161161
}
162162
}
163-
163+
parent->logInfo("DB connecting: %s@%s:%s", theConfig->dbUser.c_str(), theConfig->dbHost.c_str(), theConfig->dbName.c_str());
164164
if (mysql_real_connect(db, theConfig->dbHost.c_str(), theConfig->dbUser.c_str(), theConfig->dbPassword.c_str(), theConfig->dbName.c_str(), 0, NULL, 0)) {
165-
theLog->info("DB connected");
165+
parent->logInfo("DB connected");
166166
dbIsConnected = 1;
167167
dbConnectTrials = 0;
168168
} else {
169169
if (dbConnectTrials == 0) { // log only first attempt
170-
theLog->error("DB connection failed: %s", mysql_error(db));
170+
parent->logError("DB connection failed: %s", mysql_error(db));
171171
}
172172
dbConnectTrials++;
173173
return 1;
@@ -176,13 +176,13 @@ int InfoLoggerDispatchSQLImpl::connectDB()
176176
// create prepared insert statement
177177
stmt = mysql_stmt_init(db);
178178
if (stmt == NULL) {
179-
theLog->error("mysql_stmt_init() failed: %s", mysql_error(db));
179+
parent->logError("mysql_stmt_init() failed: %s", mysql_error(db));
180180
disconnectDB();
181181
return -1;
182182
}
183183

184184
if (mysql_stmt_prepare(stmt, sql_insert.c_str(), sql_insert.length())) {
185-
theLog->error("mysql_stmt_prepare() failed: %s", mysql_error(db));
185+
parent->logError("mysql_stmt_prepare() failed: %s", mysql_error(db));
186186
disconnectDB();
187187
return -1;
188188
}
@@ -202,7 +202,7 @@ int InfoLoggerDispatchSQLImpl::connectDB()
202202
bind[i].buffer_type = MYSQL_TYPE_DOUBLE;
203203
break;
204204
default:
205-
theLog->error("undefined field type %d", protocols[0].fields[i].type);
205+
parent->logError("undefined field type %d", protocols[0].fields[i].type);
206206
errline = __LINE__;
207207
break;
208208
}
@@ -230,7 +230,7 @@ int InfoLoggerDispatchSQLImpl::disconnectDB()
230230
db = NULL;
231231
}
232232
if (dbIsConnected) {
233-
theLog->info("DB disconnected");
233+
parent->logInfo("DB disconnected");
234234
}
235235
dbIsConnected = 0;
236236
return 0;
@@ -247,11 +247,11 @@ int InfoLoggerDispatchSQLImpl::customLoop()
247247
if (commitNumberOfMsg) {
248248
if (commitTimer.isTimeout()) {
249249
if (mysql_query(db, "COMMIT")) {
250-
theLog->error("DB transaction commit failed: %s", mysql_error(db));
250+
parent->logError("DB transaction commit failed: %s", mysql_error(db));
251251
commitEnabled = 0;
252252
} else {
253253
if (commitDebug) {
254-
theLog->info("DB commit - %d msgs", commitNumberOfMsg);
254+
parent->logInfo("DB commit - %d msgs", commitNumberOfMsg);
255255
}
256256
}
257257
commitNumberOfMsg = 0;
@@ -299,8 +299,8 @@ int InfoLoggerDispatchSQLImpl::customMessageProcess(std::shared_ptr<InfoLoggerMe
299299
}
300300

301301
int msgLen = (int)strlen(message);
302-
theLog->error("Dropping message (%d bytes): %.*s%s", msgLen, maxLen, message, (msgLen > maxLen) ? "..." : "");
303-
theLog->error(" %s", logDetails.c_str());
302+
parent->logError("Dropping message (%d bytes): %.*s%s", msgLen, maxLen, message, (msgLen > maxLen) ? "..." : "");
303+
parent->logError(" %s", logDetails.c_str());
304304
msgDroppedCount++;
305305
return 0; // remove message from queue
306306
};
@@ -350,12 +350,12 @@ int InfoLoggerDispatchSQLImpl::customMessageProcess(std::shared_ptr<InfoLoggerMe
350350
if (commitEnabled) {
351351
if (commitNumberOfMsg == 0) {
352352
if (mysql_query(db, "START TRANSACTION")) {
353-
theLog->error("DB start transaction failed: %s", mysql_error(db));
353+
parent->logError("DB start transaction failed: %s", mysql_error(db));
354354
commitEnabled = 0;
355355
return returnDelayedMessage();
356356
} else {
357357
if (commitDebug) {
358-
theLog->info("DB transaction started");
358+
parent->logInfo("DB transaction started");
359359
}
360360
}
361361
commitTimer.reset(commitTimeout);
@@ -375,15 +375,15 @@ int InfoLoggerDispatchSQLImpl::customMessageProcess(std::shared_ptr<InfoLoggerMe
375375

376376
// update bind variables
377377
if (mysql_stmt_bind_param(stmt, bind)) {
378-
theLog->error("mysql_stmt_bind() failed: %s", mysql_error(db));
379-
theLog->error("message: %s", msg);
378+
parent->logError("mysql_stmt_bind() failed: %s", mysql_error(db));
379+
parent->logError("message: %s", msg);
380380
// if can not bind, message malformed, drop it
381381
return returnDroppedMessage(msg, m);
382382
}
383383

384384
// Do the insertion
385385
if (mysql_stmt_execute(stmt)) {
386-
theLog->error("mysql_stmt_exec() failed: (%d) %s", mysql_errno(db), mysql_error(db));
386+
parent->logError("mysql_stmt_exec() failed: (%d) %s", mysql_errno(db), mysql_error(db));
387387
// column too long
388388
if (mysql_errno(db) == ER_DATA_TOO_LONG) {
389389
return returnDroppedMessage(msg, m);
@@ -398,7 +398,7 @@ int InfoLoggerDispatchSQLImpl::customMessageProcess(std::shared_ptr<InfoLoggerMe
398398

399399
if (commitDebug) {
400400
if (insertCount % 1000 == 0) {
401-
theLog->info("insert count = %llu", insertCount);
401+
parent->logInfo("insert count = %llu", insertCount);
402402
}
403403
}
404404
}

src/infoLoggerAdminDB.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ int main(int argc, char* argv[])
144144

145145
// connect database
146146
if (mysql_real_connect(&db, dbHost.c_str(), dbUser.c_str(), dbPwd.c_str(), dbName.c_str(), 0, NULL, 0) != 0) {
147-
log.info("Database connected");
147+
log.info("Database %s @ %s connected", dbName.c_str(), dbHost.c_str());
148148
} else {
149149
log.error("Failed to connect database : %s", mysql_error(&db));
150150
return -1;
@@ -171,7 +171,7 @@ int main(int argc, char* argv[])
171171

172172
// execute command(s)
173173
if (optStatus) {
174-
std::string sqlQuery = "select TABLE_NAME,TABLE_ROWS,DATA_LENGTH from information_schema.TABLES where table_name like '" INFOLOGGER_TABLE_MESSAGES "%' order by table_name";
174+
std::string sqlQuery = "select TABLE_NAME,TABLE_ROWS,DATA_LENGTH from information_schema.TABLES where table_name like '" INFOLOGGER_TABLE_MESSAGES "%' and table_schema like '" + dbName + "' order by table_name";
175175
if (mysql_query(&db, sqlQuery.c_str())) {
176176
log.error("Failed to execute %s\n%s", sqlQuery.c_str(), mysql_error(&db));
177177
return -1;

0 commit comments

Comments
 (0)