Skip to content

Commit 597dfc2

Browse files
committed
Redid the readRandomRecords function in DBRecordArray class, plus other small fixes and changes
The previous implementation was confusing and hard to understand, IMHO, and needlessly complex. I also think this new approach should be faster in practice due to collating the calls to the DB better and due to use of MultiGet. Also in this commit: Added ability for bench/test threads to use the Log(), and other small fixes and nits.
1 parent 1be39c3 commit 597dfc2

File tree

5 files changed

+198
-109
lines changed

5 files changed

+198
-109
lines changed

src/App.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ void App::parseArgs()
672672
// custom hack used only for test/bench mode to enable/disable debug output in test mode from CLI args
673673
static std::once_flag once;
674674
std::call_once(once, [&] {
675+
logger()->setDirectMode(true); // ensures any benches or tests that spawn threads that use Log(), etc, will lead to printed output
675676
if (auto found = parser.optionNames(); const auto dbgct = (found.count("d") + found.count("debug"))) {
676677
if (dbgct) options->verboseDebug = true;
677678
if (dbgct > 1) options->verboseTrace = true;
@@ -717,11 +718,11 @@ void App::parseArgs()
717718
}
718719
}
719720
if (setCtr)
720-
std::exit(0);
721+
std::exit(EXIT_SUCCESS);
721722
} catch (const std::exception & e) {
722723
// bench or test execution failed with an exception
723724
Error(Log::Color::Magenta) << "Caught exception: " << e.what();
724-
std::exit(1);
725+
std::exit(EXIT_FAILURE);
725726
}
726727

727728
const auto checkSupportsSsl = [] {

src/Logger.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace {
5050

5151
Logger::Logger(QObject *parent) : QObject(parent)
5252
{
53-
connect(this, &Logger::log, this, [this](int level, const QString &line){
53+
connGotLine = connect(this, &Logger::log, this, [this](int level, const QString &line){
5454
// we do it in a closure because in this c'tor gotLine isn't defined yet (pure virtual)
5555
gotLine(level, line);
5656
});
@@ -83,6 +83,19 @@ bool ConsoleLogger::calcIsATty(bool stdOut)
8383
return false;
8484
}
8585

86+
bool ConsoleLogger::setDirectMode(bool b) /* override */
87+
{
88+
if (b != isDirectMode()) {
89+
disconnect(connGotLine);
90+
connGotLine = connect(this, &Logger::log, this, [this](int level, const QString &line) { gotLine(level, line); },
91+
b ? Qt::DirectConnection : Qt::AutoConnection);
92+
directMode = b;
93+
}
94+
return true;
95+
}
96+
97+
bool ConsoleLogger::isDirectMode() const /* override */ { return directMode; }
98+
8699
void ConsoleLogger::gotLine(int level, const QString &l)
87100
{
88101
auto * const strm = stdOut ? stdout : stderr;

src/Logger.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,18 @@ class Logger : public QObject
3636
/// returns true if the logger is logging to a tty (and thus supports ANSI color codes, etc)
3737
virtual bool isaTTY() const { return false; }
3838

39+
/// Set "direct" mode on or off. Default is for it to be off. In direct mode the log() signal is connected
40+
/// via Qt::DirectConnection to gotLine(). Returns false on error, true on success.
41+
virtual bool setDirectMode(bool) { return false; }
42+
virtual bool isDirectMode() const { return false;}
43+
3944
signals:
4045
void log(int level, const QString & line); ///< call this or emit it to log a line
4146

4247
protected:
4348
virtual void gotLine(int level, const QString &) = 0;
49+
50+
QMetaObject::Connection connGotLine;
4451
};
4552

4653
class ConsoleLogger : public Logger
@@ -50,13 +57,17 @@ class ConsoleLogger : public Logger
5057

5158
bool isaTTY() const override { return isATty; }
5259

60+
bool setDirectMode(bool) override;
61+
bool isDirectMode() const override;
62+
5363
protected:
5464
void gotLine(int level, const QString &) override;
5565

5666
private:
5767
const bool stdOut;
5868
const bool isATty;
5969
static bool calcIsATty(bool stdOut);
70+
bool directMode = false;
6071
};
6172

6273
/// On Windows this just prints to stdout. On Unix, calls syslog()
@@ -67,6 +78,8 @@ class SysLogger : public ConsoleLogger
6778
SysLogger(QObject *parent = nullptr);
6879
bool isaTTY() const override { return !opened && ConsoleLogger::isaTTY(); }
6980

81+
bool setDirectMode(bool) override { return false; }
82+
7083
protected:
7184
void gotLine(int level, const QString &) override;
7285

0 commit comments

Comments
 (0)