Skip to content

Commit 5511b41

Browse files
authored
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
1 parent 147cdff commit 5511b41

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Diff for: core/src/main/java/google/registry/dns/DnsUtils.java

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package google.registry.dns;
1616

1717
import static com.google.common.collect.ImmutableList.toImmutableList;
18+
import static google.registry.persistence.PersistenceModule.TransactionIsolationLevel.TRANSACTION_REPEATABLE_READ;
1819
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
1920

2021
import com.google.common.collect.ImmutableCollection;
@@ -98,7 +99,9 @@ public static void requestHostDnsRefresh(ImmutableCollection<String> hostNames)
9899
*/
99100
public static ImmutableList<DnsRefreshRequest> readAndUpdateRequestsWithLatestProcessTime(
100101
String tld, Duration cooldown, int batchSize) {
102+
// It is critical that below query use repeatable-read. See b/337894387.
101103
return tm().transact(
104+
TRANSACTION_REPEATABLE_READ,
102105
() -> {
103106
DateTime transactionTime = tm().getTransactionTime();
104107
ImmutableList<DnsRefreshRequest> requests =
@@ -131,7 +134,9 @@ public static ImmutableList<DnsRefreshRequest> readAndUpdateRequestsWithLatestPr
131134
* error because all we care about is that it no longer exists after the method runs.
132135
*/
133136
public static void deleteRequests(Collection<DnsRefreshRequest> requests) {
137+
// It is critical that below query use repeatable-read. See b/337894387.
134138
tm().transact(
139+
TRANSACTION_REPEATABLE_READ,
135140
() ->
136141
tm().delete(
137142
requests.stream()

0 commit comments

Comments
 (0)