Search in sources :

Example 6 with StateStoreProvider

use of io.prestosql.statestore.StateStoreProvider in project hetu-core by openlookeng.

the class TestSplitCacheStateInitializer method testCreateStateCollectionIfNotExists.

@Test
public void testCreateStateCollectionIfNotExists() {
    StateStoreProvider provider = mock(StateStoreProvider.class);
    StateStore stateStore = mock(StateStore.class);
    when(stateStore.getName()).thenReturn("mock");
    when(stateStore.getStateCollection(StateStoreConstants.SPLIT_CACHE_METADATA_NAME)).thenReturn(null).thenReturn(new MockStateMap<>(StateStoreConstants.SPLIT_CACHE_METADATA_NAME, new HashMap<>()));
    // simulate behaviour wait until state store is ready
    when(provider.getStateStore()).thenReturn(stateStore);
    SplitCacheMap splitCacheMap = createNew();
    assertFalse(splitCacheMap.cacheExists(table1QN));
    assertFalse(splitCacheMap.cacheExists(table2QN));
    AtomicReference<SplitCacheStateInitializer.InitializationStatus> status = new AtomicReference<>(SplitCacheStateInitializer.InitializationStatus.INITIALIZING);
    SplitCacheStateInitializer initializer = new SplitCacheStateInitializer(provider, splitCacheMap, new Duration(300, TimeUnit.MILLISECONDS), new Duration(1, TimeUnit.SECONDS), objectMapper, status);
    try {
        initializer.start();
        // sleep for sometime till local split cache map is initialized
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        // ignore - nothing to do here
        }
    } finally {
        initializer.stop();
    }
    verify(provider, atLeastOnce()).getStateStore();
    verify(stateStore, times(1)).createStateMap(eq(StateStoreConstants.SPLIT_CACHE_METADATA_NAME), any(SplitCacheStateStoreChangesListener.class));
    assertEquals(status.get(), SplitCacheStateInitializer.InitializationStatus.COMPLETED);
}
Also used : HashMap(java.util.HashMap) StateStore(io.prestosql.spi.statestore.StateStore) AtomicReference(java.util.concurrent.atomic.AtomicReference) Duration(io.airlift.units.Duration) StateStoreProvider(io.prestosql.statestore.StateStoreProvider) Test(org.testng.annotations.Test)

Example 7 with StateStoreProvider

use of io.prestosql.statestore.StateStoreProvider in project hetu-core by openlookeng.

the class TestSplitCacheStateManager method testStartAndStopServicesWhenStateStoreDisabled.

@Test
public void testStartAndStopServicesWhenStateStoreDisabled() {
    StateStoreProvider provider = mock(StateStoreProvider.class);
    when(provider.getStateStore()).thenReturn(null);
    PropertyService.setProperty(HetuConstant.SPLIT_CACHE_MAP_ENABLED, true);
    PropertyService.setProperty(HetuConstant.MULTI_COORDINATOR_ENABLED, false);
    SplitCacheMap splitCacheMap = createNew(true);
    SplitCacheStateManager manager = new SplitCacheStateManager(provider, metadata, splitCacheMap);
    manager.startStateServices();
    manager.stopStateServices();
    assertNotNull(SplitCacheMap.getInstance());
}
Also used : StateStoreProvider(io.prestosql.statestore.StateStoreProvider) Test(org.testng.annotations.Test)

Example 8 with StateStoreProvider

use of io.prestosql.statestore.StateStoreProvider in project hetu-core by openlookeng.

the class TestSplitCacheStateManager method testStartAndStopServicesWhenSplitCacheDisabled.

@Test
public void testStartAndStopServicesWhenSplitCacheDisabled() {
    StateStoreProvider provider = mock(StateStoreProvider.class);
    when(provider.getStateStore()).thenReturn(null);
    PropertyService.setProperty(HetuConstant.SPLIT_CACHE_MAP_ENABLED, false);
    PropertyService.setProperty(HetuConstant.MULTI_COORDINATOR_ENABLED, true);
    SplitCacheMap splitCacheMap = createNew(false);
    SplitCacheStateManager manager = new SplitCacheStateManager(provider, metadata, splitCacheMap);
    manager.startStateServices();
    manager.stopStateServices();
    assertNull(SplitCacheMap.getInstance());
}
Also used : StateStoreProvider(io.prestosql.statestore.StateStoreProvider) Test(org.testng.annotations.Test)

Example 9 with StateStoreProvider

use of io.prestosql.statestore.StateStoreProvider in project boostkit-bigdata by kunpengcompute.

the class OmniLocalQueryRunner method createDrivers.

private List<Driver> createDrivers(Session session, Plan plan, OutputFactory outputFactory, TaskContext taskContext) {
    if (printPlan) {
        System.out.println(PlanPrinter.textLogicalPlan(plan.getRoot(), plan.getTypes(), metadata, plan.getStatsAndCosts(), session, 0, false));
    }
    SubPlan subplan = planFragmenter.createSubPlans(session, plan, true, WarningCollector.NOOP);
    if (!subplan.getChildren().isEmpty()) {
        throw new AssertionError("Expected subplan to have no children");
    }
    NodeInfo nodeInfo = new NodeInfo("test");
    FileSystemClientManager fileSystemClientManager = new FileSystemClientManager();
    SeedStoreManager seedStoreManager = new SeedStoreManager(fileSystemClientManager);
    StateStoreProvider stateStoreProvider = new LocalStateStoreProvider(seedStoreManager);
    LocalExecutionPlanner executionPlanner = new LocalExecutionPlanner(metadata, new TypeAnalyzer(sqlParser, metadata), Optional.empty(), pageSourceManager, indexManager, nodePartitioningManager, pageSinkManager, null, expressionCompiler, pageFunctionCompiler, joinFilterFunctionCompiler, new IndexJoinLookupStats(), this.taskManagerConfig, spillerFactory, singleStreamSpillerFactory, partitioningSpillerFactory, new PagesIndex.TestingFactory(false), joinCompiler, new LookupJoinOperators(), new OrderingCompiler(), nodeInfo, stateStoreProvider, new StateStoreListenerManager(stateStoreProvider), new DynamicFilterCacheManager(), heuristicIndexerManager, cubeManager);
    // plan query
    StageExecutionDescriptor stageExecutionDescriptor = subplan.getFragment().getStageExecutionDescriptor();
    LocalExecutionPlan localExecutionPlan = executionPlanner.plan(taskContext, stageExecutionDescriptor, subplan.getFragment().getRoot(), subplan.getFragment().getPartitioningScheme().getOutputLayout(), plan.getTypes(), subplan.getFragment().getPartitionedSources(), null, outputFactory, Optional.empty(), Optional.empty(), null);
    // generate sources
    List<TaskSource> sources = new ArrayList<>();
    long sequenceId = 0;
    for (TableScanNode tableScan : findTableScanNodes(subplan.getFragment().getRoot())) {
        TableHandle table = tableScan.getTable();
        SplitSource splitSource = splitManager.getSplits(session, table, stageExecutionDescriptor.isScanGroupedExecution(tableScan.getId()) ? GROUPED_SCHEDULING : UNGROUPED_SCHEDULING, null, Optional.empty(), Collections.emptyMap(), ImmutableSet.of(), tableScan.getStrategy() != ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, tableScan.getId());
        ImmutableSet.Builder<ScheduledSplit> scheduledSplits = ImmutableSet.builder();
        while (!splitSource.isFinished()) {
            for (Split split : getNextBatch(splitSource)) {
                scheduledSplits.add(new ScheduledSplit(sequenceId++, tableScan.getId(), split));
            }
        }
        sources.add(new TaskSource(tableScan.getId(), scheduledSplits.build(), true));
    }
    // create drivers
    List<Driver> drivers = new ArrayList<>();
    Map<PlanNodeId, DriverFactory> driverFactoriesBySource = new HashMap<>();
    for (DriverFactory driverFactory : localExecutionPlan.getDriverFactories()) {
        for (int i = 0; i < driverFactory.getDriverInstances().orElse(1); i++) {
            if (driverFactory.getSourceId().isPresent()) {
                checkState(driverFactoriesBySource.put(driverFactory.getSourceId().get(), driverFactory) == null);
            } else {
                DriverContext driverContext = taskContext.addPipelineContext(driverFactory.getPipelineId(), driverFactory.isInputDriver(), driverFactory.isOutputDriver(), false).addDriverContext();
                Driver driver = driverFactory.createDriver(driverContext);
                drivers.add(driver);
            }
        }
    }
    // add sources to the drivers
    ImmutableSet<PlanNodeId> partitionedSources = ImmutableSet.copyOf(subplan.getFragment().getPartitionedSources());
    for (TaskSource source : sources) {
        DriverFactory driverFactory = driverFactoriesBySource.get(source.getPlanNodeId());
        checkState(driverFactory != null);
        boolean partitioned = partitionedSources.contains(driverFactory.getSourceId().get());
        for (ScheduledSplit split : source.getSplits()) {
            DriverContext driverContext = taskContext.addPipelineContext(driverFactory.getPipelineId(), driverFactory.isInputDriver(), driverFactory.isOutputDriver(), partitioned).addDriverContext();
            Driver driver = driverFactory.createDriver(driverContext);
            driver.updateSource(new TaskSource(split.getPlanNodeId(), ImmutableSet.of(split), true));
            drivers.add(driver);
        }
    }
    for (DriverFactory driverFactory : localExecutionPlan.getDriverFactories()) {
        driverFactory.noMoreDrivers();
    }
    return ImmutableList.copyOf(drivers);
}
Also used : DriverContext(io.prestosql.operator.DriverContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StateStoreListenerManager(io.prestosql.statestore.listener.StateStoreListenerManager) Driver(io.prestosql.operator.Driver) PagesIndex(io.prestosql.operator.PagesIndex) LocalStateStoreProvider(io.prestosql.statestore.LocalStateStoreProvider) StateStoreProvider(io.prestosql.statestore.StateStoreProvider) LocalStateStoreProvider(io.prestosql.statestore.LocalStateStoreProvider) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) SeedStoreManager(io.prestosql.seedstore.SeedStoreManager) ImmutableSet(com.google.common.collect.ImmutableSet) OrderingCompiler(io.prestosql.sql.gen.OrderingCompiler) DriverFactory(io.prestosql.operator.DriverFactory) LookupJoinOperators(io.prestosql.operator.LookupJoinOperators) DynamicFilterCacheManager(io.prestosql.dynamicfilter.DynamicFilterCacheManager) ScheduledSplit(io.prestosql.execution.ScheduledSplit) LocalExecutionPlanner(io.prestosql.sql.planner.LocalExecutionPlanner) IndexJoinLookupStats(io.prestosql.operator.index.IndexJoinLookupStats) StageExecutionDescriptor(io.prestosql.operator.StageExecutionDescriptor) TypeAnalyzer(io.prestosql.sql.planner.TypeAnalyzer) FileSystemClientManager(io.prestosql.filesystem.FileSystemClientManager) LocalExecutionPlan(io.prestosql.sql.planner.LocalExecutionPlanner.LocalExecutionPlan) TableScanNode(io.prestosql.spi.plan.TableScanNode) NodeInfo(io.airlift.node.NodeInfo) TableHandle(io.prestosql.spi.metadata.TableHandle) SplitSource(io.prestosql.split.SplitSource) Split(io.prestosql.metadata.Split) ScheduledSplit(io.prestosql.execution.ScheduledSplit) SubPlan(io.prestosql.sql.planner.SubPlan) TaskSource(io.prestosql.execution.TaskSource)

Example 10 with StateStoreProvider

use of io.prestosql.statestore.StateStoreProvider in project hetu-core by openlookeng.

the class LocalQueryRunner method createDrivers.

private List<Driver> createDrivers(Session session, Plan plan, OutputFactory outputFactory, TaskContext taskContext) {
    if (printPlan) {
        System.out.println(PlanPrinter.textLogicalPlan(plan.getRoot(), plan.getTypes(), metadata, plan.getStatsAndCosts(), session, 0, false));
    }
    SubPlan subplan = planFragmenter.createSubPlans(session, plan, true, WarningCollector.NOOP);
    if (!subplan.getChildren().isEmpty()) {
        throw new AssertionError("Expected subplan to have no children");
    }
    NodeInfo nodeInfo = new NodeInfo("test");
    FileSystemClientManager fileSystemClientManager = new FileSystemClientManager();
    SeedStoreManager seedStoreManager = new SeedStoreManager(fileSystemClientManager);
    StateStoreProvider stateStoreProvider = new LocalStateStoreProvider(seedStoreManager);
    LocalExecutionPlanner executionPlanner = new LocalExecutionPlanner(metadata, new TypeAnalyzer(sqlParser, metadata), Optional.empty(), pageSourceManager, indexManager, nodePartitioningManager, pageSinkManager, null, expressionCompiler, pageFunctionCompiler, joinFilterFunctionCompiler, new IndexJoinLookupStats(), this.taskManagerConfig, spillerFactory, singleStreamSpillerFactory, partitioningSpillerFactory, new PagesIndex.TestingFactory(false), joinCompiler, new LookupJoinOperators(), new OrderingCompiler(), nodeInfo, stateStoreProvider, new StateStoreListenerManager(stateStoreProvider), new DynamicFilterCacheManager(), heuristicIndexerManager, cubeManager);
    // plan query
    StageExecutionDescriptor stageExecutionDescriptor = subplan.getFragment().getStageExecutionDescriptor();
    LocalExecutionPlan localExecutionPlan = executionPlanner.plan(taskContext, stageExecutionDescriptor, subplan.getFragment().getRoot(), subplan.getFragment().getPartitioningScheme().getOutputLayout(), plan.getTypes(), subplan.getFragment().getPartitionedSources(), null, outputFactory, Optional.empty(), Optional.empty(), null);
    // generate sources
    List<TaskSource> sources = new ArrayList<>();
    long sequenceId = 0;
    for (TableScanNode tableScan : findTableScanNodes(subplan.getFragment().getRoot())) {
        TableHandle table = tableScan.getTable();
        SplitSource splitSource = splitManager.getSplits(session, table, stageExecutionDescriptor.isScanGroupedExecution(tableScan.getId()) ? GROUPED_SCHEDULING : UNGROUPED_SCHEDULING, null, Optional.empty(), Collections.emptyMap(), ImmutableSet.of(), tableScan.getStrategy() != ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, tableScan.getId());
        ImmutableSet.Builder<ScheduledSplit> scheduledSplits = ImmutableSet.builder();
        while (!splitSource.isFinished()) {
            for (Split split : getNextBatch(splitSource)) {
                scheduledSplits.add(new ScheduledSplit(sequenceId++, tableScan.getId(), split));
            }
        }
        sources.add(new TaskSource(tableScan.getId(), scheduledSplits.build(), true));
    }
    // create drivers
    List<Driver> drivers = new ArrayList<>();
    Map<PlanNodeId, DriverFactory> driverFactoriesBySource = new HashMap<>();
    for (DriverFactory driverFactory : localExecutionPlan.getDriverFactories()) {
        for (int i = 0; i < driverFactory.getDriverInstances().orElse(1); i++) {
            if (driverFactory.getSourceId().isPresent()) {
                checkState(driverFactoriesBySource.put(driverFactory.getSourceId().get(), driverFactory) == null);
            } else {
                DriverContext driverContext = taskContext.addPipelineContext(driverFactory.getPipelineId(), driverFactory.isInputDriver(), driverFactory.isOutputDriver(), false).addDriverContext();
                Driver driver = driverFactory.createDriver(driverContext);
                drivers.add(driver);
            }
        }
    }
    // add sources to the drivers
    ImmutableSet<PlanNodeId> partitionedSources = ImmutableSet.copyOf(subplan.getFragment().getPartitionedSources());
    for (TaskSource source : sources) {
        DriverFactory driverFactory = driverFactoriesBySource.get(source.getPlanNodeId());
        checkState(driverFactory != null);
        boolean partitioned = partitionedSources.contains(driverFactory.getSourceId().get());
        for (ScheduledSplit split : source.getSplits()) {
            DriverContext driverContext = taskContext.addPipelineContext(driverFactory.getPipelineId(), driverFactory.isInputDriver(), driverFactory.isOutputDriver(), partitioned).addDriverContext();
            Driver driver = driverFactory.createDriver(driverContext);
            driver.updateSource(new TaskSource(split.getPlanNodeId(), ImmutableSet.of(split), true));
            drivers.add(driver);
        }
    }
    for (DriverFactory driverFactory : localExecutionPlan.getDriverFactories()) {
        driverFactory.noMoreDrivers();
    }
    return ImmutableList.copyOf(drivers);
}
Also used : DriverContext(io.prestosql.operator.DriverContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StateStoreListenerManager(io.prestosql.statestore.listener.StateStoreListenerManager) Driver(io.prestosql.operator.Driver) PagesIndex(io.prestosql.operator.PagesIndex) LocalStateStoreProvider(io.prestosql.statestore.LocalStateStoreProvider) StateStoreProvider(io.prestosql.statestore.StateStoreProvider) LocalStateStoreProvider(io.prestosql.statestore.LocalStateStoreProvider) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) SeedStoreManager(io.prestosql.seedstore.SeedStoreManager) ImmutableSet(com.google.common.collect.ImmutableSet) OrderingCompiler(io.prestosql.sql.gen.OrderingCompiler) DriverFactory(io.prestosql.operator.DriverFactory) LookupJoinOperators(io.prestosql.operator.LookupJoinOperators) DynamicFilterCacheManager(io.prestosql.dynamicfilter.DynamicFilterCacheManager) ScheduledSplit(io.prestosql.execution.ScheduledSplit) LocalExecutionPlanner(io.prestosql.sql.planner.LocalExecutionPlanner) IndexJoinLookupStats(io.prestosql.operator.index.IndexJoinLookupStats) StageExecutionDescriptor(io.prestosql.operator.StageExecutionDescriptor) TypeAnalyzer(io.prestosql.sql.planner.TypeAnalyzer) FileSystemClientManager(io.prestosql.filesystem.FileSystemClientManager) LocalExecutionPlan(io.prestosql.sql.planner.LocalExecutionPlanner.LocalExecutionPlan) TableScanNode(io.prestosql.spi.plan.TableScanNode) NodeInfo(io.airlift.node.NodeInfo) TableHandle(io.prestosql.spi.metadata.TableHandle) SplitSource(io.prestosql.split.SplitSource) Split(io.prestosql.metadata.Split) ScheduledSplit(io.prestosql.execution.ScheduledSplit) SubPlan(io.prestosql.sql.planner.SubPlan) TaskSource(io.prestosql.execution.TaskSource)

Aggregations

StateStoreProvider (io.prestosql.statestore.StateStoreProvider)19 StateStore (io.prestosql.spi.statestore.StateStore)10 HashMap (java.util.HashMap)10 Test (org.testng.annotations.Test)9 LocalStateStoreProvider (io.prestosql.statestore.LocalStateStoreProvider)7 Duration (io.airlift.units.Duration)5 DynamicFilterCacheManager (io.prestosql.dynamicfilter.DynamicFilterCacheManager)5 StateStoreListenerManager (io.prestosql.statestore.listener.StateStoreListenerManager)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 NodeInfo (io.airlift.node.NodeInfo)4 FileSystemClientManager (io.prestosql.filesystem.FileSystemClientManager)4 LookupJoinOperators (io.prestosql.operator.LookupJoinOperators)4 PagesIndex (io.prestosql.operator.PagesIndex)4 IndexJoinLookupStats (io.prestosql.operator.index.IndexJoinLookupStats)4 SeedStoreManager (io.prestosql.seedstore.SeedStoreManager)4 OrderingCompiler (io.prestosql.sql.gen.OrderingCompiler)4 LocalExecutionPlanner (io.prestosql.sql.planner.LocalExecutionPlanner)4 TypeAnalyzer (io.prestosql.sql.planner.TypeAnalyzer)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Split (io.prestosql.metadata.Split)3