Search in sources :

Example 1 with RamAccountingContext

use of io.crate.breaker.RamAccountingContext in project crate by crate.

the class JobsLogsTest method createScheduler.

@Before
public void createScheduler() {
    scheduler = Executors.newSingleThreadScheduledExecutor();
    ramAccountingContext = new RamAccountingContext("testRamAccountingContext", breakerService.getBreaker(CrateCircuitBreakerService.JOBS_LOG));
}
Also used : RamAccountingContext(io.crate.breaker.RamAccountingContext) Before(org.junit.Before)

Example 2 with RamAccountingContext

use of io.crate.breaker.RamAccountingContext in project crate by crate.

the class RemoteCollectorFactory method createCollector.

/**
     * create a RemoteCollector
     * The RemoteCollector will collect data from another node using a wormhole as if it was collecting on this node.
     * <p>
     * This should only be used if a shard is not available on the current node due to a relocation
     */
public CrateCollector.Builder createCollector(String index, Integer shardId, RoutedCollectPhase collectPhase, final RamAccountingContext ramAccountingContext) {
    // new job because subContexts can't be merged into an existing job
    final UUID childJobId = UUID.randomUUID();
    IndexShardRoutingTable shardRoutings = clusterService.state().routingTable().shardRoutingTable(index, shardId);
    // for update operations primaryShards must be used
    // (for others that wouldn't be the case, but at this point it is not easily visible which is the case)
    ShardRouting shardRouting = shardRoutings.primaryShard();
    final String remoteNodeId = shardRouting.currentNodeId();
    assert remoteNodeId != null : "primaryShard not assigned :(";
    final String localNodeId = clusterService.localNode().getId();
    final RoutedCollectPhase newCollectPhase = createNewCollectPhase(childJobId, collectPhase, index, shardId, remoteNodeId);
    return consumer -> new RemoteCollector(childJobId, localNodeId, remoteNodeId, transportActionProvider.transportJobInitAction(), transportActionProvider.transportKillJobsNodeAction(), jobContextService, ramAccountingContext, consumer, newCollectPhase);
}
Also used : ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) java.util(java.util) Projections(io.crate.planner.projection.Projections) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Inject(org.elasticsearch.common.inject.Inject) TreeMapBuilder(io.crate.core.collections.TreeMapBuilder) Routing(io.crate.metadata.Routing) Singleton(org.elasticsearch.common.inject.Singleton) ClusterService(org.elasticsearch.cluster.ClusterService) JobContextService(io.crate.jobs.JobContextService) TransportActionProvider(io.crate.executor.transport.TransportActionProvider) DistributionInfo(io.crate.planner.distribution.DistributionInfo) RamAccountingContext(io.crate.breaker.RamAccountingContext) RemoteCollector(io.crate.operation.collect.collectors.RemoteCollector) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) RemoteCollector(io.crate.operation.collect.collectors.RemoteCollector) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase)

Example 3 with RamAccountingContext

use of io.crate.breaker.RamAccountingContext in project crate by crate.

the class RamAccountingQueue method offer.

@Override
public boolean offer(T o) {
    context.addBytesWithoutBreaking(sizeEstimator.estimateSize(o));
    if (context.exceededBreaker() && exceeded.compareAndSet(false, true)) {
        LOGGER.error("Memory limit for breaker [{}] was exceeded. Queue [{}] is cleared.", breaker.getName(), context.contextId());
        // clear queue, close context and create new one
        close();
        context = new RamAccountingContext(contextId(), breaker);
        // add bytes to new context
        context.addBytesWithoutBreaking(sizeEstimator.estimateSize(o));
        exceeded.set(false);
    }
    return delegate.offer(o);
}
Also used : RamAccountingContext(io.crate.breaker.RamAccountingContext)

Example 4 with RamAccountingContext

use of io.crate.breaker.RamAccountingContext in project crate by crate.

the class LuceneBatchIteratorTest method testLuceneBatchIterator.

@Test
public void testLuceneBatchIterator() throws Exception {
    BatchIteratorTester tester = new BatchIteratorTester(() -> {
        return new LuceneBatchIterator(indexSearcher, new MatchAllDocsQuery(), null, false, new CollectorContext(mock(IndexFieldDataService.class), new CollectorFieldsVisitor(0)), new RamAccountingContext("dummy", new NoopCircuitBreaker("dummy")), columnRefs, columnRefs);
    });
    tester.verifyResultAndEdgeCaseBehaviour(expectedResult);
}
Also used : RamAccountingContext(io.crate.breaker.RamAccountingContext) BatchIteratorTester(io.crate.testing.BatchIteratorTester) CollectorContext(io.crate.operation.reference.doc.lucene.CollectorContext) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) NoopCircuitBreaker(org.elasticsearch.common.breaker.NoopCircuitBreaker) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

RamAccountingContext (io.crate.breaker.RamAccountingContext)4 TreeMapBuilder (io.crate.core.collections.TreeMapBuilder)1 TransportActionProvider (io.crate.executor.transport.TransportActionProvider)1 JobContextService (io.crate.jobs.JobContextService)1 Routing (io.crate.metadata.Routing)1 RemoteCollector (io.crate.operation.collect.collectors.RemoteCollector)1 CollectorContext (io.crate.operation.reference.doc.lucene.CollectorContext)1 DistributionInfo (io.crate.planner.distribution.DistributionInfo)1 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)1 Projections (io.crate.planner.projection.Projections)1 CrateUnitTest (io.crate.test.integration.CrateUnitTest)1 BatchIteratorTester (io.crate.testing.BatchIteratorTester)1 java.util (java.util)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 ClusterService (org.elasticsearch.cluster.ClusterService)1 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)1 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)1 NoopCircuitBreaker (org.elasticsearch.common.breaker.NoopCircuitBreaker)1 Inject (org.elasticsearch.common.inject.Inject)1 Singleton (org.elasticsearch.common.inject.Singleton)1