Skip to content

Commit

Permalink
Configurable long timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Keller committed Sep 17, 2024
1 parent 97d3dec commit 4ac8999
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,13 @@ public interface Config {
*/
int getMetadataQueryTimeout();

/**
* Long metadata query timeout in seconds, for longer running queries.
*
* @return Long metadata query timeout in seconds
*/
int getLongMetadataQueryTimeout();

/**
* Whether to check the existence of the iceberg metadata location before updating the table.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,11 @@ public int getMetadataQueryTimeout() {
return this.metacatProperties.getUsermetadata().getQueryTimeoutInSeconds();
}

@Override
public int getLongMetadataQueryTimeout() {
return this.metacatProperties.getUsermetadata().getLongQueryTimeoutInSeconds();
}

@Override
public boolean isIcebergPreviousMetadataLocationCheckEnabled() {
return this.metacatProperties.getHive().getIceberg().isIcebergPreviousMetadataLocationCheckEnabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class UserMetadata {
@NonNull
private Config config = new Config();
private int queryTimeoutInSeconds = 60;
private int longQueryTimeoutInSeconds = 120;

/**
* config related properties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public class MySqlTagService implements TagService {
private final LookupService lookupService;
private final MetacatJson metacatJson;
private final UserMetadataService userMetadataService;
private JdbcTemplate jdbcTemplate;
private final JdbcTemplate jdbcTemplate;
private final JdbcTemplate jdbcTemplateLongTimeout;

/**
* Constructor.
Expand All @@ -113,12 +114,14 @@ public class MySqlTagService implements TagService {
public MySqlTagService(
final Config config,
final JdbcTemplate jdbcTemplate,
final JdbcTemplate jdbcTemplateLongTimeout,
final LookupService lookupService,
final MetacatJson metacatJson,
final UserMetadataService userMetadataService
) {
this.config = Preconditions.checkNotNull(config, "config is required");
this.jdbcTemplate = jdbcTemplate;
this.jdbcTemplateLongTimeout = jdbcTemplateLongTimeout;
this.lookupService = Preconditions.checkNotNull(lookupService, "lookupService is required");
this.metacatJson = Preconditions.checkNotNull(metacatJson, "metacatJson is required");
this.userMetadataService = Preconditions.checkNotNull(userMetadataService, "userMetadataService is required");
Expand Down Expand Up @@ -320,7 +323,7 @@ public Set<String> getTags() {
* @return list of qualified names of the items
*/
@Override
@Transactional(readOnly = true, timeout = 120)
@Transactional(readOnly = true)
public List<QualifiedName> list(
@Nullable final Set<String> includeTags,
@Nullable final Set<String> excludeTags,
Expand Down Expand Up @@ -477,7 +480,7 @@ private List<String> queryTaggedItems(final String name,
new SqlParameterValue(Types.INTEGER, type == null ? 1 : 0),
new SqlParameterValue(Types.VARCHAR, type == null ? ".*" : type.getRegexValue())
).collect(Collectors.toList()));
return jdbcTemplate.query(query,
return jdbcTemplateLongTimeout.query(query,
sqlParams.toArray(),
(rs, rowNum) -> rs.getString("name"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

Expand Down Expand Up @@ -101,12 +102,13 @@ public LookupService lookupService(
@Bean
public TagService tagService(
@Qualifier("metadataJdbcTemplate") final JdbcTemplate jdbcTemplate,
@Qualifier("metadataJdbcTemplateLongTimeout") final JdbcTemplate jdbcTemplateLongTimeout,
final Config config,
final MetacatJson metacatJson,
final LookupService lookupService,
final UserMetadataService userMetadataService
) {
return new MySqlTagService(config, jdbcTemplate, lookupService, metacatJson, userMetadataService);
return new MySqlTagService(config, jdbcTemplate, jdbcTemplateLongTimeout, lookupService, metacatJson, userMetadataService);
}

/**
Expand Down Expand Up @@ -159,6 +161,7 @@ public DataSourceTransactionManager metadataTxManager(
* @return metadata JDBC template
*/
@Bean
@Primary
public JdbcTemplate metadataJdbcTemplate(
@Qualifier("metadataDataSource") final DataSource mySqlDataSource,
final Config config) {
Expand All @@ -167,4 +170,19 @@ public JdbcTemplate metadataJdbcTemplate(
return result;
}

/**
* mySql metadata JDBC template for longer running queries.
*
* @param mySqlDataSource metadata data source
* @param config System config to use
* @return metadata JDBC template
*/
@Bean
public JdbcTemplate metadataJdbcTemplateLongTimeout(
@Qualifier("metadataDataSource") final DataSource mySqlDataSource,
final Config config) {
final JdbcTemplate result = new JdbcTemplate(mySqlDataSource);
result.setQueryTimeout(config.getLongMetadataQueryTimeout());
return result;
}
}

0 comments on commit 4ac8999

Please sign in to comment.