1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00

feat(IO): MCOL-5555 Reduce number of direct writes to the file storing BRM journal and tablelocks (#2974)

This commit is contained in:
Denis Khalikov
2023-09-30 19:00:39 +03:00
committed by GitHub
parent 86c1c5d537
commit fce971dcd2
4 changed files with 71 additions and 14 deletions

View File

@ -444,7 +444,40 @@ void TableLockInfo::deserialize(istream& i)
dbrootList.resize(dbrootListSize);
for (uint32_t j = 0; j < dbrootListSize; j++)
i.read((char*)&dbrootList[j], 4);
i.read((char*)&dbrootList[j], sizeof(uint32_t));
}
uint32_t TableLockInfo::getInternalSize() const
{
const uint32_t nameLen = ownerName.length();
const uint32_t dbrootListSize = dbrootList.size();
return (32 + sizeof(time_t) + nameLen + (dbrootListSize * sizeof(uint32_t)));
}
void TableLockInfo::serializeElement(char* buffer, const char* src, const uint32_t size, uint32_t& offset)
{
std::memcpy(&buffer[offset], src, size);
offset += size;
}
void TableLockInfo::serialize(char* buffer, uint32_t& offset)
{
const uint32_t nameLen = ownerName.length();
const uint32_t dbrootListSize = dbrootList.size();
serializeElement(buffer, (char*)&id, 8, offset);
serializeElement(buffer, (char*)&tableOID, 4, offset);
serializeElement(buffer, (char*)&ownerPID, 4, offset);
serializeElement(buffer, (char*)&state, 4, offset);
serializeElement(buffer, (char*)&ownerSessionID, 4, offset);
serializeElement(buffer, (char*)&ownerTxnID, 4, offset);
serializeElement(buffer, (char*)&creationTime, sizeof(time_t), offset);
serializeElement(buffer, (char*)&nameLen, 2, offset);
serializeElement(buffer, (char*)ownerName.c_str(), nameLen, offset);
serializeElement(buffer, (char*)&dbrootListSize, 2, offset);
for (uint32_t j = 0; j < dbrootListSize; j++)
serializeElement(buffer, (char*)&dbrootList[j], sizeof(uint32_t), offset);
}
void TableLockInfo::serialize(IDBDataFile* o) const

View File

@ -254,7 +254,12 @@ struct TableLockInfo : public messageqcpp::Serializeable
EXPORT void deserialize(messageqcpp::ByteStream& bs);
EXPORT void serialize(idbdatafile::IDBDataFile*) const;
EXPORT void deserialize(idbdatafile::IDBDataFile*);
EXPORT void serialize(char* buffer, uint32_t& offset);
EXPORT uint32_t getInternalSize() const;
bool operator<(const TableLockInfo&) const;
private:
void serializeElement(char* buffer, const char* src, const uint32_t size, uint32_t& offset);
};
/// A Serializeable version of InlineLBIDRange

View File

@ -191,7 +191,6 @@ SlaveComm::SlaveComm()
slave = std::make_unique<SlaveDBRMNode>();
}
void SlaveComm::stop()
{
die = true;
@ -1928,7 +1927,8 @@ void SlaveComm::do_confirm()
{
if (!currentSaveFile)
{
currentSaveFile.reset(IDBDataFile::open(IDBPolicy::getType(tmp.c_str(), IDBPolicy::WRITEENG), tmp.c_str(), "wb", 0));
currentSaveFile.reset(
IDBDataFile::open(IDBPolicy::getType(tmp.c_str(), IDBPolicy::WRITEENG), tmp.c_str(), "wb", 0));
}
if (currentSaveFile == NULL)
@ -1951,7 +1951,8 @@ void SlaveComm::do_confirm()
if (err < (int)relative.length())
{
ostringstream os;
os << "WorkerComm: currentfile write() returned " << err << " file pointer is " << currentSaveFile.get();
os << "WorkerComm: currentfile write() returned " << err << " file pointer is "
<< currentSaveFile.get();
if (err < 0)
os << " errno: " << strerror(errno);
@ -1966,7 +1967,7 @@ void SlaveComm::do_confirm()
;
journalh.reset(IDBDataFile::open(IDBPolicy::getType(journalName.c_str(), IDBPolicy::WRITEENG),
journalName.c_str(), "w+b", 0));
journalName.c_str(), "w+b", 0));
if (!journalh)
throw runtime_error("Could not open the BRM journal for writing!");
@ -2182,11 +2183,16 @@ void SlaveComm::saveDelta()
{
try
{
uint32_t len = delta.length();
const uint32_t deltaLen = delta.length();
const uint32_t bufferSize = sizeof(deltaLen) + deltaLen;
std::unique_ptr<char[]> buffer(new char[bufferSize]);
uint32_t offset = 0;
std::memcpy(&buffer[offset], (char*)&deltaLen, sizeof(deltaLen));
offset += sizeof(deltaLen);
std::memcpy(&buffer[offset], (char*)delta.buf(), deltaLen);
journalh->seek(0, SEEK_END);
journalh->write((const char*)&len, sizeof(len));
journalh->write((const char*)delta.buf(), delta.length());
journalh->write((const char*)buffer.get(), bufferSize);
journalh->flush();
journalCount++;
}
@ -2326,4 +2332,3 @@ void SlaveComm::do_dmlReleaseLBIDRanges(ByteStream& msg)
}
} // namespace BRM

View File

@ -70,14 +70,28 @@ void TableLockServer::save()
if (!out)
throw runtime_error("TableLockServer::save(): could not open save file");
out->write((char*)&count, 4);
uint32_t bufferSize = 4;
for (const auto& lock : locks)
bufferSize += lock.second.getInternalSize();
std::unique_ptr<char[]> buffer(new char[bufferSize]);
uint32_t offset = 0;
std::memcpy(&buffer[offset], (char*)&count, 4);
offset += 4;
for (it = locks.begin(); it != locks.end(); ++it)
{
if (!out)
throw runtime_error("TableLockServer::save(): could not write save file");
it->second.serialize(buffer.get(), offset);
it->second.serialize(out.get());
uint32_t writtenSize = 0;
uint32_t sizeToWrite = bufferSize;
while (writtenSize != bufferSize)
{
uint32_t ret = out->write(&buffer[writtenSize], sizeToWrite);
if (!ret)
throw runtime_error("TableLockServer::save(): could not write to the file");
writtenSize += ret;
sizeToWrite -= ret;
}
}