-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Externalised destination table cache expiry duration for BigQuery Connector #8283
Externalised destination table cache expiry duration for BigQuery Connector #8283
Conversation
@@ -78,6 +80,10 @@ | |||
.expireAfterWrite(caseInsensitiveNameMatchingCacheTtl.toMillis(), MILLISECONDS); | |||
this.remoteDatasets = remoteNamesCacheBuilder.build(); | |||
this.remoteTables = remoteNamesCacheBuilder.build(); | |||
this.destinationTableCache = CacheBuilder.newBuilder() | |||
.expireAfterWrite(config.getDestinationTableCacheExpiry().roundTo(TimeUnit.MINUTES), TimeUnit.MINUTES) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expireAfterWrite(config.getDestinationTableCacheExpiry().toMillis(), MILLISECONDS)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
return destinationTableCacheExpiry; | ||
} | ||
|
||
@Config("bigquery.destination-table-cache-expiry") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe bigquery.views-cache-ttl
would be a better name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} | ||
|
||
@Config("bigquery.destination-table-cache-expiry") | ||
@ConfigDescription("Duration for which query and destination table will be cached") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duration for which the results of querying a view will be cached
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -47,6 +48,7 @@ | |||
private int maxReadRowsRetries = DEFAULT_MAX_READ_ROWS_RETRIES; | |||
private boolean caseInsensitiveNameMatching; | |||
private Duration caseInsensitiveNameMatchingCacheTtl = new Duration(1, MINUTES); | |||
private Duration destinationTableCacheExpiry = new Duration(15, TimeUnit.MINUTES); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe viewsCacheTtl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -130,7 +122,7 @@ private TableInfo getActualTable( | |||
String query = bigQueryClient.selectSql(table.getTableId(), requiredColumns); | |||
log.debug("query is %s", query); | |||
try { | |||
return destinationTableCache.get(query, new DestinationTableBuilder(bigQueryClient, config, query, table.getTableId())); | |||
return bigQueryClient.getDestinationTableCache().get(query, new DestinationTableBuilder(bigQueryClient, config, query, table.getTableId())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could move DestinationTableBuilder to BigQueryClient and expose a method bigQueryClient.getCachedTable(config, table.getTableId(), requiredColumns)
instead of exposing the cache directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -129,76 +109,12 @@ private TableInfo getActualTable( | |||
// get it from the view | |||
String query = bigQueryClient.selectSql(table.getTableId(), requiredColumns); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move this into bigQueryClient.getCachedTable
as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me % comments.
@@ -337,4 +362,63 @@ public boolean isAmbiguous() | |||
return remoteNames.size() > 1; | |||
} | |||
} | |||
|
|||
static class DestinationTableBuilder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the movement of this class be done in a preparatory first commit? It'll make the diff easier to understand that it's just a move and no code changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want me to make that change now? Or is it fine to go ahead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to have that since it makes it easier to make sense of history in the future.
So the move-only changes would get extracted to the first commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
TableInfo getCachedTable(ReadSessionCreatorConfig config, String query, TableInfo table) | ||
{ | ||
try { | ||
return destinationTableCache.get(query, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just noting that the cache key seems to be the entire query string (which can be large).
No changes requested at the moment though.
@@ -13,6 +13,7 @@ | |||
*/ | |||
package io.trino.plugin.bigquery; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update commit message to Move DestinationTableBuilder to BigQueryClient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -44,6 +44,7 @@ | |||
import java.util.Optional; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update commit message to Make BigQuery views cache ttl configurable
In general we try to follow https://chris.beams.io/posts/git-commit/ for commit messages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address errorprone failures. LGTM otherwise.
PTAL @ebyhr.
@@ -47,6 +48,7 @@ | |||
private int maxReadRowsRetries = DEFAULT_MAX_READ_ROWS_RETRIES; | |||
private boolean caseInsensitiveNameMatching; | |||
private Duration caseInsensitiveNameMatchingCacheTtl = new Duration(1, MINUTES); | |||
private Duration viewsCacheTtl = new Duration(15, TimeUnit.MINUTES); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: MINUTES
is already imported at L33. Please use it instead of TimeUnit.MINUTES
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh..my bad! I'll update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Merged, thanks! |
Resolves #8236
Made destination table cache expiry duration configurable. This can be configured using bigquery.destination-table-cache-expiry property. Defaults to 15m.