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 25, 2023
1 parent dca6bee commit 7a1eb63
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/v/cluster/tx_gateway_frontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ 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 tx_opt = stm->oldest_tx();
if (!tx_opt) {
vlog(
Expand All @@ -1160,7 +1160,10 @@ ss::future<cluster::init_tm_tx_reply> tx_gateway_frontend::limit_init_tm_tx(
auto tx = 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 "
"with id:{}",
stm->tx_cache_size(),
_max_transactions_per_coordinator(),
tx.id);
auto tx_units = co_await stm->lock_tx(tx.id, "init_tm_tx");

Expand Down Expand Up @@ -1190,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 7a1eb63

Please sign in to comment.