Skip to content

Add null checks in DruidSchema#6830

Merged
jihoonson merged 9 commits intoapache:masterfrom
surekhasaharan:druid-schema-npe
Feb 5, 2019
Merged

Add null checks in DruidSchema#6830
jihoonson merged 9 commits intoapache:masterfrom
surekhasaharan:druid-schema-npe

Conversation

@surekhasaharan
Copy link
Copy Markdown

Fix for #6826

Copy link
Copy Markdown
Contributor

@egor-ryashin egor-ryashin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you create a unit test which checks if the issue exists?

@surekhasaharan
Copy link
Copy Markdown
Author

@egor-ryashin I think theoretically, this issue can happen, it'd require some effort to create a unit test for multithreaded case, let me think about how can I add such test.

@fjy fjy added this to the 0.14.0 milestone Jan 16, 2019
@jihoonson jihoonson added the Bug label Jan 24, 2019
@surekhasaharan
Copy link
Copy Markdown
Author

Could you create a unit test which checks if the issue exists?

@egor-ryashin added unit tests.

}

private void removeSegment(final DataSegment segment)
protected void removeSegment(final DataSegment segment)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add @VisibleForTesting to newly exposed methods.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, forgot to add. Will do.

@Test
public void testNullDatasource() throws IOException
{
Map<DataSegment, SegmentMetadataHolder> segmentsMetadata = schema.getSegmentMetadata();
Copy link
Copy Markdown
Contributor

@egor-ryashin egor-ryashin Jan 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

segmentMetadatas makes it more clear it's multiple objects.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, renamed

final DataSegment segmentToRemove = segments.stream().findFirst().orElse(null);
Assert.assertFalse(segmentToRemove == null);
schema.removeSegment(segmentToRemove);
schema.refreshSegments(segments); // can cause NPE without dataSourceSegments null check in DruidSchema#refreshSegmentsForDataSource
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unclear that we remove the only segment of 'foo2' datasource (and not a segment from foo datasource) as getSegmentMetadata returned Map doesn't guarantee order. Which means it's unclear if we test for dataSourceSegments == null

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, changed to get segment with datasource 'foo2'

Copy link
Copy Markdown
Member

@clintropolis clintropolis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Any more comments @jihoonson?

Copy link
Copy Markdown
Contributor

@jihoonson jihoonson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@jihoonson jihoonson merged commit ef451d3 into apache:master Feb 5, 2019
@surekhasaharan surekhasaharan deleted the druid-schema-npe branch February 5, 2019 23:15
clintropolis pushed a commit to clintropolis/druid that referenced this pull request Feb 6, 2019
* Add null checks in DruidSchema

* Add unit tests

* Add VisibleForTesting annotation

* PR comments

* unused import
jihoonson pushed a commit that referenced this pull request Feb 6, 2019
* Add null checks in DruidSchema

* Add unit tests

* Add VisibleForTesting annotation

* PR comments

* unused import
surekhasaharan pushed a commit to implydata/druid-public that referenced this pull request Feb 13, 2019
* Add null checks in DruidSchema

* Add unit tests

* Add VisibleForTesting annotation

* PR comments

* unused import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants