Search in sources :

Example 6 with ReferenceCountingSegment

use of io.druid.segment.ReferenceCountingSegment in project druid by druid-io.

the class ServerManager method dropSegment.

public void dropSegment(final DataSegment segment) throws SegmentLoadingException {
    String dataSource = segment.getDataSource();
    synchronized (lock) {
        VersionedIntervalTimeline<String, ReferenceCountingSegment> loadedIntervals = dataSources.get(dataSource);
        if (loadedIntervals == null) {
            log.info("Told to delete a queryable for a dataSource[%s] that doesn't exist.", dataSource);
            return;
        }
        PartitionChunk<ReferenceCountingSegment> removed = loadedIntervals.remove(segment.getInterval(), segment.getVersion(), segment.getShardSpec().createChunk((ReferenceCountingSegment) null));
        ReferenceCountingSegment oldQueryable = (removed == null) ? null : removed.getObject();
        if (oldQueryable != null) {
            synchronized (dataSourceSizes) {
                dataSourceSizes.add(dataSource, -segment.getSize());
            }
            synchronized (dataSourceCounts) {
                dataSourceCounts.add(dataSource, -1L);
            }
            try {
                log.info("Attempting to close segment %s", segment.getIdentifier());
                oldQueryable.close();
            } catch (IOException e) {
                log.makeAlert(e, "Exception closing segment").addData("dataSource", dataSource).addData("segmentId", segment.getIdentifier()).emit();
            }
        } else {
            log.info("Told to delete a queryable on dataSource[%s] for interval[%s] and version [%s] that I don't have.", dataSource, segment.getInterval(), segment.getVersion());
        }
    }
    segmentLoader.cleanup(segment);
}
Also used : ReferenceCountingSegment(io.druid.segment.ReferenceCountingSegment) IOException(java.io.IOException)

Example 7 with ReferenceCountingSegment

use of io.druid.segment.ReferenceCountingSegment in project druid by druid-io.

the class ServerManagerTest method testReferenceCountingWhileQueryExecuting.

@Test
public void testReferenceCountingWhileQueryExecuting() throws Exception {
    loadQueryable("test", "3", new Interval("2011-04-04/2011-04-05"));
    Future future = assertQueryable(Granularities.DAY, "test", new Interval("2011-04-04/2011-04-06"), ImmutableList.<Pair<String, Interval>>of(new Pair<String, Interval>("3", new Interval("2011-04-04/2011-04-05"))));
    queryNotifyLatch.await(1000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(1, factory.getSegmentReferences().size());
    for (ReferenceCountingSegment referenceCountingSegment : factory.getSegmentReferences()) {
        Assert.assertEquals(1, referenceCountingSegment.getNumReferences());
    }
    queryWaitYieldLatch.countDown();
    Assert.assertEquals(1, factory.getAdapters().size());
    for (SegmentForTesting segmentForTesting : factory.getAdapters()) {
        Assert.assertFalse(segmentForTesting.isClosed());
    }
    dropQueryable("test", "3", new Interval("2011-04-04/2011-04-05"));
    for (SegmentForTesting segmentForTesting : factory.getAdapters()) {
        Assert.assertFalse(segmentForTesting.isClosed());
    }
    queryWaitLatch.countDown();
    future.get();
    for (SegmentForTesting segmentForTesting : factory.getAdapters()) {
        Assert.assertTrue(segmentForTesting.isClosed());
    }
}
Also used : ReferenceCountingSegment(io.druid.segment.ReferenceCountingSegment) Future(java.util.concurrent.Future) Interval(org.joda.time.Interval) Pair(io.druid.java.util.common.Pair) Test(org.junit.Test)

Example 8 with ReferenceCountingSegment

use of io.druid.segment.ReferenceCountingSegment in project druid by druid-io.

the class FireHydrant method swapSegment.

public void swapSegment(Segment newAdapter) {
    synchronized (swapLock) {
        if (adapter != null && newAdapter != null && !newAdapter.getIdentifier().equals(adapter.getIdentifier())) {
            // Sanity check: identifier should not change
            throw new ISE("WTF?! Cannot swap identifier[%s] -> [%s]!", adapter.getIdentifier(), newAdapter.getIdentifier());
        }
        if (this.adapter != null) {
            try {
                this.adapter.close();
            } catch (IOException e) {
                throw Throwables.propagate(e);
            }
        }
        this.adapter = new ReferenceCountingSegment(newAdapter);
        this.index = null;
    }
}
Also used : ReferenceCountingSegment(io.druid.segment.ReferenceCountingSegment) ISE(io.druid.java.util.common.ISE) IOException(java.io.IOException)

Aggregations

ReferenceCountingSegment (io.druid.segment.ReferenceCountingSegment)8 Interval (org.joda.time.Interval)4 Pair (io.druid.java.util.common.Pair)3 Future (java.util.concurrent.Future)3 Test (org.junit.Test)3 CachingQueryRunner (io.druid.client.CachingQueryRunner)2 ISE (io.druid.java.util.common.ISE)2 FunctionalIterable (io.druid.java.util.common.guava.FunctionalIterable)2 BySegmentQueryRunner (io.druid.query.BySegmentQueryRunner)2 CPUTimeMetricQueryRunner (io.druid.query.CPUTimeMetricQueryRunner)2 FinalizeResultsQueryRunner (io.druid.query.FinalizeResultsQueryRunner)2 MetricsEmittingQueryRunner (io.druid.query.MetricsEmittingQueryRunner)2 NoopQueryRunner (io.druid.query.NoopQueryRunner)2 Query (io.druid.query.Query)2 QueryRunner (io.druid.query.QueryRunner)2 ReferenceCountingSegmentQueryRunner (io.druid.query.ReferenceCountingSegmentQueryRunner)2 ReportTimelineMissingSegmentQueryRunner (io.druid.query.ReportTimelineMissingSegmentQueryRunner)2 SegmentDescriptor (io.druid.query.SegmentDescriptor)2 SpecificSegmentQueryRunner (io.druid.query.spec.SpecificSegmentQueryRunner)2 PartitionChunk (io.druid.timeline.partition.PartitionChunk)2