Skip to content

Commit

Permalink
tx_gateway_frontend: expire all old txs instead of one at a time
Browse files Browse the repository at this point in the history
Expiring one old txn sesison per new tx helps to maintain the txn
sessions cache size at the capacity but it won't bring the cache
size down if it's already beyond max_transactions_per_coordinator
(it may happen when a user sets max_transactions_per_coordinator
for the first time).

Fixing it by bulk expiring.
  • Loading branch information
rystsov committed Sep 26, 2023
1 parent c8398d5 commit 6bdbd57
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/v/cluster/tx_gateway_frontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1147,20 +1147,25 @@ ss::future<cluster::init_tm_tx_reply> tx_gateway_frontend::limit_init_tm_tx(

// similar to double-checked locking pattern
// it protects concurrent access to oldest_tx
if (stm->tx_cache_size() > _max_transactions_per_coordinator()) {
while (stm->tx_cache_size() > _max_transactions_per_coordinator()) {
auto old_tx_opt = stm->oldest_tx();
if (!old_tx_opt) {
vlog(
txlog.warn,
"oldest_tx shouldn't return empty when tx cache is at "
"capacity");
"oldest_tx should return oldest tx when the tx cache size "
"({}) is beyond capacity ({})",
stm->tx_cache_size(),
_max_transactions_per_coordinator());
co_return init_tm_tx_reply{tx_errc::not_coordinator};
}

auto old_tx = old_tx_opt.value();
vlog(
txlog.info,
"tx cache is at capacity; expiring oldest tx with id:{}",
"tx cache size ({}) is beyond capacity ({}); expiring oldest tx "
"(tx.id={})",
stm->tx_cache_size(),
_max_transactions_per_coordinator(),
old_tx.id);
auto tx_units = co_await stm->lock_tx(old_tx.id, "init_tm_tx");

Expand Down Expand Up @@ -1188,7 +1193,7 @@ ss::future<cluster::init_tm_tx_reply> tx_gateway_frontend::limit_init_tm_tx(
}
tx_units.return_all();
}

vlog(txlog.info, "tx cache size is reduced");
init_units.return_all();
}

Expand Down

0 comments on commit 6bdbd57

Please sign in to comment.