diff --git a/core/src/main/java/google/registry/config/RegistryConfig.java b/core/src/main/java/google/registry/config/RegistryConfig.java index 76823c0d9..1263a4aa3 100644 --- a/core/src/main/java/google/registry/config/RegistryConfig.java +++ b/core/src/main/java/google/registry/config/RegistryConfig.java @@ -1825,6 +1825,18 @@ public final class RegistryConfig { return CONFIG_SETTINGS.get().hibernate.jdbcFetchSize; } + /** + * Returns the Hibernate default batch fetch size ({@code hibernate.default_batch_fetch_size}). + * + *
This controls the maximum number of uninitialized child entities or collection proxies that
+ * Hibernate will batch together into a single {@code SELECT ... WHERE id IN (...)} query when
+ * loading / initializing child entities in the persistence context. This is not the standard
+ * "batch size" used when loading root entities in batches.
+ */
+ public static int getHibernateDefaultBatchFetchSize() {
+ return CONFIG_SETTINGS.get().hibernate.defaultBatchFetchSize;
+ }
+
/** Returns the roid suffix to be used for the roids of all hosts. */
public static String getHostRoidSuffix() {
return CONFIG_SETTINGS.get().registryPolicy.contactAndHostRoidSuffix;
diff --git a/core/src/main/java/google/registry/config/RegistryConfigSettings.java b/core/src/main/java/google/registry/config/RegistryConfigSettings.java
index 1cdf25400..bb71e9c85 100644
--- a/core/src/main/java/google/registry/config/RegistryConfigSettings.java
+++ b/core/src/main/java/google/registry/config/RegistryConfigSettings.java
@@ -130,6 +130,7 @@ public class RegistryConfigSettings {
public String hikariIdleTimeout;
public int jdbcBatchSize;
public String jdbcFetchSize;
+ public int defaultBatchFetchSize;
}
/** Configuration for Cloud SQL. */
diff --git a/core/src/main/java/google/registry/config/files/default-config.yaml b/core/src/main/java/google/registry/config/files/default-config.yaml
index 9370aa6b3..4b6fa7bda 100644
--- a/core/src/main/java/google/registry/config/files/default-config.yaml
+++ b/core/src/main/java/google/registry/config/files/default-config.yaml
@@ -247,6 +247,12 @@ hibernate:
# database cursor. Here we set a small default geared toward Nomulus server
# transactions. Large queries can override the defaults on a per-query basis.
jdbcFetchSize: 40
+ # The default batch fetch size is the maximum number of uninitialized child
+ # entities or collection proxies that Hibernate will load / initialize in a
+ # single batched SELECT query using an IN clause. This is not the same as the
+ # JDBC batch size, which controls batched insertions / updates of root
+ # entities.
+ defaultBatchFetchSize: 50
cloudSql:
# jdbc url for the Cloud SQL database.
diff --git a/core/src/main/java/google/registry/persistence/PersistenceModule.java b/core/src/main/java/google/registry/persistence/PersistenceModule.java
index 9c5844fe1..bad958313 100644
--- a/core/src/main/java/google/registry/persistence/PersistenceModule.java
+++ b/core/src/main/java/google/registry/persistence/PersistenceModule.java
@@ -17,6 +17,7 @@ package google.registry.persistence;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.config.RegistryConfig.getHibernateConnectionIsolation;
+import static google.registry.config.RegistryConfig.getHibernateDefaultBatchFetchSize;
import static google.registry.config.RegistryConfig.getHibernateHikariConnectionTimeout;
import static google.registry.config.RegistryConfig.getHibernateHikariIdleTimeout;
import static google.registry.config.RegistryConfig.getHibernateHikariMaximumPoolSize;
@@ -84,6 +85,7 @@ public abstract class PersistenceModule {
public static final String JDBC_BATCH_SIZE = "hibernate.jdbc.batch_size";
public static final String JDBC_FETCH_SIZE = "hibernate.jdbc.fetch_size";
+ public static final String DEFAULT_BATCH_FETCH_SIZE = "hibernate.default_batch_fetch_size";
@VisibleForTesting
@Provides
@@ -113,6 +115,7 @@ public abstract class PersistenceModule {
properties.put(Environment.DIALECT, NomulusPostgreSQLDialect.class.getName());
properties.put(JDBC_BATCH_SIZE, Integer.toString(getHibernateJdbcBatchSize()));
properties.put(JDBC_FETCH_SIZE, getHibernateJdbcFetchSize());
+ properties.put(DEFAULT_BATCH_FETCH_SIZE, Integer.toString(getHibernateDefaultBatchFetchSize()));
return properties.build();
}
diff --git a/core/src/test/java/google/registry/persistence/PersistenceModuleTest.java b/core/src/test/java/google/registry/persistence/PersistenceModuleTest.java
index 3b7d7984c..7fa385582 100644
--- a/core/src/test/java/google/registry/persistence/PersistenceModuleTest.java
+++ b/core/src/test/java/google/registry/persistence/PersistenceModuleTest.java
@@ -15,7 +15,11 @@
package google.registry.persistence;
import static com.google.common.truth.Truth.assertThat;
+import static google.registry.persistence.PersistenceModule.DEFAULT_BATCH_FETCH_SIZE;
+import static google.registry.persistence.PersistenceModule.JDBC_BATCH_SIZE;
+import static google.registry.persistence.PersistenceModule.JDBC_FETCH_SIZE;
+import com.google.common.collect.ImmutableMap;
import dagger.Component;
import google.registry.config.CredentialModule;
import google.registry.config.RegistryConfig.Config;
@@ -77,6 +81,14 @@ class PersistenceModuleTest {
.isEqualTo(TransactionIsolationLevel.TRANSACTION_SERIALIZABLE.name());
}
+ @Test
+ void batchAndFetchConfigs() {
+ ImmutableMap