From f781cc3846f20653ba961e9c8e017d6f9ceb8eba Mon Sep 17 00:00:00 2001 From: peri4 Date: Thu, 21 Oct 2021 18:48:01 +0300 Subject: [PATCH] binary log improvements --- libs/main/io_devices/pibinarylog.cpp | 21 ++++++++++++++------- libs/main/io_devices/pibinarylog.h | 4 ++++ libs/main/io_devices/piiodevice.cpp | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/libs/main/io_devices/pibinarylog.cpp b/libs/main/io_devices/pibinarylog.cpp index 30fbc559..9358664a 100644 --- a/libs/main/io_devices/pibinarylog.cpp +++ b/libs/main/io_devices/pibinarylog.cpp @@ -581,6 +581,7 @@ void PIBinaryLog::parseLog(PIFile * f, PIBinaryLog::BinLogInfo * info, PIVector< if (info) { BinLogIndex bl_ind; bl_ind.id = br.id; + bl_ind.data_size = br.size; bl_ind.pos = f->pos() - br.size - hdr_size; bl_ind.timestamp = br.timestamp; index->append(bl_ind); @@ -667,6 +668,18 @@ bool PIBinaryLog::createIndex() { } +int PIBinaryLog::posForTime(const PISystemTime & time) { + int ci = -1; + for (uint i = 0; i < index.size(); i++) { + if (time <= index[i].timestamp && (filterID.contains(index[i].id) || filterID.isEmpty())) { + ci = i; + break; + } + } + return ci; +} + + void PIBinaryLog::seekTo(int rindex) { // piCoutObj << "seekTo"; logmutex.lock(); @@ -688,13 +701,7 @@ void PIBinaryLog::seekTo(int rindex) { bool PIBinaryLog::seek(const PISystemTime & time) { - int ci = -1; - for (uint i=0; i= 0) { seekTo(ci); return true; diff --git a/libs/main/io_devices/pibinarylog.h b/libs/main/io_devices/pibinarylog.h index 4a5bcbea..1c9bee81 100644 --- a/libs/main/io_devices/pibinarylog.h +++ b/libs/main/io_devices/pibinarylog.h @@ -76,6 +76,7 @@ public: //! @brief Struct contains position, ID and timestamp of record in file struct PIP_EXPORT BinLogIndex { int id; + int data_size; llong pos; PISystemTime timestamp; }; @@ -236,6 +237,9 @@ public: //! Return if current binlog file is indexed bool isIndexed() {return is_indexed;} + //! Find nearest record of time \"time\". Returns -1 if not indexed or time less than first record + int posForTime(const PISystemTime & time); + //! Go to record #index void seekTo(int rindex); diff --git a/libs/main/io_devices/piiodevice.cpp b/libs/main/io_devices/piiodevice.cpp index 482e0367..a50042e2 100644 --- a/libs/main/io_devices/piiodevice.cpp +++ b/libs/main/io_devices/piiodevice.cpp @@ -163,7 +163,7 @@ bool stopThread(PIThread * t, bool hard) { return true; } else { t->stop(); - if (t->waitForFinish(10000)) { + if (!t->waitForFinish(10000)) { t->terminate(); return true; }