Skip to content

Commit

Permalink
Configurable long timeout for metadata queries (#609)
Browse files Browse the repository at this point in the history
Co-authored-by: Bryan Keller <[email protected]>
  • Loading branch information
bryanck and Bryan Keller authored Sep 17, 2024
1 parent 97d3dec commit 3dd4eb4
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,13 @@ public interface Config {
*/
int getMetadataQueryTimeout();

/**
* Metadata query timeout in seconds, for longer running queries.
*
* @return Metadata query timeout in seconds for longer running queries
*/
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 @@ -19,6 +19,7 @@
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.FileSystems;
Expand Down Expand Up @@ -81,6 +82,19 @@ public static void loadMySqlDataSource(final DataSourceManager dataSourceManager
}
dataSourceManager.load(UserMetadataService.NAME_DATASOURCE, connectionProperties);
}

/**
* Create a JDBC template with a query timeout.
*
* @param dataSource data source
* @param timeoutSec query timeout, in sec
* @return the JDBC template
*/
public static JdbcTemplate createJdbcTemplate(final DataSource dataSource, final int timeoutSec) {
final JdbcTemplate result = new JdbcTemplate(dataSource);
result.setQueryTimeout(timeoutSec);
return result;
}
}


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 @@ -119,6 +120,8 @@ public MySqlTagService(
) {
this.config = Preconditions.checkNotNull(config, "config is required");
this.jdbcTemplate = jdbcTemplate;
this.jdbcTemplateLongTimeout = MySqlServiceUtil.createJdbcTemplate(
jdbcTemplate.getDataSource(), config.getLongMetadataQueryTimeout());
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 @@ -162,9 +162,7 @@ public DataSourceTransactionManager metadataTxManager(
public JdbcTemplate metadataJdbcTemplate(
@Qualifier("metadataDataSource") final DataSource mySqlDataSource,
final Config config) {
final JdbcTemplate result = new JdbcTemplate(mySqlDataSource);
result.setQueryTimeout(config.getMetadataQueryTimeout());
return result;
return MySqlServiceUtil.createJdbcTemplate(
mySqlDataSource, config.getMetadataQueryTimeout());
}

}

0 comments on commit 3dd4eb4

Please sign in to comment.