Search in sources :

Example 6 with SegmentManager

use of org.apache.druid.server.SegmentManager in project druid by druid-io.

the class DruidSchemaNoDataInitTest method testInitializationWithNoData.

@Test
public void testInitializationWithNoData() throws Exception {
    try (final Closer closer = Closer.create()) {
        final QueryRunnerFactoryConglomerate conglomerate = QueryStackTests.createQueryRunnerFactoryConglomerate(closer);
        final DruidSchema druidSchema = new DruidSchema(CalciteTests.createMockQueryLifecycleFactory(new SpecificSegmentsQuerySegmentWalker(conglomerate), conglomerate), new TestServerInventoryView(Collections.emptyList()), new SegmentManager(EasyMock.createMock(SegmentLoader.class)), new MapJoinableFactory(ImmutableSet.of(), ImmutableMap.of()), PLANNER_CONFIG_DEFAULT, new NoopEscalator(), new BrokerInternalQueryConfig(), null);
        druidSchema.start();
        druidSchema.awaitInitialization();
        Assert.assertEquals(ImmutableMap.of(), druidSchema.getTableMap());
    }
}
Also used : Closer(org.apache.druid.java.util.common.io.Closer) NoopEscalator(org.apache.druid.server.security.NoopEscalator) QueryRunnerFactoryConglomerate(org.apache.druid.query.QueryRunnerFactoryConglomerate) SpecificSegmentsQuerySegmentWalker(org.apache.druid.sql.calcite.util.SpecificSegmentsQuerySegmentWalker) SegmentManager(org.apache.druid.server.SegmentManager) TestServerInventoryView(org.apache.druid.sql.calcite.util.TestServerInventoryView) BrokerInternalQueryConfig(org.apache.druid.client.BrokerInternalQueryConfig) MapJoinableFactory(org.apache.druid.segment.join.MapJoinableFactory) Test(org.junit.Test)

Example 7 with SegmentManager

use of org.apache.druid.server.SegmentManager in project druid by druid-io.

the class DruidSchemaTestCommon method setUpCommon.

@Before
public void setUpCommon() {
    segmentDataSourceNames = Sets.newConcurrentHashSet();
    joinableDataSourceNames = Sets.newConcurrentHashSet();
    segmentManager = new SegmentManager(EasyMock.createMock(SegmentLoader.class)) {

        @Override
        public Set<String> getDataSourceNames() {
            getDatasourcesLatch.countDown();
            return segmentDataSourceNames;
        }
    };
    globalTableJoinable = new JoinableFactory() {

        @Override
        public boolean isDirectlyJoinable(DataSource dataSource) {
            return dataSource instanceof GlobalTableDataSource && joinableDataSourceNames.contains(((GlobalTableDataSource) dataSource).getName());
        }

        @Override
        public Optional<Joinable> build(DataSource dataSource, JoinConditionAnalysis condition) {
            return Optional.empty();
        }
    };
}
Also used : Set(java.util.Set) SegmentManager(org.apache.druid.server.SegmentManager) Optional(java.util.Optional) GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) JoinConditionAnalysis(org.apache.druid.segment.join.JoinConditionAnalysis) JoinableFactory(org.apache.druid.segment.join.JoinableFactory) GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) DataSource(org.apache.druid.query.DataSource) Before(org.junit.Before)

Example 8 with SegmentManager

use of org.apache.druid.server.SegmentManager in project druid by druid-io.

the class SegmentLoadDropHandlerTest method setUp.

@Before
public void setUp() throws IOException {
    try {
        testStorageLocation = new TestStorageLocation(temporaryFolder);
        infoDir = testStorageLocation.getInfoDir();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    locations = Collections.singletonList(testStorageLocation.toStorageLocationConfig());
    scheduledRunnable = new ArrayList<>();
    segmentCacheManager = new CacheTestSegmentCacheManager();
    segmentLoader = new CacheTestSegmentLoader();
    segmentManager = new SegmentManager(segmentLoader);
    segmentsAnnouncedByMe = new ConcurrentSkipListSet<>();
    announceCount = new AtomicInteger(0);
    announcer = new DataSegmentAnnouncer() {

        @Override
        public void announceSegment(DataSegment segment) {
            segmentsAnnouncedByMe.add(segment);
            announceCount.incrementAndGet();
        }

        @Override
        public void unannounceSegment(DataSegment segment) {
            segmentsAnnouncedByMe.remove(segment);
            announceCount.decrementAndGet();
        }

        @Override
        public void announceSegments(Iterable<DataSegment> segments) {
            for (DataSegment segment : segments) {
                segmentsAnnouncedByMe.add(segment);
            }
            announceCount.addAndGet(Iterables.size(segments));
        }

        @Override
        public void unannounceSegments(Iterable<DataSegment> segments) {
            for (DataSegment segment : segments) {
                segmentsAnnouncedByMe.remove(segment);
            }
            announceCount.addAndGet(-Iterables.size(segments));
        }
    };
    segmentLoaderConfig = new SegmentLoaderConfig() {

        @Override
        public File getInfoDir() {
            return testStorageLocation.getInfoDir();
        }

        @Override
        public int getNumLoadingThreads() {
            return 5;
        }

        @Override
        public int getAnnounceIntervalMillis() {
            return 50;
        }

        @Override
        public List<StorageLocationConfig> getLocations() {
            return locations;
        }

        @Override
        public int getDropSegmentDelayMillis() {
            return 0;
        }
    };
    noAnnouncerSegmentLoaderConfig = new SegmentLoaderConfig() {

        @Override
        public File getInfoDir() {
            return testStorageLocation.getInfoDir();
        }

        @Override
        public int getNumLoadingThreads() {
            return 5;
        }

        @Override
        public int getAnnounceIntervalMillis() {
            return 0;
        }

        @Override
        public List<StorageLocationConfig> getLocations() {
            return locations;
        }

        @Override
        public int getDropSegmentDelayMillis() {
            return 0;
        }
    };
    segmentLoaderConfigNoLocations = new SegmentLoaderConfig() {

        @Override
        public int getNumLoadingThreads() {
            return 5;
        }

        @Override
        public int getAnnounceIntervalMillis() {
            return 50;
        }

        @Override
        public int getDropSegmentDelayMillis() {
            return 0;
        }
    };
    scheduledExecutorFactory = new ScheduledExecutorFactory() {

        @Override
        public ScheduledExecutorService create(int corePoolSize, String nameFormat) {
            /*
               Override normal behavoir by adding the runnable to a list so that you can make sure
               all the shceduled runnables are executed by explicitly calling run() on each item in the list
             */
            return new ScheduledThreadPoolExecutor(corePoolSize, Execs.makeThreadFactory(nameFormat)) {

                @Override
                public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
                    scheduledRunnable.add(command);
                    return null;
                }
            };
        }
    };
    segmentLoadDropHandler = new SegmentLoadDropHandler(jsonMapper, segmentLoaderConfig, announcer, Mockito.mock(DataSegmentServerAnnouncer.class), segmentManager, segmentCacheManager, scheduledExecutorFactory.create(5, "SegmentLoadDropHandlerTest-[%d]"), new ServerTypeConfig(ServerType.HISTORICAL));
}
Also used : SegmentManager(org.apache.druid.server.SegmentManager) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) DataSegment(org.apache.druid.timeline.DataSegment) TimeUnit(java.util.concurrent.TimeUnit) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) SegmentLoaderConfig(org.apache.druid.segment.loading.SegmentLoaderConfig) CacheTestSegmentCacheManager(org.apache.druid.segment.loading.CacheTestSegmentCacheManager) CacheTestSegmentLoader(org.apache.druid.segment.loading.CacheTestSegmentLoader) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) IOException(java.io.IOException) ScheduledFuture(java.util.concurrent.ScheduledFuture) ScheduledExecutorFactory(org.apache.druid.java.util.common.concurrent.ScheduledExecutorFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) File(java.io.File) ServerTypeConfig(org.apache.druid.guice.ServerTypeConfig) Before(org.junit.Before)

Example 9 with SegmentManager

use of org.apache.druid.server.SegmentManager in project druid by druid-io.

the class SegmentLoadDropHandlerTest method testProcessBatchLoadDropLoadSequenceForSameSegment.

@Test(timeout = 60_000L)
public void testProcessBatchLoadDropLoadSequenceForSameSegment() throws Exception {
    final SegmentManager segmentManager = Mockito.mock(SegmentManager.class);
    Mockito.when(segmentManager.loadSegment(ArgumentMatchers.any(), ArgumentMatchers.anyBoolean(), ArgumentMatchers.any())).thenReturn(true);
    Mockito.doNothing().when(segmentManager).dropSegment(ArgumentMatchers.any());
    final SegmentLoadDropHandler segmentLoadDropHandler = new SegmentLoadDropHandler(jsonMapper, noAnnouncerSegmentLoaderConfig, announcer, Mockito.mock(DataSegmentServerAnnouncer.class), segmentManager, segmentCacheManager, scheduledExecutorFactory.create(5, "SegmentLoadDropHandlerTest-[%d]"), new ServerTypeConfig(ServerType.HISTORICAL));
    segmentLoadDropHandler.start();
    DataSegment segment1 = makeSegment("batchtest1", "1", Intervals.of("P1d/2011-04-01"));
    List<DataSegmentChangeRequest> batch = ImmutableList.of(new SegmentChangeRequestLoad(segment1));
    // load the segment
    ListenableFuture<List<DataSegmentChangeRequestAndStatus>> future = segmentLoadDropHandler.processBatch(batch);
    for (Runnable runnable : scheduledRunnable) {
        runnable.run();
    }
    List<DataSegmentChangeRequestAndStatus> result = future.get();
    Assert.assertEquals(STATE.SUCCESS, result.get(0).getStatus().getState());
    scheduledRunnable.clear();
    // drop the segment
    batch = ImmutableList.of(new SegmentChangeRequestDrop(segment1));
    future = segmentLoadDropHandler.processBatch(batch);
    for (Runnable runnable : scheduledRunnable) {
        runnable.run();
    }
    result = future.get();
    Assert.assertEquals(STATE.SUCCESS, result.get(0).getStatus().getState());
    scheduledRunnable.clear();
    // check invocations after a load-drop sequence
    Mockito.verify(segmentManager, Mockito.times(1)).loadSegment(ArgumentMatchers.any(), ArgumentMatchers.anyBoolean(), ArgumentMatchers.any());
    Mockito.verify(segmentManager, Mockito.times(1)).dropSegment(ArgumentMatchers.any());
    // try to reload the segment - this should be a no-op since it might be the case that this is the first load client
    // with this request, we'll forget about the success of the load request
    batch = ImmutableList.of(new SegmentChangeRequestLoad(segment1));
    future = segmentLoadDropHandler.processBatch(batch);
    Assert.assertEquals(scheduledRunnable.size(), 0);
    result = future.get();
    Assert.assertEquals(STATE.SUCCESS, result.get(0).getStatus().getState());
    // check invocations - should stay the same
    Mockito.verify(segmentManager, Mockito.times(1)).loadSegment(ArgumentMatchers.any(), ArgumentMatchers.anyBoolean(), ArgumentMatchers.any());
    Mockito.verify(segmentManager, Mockito.times(1)).dropSegment(ArgumentMatchers.any());
    // try to reload the segment - this time the loader will know that is a fresh request to load
    // so, the segment manager will be asked to load
    batch = ImmutableList.of(new SegmentChangeRequestLoad(segment1));
    future = segmentLoadDropHandler.processBatch(batch);
    for (Runnable runnable : scheduledRunnable) {
        runnable.run();
    }
    result = future.get();
    Assert.assertEquals(STATE.SUCCESS, result.get(0).getStatus().getState());
    scheduledRunnable.clear();
    // check invocations - the load segment counter should bump up
    Mockito.verify(segmentManager, Mockito.times(2)).loadSegment(ArgumentMatchers.any(), ArgumentMatchers.anyBoolean(), ArgumentMatchers.any());
    Mockito.verify(segmentManager, Mockito.times(1)).dropSegment(ArgumentMatchers.any());
    segmentLoadDropHandler.stop();
}
Also used : SegmentManager(org.apache.druid.server.SegmentManager) DataSegment(org.apache.druid.timeline.DataSegment) DataSegmentChangeRequestAndStatus(org.apache.druid.server.coordination.SegmentLoadDropHandler.DataSegmentChangeRequestAndStatus) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ServerTypeConfig(org.apache.druid.guice.ServerTypeConfig) Test(org.junit.Test)

Aggregations

SegmentManager (org.apache.druid.server.SegmentManager)9 Before (org.junit.Before)5 ServerTypeConfig (org.apache.druid.guice.ServerTypeConfig)4 DataSegment (org.apache.druid.timeline.DataSegment)4 ImmutableList (com.google.common.collect.ImmutableList)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 BrokerInternalQueryConfig (org.apache.druid.client.BrokerInternalQueryConfig)3 File (java.io.File)2 Set (java.util.Set)2 QueryRunnerFactoryConglomerate (org.apache.druid.query.QueryRunnerFactoryConglomerate)2 MapJoinableFactory (org.apache.druid.segment.join.MapJoinableFactory)2 SegmentLoader (org.apache.druid.segment.loading.SegmentLoader)2 SegmentLoaderConfig (org.apache.druid.segment.loading.SegmentLoaderConfig)2 NoopServiceEmitter (org.apache.druid.server.metrics.NoopServiceEmitter)2 Test (org.junit.Test)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Optional (java.util.Optional)1