clintropolis commented on a change in pull request #8106: fix npe with sql
metadata manager polling and empty database
URL: https://github.com/apache/incubator-druid/pull/8106#discussion_r305277531
##########
File path:
server/src/main/java/org/apache/druid/metadata/SQLMetadataSegmentManager.java
##########
@@ -967,10 +961,18 @@ public DataSegment map(int index, ResultSet r,
StatementContext ctx) throws SQLE
// segment mark calls in rapid succession. So the snapshot update is not
done outside of database poll at this time.
// Updates outside of database polls were primarily for the user
experience, so users would immediately see the
// effect of a segment mark call reflected in MetadataResource API calls.
- dataSourcesSnapshot = DataSourcesSnapshot.fromUsedSegments(
- Iterables.filter(segments, Objects::nonNull), // Filter corrupted
entries (see above in this method).
- dataSourceProperties
- );
+
+ ImmutableMap<String, String> dataSourceProperties =
createDefaultDataSourceProperties();
+ if (segments == null || segments.isEmpty()) {
+ log.info("No segments found in the database!");
+ dataSourcesSnapshot =
DataSourcesSnapshot.fromUsedSegments(Collections.emptyList(),
dataSourceProperties);
Review comment:
Yea, I was not able to observe `segments` being `null` in my experiments,
which mostly consisted of killing and restarting the mysql i was testing
against. It doesn't look like it _should_ be able to be null, the javadoc for
the `Query.list` method
```
* Executes the select
* <p/>
* Will eagerly load all results
*
* @throws org.skife.jdbi.v2.exceptions.UnableToCreateStatementException
* if there is an error creating the statement
* @throws org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException
* if there is an error executing the
statement
* @throws org.skife.jdbi.v2.exceptions.ResultSetException if there is
an error dealing with the result set
```
makes it look like it's either going to make a list or throw an exception.
If we are confident it shouldn't happen then it should just be removed i
think, but if still unsure it might make more sense to handle `segments ==
null` separate and log and probably not update the snapshot even if it's still
null, because it's an unexpected condition that doesn't necessarily mean the
same thing as a truly empty segments table. 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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]