Search in sources :

Example 1 with ServiceEnvironment

use of org.apache.accumulo.core.spi.common.ServiceEnvironment in project accumulo by apache.

the class TabletServerResourceManager method executeReadAhead.

public void executeReadAhead(KeyExtent tablet, ScanDispatcher dispatcher, ScanSession scanInfo, Runnable task) {
    task = ScanSession.wrap(scanInfo, task);
    if (tablet.isRootTablet()) {
        // TODO make meta dispatch??
        scanInfo.scanParams.setScanDispatch(ScanDispatch.builder().build());
        task.run();
    } else if (tablet.isMeta()) {
        // TODO make meta dispatch??
        scanInfo.scanParams.setScanDispatch(ScanDispatch.builder().build());
        scanExecutors.get("meta").execute(task);
    } else {
        DispatchParameters params = new DispatchParamsImpl() {

            // in scan critical path so only create ServiceEnv if needed
            private final Supplier<ServiceEnvironment> senvSupplier = Suppliers.memoize(() -> new ServiceEnvironmentImpl(context));

            @Override
            public ScanInfo getScanInfo() {
                return scanInfo;
            }

            @Override
            public Map<String, ScanExecutor> getScanExecutors() {
                return scanExecutorChoices;
            }

            @Override
            public ServiceEnvironment getServiceEnv() {
                return senvSupplier.get();
            }
        };
        ScanDispatch prefs = dispatcher.dispatch(params);
        scanInfo.scanParams.setScanDispatch(prefs);
        ThreadPoolExecutor executor = scanExecutors.get(prefs.getExecutorName());
        if (executor == null) {
            log.warn("For table id {}, {} dispatched to non-existent executor {} Using default executor.", tablet.tableId(), dispatcher.getClass().getName(), prefs.getExecutorName());
            executor = scanExecutors.get(SimpleScanDispatcher.DEFAULT_SCAN_EXECUTOR_NAME);
        } else if ("meta".equals(prefs.getExecutorName())) {
            log.warn("For table id {}, {} dispatched to meta executor. Using default executor.", tablet.tableId(), dispatcher.getClass().getName());
            executor = scanExecutors.get(SimpleScanDispatcher.DEFAULT_SCAN_EXECUTOR_NAME);
        }
        executor.execute(task);
    }
}
Also used : ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) ServiceEnvironmentImpl(org.apache.accumulo.server.ServiceEnvironmentImpl) DispatchParameters(org.apache.accumulo.core.spi.scan.ScanDispatcher.DispatchParameters) ScanInfo(org.apache.accumulo.core.spi.scan.ScanInfo) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Collectors.toUnmodifiableMap(java.util.stream.Collectors.toUnmodifiableMap) ScanDispatch(org.apache.accumulo.core.spi.scan.ScanDispatch)

Example 2 with ServiceEnvironment

use of org.apache.accumulo.core.spi.common.ServiceEnvironment in project accumulo by apache.

the class DefaultCompactionPlannerTest method createPlanner.

private static DefaultCompactionPlanner createPlanner(boolean withHugeExecutor) {
    DefaultCompactionPlanner planner = new DefaultCompactionPlanner();
    Configuration conf = EasyMock.createMock(Configuration.class);
    EasyMock.expect(conf.isSet(EasyMock.anyString())).andReturn(false).anyTimes();
    ServiceEnvironment senv = EasyMock.createMock(ServiceEnvironment.class);
    EasyMock.expect(senv.getConfiguration()).andReturn(conf).anyTimes();
    EasyMock.replay(conf, senv);
    StringBuilder execBldr = new StringBuilder("[{'name':'small','type': 'internal','maxSize':'32M','numThreads':1}," + "{'name':'medium','type': 'internal','maxSize':'128M','numThreads':2}," + "{'name':'large','type': 'internal','maxSize':'512M','numThreads':3}");
    if (withHugeExecutor) {
        execBldr.append(",{'name':'huge','type': 'internal','numThreads':4}]");
    } else {
        execBldr.append("]");
    }
    String executors = execBldr.toString().replaceAll("'", "\"");
    planner.init(new CompactionPlanner.InitParameters() {

        @Override
        public ServiceEnvironment getServiceEnvironment() {
            return senv;
        }

        @Override
        public Map<String, String> getOptions() {
            return Map.of("executors", executors, "maxOpen", "15");
        }

        @Override
        public String getFullyQualifiedOption(String key) {
            assertEquals("maxOpen", key);
            return Property.TSERV_COMPACTION_SERVICE_PREFIX.getKey() + "cs1.planner.opts." + key;
        }

        @Override
        public ExecutorManager getExecutorManager() {
            return new ExecutorManager() {

                @Override
                public CompactionExecutorId createExecutor(String name, int threads) {
                    switch(name) {
                        case "small":
                            assertEquals(1, threads);
                            break;
                        case "medium":
                            assertEquals(2, threads);
                            break;
                        case "large":
                            assertEquals(3, threads);
                            break;
                        case "huge":
                            assertEquals(4, threads);
                            break;
                        default:
                            fail("Unexpected name " + name);
                            break;
                    }
                    return CompactionExecutorIdImpl.externalId(name);
                }

                @Override
                public CompactionExecutorId getExternalExecutor(String name) {
                    throw new UnsupportedOperationException();
                }
            };
        }
    });
    return planner;
}
Also used : Configuration(org.apache.accumulo.core.spi.common.ServiceEnvironment.Configuration) ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) Map(java.util.Map)

Example 3 with ServiceEnvironment

use of org.apache.accumulo.core.spi.common.ServiceEnvironment in project accumulo by apache.

the class DefaultCompactionPlannerTest method testErrorOnlyOneMaxSize.

/**
 * Tests executors can only have one without a max size.
 */
@Test
public void testErrorOnlyOneMaxSize() {
    DefaultCompactionPlanner planner = new DefaultCompactionPlanner();
    Configuration conf = EasyMock.createMock(Configuration.class);
    EasyMock.expect(conf.isSet(EasyMock.anyString())).andReturn(false).anyTimes();
    ServiceEnvironment senv = EasyMock.createMock(ServiceEnvironment.class);
    EasyMock.expect(senv.getConfiguration()).andReturn(conf).anyTimes();
    EasyMock.replay(conf, senv);
    String executors = getExecutors("'type': 'internal','maxSize':'32M','numThreads':1", "'type': 'internal','numThreads':2", "'type': 'external','queue':'q1'");
    var e = assertThrows(IllegalArgumentException.class, () -> planner.init(getInitParams(senv, executors)), "Failed to throw error");
    assertTrue(e.getMessage().contains("maxSize"), "Error message didn't contain maxSize");
}
Also used : ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) Configuration(org.apache.accumulo.core.spi.common.ServiceEnvironment.Configuration) Test(org.junit.jupiter.api.Test)

Example 4 with ServiceEnvironment

use of org.apache.accumulo.core.spi.common.ServiceEnvironment in project accumulo by apache.

the class DefaultCompactionPlannerTest method testErrorInternalTypeNoNumThreads.

/**
 * Tests internal type executor with no numThreads set throws error
 */
@Test
public void testErrorInternalTypeNoNumThreads() {
    DefaultCompactionPlanner planner = new DefaultCompactionPlanner();
    Configuration conf = EasyMock.createMock(Configuration.class);
    EasyMock.expect(conf.isSet(EasyMock.anyString())).andReturn(false).anyTimes();
    ServiceEnvironment senv = EasyMock.createMock(ServiceEnvironment.class);
    EasyMock.expect(senv.getConfiguration()).andReturn(conf).anyTimes();
    EasyMock.replay(conf, senv);
    String executors = getExecutors("'type': 'internal','maxSize':'32M'", "'type': 'internal','maxSize':'128M','numThreads':2", "'type': 'internal','maxSize':'512M','numThreads':3");
    var e = assertThrows(NullPointerException.class, () -> planner.init(getInitParams(senv, executors)), "Failed to throw error");
    assertTrue(e.getMessage().contains("numThreads"), "Error message didn't contain numThreads");
}
Also used : ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) Configuration(org.apache.accumulo.core.spi.common.ServiceEnvironment.Configuration) Test(org.junit.jupiter.api.Test)

Example 5 with ServiceEnvironment

use of org.apache.accumulo.core.spi.common.ServiceEnvironment in project accumulo by apache.

the class DefaultCompactionPlannerTest method testErrorDuplicateMaxSize.

/**
 * Tests executors can only have one without a max size.
 */
@Test
public void testErrorDuplicateMaxSize() {
    DefaultCompactionPlanner planner = new DefaultCompactionPlanner();
    Configuration conf = EasyMock.createMock(Configuration.class);
    EasyMock.expect(conf.isSet(EasyMock.anyString())).andReturn(false).anyTimes();
    ServiceEnvironment senv = EasyMock.createMock(ServiceEnvironment.class);
    EasyMock.expect(senv.getConfiguration()).andReturn(conf).anyTimes();
    EasyMock.replay(conf, senv);
    String executors = getExecutors("'type': 'internal','maxSize':'32M','numThreads':1", "'type': 'internal','maxSize':'128M','numThreads':2", "'type': 'external','maxSize':'128M','queue':'q1'");
    var e = assertThrows(IllegalArgumentException.class, () -> planner.init(getInitParams(senv, executors)), "Failed to throw error");
    assertTrue(e.getMessage().contains("maxSize"), "Error message didn't contain maxSize");
}
Also used : ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) Configuration(org.apache.accumulo.core.spi.common.ServiceEnvironment.Configuration) Test(org.junit.jupiter.api.Test)

Aggregations

ServiceEnvironment (org.apache.accumulo.core.spi.common.ServiceEnvironment)15 Map (java.util.Map)8 HashMap (java.util.HashMap)7 ServiceEnvironmentImpl (org.apache.accumulo.server.ServiceEnvironmentImpl)7 Configuration (org.apache.accumulo.core.spi.common.ServiceEnvironment.Configuration)6 TableId (org.apache.accumulo.core.data.TableId)5 Test (org.junit.jupiter.api.Test)5 Collection (java.util.Collection)3 SortedMap (java.util.SortedMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)3 Cache (com.google.common.cache.Cache)2 CacheBuilder (com.google.common.cache.CacheBuilder)2 IOException (java.io.IOException)2 Collections (java.util.Collections)2 EnumMap (java.util.EnumMap)2 Optional (java.util.Optional)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 PluginEnvironment (org.apache.accumulo.core.client.PluginEnvironment)2 ScanDispatcher (org.apache.accumulo.core.spi.scan.ScanDispatcher)2