You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-30 19:23:07 +03:00
Improve batch inserts.
1) Instead of making dbrm calls to writeVBEntry() per block, we make these calls per batch. This can have non-trivial reductions in the overhead of these calls if the batch size is large. 2) In dmlproc, do not deserialize the whole insertpackage, which consists of the complete record set per column, which would be wasteful as we only need some metadata fields from insertpackage here. This is only done for batch inserts at the moment, this should also be applied to single inserts.
This commit is contained in:
@ -507,6 +507,7 @@ const uint8_t RELEASE_LBID_RANGES = 91;
|
||||
/* More main BRM functions 100-110 */
|
||||
const uint8_t BULK_UPDATE_DBROOT = 100;
|
||||
const uint8_t GET_SYSTEM_CATALOG = 101;
|
||||
const uint8_t BULK_WRITE_VB_ENTRY = 102;
|
||||
|
||||
|
||||
/* Error codes returned by the DBRM functions. */
|
||||
|
@ -2226,6 +2226,42 @@ int DBRM::writeVBEntry(VER_t transID, LBID_t lbid, OID_t vbOID,
|
||||
return err;
|
||||
}
|
||||
|
||||
int DBRM::bulkWriteVBEntry(VER_t transID,
|
||||
const std::vector<BRM::LBID_t>& lbids,
|
||||
OID_t vbOID,
|
||||
const std::vector<uint32_t>& vbFBOs) DBRM_THROW
|
||||
{
|
||||
|
||||
#ifdef BRM_INFO
|
||||
|
||||
if (fDebug)
|
||||
{
|
||||
TRACER_WRITELATER("bulkWriteVBEntry");
|
||||
TRACER_WRITE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
ByteStream command, response;
|
||||
uint8_t err;
|
||||
|
||||
command << BULK_WRITE_VB_ENTRY << (uint32_t) transID;
|
||||
serializeInlineVector(command, lbids);
|
||||
command << (uint32_t) vbOID;
|
||||
serializeInlineVector(command, vbFBOs);
|
||||
err = send_recv(command, response);
|
||||
|
||||
if (err != ERR_OK)
|
||||
return err;
|
||||
|
||||
if (response.length() != 1)
|
||||
return ERR_NETWORK;
|
||||
|
||||
response >> err;
|
||||
CHECK_EMPTY(response);
|
||||
return err;
|
||||
}
|
||||
|
||||
struct _entry
|
||||
{
|
||||
_entry(LBID_t l) : lbid(l) { };
|
||||
|
@ -608,6 +608,20 @@ public:
|
||||
EXPORT int writeVBEntry(VER_t transID, LBID_t lbid, OID_t vbOID,
|
||||
uint32_t vbFBO) DBRM_THROW;
|
||||
|
||||
/** @brief Bulk registers a version buffer entry.
|
||||
*
|
||||
* Similar to writeVBEntry, but registers the version buffer
|
||||
* entries in bulk for a list of lbids and vbFBOs, for a given
|
||||
* transID and vbOID.
|
||||
* @note The version buffer locations must hold the 'copy' lock
|
||||
* first.
|
||||
* @return 0 on success, non-0 on error (see brmtypes.h)
|
||||
*/
|
||||
EXPORT int bulkWriteVBEntry(VER_t transID,
|
||||
const std::vector<BRM::LBID_t>& lbids,
|
||||
OID_t vbOID,
|
||||
const std::vector<uint32_t>& vbFBOs) DBRM_THROW;
|
||||
|
||||
/** @brief Retrieves a list of uncommitted LBIDs.
|
||||
*
|
||||
* Retrieves a list of uncommitted LBIDs for the given transaction ID.
|
||||
|
@ -375,6 +375,10 @@ void SlaveComm::processCommand(ByteStream& msg)
|
||||
do_writeVBEntry(msg);
|
||||
break;
|
||||
|
||||
case BULK_WRITE_VB_ENTRY:
|
||||
do_bulkWriteVBEntry(msg);
|
||||
break;
|
||||
|
||||
case BEGIN_VB_COPY:
|
||||
do_beginVBCopy(msg);
|
||||
break;
|
||||
@ -1758,6 +1762,49 @@ void SlaveComm::do_writeVBEntry(ByteStream& msg)
|
||||
doSaveDelta = true;
|
||||
}
|
||||
|
||||
void SlaveComm::do_bulkWriteVBEntry(ByteStream& msg)
|
||||
{
|
||||
VER_t transID;
|
||||
std::vector<BRM::LBID_t> lbids;
|
||||
OID_t vbOID;
|
||||
std::vector<uint32_t> vbFBOs;
|
||||
uint32_t tmp;
|
||||
int err;
|
||||
ByteStream reply;
|
||||
|
||||
#ifdef BRM_VERBOSE
|
||||
cerr << "WorkerComm: do_bulkWriteVBEntry()" << endl;
|
||||
#endif
|
||||
|
||||
msg >> tmp;
|
||||
transID = tmp;
|
||||
deserializeInlineVector(msg, lbids);
|
||||
msg >> tmp;
|
||||
vbOID = tmp;
|
||||
deserializeInlineVector(msg, vbFBOs);
|
||||
|
||||
if (printOnly)
|
||||
{
|
||||
cout << "bulkWriteVBEntry: transID=" << transID << endl;
|
||||
|
||||
for (size_t i = 0; i < lbids.size(); i++)
|
||||
cout << "bulkWriteVBEntry arg " << i + 1 << ": lbid=" << lbids[i] << " vbOID=" <<
|
||||
vbOID << " vbFBO=" << vbFBOs[i] << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
err = slave->bulkWriteVBEntry(transID, lbids, vbOID, vbFBOs);
|
||||
reply << (uint8_t) err;
|
||||
#ifdef BRM_VERBOSE
|
||||
cerr << "WorkerComm: do_bulkWriteVBEntry() err code is " << err << endl;
|
||||
#endif
|
||||
|
||||
if (!standalone)
|
||||
master.write(reply);
|
||||
|
||||
doSaveDelta = true;
|
||||
}
|
||||
|
||||
void SlaveComm::do_beginVBCopy(ByteStream& msg)
|
||||
{
|
||||
VER_t transID;
|
||||
|
@ -91,6 +91,7 @@ private:
|
||||
void do_bulkSetHWM(messageqcpp::ByteStream& msg);
|
||||
void do_bulkSetHWMAndCP(messageqcpp::ByteStream& msg);
|
||||
void do_writeVBEntry(messageqcpp::ByteStream& msg);
|
||||
void do_bulkWriteVBEntry(messageqcpp::ByteStream& msg);
|
||||
void do_beginVBCopy(messageqcpp::ByteStream& msg);
|
||||
void do_endVBCopy(messageqcpp::ByteStream& msg);
|
||||
void do_vbRollback1(messageqcpp::ByteStream& msg);
|
||||
|
@ -523,6 +523,70 @@ int SlaveDBRMNode::writeVBEntry(VER_t transID, LBID_t lbid, OID_t vbOID,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SlaveDBRMNode::bulkWriteVBEntry(VER_t transID,
|
||||
const std::vector<BRM::LBID_t>& lbids,
|
||||
OID_t vbOID,
|
||||
const std::vector<uint32_t>& vbFBOs) throw()
|
||||
{
|
||||
VER_t oldVerID;
|
||||
|
||||
/*
|
||||
LBIDRange r;
|
||||
r.start = lbid;
|
||||
r.size = 1;
|
||||
if (!copylocks.isLocked(r))
|
||||
cout << "Copylock error: lbid " << lbid << " isn't locked\n";
|
||||
*/
|
||||
|
||||
try
|
||||
{
|
||||
vbbm.lock(VBBM::WRITE);
|
||||
locked[0] = true;
|
||||
vss.lock(VSS::WRITE);
|
||||
locked[1] = true;
|
||||
|
||||
for (size_t i = 0; i < lbids.size(); i++)
|
||||
{
|
||||
// figure out the current version of the block
|
||||
// NOTE! This will currently error out to preserve the assumption that
|
||||
// larger version numbers imply more recent changes. If we ever change that
|
||||
// assumption, we'll need to revise the vbRollback() fcns as well.
|
||||
oldVerID = vss.getCurrentVersion(lbids[i], NULL);
|
||||
|
||||
if (oldVerID == transID)
|
||||
continue;
|
||||
else if (oldVerID > transID)
|
||||
{
|
||||
ostringstream str;
|
||||
|
||||
str << "WorkerDBRMNode::bulkWriteVBEntry(): Overlapping transactions detected. "
|
||||
"Transaction " << transID << " cannot overwrite blocks written by "
|
||||
"transaction " << oldVerID;
|
||||
log(str.str());
|
||||
return ERR_OLDTXN_OVERWRITING_NEWTXN;
|
||||
}
|
||||
|
||||
vbbm.insert(lbids[i], oldVerID, vbOID, vbFBOs[i]);
|
||||
|
||||
if (oldVerID > 0)
|
||||
vss.setVBFlag(lbids[i], oldVerID, true);
|
||||
else
|
||||
vss.insert(lbids[i], oldVerID, true, false);
|
||||
|
||||
// XXXPAT: There's a problem if we use transID as the new version here.
|
||||
// Need to use at least oldVerID + 1. OldverID can be > TransID
|
||||
vss.insert(lbids[i], transID, false, true);
|
||||
}
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
cerr << e.what() << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SlaveDBRMNode::beginVBCopy(VER_t transID, uint16_t vbOID,
|
||||
const LBIDRange_v& ranges, VBRange_v& freeList, bool flushPMCache) throw()
|
||||
{
|
||||
|
@ -364,6 +364,20 @@ public:
|
||||
EXPORT int writeVBEntry(VER_t transID, LBID_t lbid, OID_t vbOID,
|
||||
uint32_t vbFBO) throw();
|
||||
|
||||
/** @brief Bulk registers a version buffer entry.
|
||||
*
|
||||
* Similar to writeVBEntry, but registers the version buffer
|
||||
* entries in bulk for a list of lbids and vbFBOs, for a given
|
||||
* transID and vbOID.
|
||||
* @note The version buffer locations must hold the 'copy' lock
|
||||
* first.
|
||||
* @return 0 on success, -1 on error
|
||||
*/
|
||||
EXPORT int bulkWriteVBEntry(VER_t transID,
|
||||
const std::vector<BRM::LBID_t>& lbids,
|
||||
OID_t vbOID,
|
||||
const std::vector<uint32_t>& vbFBOs) throw();
|
||||
|
||||
/** @brief Atomically prepare to copy data to the version buffer
|
||||
*
|
||||
* Atomically sets the copy flag on the specified LBID ranges
|
||||
|
Reference in New Issue
Block a user