use of io.crate.memory.OnHeapMemoryManager in project crate by crate.
the class RootTaskTest method testFailureClosesAllSubContexts.
@Test
public void testFailureClosesAllSubContexts() throws Throwable {
String localNodeId = "localNodeId";
RoutedCollectPhase collectPhase = Mockito.mock(RoutedCollectPhase.class);
Routing routing = Mockito.mock(Routing.class);
when(routing.containsShards(localNodeId)).thenReturn(false);
when(collectPhase.phaseId()).thenReturn(1);
when(collectPhase.routing()).thenReturn(routing);
when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.DOC);
RootTask.Builder builder = new RootTask.Builder(logger, UUID.randomUUID(), "dummy-user", coordinatorNode, Collections.emptySet(), mock(JobsLogs.class));
CollectTask collectChildTask = new CollectTask(collectPhase, CoordinatorTxnCtx.systemTransactionContext(), mock(MapSideDataCollectOperation.class), RamAccounting.NO_ACCOUNTING, ramAccounting -> new OnHeapMemoryManager(ramAccounting::addBytes), new TestingRowConsumer(), mock(SharedShardContexts.class), Version.CURRENT, 4096);
TestingRowConsumer batchConsumer = new TestingRowConsumer();
PageBucketReceiver pageBucketReceiver = new CumulativePageBucketReceiver("n1", 2, Runnable::run, new Streamer[] { IntegerType.INSTANCE.streamer() }, batchConsumer, PassThroughPagingIterator.oneShot(), 1);
DistResultRXTask distResultRXTask = spy(new DistResultRXTask(2, "dummy", pageBucketReceiver, RamAccounting.NO_ACCOUNTING, 1));
builder.addTask(collectChildTask);
builder.addTask(distResultRXTask);
RootTask rootTask = builder.build();
Exception failure = new Exception("failure!");
collectChildTask.kill(failure);
// other contexts must be killed with same failure
verify(distResultRXTask, times(1)).kill(failure);
assertThat(rootTask.getTask(1).completionFuture().isDone(), is(true));
assertThat(rootTask.getTask(2).completionFuture().isDone(), is(true));
}
use of io.crate.memory.OnHeapMemoryManager in project crate by crate.
the class CollectTaskTest method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
localNodeId = "dummyLocalNodeId";
collectPhase = Mockito.mock(RoutedCollectPhase.class);
Routing routing = Mockito.mock(Routing.class);
when(routing.containsShards(localNodeId)).thenReturn(true);
when(collectPhase.routing()).thenReturn(routing);
when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.DOC);
collectOperation = mock(MapSideDataCollectOperation.class);
Mockito.doAnswer(new Answer<>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Runnable runnable = invocation.getArgument(0);
runnable.run();
return null;
}
}).when(collectOperation).launch(Mockito.any(), Mockito.anyString());
consumer = new TestingRowConsumer();
collectTask = new CollectTask(collectPhase, CoordinatorTxnCtx.systemTransactionContext(), collectOperation, RamAccounting.NO_ACCOUNTING, ramAccounting -> new OnHeapMemoryManager(ramAccounting::addBytes), consumer, mock(SharedShardContexts.class), Version.CURRENT, 4096);
}
use of io.crate.memory.OnHeapMemoryManager in project crate by crate.
the class AbstractWindowFunctionTest method prepareFunctions.
@Before
public void prepareFunctions() {
DocTableInfo tableInfo = SQLExecutor.tableInfo(new RelationName("doc", "t1"), "create table doc.t1 (x int, y bigint, z string, d double)", clusterService);
DocTableRelation tableRelation = new DocTableRelation(tableInfo);
Map<RelationName, AnalyzedRelation> tableSources = Map.of(tableInfo.ident(), tableRelation);
memoryManager = new OnHeapMemoryManager(bytes -> {
});
sqlExpressions = new SqlExpressions(tableSources, tableRelation, User.CRATE_USER, additionalModules);
inputFactory = new InputFactory(sqlExpressions.nodeCtx);
}
use of io.crate.memory.OnHeapMemoryManager in project crate by crate.
the class ProjectingRowConsumerTest method prepare.
@Before
public void prepare() {
nodeCtx = createNodeContext();
memoryManager = new OnHeapMemoryManager(usedBytes -> {
});
projectorFactory = new ProjectionToProjectorVisitor(clusterService, new NodeLimits(new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)), new NoneCircuitBreakerService(), nodeCtx, THREAD_POOL, Settings.EMPTY, mock(TransportActionProvider.class, Answers.RETURNS_DEEP_STUBS), new InputFactory(nodeCtx), new EvaluatingNormalizer(nodeCtx, RowGranularity.SHARD, r -> Literal.ofUnchecked(r.valueType(), r.valueType().implicitCast("1")), null), t -> null, t -> null, Version.CURRENT, new ShardId("dummy", UUID.randomUUID().toString(), 0), Map.of(LocalFsFileOutputFactory.NAME, new LocalFsFileOutputFactory()));
}
use of io.crate.memory.OnHeapMemoryManager in project crate by crate.
the class GroupingLongCollectorBenchmark method createGroupingCollector.
@Setup
public void createGroupingCollector() throws Exception {
IndexWriter iw = new IndexWriter(new ByteBuffersDirectory(), new IndexWriterConfig(new StandardAnalyzer()));
Functions functions = new ModulesBuilder().add(new AggregationImplModule()).createInjector().getInstance(Functions.class);
SumAggregation<?> sumAgg = (SumAggregation<?>) functions.getQualified(Signature.aggregate(SumAggregation.NAME, DataTypes.INTEGER.getTypeSignature(), DataTypes.LONG.getTypeSignature()), List.of(DataTypes.INTEGER), DataTypes.INTEGER);
var memoryManager = new OnHeapMemoryManager(bytes -> {
});
groupBySumCollector = createGroupBySumCollector(sumAgg, memoryManager);
int size = 20_000_000;
rows = new ArrayList<>(size);
numbers = new long[size];
for (int i = 0; i < size; i++) {
long value = (long) i % 200;
rows.add(new Row1(value));
numbers[i] = value;
var doc = new Document();
doc.add(new NumericDocValuesField("x", value));
doc.add(new SortedNumericDocValuesField("y", value));
iw.addDocument(doc);
}
iw.commit();
iw.forceMerge(1, true);
searcher = new IndexSearcher(DirectoryReader.open(iw));
}
Aggregations