Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions core/src/main/java/google/registry/config/RegistryConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,18 @@ public static String getHibernateJdbcFetchSize() {
return CONFIG_SETTINGS.get().hibernate.jdbcFetchSize;
}

/**
* Returns the Hibernate default batch fetch size ({@code hibernate.default_batch_fetch_size}).
*
* <p>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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public static class Hibernate {
public String hikariIdleTimeout;
public int jdbcBatchSize;
public String jdbcFetchSize;
public int defaultBatchFetchSize;
}

/** Configuration for Cloud SQL. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -113,6 +115,7 @@ public static ImmutableMap<String, String> provideDefaultDatabaseConfigs() {
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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -77,6 +81,14 @@ void connectionIsolation() {
.isEqualTo(TransactionIsolationLevel.TRANSACTION_SERIALIZABLE.name());
}

@Test
void batchAndFetchConfigs() {
ImmutableMap<String, String> configs = PersistenceModule.provideDefaultDatabaseConfigs();
assertThat(configs.get(JDBC_BATCH_SIZE)).isEqualTo("50");
assertThat(configs.get(JDBC_FETCH_SIZE)).isEqualTo("40");
assertThat(configs.get(DEFAULT_BATCH_FETCH_SIZE)).isEqualTo("50");
}

@Singleton
@Component(
modules = {
Expand Down
Loading