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);
}
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());
}
}
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;
}
}
Aggregations