Search in sources :

Example 6 with SegmentLoaderConfig

use of org.apache.druid.segment.loading.SegmentLoaderConfig in project druid by druid-io.

the class IndexTaskTest method setup.

@Before
public void setup() throws IOException {
    appenderatorsManager = new TestAppenderatorsManager();
    final File cacheDir = temporaryFolder.newFolder();
    segmentCacheManager = new SegmentLocalCacheManager(new SegmentLoaderConfig() {

        @Override
        public List<StorageLocationConfig> getLocations() {
            return Collections.singletonList(new StorageLocationConfig(cacheDir, null, null));
        }
    }, jsonMapper);
    taskRunner = new TestTaskRunner();
}
Also used : StorageLocationConfig(org.apache.druid.segment.loading.StorageLocationConfig) SegmentLocalCacheManager(org.apache.druid.segment.loading.SegmentLocalCacheManager) SegmentLoaderConfig(org.apache.druid.segment.loading.SegmentLoaderConfig) File(java.io.File) Before(org.junit.Before)

Example 7 with SegmentLoaderConfig

use of org.apache.druid.segment.loading.SegmentLoaderConfig in project druid by druid-io.

the class DruidServerConfigTest method testServerMaxSizePrecedence.

@Test
public void testServerMaxSizePrecedence() throws Exception {
    String serverConfigWithDefaultSizeStr = "{\"maxSize\":0,\"tier\":\"_default_tier\",\"priority\":0," + "\"hiddenProperties\":[\"druid.metadata.storage.connector.password\"," + "\"druid.s3.accessKey\",\"druid.s3.secretKey\"]}\n";
    String serverConfigWithNonDefaultSizeStr = "{\"maxSize\":123456,\"tier\":\"_default_tier\",\"priority\":0," + "\"hiddenProperties\":[\"druid.metadata.storage.connector.password\"," + "\"druid.s3.accessKey\",\"druid.s3.secretKey\"]}\n";
    final List<StorageLocationConfig> locations = new ArrayList<>();
    final StorageLocationConfig locationConfig1 = new StorageLocationConfig(testSegmentCacheDir1, 10000000000L, null);
    locations.add(locationConfig1);
    mapper.setInjectableValues(new InjectableValues.Std().addValue(ObjectMapper.class, new DefaultObjectMapper()).addValue(SegmentLoaderConfig.class, new SegmentLoaderConfig().withLocations(locations)));
    DruidServerConfig serverConfigWithDefaultSize = mapper.readValue(mapper.writeValueAsString(mapper.readValue(serverConfigWithDefaultSizeStr, DruidServerConfig.class)), DruidServerConfig.class);
    DruidServerConfig serverConfigWithNonDefaultSize = mapper.readValue(mapper.writeValueAsString(mapper.readValue(serverConfigWithNonDefaultSizeStr, DruidServerConfig.class)), DruidServerConfig.class);
    Assert.assertEquals(serverConfigWithDefaultSize.getMaxSize(), 10000000000L);
    Assert.assertEquals(serverConfigWithNonDefaultSize.getMaxSize(), 123456L);
}
Also used : StorageLocationConfig(org.apache.druid.segment.loading.StorageLocationConfig) ArrayList(java.util.ArrayList) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) SegmentLoaderConfig(org.apache.druid.segment.loading.SegmentLoaderConfig) InjectableValues(com.fasterxml.jackson.databind.InjectableValues) Test(org.junit.Test)

Example 8 with SegmentLoaderConfig

use of org.apache.druid.segment.loading.SegmentLoaderConfig 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 SegmentLoaderConfig

use of org.apache.druid.segment.loading.SegmentLoaderConfig in project druid by druid-io.

the class SegmentLoadDropHandlerTest method testStartStop.

@Test
public void testStartStop() throws Exception {
    SegmentLoadDropHandler handler = new SegmentLoadDropHandler(jsonMapper, new SegmentLoaderConfig() {

        @Override
        public File getInfoDir() {
            return infoDir;
        }

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

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

        @Override
        public int getAnnounceIntervalMillis() {
            return 50;
        }
    }, announcer, Mockito.mock(DataSegmentServerAnnouncer.class), segmentManager, segmentCacheManager, new ServerTypeConfig(ServerType.HISTORICAL));
    Set<DataSegment> segments = new HashSet<>();
    for (int i = 0; i < COUNT; ++i) {
        segments.add(makeSegment("test" + i, "1", Intervals.of("P1d/2011-04-01")));
        segments.add(makeSegment("test" + i, "1", Intervals.of("P1d/2011-04-02")));
        segments.add(makeSegment("test" + i, "2", Intervals.of("P1d/2011-04-02")));
        segments.add(makeSegment("test_two" + i, "1", Intervals.of("P1d/2011-04-01")));
        segments.add(makeSegment("test_two" + i, "1", Intervals.of("P1d/2011-04-02")));
    }
    for (DataSegment segment : segments) {
        testStorageLocation.writeSegmentInfoToCache(segment);
    }
    testStorageLocation.checkInfoCache(segments);
    Assert.assertTrue(segmentManager.getDataSourceCounts().isEmpty());
    handler.start();
    Assert.assertTrue(!segmentManager.getDataSourceCounts().isEmpty());
    for (int i = 0; i < COUNT; ++i) {
        Assert.assertEquals(3L, segmentManager.getDataSourceCounts().get("test" + i).longValue());
        Assert.assertEquals(2L, segmentManager.getDataSourceCounts().get("test_two" + i).longValue());
    }
    Assert.assertEquals(5 * COUNT, announceCount.get());
    handler.stop();
    for (DataSegment segment : segments) {
        testStorageLocation.deleteSegmentInfoFromCache(segment);
    }
    Assert.assertEquals(0, infoDir.listFiles().length);
    Assert.assertTrue(infoDir.delete());
}
Also used : ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) SegmentLoaderConfig(org.apache.druid.segment.loading.SegmentLoaderConfig) File(java.io.File) DataSegment(org.apache.druid.timeline.DataSegment) ServerTypeConfig(org.apache.druid.guice.ServerTypeConfig) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

SegmentLoaderConfig (org.apache.druid.segment.loading.SegmentLoaderConfig)9 StorageLocationConfig (org.apache.druid.segment.loading.StorageLocationConfig)5 Before (org.junit.Before)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 ServerTypeConfig (org.apache.druid.guice.ServerTypeConfig)4 SegmentLocalCacheManager (org.apache.druid.segment.loading.SegmentLocalCacheManager)4 NoopServiceEmitter (org.apache.druid.server.metrics.NoopServiceEmitter)4 Test (org.junit.Test)4 List (java.util.List)3 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)3 SegmentLocalCacheLoader (org.apache.druid.segment.loading.SegmentLocalCacheLoader)3 SegmentManager (org.apache.druid.server.SegmentManager)3 DataSegment (org.apache.druid.timeline.DataSegment)3 InjectableValues (com.fasterxml.jackson.databind.InjectableValues)2 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)2 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)2 ImmutableList (com.google.common.collect.ImmutableList)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 IndexIO (org.apache.druid.segment.IndexIO)2