Skip to content

Commit a150dd9

Browse files
committed
clang format
1 parent db69533 commit a150dd9

File tree

3 files changed

+192
-183
lines changed

3 files changed

+192
-183
lines changed

src/InfoLogger.cxx

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ class InfoLogger::Impl
301301

302302
// message flood prevention
303303
// constants
304-
const bool flood_protection = 1; // if set, flood protection mechanism enabled
304+
const bool flood_protection = 1; // if set, flood protection mechanism enabled
305305
const unsigned int flood_maxmsg_sec=500; // maximum messages in one second to trigger flood
306306
const unsigned int flood_maxmsg_min=1000; // maximum messages in one minute to trigger flood
307307
const unsigned int flood_maxmsg_file=1000; // maximum number of messages in overflow log file
@@ -477,81 +477,81 @@ int InfoLogger::Impl::pushMessage(const InfoLoggerMessageOption& options, const
477477
}
478478

479479
if (flood_protection) {
480-
481-
// update message statistics */
482-
if (now-floodStat_time_lastsec>1) {
483-
floodStat_time_lastsec=now;
484-
floodStat_msgs_sec=1;
485-
} else {
486-
floodStat_msgs_sec++;
487-
}
488-
if (now-floodStat_time_lastmin>60) {
489-
floodStat_time_lastmin=now;
490-
floodStat_msgs_lastmin=floodStat_msgs_min;
491-
floodStat_msgs_min=1;
492-
} else {
493-
floodStat_msgs_min++;
494-
}
495-
496-
// message flood prevention
497-
if (!noFlood) {
498-
switch (floodMode) {
499-
case 0:
500-
if ((floodStat_msgs_sec>flood_maxmsg_sec)||(floodStat_msgs_min>flood_maxmsg_min)) {
501-
floodFile_msg=0;
502-
floodFile_msg_drop=0;
503-
std::string floodFile_path = floodFile_dir + "/infoLogger.flood-" + std::to_string(context.processId) + "@" + context.hostName + "-" + std::to_string((int)now);
504-
floodFile_fp=fopen(floodFile_path.c_str(),"w");
505-
if (floodFile_fp==NULL) {
506-
floodMode=2;
507-
std::string msg = "Message flood detected - further messages will be dropped (failed to create flood file " + floodFile_path + ")";
508-
pushMessage(LogWarningSupport_(1101), currentContext, msg.c_str(),1);
509-
goto case2;
480+
481+
// update message statistics */
482+
if (now - floodStat_time_lastsec > 1) {
483+
floodStat_time_lastsec = now;
484+
floodStat_msgs_sec = 1;
485+
} else {
486+
floodStat_msgs_sec++;
487+
}
488+
if (now - floodStat_time_lastmin > 60) {
489+
floodStat_time_lastmin = now;
490+
floodStat_msgs_lastmin = floodStat_msgs_min;
491+
floodStat_msgs_min = 1;
492+
} else {
493+
floodStat_msgs_min++;
494+
}
495+
496+
// message flood prevention
497+
if (!noFlood) {
498+
switch (floodMode) {
499+
case 0:
500+
if ((floodStat_msgs_sec > flood_maxmsg_sec) || (floodStat_msgs_min > flood_maxmsg_min)) {
501+
floodFile_msg = 0;
502+
floodFile_msg_drop = 0;
503+
std::string floodFile_path = floodFile_dir + "/infoLogger.flood-" + std::to_string(context.processId) + "@" + context.hostName + "-" + std::to_string((int)now);
504+
floodFile_fp = fopen(floodFile_path.c_str(), "w");
505+
if (floodFile_fp == NULL) {
506+
floodMode = 2;
507+
std::string msg = "Message flood detected - further messages will be dropped (failed to create flood file " + floodFile_path + ")";
508+
pushMessage(LogWarningSupport_(1101), currentContext, msg.c_str(), 1);
509+
goto case2;
510+
} else {
511+
floodMode = 1;
512+
std::string msg = "Message flood detected - further messages will be stored locally in " + floodFile_path;
513+
pushMessage(LogWarningSupport_(1101), currentContext, msg.c_str(), 1);
514+
}
515+
} else {
516+
break;
517+
}
518+
case 1:
519+
if (floodStat_msgs_lastmin < flood_maxmsg_reset) {
520+
// reset flood mode
521+
break;
522+
}
523+
if (floodFile_msg >= flood_maxmsg_file) {
524+
if (floodFile_fp != nullptr) {
525+
fclose(floodFile_fp);
526+
floodFile_fp = nullptr;
527+
}
528+
pushMessage(LogWarningSupport_(1101), currentContext, "Message flood - maximum entries in local file exceeded, further messages will be dropped", 1);
529+
floodMode = 2;
510530
} else {
511-
floodMode=1;
512-
std::string msg = "Message flood detected - further messages will be stored locally in " + floodFile_path;
513-
pushMessage(LogWarningSupport_(1101), currentContext, msg.c_str(),1);
531+
// log to flood file
532+
fprintf(floodFile_fp, "%f\t%c\t%s\t%s\n", now, (char)options.severity, context.facility.c_str(), messageBody);
533+
fflush(floodFile_fp);
534+
floodFile_msg++;
535+
return 0;
514536
}
515-
} else {
516-
break;
517-
}
518-
case 1:
519-
if (floodStat_msgs_lastmin<flood_maxmsg_reset) {
520-
// reset flood mode
521-
break;
522-
}
523-
if (floodFile_msg>=flood_maxmsg_file) {
524-
if (floodFile_fp!=nullptr) {
525-
fclose(floodFile_fp);
526-
floodFile_fp=nullptr;
537+
case 2:
538+
case2:
539+
if (floodStat_msgs_lastmin < flood_maxmsg_reset) {
540+
// reset flood mode
541+
break;
527542
}
528-
pushMessage(LogWarningSupport_(1101), currentContext, "Message flood - maximum entries in local file exceeded, further messages will be dropped",1);
529-
floodMode=2;
530-
} else {
531-
// log to flood file
532-
fprintf(floodFile_fp,"%f\t%c\t%s\t%s\n",now,(char)options.severity,context.facility.c_str(),messageBody);
533-
fflush(floodFile_fp);
534-
floodFile_msg++;
543+
// drop message
544+
floodFile_msg_drop++;
535545
return 0;
536-
}
537-
case 2:
538-
case2:
539-
if (floodStat_msgs_lastmin<flood_maxmsg_reset) {
540-
// reset flood mode
541-
break;
542-
}
543-
// drop message
544-
floodFile_msg_drop++;
545-
return 0;
546-
}
547-
if (floodMode) {
548-
std::string msg = "Message flood - resuming normal operation: " + std::to_string(floodFile_msg) + " messages stored locally, " + std::to_string(floodFile_msg_drop) + " messages dropped";
549-
pushMessage(LogWarningSupport_(1102), currentContext, msg.c_str(),1);
550-
floodReset();
546+
}
547+
if (floodMode) {
548+
std::string msg = "Message flood - resuming normal operation: " + std::to_string(floodFile_msg) + " messages stored locally, " + std::to_string(floodFile_msg_drop) + " messages dropped";
549+
pushMessage(LogWarningSupport_(1102), currentContext, msg.c_str(), 1);
550+
floodReset();
551+
}
551552
}
552553
}
553-
}
554-
554+
555555
if (client != nullptr) {
556556
char buffer[LOG_MAX_SIZE];
557557
msgHelper.MessageToText(&msg, buffer, sizeof(buffer), InfoLoggerMessageHelper::Format::Encoded);

src/InfoLoggerDispatchSQL.cxx

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ class InfoLoggerDispatchSQLImpl
5252

5353
int connectDB(); // function to connect to database
5454
int disconnectDB(); // disconnect/cleanup DB connection
55-
56-
int commitEnabled = 1; // flag to enable transactions
57-
int commitDebug = 0; // log transactions
55+
56+
int commitEnabled = 1; // flag to enable transactions
57+
int commitDebug = 0; // log transactions
5858
int commitTimeout = 1000000; // time between commits
59-
Timer commitTimer; // timer for transaction
60-
int commitNumberOfMsg; // number of messages since last commit
59+
Timer commitTimer; // timer for transaction
60+
int commitNumberOfMsg; // number of messages since last commit
6161
};
6262

6363
void InfoLoggerDispatchSQLImpl::start()
@@ -208,7 +208,7 @@ int InfoLoggerDispatchSQLImpl::connectDB()
208208
disconnectDB();
209209
return -1;
210210
}
211-
211+
212212
// reset transactions
213213
commitNumberOfMsg = 0;
214214
}
@@ -243,19 +243,19 @@ int InfoLoggerDispatchSQLImpl::customLoop()
243243
// complete pending transactions
244244
if (commitNumberOfMsg) {
245245
if (commitTimer.isTimeout()) {
246-
if (mysql_query (db, "COMMIT")) {
247-
theLog->error("DB transaction commit failed: %s", mysql_error(db));
248-
commitEnabled = 0;
249-
} else {
246+
if (mysql_query(db, "COMMIT")) {
247+
theLog->error("DB transaction commit failed: %s", mysql_error(db));
248+
commitEnabled = 0;
249+
} else {
250250
if (commitDebug) {
251-
theLog->info("DB commit - %d msgs", commitNumberOfMsg);
252-
}
253-
}
254-
commitNumberOfMsg = 0;
251+
theLog->info("DB commit - %d msgs", commitNumberOfMsg);
252+
}
253+
}
254+
commitNumberOfMsg = 0;
255255
}
256256
}
257257
}
258-
258+
259259
return err;
260260
}
261261

@@ -302,19 +302,19 @@ int InfoLoggerDispatchSQLImpl::customMessageProcess(std::shared_ptr<InfoLoggerMe
302302

303303
if (commitEnabled) {
304304
if (commitNumberOfMsg == 0) {
305-
if (mysql_query (db, "START TRANSACTION")) {
306-
theLog->error("DB start transaction failed: %s", mysql_error(db));
307-
commitEnabled = 0;
308-
return -1;
309-
} else {
310-
if (commitDebug) {
305+
if (mysql_query(db, "START TRANSACTION")) {
306+
theLog->error("DB start transaction failed: %s", mysql_error(db));
307+
commitEnabled = 0;
308+
return -1;
309+
} else {
310+
if (commitDebug) {
311311
theLog->info("DB transaction started");
312-
}
313-
}
312+
}
313+
}
314314
commitTimer.reset(commitTimeout);
315315
}
316316
}
317-
317+
318318
// re-format message with multiple line - assumes it is the LAST field in the protocol
319319
for (msg = (char*)m->values[nFields - 1].value.vString; msg != NULL; msg = nl) {
320320
nl = strchr(msg, '\f');
@@ -345,13 +345,12 @@ int InfoLoggerDispatchSQLImpl::customMessageProcess(std::shared_ptr<InfoLoggerMe
345345

346346
insertCount++;
347347
commitNumberOfMsg++;
348-
349-
if (commitDebug) {
350-
if (insertCount%1000==0) {
351-
theLog->info("insert count = %llu",insertCount);
348+
349+
if (commitDebug) {
350+
if (insertCount % 1000 == 0) {
351+
theLog->info("insert count = %llu", insertCount);
352352
}
353353
}
354-
355354
}
356355
}
357356
return 0;

0 commit comments

Comments
 (0)