Skip to content

Commit

Permalink
Import wiredtiger: 60aff05f989a45c8e0de7bf822f650f4a4b0dcc8 from bran…
Browse files Browse the repository at this point in the history
…ch mongodb-master

ref: 5aa312f432..60aff05f98
for: 8.0.0-rc0

WT-12504 Ensure mirrored operations in Workgen are done within the same transaction

GitOrigin-RevId: 464939f7261e7a5ed20ed66f4ac6ff8e4098d671
  • Loading branch information
ruby-oujo authored and MongoDB Bot committed Feb 27, 2024
1 parent 7d23e00 commit 19a5280
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
39 changes: 30 additions & 9 deletions src/third_party/wiredtiger/bench/workgen/workgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,14 @@ pareto_calculation(uint32_t randint, uint64_t recno_max, ParetoOptions &pareto)
return testutil_pareto((uint64_t)r, recno_max, pareto.param);
}

bool
ThreadRunner::op_has_mirror(tint_t tint) const
{
const std::shared_lock lock(*_icontext->_dyn_mutex);
return _icontext->_dyn_table_runtime.count(tint) > 0 &&
_icontext->_dyn_table_runtime.at(tint).has_mirror();
}

uint64_t
ThreadRunner::op_get_key_recno(Operation *op, uint64_t range, tint_t tint)
{
Expand Down Expand Up @@ -1855,6 +1863,9 @@ ThreadRunner::op_run(Operation *op)
_in_transaction = true;
}
if (op->is_table_op()) {
bool has_mirror = op_has_mirror(tint);
// Ensure explicit transactions are used for mirrored operations.
ASSERT(!has_mirror || _in_transaction);
switch (op->_optype) {
case Operation::OP_INSERT:
ret = cursor->insert(cursor);
Expand Down Expand Up @@ -1888,22 +1899,21 @@ ThreadRunner::op_run(Operation *op)
cursor->reset(cursor);
else {
/*
* We don't retry on a WT_ROLLBACK error when:
* - it is a mirrored operation as Workgen will create a new transaction and
* - the mirror table is the one that faced the WT_ROLLBACK error as the operation
* on the base table will be lost.
* We don't retry on a WT_ROLLBACK error when it is a mirrored operation as Workgen
* will create a new transaction.
*/
if (op->_random_table && _icontext->_dyn_table_runtime[tint].has_mirror() &&
!_icontext->_dyn_table_runtime[tint]._is_base) {
if (op->_random_table && has_mirror) {
VERBOSE(*this,
"The table "
<< table_uri
<< " faced a WT_ROLLBACK error, giving up on the mirrored operation");
} else
retry_op = true;
track->rollbacks++;
_in_transaction = false;
WT_ERR(_session->rollback_transaction(_session, nullptr));
if (_in_transaction) {
_in_transaction = false;
WT_ERR(_session->rollback_transaction(_session, nullptr));
}
}
} else {
// Never retry on an internal op.
Expand Down Expand Up @@ -1932,10 +1942,21 @@ ThreadRunner::op_run(Operation *op)

do {
// Wait for transactions to complete before stopping.
bool has_mirror;
for (int count = 0; (!_stop || _in_transaction) && count < op->_repeatgroup; count++) {
for (std::vector<Operation>::iterator i = op->_group->begin();
i != op->_group->end(); i++) {
WT_ERR(op_run_setup(&*i));
auto [table_uri, tint] = op_get_table(&*i);
has_mirror = op_has_mirror(tint);
/*
* If a mirrored operation has started and there is no active transaction, it
* means it has been interrupted, quit.
*/
if ((*i)._random_table && has_mirror && (i != op->_group->begin()) &&
!_in_transaction)
goto err;
else
WT_ERR(op_run_setup(&*i));
}
}
workgen_clock(&now);
Expand Down
1 change: 1 addition & 0 deletions src/third_party/wiredtiger/bench/workgen/workgen_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ struct ThreadRunner {
uint64_t op_get_key_recno(Operation *, uint64_t range, tint_t tint);
void op_get_static_counts(Operation *, Stats &, int);
std::tuple<std::string, tint_t> op_get_table(Operation *op) const;
bool op_has_mirror(tint_t tint) const;
bool op_has_table(Operation *op) const;
void op_kv_gen(Operation *op, const tint_t tint);
int op_run(Operation *);
Expand Down
2 changes: 1 addition & 1 deletion src/third_party/wiredtiger/import.data
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"vendor": "wiredtiger",
"github": "wiredtiger/wiredtiger.git",
"branch": "mongodb-master",
"commit": "5aa312f4320bdec3ccead6b3baa42ad16ab32ab4"
"commit": "60aff05f989a45c8e0de7bf822f650f4a4b0dcc8"
}

0 comments on commit 19a5280

Please sign in to comment.