mirror of https://gitee.com/bigwinds/arangodb
agency write handles large++ collections of transactions at once
This commit is contained in:
parent
8dc1e4a4f9
commit
cc821c6216
|
@ -420,8 +420,7 @@ void Agent::sendAppendEntriesRPC() {
|
||||||
commitIndex = _commitIndex;
|
commitIndex = _commitIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<log_t> unconfirmed =
|
std::vector<log_t> unconfirmed = _state.get(lastConfirmed);
|
||||||
_state.get(lastConfirmed, lastConfirmed + _config.maxAppendSize());
|
|
||||||
|
|
||||||
// Note that dispite compaction this vector can never be empty, since
|
// Note that dispite compaction this vector can never be empty, since
|
||||||
// any compaction keeps at least one active log entry!
|
// any compaction keeps at least one active log entry!
|
||||||
|
@ -923,8 +922,24 @@ write_ret_t Agent::write(query_t const& query, bool discardStartup) {
|
||||||
|
|
||||||
addTrxsOngoing(query->slice()); // remember that these are ongoing
|
addTrxsOngoing(query->slice()); // remember that these are ongoing
|
||||||
|
|
||||||
|
auto slice = query->slice();
|
||||||
|
size_t ntrans = slice.length();
|
||||||
|
size_t npacks = ntrans/_config.maxAppendSize();
|
||||||
|
if (ntrans%_config.maxAppendSize()!=0) {
|
||||||
|
npacks++;
|
||||||
|
}
|
||||||
|
|
||||||
// Apply to spearhead and get indices for log entries
|
// Apply to spearhead and get indices for log entries
|
||||||
{
|
// Avoid keeping lock indefinitely
|
||||||
|
for (size_t i = 0, l = 0; i < npacks; ++i) {
|
||||||
|
query_t chunk = std::make_shared<Builder>();
|
||||||
|
{
|
||||||
|
VPackArrayBuilder b(chunk.get());
|
||||||
|
for (size_t j = 0; j < _config.maxAppendSize() && l < ntrans; ++j, ++l) {
|
||||||
|
chunk->add(slice.at(l));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MUTEX_LOCKER(ioLocker, _ioLock);
|
MUTEX_LOCKER(ioLocker, _ioLock);
|
||||||
|
|
||||||
// Only leader else redirect
|
// Only leader else redirect
|
||||||
|
@ -933,8 +948,10 @@ write_ret_t Agent::write(query_t const& query, bool discardStartup) {
|
||||||
return write_ret_t(false, NO_LEADER);
|
return write_ret_t(false, NO_LEADER);
|
||||||
}
|
}
|
||||||
|
|
||||||
applied = _spearhead.applyTransactions(query);
|
applied = _spearhead.applyTransactions(chunk);
|
||||||
indices = _state.log(query, applied, term());
|
auto tmp = _state.log(chunk, applied, term());
|
||||||
|
indices.insert(indices.end(), tmp.begin(), tmp.end());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeTrxsOngoing(query->slice());
|
removeTrxsOngoing(query->slice());
|
||||||
|
|
|
@ -134,7 +134,7 @@ function agencyTestSuite () {
|
||||||
let trx = [{}];
|
let trx = [{}];
|
||||||
trx[0][key] = "value" + i;
|
trx[0][key] = "value" + i;
|
||||||
trxs.push(trx);
|
trxs.push(trx);
|
||||||
if (trxs.length >= 200 || i === start + count - 1) {
|
if (trxs.length >= 200000 || i === start + count - 1) {
|
||||||
res = accessAgency("write", trxs);
|
res = accessAgency("write", trxs);
|
||||||
assertEqual(200, res.statusCode);
|
assertEqual(200, res.statusCode);
|
||||||
trxs = [];
|
trxs = [];
|
||||||
|
|
Loading…
Reference in New Issue