Skip to content

Commit

Permalink
FireHydrant: Return empty from getSegmentForQuery when adapter is null.
Browse files Browse the repository at this point in the history
This can happen if the segment is removed while a query is in progress.
Returning empty causes the server to use ReportTimelineMissingSegmentQueryRunner,
which causes the Broker to look for the segment somewhere else.

Fixes apache#12168.
  • Loading branch information
gianm committed Oct 26, 2023
1 parent 7a25ee4 commit ac215fe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ public Optional<Pair<SegmentReference, Closeable>> getSegmentForQuery(
)
{
ReferenceCountingSegment sinkSegment = adapter.get();

if (sinkSegment == null) {
// adapter can be null if this segment is removed while being queried.
return Optional.empty();
}

SegmentReference segment = segmentMapFn.apply(sinkSegment);
while (true) {
Optional<Closeable> reference = segment.acquireReferences();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ public void testGetSegmentForQuerySwapped() throws IOException
Assert.assertEquals(0, queryableSegmentReference.getNumReferences());
}

@Test
public void testGetSegmentForQuerySwappedWithNull() throws IOException
{
ReferenceCountingSegment incrementalSegmentReference = hydrant.getHydrantSegment();
hydrant.swapSegment(null);
ReferenceCountingSegment queryableSegmentReference = hydrant.getHydrantSegment();
Assert.assertEquals(0, incrementalSegmentReference.getNumReferences());
Assert.assertNull(queryableSegmentReference);

Optional<Pair<SegmentReference, Closeable>> maybeSegmentAndCloseable = hydrant.getSegmentForQuery(
Function.identity()
);
Assert.assertEquals(0, incrementalSegmentReference.getNumReferences());
Assert.assertFalse(maybeSegmentAndCloseable.isPresent());
}

@Test
public void testGetSegmentForQueryButNotAbleToAcquireReferences()
{
Expand Down

0 comments on commit ac215fe

Please sign in to comment.