Skip to content

Commit 6ccaf7e

Browse files
committed
ensure that garbage::min_begin_epoch is non-decreasing
1 parent 9c0282b commit 6ccaf7e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/concurrency_control/garbage.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,23 @@ void work_manager() {
108108
LOG_FIRST_N(ERROR, 1) << log_location_prefix
109109
<< log_location_prefix << "epoch error";
110110
}
111-
set_min_begin_epoch(min_begin_epoch);
112111
} else {
113112
/**
114113
* above loop didn't find living tx. at least, befor_loop epoch is
115114
* minimum begin epoch.
116115
*/
117-
set_min_begin_epoch(before_loop);
116+
min_begin_epoch = before_loop;
117+
}
118+
// NB. The calculation method used in the code above has a potential concurrency flaws,
119+
// as it can miss recently begun transactions,
120+
// which can result in a smaller value than the previously calculated value of min_begin_epoch.
121+
// But even if the calculated value of min_begin_epoch is small,
122+
// OCC reads/writes the latest version, and never reads/writes that version.
123+
// Therefore, instead of correcting the calculation method, simply discards the smaller value.
124+
if (auto old = get_min_begin_epoch(); min_begin_epoch > old) {
125+
set_min_begin_epoch(min_begin_epoch);
126+
} else if (min_begin_epoch < old) {
127+
VLOG(log_debug) << log_location_prefix << "min_begin_epoch back from " << old << " to " << min_begin_epoch << " (ignored)";
118128
}
119129
// computing about ltx
120130
if (valid_epoch != 0) {

0 commit comments

Comments
 (0)