You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "Akshat-Jain (via GitHub)" <gi...@apache.org> on 2024/04/18 07:51:28 UTC
[PR] Fix NPE while loading lookups from empty JDBC source (druid)
Akshat-Jain opened a new pull request, #16307:
URL: https://github.com/apache/druid/pull/16307
### Description
Currently, when we add a lookup with the lookupExtractorFactory's type as `cachedNamespace` configured with a JDBC source, we run into NPE while loading the lookup if the configured JDBC source table has no rows.
Sample NPE logs:
```java
2024-04-17T09:44:32,936 ERROR [NamespaceExtractionCacheManager-0] org.apache.druid.server.lookup.namespace.cache.CacheScheduler - Failed to update namespace [JdbcExtractionNamespace{connectorConfig=DbConnectorConfig{createTables=true, connectURI='jdbc:postgresql://localhost:5432/druid', user='druid', passwordProvider=org.apache.druid.metadata.DefaultPasswordProvider, dbcpProperties=null}, table='pglookuptable1', keyColumn='country_id', valueColumn='country_name', tsColumn='timeColumn', filter='null', pollPeriod=PT1M, jitterSeconds=0, loadTimeoutSeconds=120, maxHeapPercentage=10}] : org.apache.druid.server.lookup.namespace.cache.CacheScheduler$EntryImpl@64c4522
java.lang.NullPointerException: null
at org.apache.druid.server.lookup.namespace.JdbcCacheGenerator.lastUpdates(JdbcCacheGenerator.java:219) ~[?:?]
at org.apache.druid.server.lookup.namespace.JdbcCacheGenerator.generateCache(JdbcCacheGenerator.java:72) ~[?:?]
at org.apache.druid.server.lookup.namespace.JdbcCacheGenerator.generateCache(JdbcCacheGenerator.java:48) ~[?:?]
at org.apache.druid.server.lookup.namespace.cache.CacheScheduler$EntryImpl.tryUpdateCache(CacheScheduler.java:236) ~[?:?]
at org.apache.druid.server.lookup.namespace.cache.CacheScheduler$EntryImpl.updateCache(CacheScheduler.java:208) ~[?:?]
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
at java.base/java.util.concurrent.FutureTask.runAndReset$$$capture(FutureTask.java:305) [?:?]
at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java) [?:?]
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) [?:?]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.base/java.lang.Thread.run(Thread.java:829) [?:?]
```
This PR handles the NPE, and adds a test for validating the corresponding flow.
This PR has:
- [x] been self-reviewed.
- [ ] added documentation for new or modified features or behaviors.
- [ ] a release note entry in the PR description.
- [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
- [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
- [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
- [x] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
- [ ] added integration tests.
- [ ] been tested in a test Druid cluster.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix NPE while loading lookups from empty JDBC source (druid)
Posted by "cryptoe (via GitHub)" <gi...@apache.org>.
cryptoe commented on code in PR #16307:
URL: https://github.com/apache/druid/pull/16307#discussion_r1570414617
##########
extensions-core/lookups-cached-global/src/main/java/org/apache/druid/server/lookup/namespace/JdbcCacheGenerator.java:
##########
@@ -204,18 +204,20 @@ private Long lastUpdates(CacheScheduler.EntryImpl<JdbcExtractionNamespace> key,
if (tsColumn == null) {
return null;
}
+ final String query = StringUtils.format(
+ "SELECT MAX(%s) FROM %s",
+ tsColumn, table
+ );
final Timestamp update = dbi.withHandle(
- handle -> {
- final String query = StringUtils.format(
- "SELECT MAX(%s) FROM %s",
- tsColumn, table
- );
- return handle
- .createQuery(query)
- .map(TimestampMapper.FIRST)
- .first();
- }
+ handle -> handle
+ .createQuery(query)
+ .map(TimestampMapper.FIRST)
+ .first()
);
+ if (update == null) {
+ LOG.info("Lookup table is empty. No rows returned for the query: %s", query);
Review Comment:
Lets add the look up name here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix NPE while loading lookups from empty JDBC source (druid)
Posted by "Akshat-Jain (via GitHub)" <gi...@apache.org>.
Akshat-Jain commented on code in PR #16307:
URL: https://github.com/apache/druid/pull/16307#discussion_r1570512941
##########
extensions-core/lookups-cached-global/src/main/java/org/apache/druid/server/lookup/namespace/JdbcCacheGenerator.java:
##########
@@ -204,18 +204,20 @@ private Long lastUpdates(CacheScheduler.EntryImpl<JdbcExtractionNamespace> key,
if (tsColumn == null) {
return null;
}
+ final String query = StringUtils.format(
+ "SELECT MAX(%s) FROM %s",
+ tsColumn, table
+ );
final Timestamp update = dbi.withHandle(
- handle -> {
- final String query = StringUtils.format(
- "SELECT MAX(%s) FROM %s",
- tsColumn, table
- );
- return handle
- .createQuery(query)
- .map(TimestampMapper.FIRST)
- .first();
- }
+ handle -> handle
+ .createQuery(query)
+ .map(TimestampMapper.FIRST)
+ .first()
);
+ if (update == null) {
+ LOG.info("Lookup table is empty. No rows returned for the query: %s", query);
Review Comment:
@cryptoe The cache scheduler layer doesn't seem to have lookup name information. It only has the JdbcExtractionNamespace level information - which is what gets logged everywhere else in the cache scheduler layer as well.
Technically we can add an extra method param to send lookup name info all the way down to the cache layer through the whole method chain, but that seems unnecessary to me. That would also then require us to change logging everywhere else in the cache layer, just to ensure consistency - so it would end up as a much wider change.
Thoughts?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix NPE while loading lookups from empty JDBC source (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on PR #16307:
URL: https://github.com/apache/druid/pull/16307#issuecomment-2064433188
Thanks for the fix, @Akshat-Jain !
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix NPE while loading lookups from empty JDBC source (druid)
Posted by "LakshSingla (via GitHub)" <gi...@apache.org>.
LakshSingla commented on code in PR #16307:
URL: https://github.com/apache/druid/pull/16307#discussion_r1570948900
##########
extensions-core/lookups-cached-global/src/main/java/org/apache/druid/server/lookup/namespace/JdbcCacheGenerator.java:
##########
@@ -204,18 +204,20 @@ private Long lastUpdates(CacheScheduler.EntryImpl<JdbcExtractionNamespace> key,
if (tsColumn == null) {
return null;
}
+ final String query = StringUtils.format(
+ "SELECT MAX(%s) FROM %s",
+ tsColumn, table
+ );
final Timestamp update = dbi.withHandle(
- handle -> {
- final String query = StringUtils.format(
- "SELECT MAX(%s) FROM %s",
- tsColumn, table
- );
- return handle
- .createQuery(query)
- .map(TimestampMapper.FIRST)
- .first();
- }
+ handle -> handle
+ .createQuery(query)
+ .map(TimestampMapper.FIRST)
+ .first()
);
+ if (update == null) {
+ LOG.info("Lookup table is empty. No rows returned for the query: %s", query);
Review Comment:
Wouldn't INFO logging be too noisy, given that this will log every time we run a check (to see whether to update the table or not)? (By default, it is set to not poll, so the default behaviour is cool)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix NPE while loading lookups from empty JDBC source (druid)
Posted by "Akshat-Jain (via GitHub)" <gi...@apache.org>.
Akshat-Jain commented on code in PR #16307:
URL: https://github.com/apache/druid/pull/16307#discussion_r1570512941
##########
extensions-core/lookups-cached-global/src/main/java/org/apache/druid/server/lookup/namespace/JdbcCacheGenerator.java:
##########
@@ -204,18 +204,20 @@ private Long lastUpdates(CacheScheduler.EntryImpl<JdbcExtractionNamespace> key,
if (tsColumn == null) {
return null;
}
+ final String query = StringUtils.format(
+ "SELECT MAX(%s) FROM %s",
+ tsColumn, table
+ );
final Timestamp update = dbi.withHandle(
- handle -> {
- final String query = StringUtils.format(
- "SELECT MAX(%s) FROM %s",
- tsColumn, table
- );
- return handle
- .createQuery(query)
- .map(TimestampMapper.FIRST)
- .first();
- }
+ handle -> handle
+ .createQuery(query)
+ .map(TimestampMapper.FIRST)
+ .first()
);
+ if (update == null) {
+ LOG.info("Lookup table is empty. No rows returned for the query: %s", query);
Review Comment:
@cryptoe The cache scheduler layer doesn't seem to have lookup name information. It only has the JdbcExtractionNamespace level information - which is what gets logged everywhere else in the cache scheduler layer as well.
Technically we can add an extra method param to send lookup name info all the way down to the cache layer, but that seems unnecessary to me. That would also then require us to change logging everywhere else in the cache layer, just to ensure consistency - so it would end up as a much wider change.
Thoughts?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix NPE while loading lookups from empty JDBC source (druid)
Posted by "Akshat-Jain (via GitHub)" <gi...@apache.org>.
Akshat-Jain commented on code in PR #16307:
URL: https://github.com/apache/druid/pull/16307#discussion_r1570779944
##########
extensions-core/lookups-cached-global/src/main/java/org/apache/druid/server/lookup/namespace/JdbcCacheGenerator.java:
##########
@@ -204,18 +204,20 @@ private Long lastUpdates(CacheScheduler.EntryImpl<JdbcExtractionNamespace> key,
if (tsColumn == null) {
return null;
}
+ final String query = StringUtils.format(
+ "SELECT MAX(%s) FROM %s",
+ tsColumn, table
+ );
final Timestamp update = dbi.withHandle(
- handle -> {
- final String query = StringUtils.format(
- "SELECT MAX(%s) FROM %s",
- tsColumn, table
- );
- return handle
- .createQuery(query)
- .map(TimestampMapper.FIRST)
- .first();
- }
+ handle -> handle
+ .createQuery(query)
+ .map(TimestampMapper.FIRST)
+ .first()
);
+ if (update == null) {
+ LOG.info("Lookup table is empty. No rows returned for the query: %s", query);
Review Comment:
@kfaraz Have made the suggested change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix NPE while loading lookups from empty JDBC source (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #16307:
URL: https://github.com/apache/druid/pull/16307#discussion_r1570766211
##########
extensions-core/lookups-cached-global/src/main/java/org/apache/druid/server/lookup/namespace/JdbcCacheGenerator.java:
##########
@@ -204,18 +204,20 @@ private Long lastUpdates(CacheScheduler.EntryImpl<JdbcExtractionNamespace> key,
if (tsColumn == null) {
return null;
}
+ final String query = StringUtils.format(
+ "SELECT MAX(%s) FROM %s",
+ tsColumn, table
+ );
final Timestamp update = dbi.withHandle(
- handle -> {
- final String query = StringUtils.format(
- "SELECT MAX(%s) FROM %s",
- tsColumn, table
- );
- return handle
- .createQuery(query)
- .map(TimestampMapper.FIRST)
- .first();
- }
+ handle -> handle
+ .createQuery(query)
+ .map(TimestampMapper.FIRST)
+ .first()
);
+ if (update == null) {
+ LOG.info("Lookup table is empty. No rows returned for the query: %s", query);
Review Comment:
You can do this:
```suggestion
LOG.info("Lookup table[%s] is empty. No rows returned for the query[%s].", table, query);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix NPE while loading lookups from empty JDBC source (druid)
Posted by "Akshat-Jain (via GitHub)" <gi...@apache.org>.
Akshat-Jain commented on code in PR #16307:
URL: https://github.com/apache/druid/pull/16307#discussion_r1570954139
##########
extensions-core/lookups-cached-global/src/main/java/org/apache/druid/server/lookup/namespace/JdbcCacheGenerator.java:
##########
@@ -204,18 +204,20 @@ private Long lastUpdates(CacheScheduler.EntryImpl<JdbcExtractionNamespace> key,
if (tsColumn == null) {
return null;
}
+ final String query = StringUtils.format(
+ "SELECT MAX(%s) FROM %s",
+ tsColumn, table
+ );
final Timestamp update = dbi.withHandle(
- handle -> {
- final String query = StringUtils.format(
- "SELECT MAX(%s) FROM %s",
- tsColumn, table
- );
- return handle
- .createQuery(query)
- .map(TimestampMapper.FIRST)
- .first();
- }
+ handle -> handle
+ .createQuery(query)
+ .map(TimestampMapper.FIRST)
+ .first()
);
+ if (update == null) {
+ LOG.info("Lookup table is empty. No rows returned for the query: %s", query);
Review Comment:
@LakshSingla This is going to be logged only if the table is empty, so I think it should be fine.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix NPE while loading lookups from empty JDBC source (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz merged PR #16307:
URL: https://github.com/apache/druid/pull/16307
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix NPE while loading lookups from empty JDBC source (druid)
Posted by "cryptoe (via GitHub)" <gi...@apache.org>.
cryptoe commented on code in PR #16307:
URL: https://github.com/apache/druid/pull/16307#discussion_r1570414617
##########
extensions-core/lookups-cached-global/src/main/java/org/apache/druid/server/lookup/namespace/JdbcCacheGenerator.java:
##########
@@ -204,18 +204,20 @@ private Long lastUpdates(CacheScheduler.EntryImpl<JdbcExtractionNamespace> key,
if (tsColumn == null) {
return null;
}
+ final String query = StringUtils.format(
+ "SELECT MAX(%s) FROM %s",
+ tsColumn, table
+ );
final Timestamp update = dbi.withHandle(
- handle -> {
- final String query = StringUtils.format(
- "SELECT MAX(%s) FROM %s",
- tsColumn, table
- );
- return handle
- .createQuery(query)
- .map(TimestampMapper.FIRST)
- .first();
- }
+ handle -> handle
+ .createQuery(query)
+ .map(TimestampMapper.FIRST)
+ .first()
);
+ if (update == null) {
+ LOG.info("Lookup table is empty. No rows returned for the query: %s", query);
Review Comment:
Lets add the look up table name here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org