binlog fixes
This commit is contained in:
@@ -374,7 +374,7 @@ void PIBinaryLog::setHeader(const PIByteArray & header) {
|
|||||||
|
|
||||||
|
|
||||||
PIByteArray PIBinaryLog::getHeader() {
|
PIByteArray PIBinaryLog::getHeader() {
|
||||||
return user_header_readed;
|
return binfo.user_header;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -436,7 +436,7 @@ bool PIBinaryLog::writeFileHeader() {
|
|||||||
|
|
||||||
|
|
||||||
bool PIBinaryLog::checkFileHeader() {
|
bool PIBinaryLog::checkFileHeader() {
|
||||||
user_header_readed.clear();
|
binfo.user_header.clear();
|
||||||
uchar read_sig[PIBINARYLOG_SIGNATURE_SIZE];
|
uchar read_sig[PIBINARYLOG_SIGNATURE_SIZE];
|
||||||
for (uint i=0; i<PIBINARYLOG_SIGNATURE_SIZE; i++) read_sig[i] = 0;
|
for (uint i=0; i<PIBINARYLOG_SIGNATURE_SIZE; i++) read_sig[i] = 0;
|
||||||
if (file.read(read_sig, PIBINARYLOG_SIGNATURE_SIZE) < 0) return false;
|
if (file.read(read_sig, PIBINARYLOG_SIGNATURE_SIZE) < 0) return false;
|
||||||
@@ -458,7 +458,7 @@ bool PIBinaryLog::checkFileHeader() {
|
|||||||
uint32_t sz = 0;
|
uint32_t sz = 0;
|
||||||
file.read(&sz, 4);
|
file.read(&sz, 4);
|
||||||
if (sz > 0) {
|
if (sz > 0) {
|
||||||
user_header_readed = file.read(sz);
|
binfo.user_header = file.read(sz);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -505,33 +505,37 @@ PIBinaryLog::BinLogRecord PIBinaryLog::readRecord() {
|
|||||||
|
|
||||||
|
|
||||||
void PIBinaryLog::parseLog(PIFile * f, PIBinaryLog::BinLogInfo * info, PIVector<PIBinaryLog::BinLogIndex> * index) {
|
void PIBinaryLog::parseLog(PIFile * f, PIBinaryLog::BinLogInfo * info, PIVector<PIBinaryLog::BinLogIndex> * index) {
|
||||||
BinLogInfo * bi = info;
|
if (!info && !index) return;
|
||||||
bool ginfo = info != 0;
|
if (info) {
|
||||||
bool gindex = index != 0;
|
info->log_size = -1;
|
||||||
if (!ginfo && !gindex) return;
|
info->records_count = 0;
|
||||||
if (ginfo) {
|
info->records.clear();
|
||||||
bi->log_size = -1;
|
|
||||||
bi->records_count = 0;
|
|
||||||
bi->records.clear();
|
|
||||||
}
|
}
|
||||||
if (gindex) index->clear();
|
if (index) index->clear();
|
||||||
if (f == 0) return;
|
if (f == 0) return;
|
||||||
if (!f->canRead()) return;
|
if (!f->canRead()) return;
|
||||||
if (ginfo) {
|
if (info) {
|
||||||
bi->path = f->path();
|
info->path = f->path();
|
||||||
bi->log_size = f->size();
|
info->log_size = f->size();
|
||||||
}
|
}
|
||||||
uchar read_sig[PIBINARYLOG_SIGNATURE_SIZE];
|
uchar read_sig[PIBINARYLOG_SIGNATURE_SIZE];
|
||||||
for (uint i=0; i<PIBINARYLOG_SIGNATURE_SIZE; i++) read_sig[i] = 0;
|
for (uint i=0; i<PIBINARYLOG_SIGNATURE_SIZE; i++) read_sig[i] = 0;
|
||||||
bool ok = true;
|
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++)
|
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;
|
uchar read_version = 0;
|
||||||
if (f->read(&read_version, 1) < 0) {if (ginfo) bi->records_count = -3; ok = false;}
|
if (f->read(&read_version, 1) < 0) {if (info) info->records_count = -3; ok = false;}
|
||||||
if (read_version == 0) {if (ginfo) bi->records_count = -4; ok = false;}
|
if (read_version == 0) {if (info) info->records_count = -4; ok = false;}
|
||||||
if (read_version < PIBINARYLOG_VERSION) {if (ginfo) bi->records_count = -5; ok = false;}
|
if (read_version < PIBINARYLOG_VERSION_OLD) {if (info) info->records_count = -5; ok = false;}
|
||||||
if (read_version > PIBINARYLOG_VERSION) {if (ginfo) bi->records_count = -6; 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;
|
if (!ok) return;
|
||||||
PIByteArray ba;
|
PIByteArray ba;
|
||||||
BinLogRecord br;
|
BinLogRecord br;
|
||||||
@@ -545,26 +549,26 @@ void PIBinaryLog::parseLog(PIFile * f, PIBinaryLog::BinLogInfo * info, PIVector<
|
|||||||
ba >> br.id >> br.size >> br.timestamp;
|
ba >> br.id >> br.size >> br.timestamp;
|
||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
if (bi->log_size - f->pos() >= br.size)
|
if (info->log_size - f->pos() >= br.size)
|
||||||
f->seek(f->pos() + br.size);
|
f->seek(f->pos() + br.size);
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (br.id > 0) {
|
if (br.id > 0) {
|
||||||
if (gindex) {
|
if (info) {
|
||||||
BinLogIndex bl_ind;
|
BinLogIndex bl_ind;
|
||||||
bl_ind.id = br.id;
|
bl_ind.id = br.id;
|
||||||
bl_ind.pos = f->pos() - br.size - hdr_size;
|
bl_ind.pos = f->pos() - br.size - hdr_size;
|
||||||
bl_ind.timestamp = br.timestamp;
|
bl_ind.timestamp = br.timestamp;
|
||||||
index->append(bl_ind);
|
index->append(bl_ind);
|
||||||
}
|
}
|
||||||
if (ginfo) {
|
if (info) {
|
||||||
bi->records_count++;
|
info->records_count++;
|
||||||
if (first) {
|
if (first) {
|
||||||
bi->start_time = br.timestamp;
|
info->start_time = br.timestamp;
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
BinLogRecordInfo &bri(bi->records[br.id]);
|
BinLogRecordInfo &bri(info->records[br.id]);
|
||||||
bri.count++;
|
bri.count++;
|
||||||
if (bri.id == 0) {
|
if (bri.id == 0) {
|
||||||
bri.id = br.id;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ public:
|
|||||||
PISystemTime start_time;
|
PISystemTime start_time;
|
||||||
PISystemTime end_time;
|
PISystemTime end_time;
|
||||||
PIMap<int, BinLogRecordInfo> records;
|
PIMap<int, BinLogRecordInfo> records;
|
||||||
|
PIByteArray user_header;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! \brief Struct contains position, ID and timestamp of record in file
|
//! \brief Struct contains position, ID and timestamp of record in file
|
||||||
@@ -319,7 +320,7 @@ private:
|
|||||||
llong split_size, log_size;
|
llong split_size, log_size;
|
||||||
int write_count, split_count, default_id, current_index;
|
int write_count, split_count, default_id, current_index;
|
||||||
bool is_started, is_thread_ok, is_indexed, rapid_start, is_pause;
|
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
|
//! \relatesalso PICout \relatesalso PIBinaryLog::BinLogInfo \brief Output operator to PICout
|
||||||
|
|||||||
Reference in New Issue
Block a user