Adds immediate migration results in progress

This commit is contained in:
torsten committed 2026-08-19 11:18:24 +02:00
1 parent 8453e104c5
commit 3bb6e89496
2102 files changed
+17482 -15071

No files matched your search

@@ -23,13 +23,12 @@
namespace RecordingManagement
{
DbWriter::DbWriter(const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector)
: m_query(nullptr)
DbWriter::DbWriter(const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector) : m_query(nullptr)
, m_recordTimer(new QTimer(this))
, m_ddsConnector(ddsConnector)
, m_dbWriterSnapshot(nullptr)
, m_dbWriterSnapshotThread(nullptr)
{}
, m_dbWriterSnapshotThread(nullptr),
m_logger(NGL::NGLLoggerBootstrap::getLogger()) {}
DbWriter::~DbWriter()
{
@@ -52,18 +51,18 @@ bool DbWriter::loadPlugin(const LtsPluginManager::PluginInstance &pi)
RecordReplay::RecordReplayPlugin *recPlugin = qobject_cast<RecordReplay::RecordReplayPlugin *>(pi.plugin);
if (!recPlugin)
{
ERROR_LOG() << "Cannot load RecordReplayPlugin " << pi.fileName;
ERROR_LOG(m_logger) << "Cannot load RecordReplayPlugin " << pi.fileName;
return false;
}
INFO_LOG() << "Loading RecordReplayPlugin " << pi.fileName;
INFO_LOG(m_logger) << "Loading RecordReplayPlugin " << pi.fileName;
// exId == partId da wir hier in IDL::PartitionType::Exercise arbeiten
if (!recPlugin->initDtc(m_ddsConnector, m_ddsConnector->getPartitionId()))
{
ERROR_LOG() << "Initialisation for RecordReplayPlugin " << pi.fileName << " failed ";
ERROR_LOG(m_logger) << "Initialisation for RecordReplayPlugin " << pi.fileName << " failed ";
return false;
}
INFO_LOG() << "Loaded record replay plugin " << recPlugin->pluginName();
INFO_LOG(m_logger) << "Loaded record replay plugin " << recPlugin->pluginName();
m_plugins += recPlugin;
return true;
@@ -81,7 +80,7 @@ bool DbWriter::init(const std::shared_ptr<DatabaseInterface> &db)
// Start recording data
qint64 msecs = Settings::updateFrequency();
INFO_LOG() << "Updating recording tables every " << msecs << " milliseconds.";
INFO_LOG(m_logger) << "Updating recording tables every " << msecs << " milliseconds.";
connect(m_recordTimer, &QTimer::timeout, this, &DbWriter::ddsTopicsToDatabase);
m_recordTimer->start(msecs);
@@ -113,7 +112,7 @@ bool DbWriter::initSnapshot()
void DbWriter::ddsTopicsToDatabase()
{
DEBUG_LOG() << "IN ddsTopicsToDatabase";
DEBUG_LOG(m_logger) << "IN ddsTopicsToDatabase";
DBTransaction trans(m_db->database());
QHash<QString, qint64> minRecordSampleTimes;
@@ -124,7 +123,7 @@ void DbWriter::ddsTopicsToDatabase()
if (!recPlugin->ddsTopicsToDatabase(*m_query, minRecordSampleTimes))
{
// should never happen but who knows
ERROR_LOG() << "Error recording dds topics - aborting recording data";
ERROR_LOG(m_logger) << "Error recording dds topics - aborting recording data";
return;
}
}
@@ -35,6 +35,7 @@ public:
bool init(const std::shared_ptr<DatabaseInterface> &db);
protected:
NGL::INGLLogger &m_logger;
bool initSnapshot();
bool loadPlugin(const LtsPluginManager::PluginInstance &pi);
@@ -36,13 +36,12 @@ void DbWriterSnapshotThread::run()
DbWriterSnapshot::DbWriterSnapshot(const QVector<RecordReplay::RecordReplayPlugin *> &plugins,
int exerciseId,
NGL::Settings *settings)
: QObject()
NGL::Settings *settings) : QObject()
, m_plugins(plugins)
, m_snapshotInterval(1 * 60 * 1000) // TODO: make config variable // Interval: 1 min in milliseconds
, m_exerciseId(exerciseId)
, m_settings(settings)
{
, m_settings(settings),
m_logger(NGL::NGLLoggerBootstrap::getLogger()) {
}
DbWriterSnapshot::~DbWriterSnapshot()
@@ -76,14 +75,14 @@ void DbWriterSnapshot::init()
// Set search path
const QString stmt = QLatin1String("SET SEARCH_PATH TO ") + m_dbInterface->schemaName() + QLatin1String(", PUBLIC");
INFO_LOG() << "SearchPath Stmt: " << stmt;
INFO_LOG(m_logger) << "SearchPath Stmt: " << stmt;
NSqlQuery q(dbConn);
q.exec(stmt);
if (!m_dbInterface->init(dbConn))
{
ERROR_LOG() << "Error initializing database interface - can not initialize DbWriterSnapshot";
ERROR_LOG(m_logger) << "Error initializing database interface - can not initialize DbWriterSnapshot";
m_dbInterface = nullptr;
return;
}
@@ -107,7 +106,7 @@ void DbWriterSnapshot::setMinRecordedSampleTimes(const QHash<QString, qint64> &m
const QString &topicName = it.key();
if (minRecordedSampleTime == 0)
{
WARNING_LOG() << "Minimum recorded Sample Time for topic " << topicName <<
WARNING_LOG(m_logger) << "Minimum recorded Sample Time for topic " << topicName <<
" is zero - looks like a service did not properly set the sample time!";
continue;
}
@@ -122,7 +121,7 @@ void DbWriterSnapshot::setMinRecordedSampleTimes(const QHash<QString, qint64> &m
// already a minimum time - make sure to get the minimum from both
m_minRecordedSampleTimes[topicName] = std::min(minRecordedSampleTime, mrstIt.value());
}
INFO_LOG() << "Current minimum sample time for " << topicName
INFO_LOG(m_logger) << "Current minimum sample time for " << topicName
<< " is " << m_minRecordedSampleTimes.value(topicName)
<< " = " << QDateTime::fromMSecsSinceEpoch(m_minRecordedSampleTimes.value(topicName)).toString();
}
@@ -157,7 +156,7 @@ void DbWriterSnapshot::initSnapshot()
topicRecIdQuery.prepare(QStringLiteral("SELECT MAX(time_stamp) FROM rec_snapshot WHERE svc_name = :svc_name AND topic_name = :topic_name"));
const qint64 tNow(time(nullptr) * 1000 - 60 * 1 * 1000); // jetzt vor einer Minute
INFO_LOG() << "tNow (-1min): " << tNow;
INFO_LOG(m_logger) << "tNow (-1min): " << tNow;
QHash<QString, qint64> minRecordedSampleTimes;
@@ -198,7 +197,7 @@ void DbWriterSnapshot::initSnapshot()
fromWhere = "snapshot + last sample";
else if (timeToStartSnapshotCreationFrom == tNow)
fromWhere = "current time";
INFO_LOG() << "last snapshot time for topic '" << topicName
INFO_LOG(m_logger) << "last snapshot time for topic '" << topicName
<< "' is: " << timeToStartSnapshotCreationFrom
<< " from " << fromWhere;
minRecordedSampleTimes[topicName] = timeToStartSnapshotCreationFrom;
@@ -218,7 +217,7 @@ void DbWriterSnapshot::writeSnapshotData()
const QHash<QString, qint64> minRecSampleTimes(getMinRecordedSampleTimes(lastSnapshotTimeToGenerateNow));
if (minRecSampleTimes.isEmpty())
{
INFO_LOG() << "minRecSampleTimes has no entries with time < " << lastSnapshotTimeToGenerateNow
INFO_LOG(m_logger) << "minRecSampleTimes has no entries with time < " << lastSnapshotTimeToGenerateNow
<< " nothing to do...";
QTimer::singleShot(m_snapshotInterval, Qt::VeryCoarseTimer,
this, &DbWriterSnapshot::writeSnapshotData);
@@ -229,25 +228,25 @@ void DbWriterSnapshot::writeSnapshotData()
qint64 startTime = std::numeric_limits<qint64>::max();
for(const qint64 st : std::as_const(minRecSampleTimes))
startTime = std::min(startTime, st);
INFO_LOG() << "writeSnapshotData - lastSnapshotTimeToGenerateNow: " << lastSnapshotTimeToGenerateNow
INFO_LOG(m_logger) << "writeSnapshotData - lastSnapshotTimeToGenerateNow: " << lastSnapshotTimeToGenerateNow
<< ", minRecTime is " << startTime;
if (startTime <= 0 || startTime > endTime)
{
WARNING_LOG() << "Spurious start time (" << startTime
WARNING_LOG(m_logger) << "Spurious start time (" << startTime
<< ") - using end time for start (" << endTime << ")";
startTime = endTime - 1; // -1 -> create at least one interval
}
if (startTime > lastSnapshotTimeToGenerateNow)
{
INFO_LOG() << "Nothing changed in the last interval until " << lastSnapshotTimeToGenerateNow << " youngest topic is at " << startTime;
INFO_LOG(m_logger) << "Nothing changed in the last interval until " << lastSnapshotTimeToGenerateNow << " youngest topic is at " << startTime;
QTimer::singleShot(m_snapshotInterval, Qt::VeryCoarseTimer,
this, &DbWriterSnapshot::writeSnapshotData);
return;
}
// we know something changed between startTime and lastSnapshotTimeToGenerateNow - let's do some work
INFO_LOG() << "startTime: " << startTime
INFO_LOG(m_logger) << "startTime: " << startTime
<< " lastSnapshotTimeToGenerateNow: " << lastSnapshotTimeToGenerateNow << " - BEGIN";
DBTransaction trans(QSqlDatabase::database(dbConnectionName()));
NSqlQuery recSnapshotQuery(QSqlDatabase::database(dbConnectionName()));
@@ -255,7 +254,7 @@ void DbWriterSnapshot::writeSnapshotData()
writeSnapshotDataPlugin(lastSnapshotTimeToGenerateNow, recSnapshotQuery, recPlugin, minRecSampleTimes);
trans.commit();
INFO_LOG() << "startTime: " << startTime
INFO_LOG(m_logger) << "startTime: " << startTime
<< " lastSnapshotTimeToGenerateNow: " << lastSnapshotTimeToGenerateNow << " - FINISHED";
@@ -288,7 +287,7 @@ void DbWriterSnapshot::writeSnapshotDataPlugin(qint64 endInterval,
for (auto &snapshotData : vec)
{
INFO_LOG() << "svc: " << recSnapshot.svcName
INFO_LOG(m_logger) << "svc: " << recSnapshot.svcName
<< " topic: " << recSnapshot.topicName
<< " timestamp: " << snapshotData.timeStamp
<< " #elements: " << snapshotData.recIdArray.size();
@@ -298,7 +297,7 @@ void DbWriterSnapshot::writeSnapshotDataPlugin(qint64 endInterval,
recSnapshot.recIdArray = LtsUtils::BigintArray2D(std::move(snapshotData.recIdArray));
if (!m_dbInterface->insert(recSnapshot))
ERROR_LOG() << "Error while recording snaphshot for topic " << recSnapshot.topicName;
ERROR_LOG(m_logger) << "Error while recording snaphshot for topic " << recSnapshot.topicName;
}
}
}
@@ -74,6 +74,7 @@ public:
, m_dbWriterSnapshot(dbWriterSnapshot)
{}
protected:
NGL::INGLLogger &m_logger;
void run() override final;
private:
DbWriterSnapshot *m_dbWriterSnapshot;
@@ -16,14 +16,14 @@ namespace RecordingManagement
DdsHandler::DdsHandler(int domainId, int exerciseId)
: m_ddsConnector(std::make_shared<DDSConnector::DdsConnector>(domainId, IDL::PartitionType::Exercise, exerciseId))
{
DEBUG_LOG() << "DdsHandler(" << domainId << ") for partition: " << m_ddsConnector->getDefaultPartition();
DEBUG_LOG(m_logger) << "DdsHandler(" << domainId << ") for partition: " << m_ddsConnector->getDefaultPartition();
}
bool DdsHandler::init(const QStringList &qosFileList)
{
if (!m_ddsConnector->init(qosFileList))
{
ERROR_LOG() << "Error initializing dds connections - aborting";
ERROR_LOG(m_logger) << "Error initializing dds connections - aborting";
return false;
}
@@ -33,6 +33,7 @@ public:
std::shared_ptr<DDSConnector::DdsConnector> dds() const { return m_ddsConnector; }
private:
NGL::INGLLogger &m_logger;
std::shared_ptr<DDSConnector::DdsConnector> m_ddsConnector;
std::shared_ptr<Core::Pacemaker> m_pacemaker;
};
@@ -31,6 +31,8 @@ public:
private:
NGL::INGLLogger &m_logger;
std::shared_ptr<DdsHandler> m_ddsHandler;
std::shared_ptr<DbHandler> m_dbHandler;
std::shared_ptr<DbWriter> m_dbWriter;