use of org.apache.druid.segment.ReferenceCountingSegment in project druid by druid-io.
the class FireHydrant method swapSegment.
public void swapSegment(@Nullable Segment newSegment) {
while (true) {
ReferenceCountingSegment currentSegment = adapter.get();
if (currentSegment == null && newSegment == null) {
return;
}
if (currentSegment != null && newSegment != null && !newSegment.getId().equals(currentSegment.getId())) {
// Sanity check: identifier should not change
throw new ISE("Cannot swap identifier[%s] -> [%s]", currentSegment.getId(), newSegment.getId());
}
if (currentSegment == newSegment) {
throw new ISE("Cannot swap to the same segment");
}
ReferenceCountingSegment newReferenceCountingSegment = newSegment != null ? ReferenceCountingSegment.wrapRootGenerationSegment(newSegment) : null;
if (adapter.compareAndSet(currentSegment, newReferenceCountingSegment)) {
if (currentSegment != null) {
currentSegment.close();
}
index = null;
return;
}
}
}
use of org.apache.druid.segment.ReferenceCountingSegment in project druid by druid-io.
the class FireHydrantTest method testGetAndIncrementSegment.
@Test
public void testGetAndIncrementSegment() throws IOException {
ReferenceCountingSegment incrementalSegmentReference = hydrant.getHydrantSegment();
Assert.assertEquals(0, incrementalSegmentReference.getNumReferences());
Pair<ReferenceCountingSegment, Closeable> segmentAndCloseable = hydrant.getAndIncrementSegment();
Assert.assertEquals(1, segmentAndCloseable.lhs.getNumReferences());
segmentAndCloseable.rhs.close();
Assert.assertEquals(0, segmentAndCloseable.lhs.getNumReferences());
}
use of org.apache.druid.segment.ReferenceCountingSegment in project druid by druid-io.
the class FireHydrantTest method testGetSegmentForQuerySwapped.
@Test
public void testGetSegmentForQuerySwapped() throws IOException {
ReferenceCountingSegment incrementalSegmentReference = hydrant.getHydrantSegment();
hydrant.swapSegment(queryableIndexSegment);
ReferenceCountingSegment queryableSegmentReference = hydrant.getHydrantSegment();
Assert.assertEquals(0, incrementalSegmentReference.getNumReferences());
Assert.assertEquals(0, queryableSegmentReference.getNumReferences());
Optional<Pair<SegmentReference, Closeable>> maybeSegmentAndCloseable = hydrant.getSegmentForQuery(Function.identity());
Assert.assertTrue(maybeSegmentAndCloseable.isPresent());
Assert.assertEquals(0, incrementalSegmentReference.getNumReferences());
Assert.assertEquals(1, queryableSegmentReference.getNumReferences());
Pair<SegmentReference, Closeable> segmentAndCloseable = maybeSegmentAndCloseable.get();
segmentAndCloseable.rhs.close();
Assert.assertEquals(0, incrementalSegmentReference.getNumReferences());
Assert.assertEquals(0, queryableSegmentReference.getNumReferences());
}
use of org.apache.druid.segment.ReferenceCountingSegment in project druid by druid-io.
the class FireHydrantTest method testGetSegmentForQuery.
@Test
public void testGetSegmentForQuery() throws IOException {
ReferenceCountingSegment incrementalSegmentReference = hydrant.getHydrantSegment();
Assert.assertEquals(0, incrementalSegmentReference.getNumReferences());
Optional<Pair<SegmentReference, Closeable>> maybeSegmentAndCloseable = hydrant.getSegmentForQuery(Function.identity());
Assert.assertTrue(maybeSegmentAndCloseable.isPresent());
Assert.assertEquals(1, incrementalSegmentReference.getNumReferences());
Pair<SegmentReference, Closeable> segmentAndCloseable = maybeSegmentAndCloseable.get();
segmentAndCloseable.rhs.close();
Assert.assertEquals(0, incrementalSegmentReference.getNumReferences());
}
use of org.apache.druid.segment.ReferenceCountingSegment in project druid by druid-io.
the class TimeBoundaryQueryRunnerTest method getCustomRunner.
private QueryRunner getCustomRunner() throws IOException {
CharSource v_0112 = CharSource.wrap(StringUtils.join(V_0112, "\n"));
CharSource v_0113 = CharSource.wrap(StringUtils.join(V_0113, "\n"));
IncrementalIndex index0 = TestIndex.loadIncrementalIndex(newIndex("2011-01-12T00:00:00.000Z"), v_0112);
IncrementalIndex index1 = TestIndex.loadIncrementalIndex(newIndex("2011-01-14T00:00:00.000Z"), v_0113);
segment0 = new IncrementalIndexSegment(index0, makeIdentifier(index0, "v1"));
segment1 = new IncrementalIndexSegment(index1, makeIdentifier(index1, "v1"));
VersionedIntervalTimeline<String, ReferenceCountingSegment> timeline = new VersionedIntervalTimeline<>(StringComparators.LEXICOGRAPHIC);
timeline.add(index0.getInterval(), "v1", new SingleElementPartitionChunk<>(ReferenceCountingSegment.wrapRootGenerationSegment(segment0)));
timeline.add(index1.getInterval(), "v1", new SingleElementPartitionChunk<>(ReferenceCountingSegment.wrapRootGenerationSegment(segment1)));
return QueryRunnerTestHelper.makeFilteringQueryRunner(timeline, FACTORY);
}
Aggregations