org.elasticsearch.common.settings.ClusterSettings Java Examples

The following examples show how to use org.elasticsearch.common.settings.ClusterSettings. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MockTransportService.java    From crate with Apache License 2.0 6 votes vote down vote up
private MockTransportService(Settings settings,
                             StubbableTransport transport,
                             ThreadPool threadPool,
                             TransportInterceptor interceptor,
                             Function<BoundTransportAddress, DiscoveryNode> localNodeFactory,
                             @Nullable ClusterSettings clusterSettings) {
    super(
        settings,
        transport,
        threadPool,
        interceptor,
        localNodeFactory,
        clusterSettings,
        new StubbableConnectionManager(new ConnectionManager(settings, transport, threadPool), settings, transport, threadPool)
    );
    this.original = transport.getDelegate();
}
 
Example #2
Source File: InternalClusterInfoService.java    From crate with Apache License 2.0 6 votes vote down vote up
public InternalClusterInfoService(Settings settings, ClusterService clusterService, ThreadPool threadPool, NodeClient client) {
    this.leastAvailableSpaceUsages = ImmutableOpenMap.of();
    this.mostAvailableSpaceUsages = ImmutableOpenMap.of();
    this.shardRoutingToDataPath = ImmutableOpenMap.of();
    this.shardSizes = ImmutableOpenMap.of();
    this.clusterService = clusterService;
    this.threadPool = threadPool;
    this.client = client;
    this.updateFrequency = INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL_SETTING.get(settings);
    this.fetchTimeout = INTERNAL_CLUSTER_INFO_TIMEOUT_SETTING.get(settings);
    this.enabled = DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING.get(settings);
    ClusterSettings clusterSettings = clusterService.getClusterSettings();
    //clusterSettings.addSettingsUpdateConsumer(INTERNAL_CLUSTER_INFO_TIMEOUT_SETTING, this::setFetchTimeout);
    //clusterSettings.addSettingsUpdateConsumer(INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL_SETTING, this::setUpdateFrequency);
    clusterSettings.addSettingsUpdateConsumer(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING, this::setEnabled);

    // Add InternalClusterInfoService to listen for Master changes
    this.clusterService.addLocalNodeMasterListener(this);
    // Add to listen for state changes (when nodes are added)
    this.clusterService.addListener(this);
}
 
Example #3
Source File: CoordinatorTests.java    From crate with Apache License 2.0 6 votes vote down vote up
DisruptableClusterApplierService(String nodeName, Settings settings, ClusterSettings clusterSettings,
                                 DeterministicTaskQueue deterministicTaskQueue, Function<Runnable, Runnable> runnableWrapper) {
    super(nodeName, settings, clusterSettings, deterministicTaskQueue.getThreadPool(runnableWrapper));
    this.nodeName = nodeName;
    this.deterministicTaskQueue = deterministicTaskQueue;
    addStateApplier(event -> {
        switch (clusterStateApplyResponse) {
            case SUCCEED:
            case HANG:
                final ClusterState oldClusterState = event.previousState();
                final ClusterState newClusterState = event.state();
                assert oldClusterState.version() <= newClusterState.version() : "updating cluster state from version "
                    + oldClusterState.version() + " to stale version " + newClusterState.version();
                break;
            case FAIL:
                throw new ElasticsearchException("simulated cluster state applier failure");
        }
    });
}
 
Example #4
Source File: ZentityPlugin.java    From zentity with Apache License 2.0 6 votes vote down vote up
@Override
public List<RestHandler> getRestHandlers(
        Settings settings,
        RestController restController,
        ClusterSettings clusterSettings,
        IndexScopedSettings indexScopedSettings,
        SettingsFilter settingsFilter,
        IndexNameExpressionResolver indexNameExpressionResolver,
        Supplier<DiscoveryNodes> nodesInCluster) {
    List<RestHandler> handlers = new ArrayList<RestHandler>() {{
        new HomeAction(restController);
        new ModelsAction(restController);
        new ResolutionAction(restController);
        new SetupAction(restController);
    }};
    return handlers;
}
 
Example #5
Source File: MockTransportService.java    From crate with Apache License 2.0 6 votes vote down vote up
public static MockTransportService createNewService(Settings settings,
                                                    Transport transport,
                                                    Version version,
                                                    ThreadPool threadPool,
                                                    @Nullable ClusterSettings clusterSettings) {
    return new MockTransportService(
        settings,
        transport,
        threadPool,
        TransportService.NOOP_TRANSPORT_INTERCEPTOR,
        boundAddress -> new DiscoveryNode(
            Node.NODE_NAME_SETTING.get(settings),
            UUIDs.randomBase64UUID(),
            boundAddress.publishAddress(),
            Node.NODE_ATTRIBUTES.getAsMap(settings),
            DiscoveryNode.getRolesFromSettings(settings),
            version
        ),
        clusterSettings
    );
}
 
Example #6
Source File: BundlePlugin.java    From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<RestHandler> getRestHandlers(Settings settings,
                                         RestController restController,
                                         ClusterSettings clusterSettings,
                                         IndexScopedSettings indexScopedSettings,
                                         SettingsFilter settingsFilter,
                                         IndexNameExpressionResolver indexNameExpressionResolver,
                                         Supplier<DiscoveryNodes> nodesInCluster) {
    List<RestHandler> extra = new ArrayList<>();
    if (settings.getAsBoolean("plugins.xbib.isbnformat.enabled", true)) {
        extra.add(new RestISBNFormatterAction(settings, restController));
    }
    if (settings.getAsBoolean("plugins.xbib.langdetect.enabled", true)) {
        extra.add(new RestLangdetectAction(settings, restController));
    }
    return extra;
}
 
Example #7
Source File: MockTransportService.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Build the service.
 *
 * @param clusterSettings if non null the {@linkplain TransportService} will register with the {@link ClusterSettings} for settings
 *                        updates for {@link TransportSettings#TRACE_LOG_EXCLUDE_SETTING} and {@link TransportSettings#TRACE_LOG_INCLUDE_SETTING}.
 */
public MockTransportService(Settings settings, Transport transport, ThreadPool threadPool, TransportInterceptor interceptor,
                            @Nullable ClusterSettings clusterSettings) {
    this(
        settings,
        transport,
        threadPool,
        interceptor,
        (boundAddress) -> DiscoveryNode.createLocal(
            settings,
            boundAddress.publishAddress(),
            settings.get(Node.NODE_NAME_SETTING.getKey(),
            UUIDs.randomBase64UUID())
        ),
        clusterSettings
    );
}
 
Example #8
Source File: TransportService.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
    * Build the service.
    *
    * @param clusterSettings if non null, the {@linkplain TransportService} will register with the {@link ClusterSettings} for settings
*        updates for {@link TransportSettings#TRACE_LOG_EXCLUDE_SETTING} and {@link TransportSettings#TRACE_LOG_INCLUDE_SETTING}.
    */
   public TransportService(Settings settings,
                           Transport transport,
                           ThreadPool threadPool,
                           TransportInterceptor transportInterceptor,
                           Function<BoundTransportAddress, DiscoveryNode> localNodeFactory,
                           @Nullable ClusterSettings clusterSettings) {
       this(
           settings,
           transport,
           threadPool,
           transportInterceptor,
           localNodeFactory,
           clusterSettings,
           new ConnectionManager(settings, transport, threadPool)
       );
   }
 
Example #9
Source File: ClusterStateUpdaters.java    From crate with Apache License 2.0 6 votes vote down vote up
static ClusterState upgradeAndArchiveUnknownOrInvalidSettings(final ClusterState clusterState,
                                                              final ClusterSettings clusterSettings) {
    final MetaData.Builder metaDataBuilder = MetaData.builder(clusterState.metaData());

    metaDataBuilder.persistentSettings(
        clusterSettings.archiveUnknownOrInvalidSettings(
            clusterSettings.upgradeSettings(metaDataBuilder.persistentSettings()),
            e -> logUnknownSetting("persistent", e),
            (e, ex) -> logInvalidSetting("persistent", e, ex)));
    metaDataBuilder.transientSettings(
        clusterSettings.archiveUnknownOrInvalidSettings(
            clusterSettings.upgradeSettings(metaDataBuilder.transientSettings()),
            e -> logUnknownSetting("transient", e),
            (e, ex) -> logInvalidSetting("transient", e, ex)));
    return ClusterState.builder(clusterState).metaData(metaDataBuilder).build();
}
 
Example #10
Source File: ClusterModule.java    From crate with Apache License 2.0 6 votes vote down vote up
private static ShardsAllocator createShardsAllocator(Settings settings, ClusterSettings clusterSettings,
                                                     List<ClusterPlugin> clusterPlugins) {
    Map<String, Supplier<ShardsAllocator>> allocators = new HashMap<>();
    allocators.put(BALANCED_ALLOCATOR, () -> new BalancedShardsAllocator(settings, clusterSettings));

    for (ClusterPlugin plugin : clusterPlugins) {
        plugin.getShardsAllocators(settings, clusterSettings).forEach((k, v) -> {
            if (allocators.put(k, v) != null) {
                throw new IllegalArgumentException("ShardsAllocator [" + k + "] already defined");
            }
        });
    }
    String allocatorName = SHARDS_ALLOCATOR_TYPE_SETTING.get(settings);
    Supplier<ShardsAllocator> allocatorSupplier = allocators.get(allocatorName);
    if (allocatorSupplier == null) {
        throw new IllegalArgumentException("Unknown ShardsAllocator [" + allocatorName + "]");
    }
    return Objects.requireNonNull(allocatorSupplier.get(),
        "ShardsAllocator factory for [" + allocatorName + "] returned null");
}
 
Example #11
Source File: DiskThresholdSettings.java    From crate with Apache License 2.0 6 votes vote down vote up
public DiskThresholdSettings(Settings settings, ClusterSettings clusterSettings) {
    final String lowWatermark = CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.get(settings);
    final String highWatermark = CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.get(settings);
    final String floodStage = CLUSTER_ROUTING_ALLOCATION_DISK_FLOOD_STAGE_WATERMARK_SETTING.get(settings);
    setHighWatermark(highWatermark);
    setLowWatermark(lowWatermark);
    setFloodStageRaw(floodStage);
    this.includeRelocations = CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING.get(settings);
    this.rerouteInterval = CLUSTER_ROUTING_ALLOCATION_REROUTE_INTERVAL_SETTING.get(settings);
    this.enabled = CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING.get(settings);
    clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING, this::setLowWatermark);
    clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING, this::setHighWatermark);
    clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_ALLOCATION_DISK_FLOOD_STAGE_WATERMARK_SETTING, this::setFloodStageRaw);
    clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING, this::setIncludeRelocations);
    clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_ALLOCATION_REROUTE_INTERVAL_SETTING, this::setRerouteInterval);
    clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING, this::setEnabled);
}
 
Example #12
Source File: ClusterServiceUtils.java    From crate with Apache License 2.0 6 votes vote down vote up
public static ClusterService createClusterService(ThreadPool threadPool, DiscoveryNode localNode, ClusterSettings clusterSettings) {
    Settings settings = Settings.builder()
            .put("node.name", "test")
            .put("cluster.name", "ClusterServiceTests")
            .build();
    ClusterService clusterService = new ClusterService(settings, clusterSettings, threadPool);
    clusterService.setNodeConnectionsService(createNoOpNodeConnectionsService());
    ClusterState initialClusterState = ClusterState.builder(new ClusterName(ClusterServiceUtils.class.getSimpleName()))
        .nodes(DiscoveryNodes.builder()
            .add(localNode)
            .localNodeId(localNode.getId())
            .masterNodeId(localNode.getId()))
        .blocks(ClusterBlocks.EMPTY_CLUSTER_BLOCK).build();
    clusterService.getClusterApplierService().setInitialState(initialClusterState);
    clusterService.getMasterService().setClusterStatePublisher(
        createClusterStatePublisher(clusterService.getClusterApplierService()));
    clusterService.getMasterService().setClusterStateSupplier(clusterService.getClusterApplierService()::state);
    clusterService.start();
    return clusterService;
}
 
Example #13
Source File: ThrottlingAllocationDecider.java    From crate with Apache License 2.0 6 votes vote down vote up
public ThrottlingAllocationDecider(Settings settings, ClusterSettings clusterSettings) {
    this.primariesInitialRecoveries = CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES_SETTING.get(settings);
    concurrentIncomingRecoveries = CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_INCOMING_RECOVERIES_SETTING.get(settings);
    concurrentOutgoingRecoveries = CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_OUTGOING_RECOVERIES_SETTING.get(settings);

    clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES_SETTING,
            this::setPrimariesInitialRecoveries);
    clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_INCOMING_RECOVERIES_SETTING,
            this::setConcurrentIncomingRecoverries);
    clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_OUTGOING_RECOVERIES_SETTING,
            this::setConcurrentOutgoingRecoverries);

    LOGGER.debug("using node_concurrent_outgoing_recoveries [{}], node_concurrent_incoming_recoveries [{}], " +
                    "node_initial_primaries_recoveries [{}]",
            concurrentOutgoingRecoveries, concurrentIncomingRecoveries, primariesInitialRecoveries);
}
 
Example #14
Source File: MockNode.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
protected TransportService newTransportService(Settings settings,
                                               Transport transport,
                                               ThreadPool threadPool,
                                               TransportInterceptor interceptor,
                                               Function<BoundTransportAddress, DiscoveryNode> localNodeFactory,
                                               ClusterSettings clusterSettings) {
    // we use the MockTransportService.TestPlugin class as a marker to create a network
    // module with this MockNetworkService. NetworkService is such an integral part of the systme
    // we don't allow to plug it in from plugins or anything. this is a test-only override and
    // can't be done in a production env.
    if (getPluginsService().filterPlugins(MockTransportService.TestPlugin.class).isEmpty()) {
        return super.newTransportService(settings, transport, threadPool, interceptor, localNodeFactory, clusterSettings);
    } else {
        return new MockTransportService(settings, transport, threadPool, interceptor, localNodeFactory, clusterSettings);
    }
}
 
Example #15
Source File: TransportClusterUpdateSettingsAction.java    From crate with Apache License 2.0 6 votes vote down vote up
@Inject
public TransportClusterUpdateSettingsAction(TransportService transportService,
                                            ClusterService clusterService,
                                            ThreadPool threadPool,
                                            AllocationService allocationService,
                                            IndexNameExpressionResolver indexNameExpressionResolver,
                                            ClusterSettings clusterSettings) {
    super(
        ClusterUpdateSettingsAction.NAME,
        false,
        transportService,
        clusterService,
        threadPool,
        ClusterUpdateSettingsRequest::new,
        indexNameExpressionResolver
    );
    this.allocationService = allocationService;
    this.clusterSettings = clusterSettings;
}
 
Example #16
Source File: CrateDummyClusterServiceUnitTest.java    From crate with Apache License 2.0 5 votes vote down vote up
protected ClusterService createClusterService(Collection<Setting<?>> additionalClusterSettings, Version version) {
    Set<Setting<?>> clusterSettingsSet = Sets.newHashSet(ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    clusterSettingsSet.addAll(additionalClusterSettings);
    ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, clusterSettingsSet);
    ClusterService clusterService = new ClusterService(
        Settings.builder()
            .put("cluster.name", "ClusterServiceTests")
            .put(Node.NODE_NAME_SETTING.getKey(), NODE_NAME)
            .build(),
        clusterSettings,
        THREAD_POOL
    );
    clusterService.setNodeConnectionsService(createNoOpNodeConnectionsService());
    DiscoveryNode discoveryNode = new DiscoveryNode(
        NODE_NAME,
        NODE_ID,
        buildNewFakeTransportAddress(),
        Collections.emptyMap(),
        new HashSet<>(Arrays.asList(DiscoveryNode.Role.values())),
        version
    );
    DiscoveryNodes nodes = DiscoveryNodes.builder()
        .add(discoveryNode)
        .localNodeId(NODE_ID)
        .masterNodeId(NODE_ID)
        .build();
    ClusterState clusterState = ClusterState.builder(new ClusterName(this.getClass().getSimpleName()))
        .nodes(nodes).blocks(ClusterBlocks.EMPTY_CLUSTER_BLOCK).build();

    ClusterApplierService clusterApplierService = clusterService.getClusterApplierService();
    clusterApplierService.setInitialState(clusterState);

    MasterService masterService = clusterService.getMasterService();
    masterService.setClusterStatePublisher(createClusterStatePublisher(clusterApplierService));
    masterService.setClusterStateSupplier(clusterApplierService::state);

    clusterService.start();
    return clusterService;
}
 
Example #17
Source File: FilterAllocationDecider.java    From crate with Apache License 2.0 5 votes vote down vote up
public FilterAllocationDecider(Settings settings, ClusterSettings clusterSettings) {
    setClusterRequireFilters(CLUSTER_ROUTING_REQUIRE_GROUP_SETTING.getAsMap(settings));
    setClusterExcludeFilters(CLUSTER_ROUTING_EXCLUDE_GROUP_SETTING.getAsMap(settings));
    setClusterIncludeFilters(CLUSTER_ROUTING_INCLUDE_GROUP_SETTING.getAsMap(settings));
    clusterSettings.addAffixMapUpdateConsumer(CLUSTER_ROUTING_REQUIRE_GROUP_SETTING, this::setClusterRequireFilters, (a, b) -> {});
    clusterSettings.addAffixMapUpdateConsumer(CLUSTER_ROUTING_EXCLUDE_GROUP_SETTING, this::setClusterExcludeFilters, (a, b) -> {});
    clusterSettings.addAffixMapUpdateConsumer(CLUSTER_ROUTING_INCLUDE_GROUP_SETTING, this::setClusterIncludeFilters, (a, b) -> {});
}
 
Example #18
Source File: ClusterService.java    From crate with Apache License 2.0 5 votes vote down vote up
public ClusterService(Settings settings,
                      ClusterSettings clusterSettings,
                      MasterService masterService,
                      ClusterApplierService clusterApplierService) {
    this.settings = settings;
    this.masterService = masterService;
    this.operationRouting = new OperationRouting(settings, clusterSettings);
    this.clusterSettings = clusterSettings;
    this.clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings);
    this.clusterSettings.addSettingsUpdateConsumer(CLUSTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING,
        this::setSlowTaskLoggingThreshold);
    // Add a no-op update consumer so changes are logged
    this.clusterSettings.addAffixUpdateConsumer(USER_DEFINED_META_DATA, (first, second) -> {}, (first, second) -> {});
    this.clusterApplierService = clusterApplierService;
}
 
Example #19
Source File: JobsLogService.java    From crate with Apache License 2.0 5 votes vote down vote up
@Inject
public JobsLogService(Settings settings,
                      ClusterService clusterService,
                      ClusterSettings clusterSettings,
                      Functions functions,
                      CircuitBreakerService breakerService) {
    this(
        settings,
        clusterService::localNode,
        clusterSettings,
        functions,
        Executors.newSingleThreadScheduledExecutor(),
        breakerService
    );
}
 
Example #20
Source File: RestoreService.java    From crate with Apache License 2.0 5 votes vote down vote up
@Inject
public RestoreService(ClusterService clusterService, RepositoriesService repositoriesService,
                      AllocationService allocationService, MetaDataCreateIndexService createIndexService,
                      MetaDataIndexUpgradeService metaDataIndexUpgradeService, ClusterSettings clusterSettings) {
    this.clusterService = clusterService;
    this.repositoriesService = repositoriesService;
    this.allocationService = allocationService;
    this.createIndexService = createIndexService;
    this.metaDataIndexUpgradeService = metaDataIndexUpgradeService;
    clusterService.addStateApplier(this);
    this.clusterSettings = clusterSettings;
    this.cleanRestoreStateTaskExecutor = new CleanRestoreStateTaskExecutor(LOGGER);
}
 
Example #21
Source File: DisruptableMockTransport.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public TransportService createTransportService(Settings settings,
                                               ThreadPool threadPool,
                                               TransportInterceptor interceptor,
                                               Function<BoundTransportAddress, DiscoveryNode> localNodeFactory,
                                               @Nullable ClusterSettings clusterSettings) {
    return new TransportService(settings, this, threadPool, interceptor, localNodeFactory, clusterSettings);
}
 
Example #22
Source File: AppendLucenePlugin.java    From ES-Fastloader with Apache License 2.0 5 votes vote down vote up
@Override
public List<RestHandler> getRestHandlers(Settings settings,
                                         RestController restController,
                                         ClusterSettings clusterSettings,
                                         IndexScopedSettings indexScopedSettings,
                                         SettingsFilter settingsFilter,
                                         IndexNameExpressionResolver indexNameExpressionResolver,
                                         Supplier<DiscoveryNodes> nodesInCluster) {
    return Arrays.asList( new AppendLuceneRestHandler(settings, restController));
}
 
Example #23
Source File: CrateCircuitBreakerServiceTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Before
public void registerSettings() {
    SQLPlugin sqlPlugin = new SQLPlugin(Settings.EMPTY);
    Set<Setting<?>> settings = new HashSet<>();
    settings.addAll(ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    settings.addAll(sqlPlugin.getSettings());
    clusterSettings = new ClusterSettings(Settings.EMPTY, settings);
}
 
Example #24
Source File: DecommissionAllocationDecider.java    From crate with Apache License 2.0 5 votes vote down vote up
public DecommissionAllocationDecider(Settings settings, ClusterSettings clusterSettings) {
    updateDecommissioningNodes(DecommissioningService.DECOMMISSION_INTERNAL_SETTING_GROUP.setting().get(settings));
    dataAvailability = DecommissioningService.GRACEFUL_STOP_MIN_AVAILABILITY_SETTING.setting().get(settings);

    clusterSettings.addSettingsUpdateConsumer(
        DecommissioningService.DECOMMISSION_INTERNAL_SETTING_GROUP.setting(), this::updateDecommissioningNodes);
    clusterSettings.addSettingsUpdateConsumer(
        DecommissioningService.GRACEFUL_STOP_MIN_AVAILABILITY_SETTING.setting(), this::updateMinAvailability);
}
 
Example #25
Source File: DecommissioningService.java    From crate with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
protected DecommissioningService(Settings settings,
                                 final ClusterService clusterService,
                                 JobsLogs jobsLogs,
                                 ScheduledExecutorService executorService,
                                 SQLOperations sqlOperations,
                                 IntSupplier numActiveContexts,
                                 @Nullable Runnable safeExitAction,
                                 final TransportClusterHealthAction healthAction,
                                 final TransportClusterUpdateSettingsAction updateSettingsAction) {
    this.clusterService = clusterService;
    this.jobsLogs = jobsLogs;
    this.sqlOperations = sqlOperations;
    this.numActiveContexts = numActiveContexts;
    this.healthAction = healthAction;
    this.updateSettingsAction = updateSettingsAction;

    // There is a window where this node removed the last shards but still receives new operations because
    // other nodes created the routing based on an earlier clusterState.
    // We delay here to give these requests a chance to finish
    this.safeExitAction = safeExitAction == null
        ? () -> executorService.schedule(this::exit, 5, TimeUnit.SECONDS)
        : safeExitAction;

    gracefulStopTimeout = GRACEFUL_STOP_TIMEOUT_SETTING.setting().get(settings);
    forceStop = GRACEFUL_STOP_FORCE_SETTING.setting().get(settings);
    dataAvailability = GRACEFUL_STOP_MIN_AVAILABILITY_SETTING.setting().get(settings);

    ClusterSettings clusterSettings = clusterService.getClusterSettings();
    clusterSettings.addSettingsUpdateConsumer(GRACEFUL_STOP_TIMEOUT_SETTING.setting(), this::setGracefulStopTimeout);
    clusterSettings.addSettingsUpdateConsumer(GRACEFUL_STOP_FORCE_SETTING.setting(), this::setGracefulStopForce);
    clusterSettings.addSettingsUpdateConsumer(GRACEFUL_STOP_MIN_AVAILABILITY_SETTING.setting(), this::setDataAvailability);
    this.executorService = executorService;
}
 
Example #26
Source File: ClusterRebalanceAllocationDecider.java    From crate with Apache License 2.0 5 votes vote down vote up
public ClusterRebalanceAllocationDecider(Settings settings, ClusterSettings clusterSettings) {
    try {
        type = CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING.get(settings);
    } catch (IllegalStateException e) {
        LOGGER.warn("[{}] has a wrong value {}, defaulting to 'indices_all_active'",
                CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING,
                CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING.getRaw(settings));
        type = ClusterRebalanceType.INDICES_ALL_ACTIVE;
    }
    LOGGER.debug("using [{}] with [{}]", CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE, type);

    clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING, this::setType);
}
 
Example #27
Source File: PeerRecoverySourceServiceTests.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testDuplicateRecoveries() throws IOException {
    IndexShard primary = newStartedShard(true);
    PeerRecoverySourceService peerRecoverySourceService = new PeerRecoverySourceService(
        mock(TransportService.class), mock(IndicesService.class),
        new RecoverySettings(
            Settings.EMPTY,
            new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)));
    StartRecoveryRequest startRecoveryRequest = new StartRecoveryRequest(
        primary.shardId(),
        randomAlphaOfLength(10),
        getFakeDiscoNode("source"),
        getFakeDiscoNode("target"),
        Store.MetadataSnapshot.EMPTY,
        randomBoolean(),
        randomLong(),
        SequenceNumbers.UNASSIGNED_SEQ_NO);
    RecoverySourceHandler handler = peerRecoverySourceService.ongoingRecoveries
        .addNewRecovery(startRecoveryRequest, primary);
    DelayRecoveryException delayRecoveryException = expectThrows(
        DelayRecoveryException.class,
        () -> peerRecoverySourceService.ongoingRecoveries.addNewRecovery(
            startRecoveryRequest,
            primary));
    assertThat(delayRecoveryException.getMessage(), containsString("recovery with same target already registered"));
    peerRecoverySourceService.ongoingRecoveries.remove(primary, handler);
    // re-adding after removing previous attempt works
    handler = peerRecoverySourceService.ongoingRecoveries.addNewRecovery(startRecoveryRequest, primary);
    peerRecoverySourceService.ongoingRecoveries.remove(primary, handler);
    closeShards(primary);
}
 
Example #28
Source File: NodePrometheusMetricsResponse.java    From elasticsearch-prometheus-exporter with Apache License 2.0 5 votes vote down vote up
public NodePrometheusMetricsResponse(ClusterHealthResponse clusterHealth, NodeStats nodesStats,
                                     @Nullable IndicesStatsResponse indicesStats,
                                     @Nullable ClusterStateResponse clusterStateResponse,
                                     Settings settings,
                                     ClusterSettings clusterSettings) {
    this.clusterHealth = clusterHealth;
    this.nodeStats = nodesStats;
    this.indicesStats = indicesStats;
    if (clusterStateResponse != null) {
        this.clusterStatsData = new ClusterStatsData(clusterStateResponse, settings, clusterSettings);
    }
}
 
Example #29
Source File: BalancedShardsAllocator.java    From crate with Apache License 2.0 5 votes vote down vote up
@Inject
public BalancedShardsAllocator(Settings settings, ClusterSettings clusterSettings) {
    setWeightFunction(INDEX_BALANCE_FACTOR_SETTING.get(settings), SHARD_BALANCE_FACTOR_SETTING.get(settings));
    setThreshold(THRESHOLD_SETTING.get(settings));
    clusterSettings.addSettingsUpdateConsumer(INDEX_BALANCE_FACTOR_SETTING, SHARD_BALANCE_FACTOR_SETTING, this::setWeightFunction);
    clusterSettings.addSettingsUpdateConsumer(THRESHOLD_SETTING, this::setThreshold);
}
 
Example #30
Source File: TestHelpers.java    From anomaly-detection with Apache License 2.0 5 votes vote down vote up
public static ClusterService createClusterService(ThreadPool threadPool, ClusterSettings clusterSettings) {
    DiscoveryNode discoveryNode = new DiscoveryNode(
        "node",
        ESTestCase.buildNewFakeTransportAddress(),
        Collections.emptyMap(),
        BUILT_IN_ROLES,
        Version.CURRENT
    );
    return ClusterServiceUtils.createClusterService(threadPool, discoveryNode, clusterSettings);
}