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