1
0
mirror of https://github.com/google/nomulus synced 2026-01-03 11:45:39 +00:00

Avoid contention over the RefreshDnsRequest table (#2428)

* Avoid contention over the RefreshDnsRequest table

This table can be small at times, when PSQL may use table scan in
queries by keys. At the SERIALIZABLE isolation level, updates to
unrelated rows may conflict due to this `optimization`.

Lower the isolation level to repeatable read.

* Code review
This commit is contained in:
Weimin Yu
2024-05-03 16:31:54 -04:00
committed by GitHub
parent 147cdff555
commit 5511b41f93

View File

@@ -15,6 +15,7 @@
package google.registry.dns;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.persistence.PersistenceModule.TransactionIsolationLevel.TRANSACTION_REPEATABLE_READ;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import com.google.common.collect.ImmutableCollection;
@@ -98,7 +99,9 @@ public final class DnsUtils {
*/
public static ImmutableList<DnsRefreshRequest> readAndUpdateRequestsWithLatestProcessTime(
String tld, Duration cooldown, int batchSize) {
// It is critical that below query use repeatable-read. See b/337894387.
return tm().transact(
TRANSACTION_REPEATABLE_READ,
() -> {
DateTime transactionTime = tm().getTransactionTime();
ImmutableList<DnsRefreshRequest> requests =
@@ -131,7 +134,9 @@ public final class DnsUtils {
* error because all we care about is that it no longer exists after the method runs.
*/
public static void deleteRequests(Collection<DnsRefreshRequest> requests) {
// It is critical that below query use repeatable-read. See b/337894387.
tm().transact(
TRANSACTION_REPEATABLE_READ,
() ->
tm().delete(
requests.stream()