binlog fixes

This commit is contained in:
2020-08-13 18:03:25 +03:00
parent 31a347250f
commit e76a07a3f3
2 changed files with 34 additions and 29 deletions

View File

@@ -374,7 +374,7 @@ void PIBinaryLog::setHeader(const PIByteArray & header) {
PIByteArray PIBinaryLog::getHeader() {
return user_header_readed;
return binfo.user_header;
}
@@ -436,7 +436,7 @@ bool PIBinaryLog::writeFileHeader() {
bool PIBinaryLog::checkFileHeader() {
user_header_readed.clear();
binfo.user_header.clear();
uchar read_sig[PIBINARYLOG_SIGNATURE_SIZE];
for (uint i=0; i<PIBINARYLOG_SIGNATURE_SIZE; i++) read_sig[i] = 0;
if (file.read(read_sig, PIBINARYLOG_SIGNATURE_SIZE) < 0) return false;
@@ -458,7 +458,7 @@ bool PIBinaryLog::checkFileHeader() {
uint32_t sz = 0;
file.read(&sz, 4);
if (sz > 0) {
user_header_readed = file.read(sz);
binfo.user_header = file.read(sz);
}
return true;
}
@@ -505,33 +505,37 @@ PIBinaryLog::BinLogRecord PIBinaryLog::readRecord() {
void PIBinaryLog::parseLog(PIFile * f, PIBinaryLog::BinLogInfo * info, PIVector<PIBinaryLog::BinLogIndex> * index) {
BinLogInfo * bi = info;
bool ginfo = info != 0;
bool gindex = index != 0;
if (!ginfo && !gindex) return;
if (ginfo) {
bi->log_size = -1;
bi->records_count = 0;
bi->records.clear();
if (!info && !index) return;
if (info) {
info->log_size = -1;
info->records_count = 0;
info->records.clear();
}
if (gindex) index->clear();
if (index) index->clear();
if (f == 0) return;
if (!f->canRead()) return;
if (ginfo) {
bi->path = f->path();
bi->log_size = f->size();
if (info) {
info->path = f->path();
info->log_size = f->size();
}
uchar read_sig[PIBINARYLOG_SIGNATURE_SIZE];
for (uint i=0; i<PIBINARYLOG_SIGNATURE_SIZE; i++) read_sig[i] = 0;
bool ok = true;
if (f->read(read_sig, PIBINARYLOG_SIGNATURE_SIZE) < 0) {if (ginfo) bi->records_count = -1; ok = false;}
if (f->read(read_sig, PIBINARYLOG_SIGNATURE_SIZE) < 0) {if (info) info->records_count = -1; ok = false;}
for (uint i=0; i<PIBINARYLOG_SIGNATURE_SIZE; i++)
if (read_sig[i] != binlog_sig[i]) {if (ginfo) bi->records_count = -2; ok = false;}
if (read_sig[i] != binlog_sig[i]) {if (info) info->records_count = -2; ok = false;}
uchar read_version = 0;
if (f->read(&read_version, 1) < 0) {if (ginfo) bi->records_count = -3; ok = false;}
if (read_version == 0) {if (ginfo) bi->records_count = -4; ok = false;}
if (read_version < PIBINARYLOG_VERSION) {if (ginfo) bi->records_count = -5; ok = false;}
if (read_version > PIBINARYLOG_VERSION) {if (ginfo) bi->records_count = -6; ok = false;}
if (f->read(&read_version, 1) < 0) {if (info) info->records_count = -3; ok = false;}
if (read_version == 0) {if (info) info->records_count = -4; ok = false;}
if (read_version < PIBINARYLOG_VERSION_OLD) {if (info) info->records_count = -5; ok = false;}
if (read_version > PIBINARYLOG_VERSION) {if (info) info->records_count = -6; ok = false;}
if (read_version == PIBINARYLOG_VERSION) {
uint32_t sz = 0;
f->read(&sz, 4);
if (sz > 0 && info) {
info->user_header = f->read(sz);
}
}
if (!ok) return;
PIByteArray ba;
BinLogRecord br;
@@ -545,26 +549,26 @@ void PIBinaryLog::parseLog(PIFile * f, PIBinaryLog::BinLogInfo * info, PIVector<
ba >> br.id >> br.size >> br.timestamp;
} else
break;
if (bi->log_size - f->pos() >= br.size)
if (info->log_size - f->pos() >= br.size)
f->seek(f->pos() + br.size);
else
break;
}
if (br.id > 0) {
if (gindex) {
if (info) {
BinLogIndex bl_ind;
bl_ind.id = br.id;
bl_ind.pos = f->pos() - br.size - hdr_size;
bl_ind.timestamp = br.timestamp;
index->append(bl_ind);
}
if (ginfo) {
bi->records_count++;
if (info) {
info->records_count++;
if (first) {
bi->start_time = br.timestamp;
info->start_time = br.timestamp;
first = false;
}
BinLogRecordInfo &bri(bi->records[br.id]);
BinLogRecordInfo &bri(info->records[br.id]);
bri.count++;
if (bri.id == 0) {
bri.id = br.id;
@@ -578,7 +582,7 @@ void PIBinaryLog::parseLog(PIFile * f, PIBinaryLog::BinLogInfo * info, PIVector<
}
}
}
if (ginfo) bi->end_time = br.timestamp;
if (info) info->end_time = br.timestamp;
}

View File

@@ -70,6 +70,7 @@ public:
PISystemTime start_time;
PISystemTime end_time;
PIMap<int, BinLogRecordInfo> records;
PIByteArray user_header;
};
//! \brief Struct contains position, ID and timestamp of record in file
@@ -319,7 +320,7 @@ private:
llong split_size, log_size;
int write_count, split_count, default_id, current_index;
bool is_started, is_thread_ok, is_indexed, rapid_start, is_pause;
PIByteArray user_header, user_header_readed;
PIByteArray user_header;
};
//! \relatesalso PICout \relatesalso PIBinaryLog::BinLogInfo \brief Output operator to PICout