Search in sources :

Example 91 with ByteSizeValue

use of org.elasticsearch.common.unit.ByteSizeValue in project elasticsearch by elastic.

the class IndexSettingsTests method testTranslogFlushSizeThreshold.

public void testTranslogFlushSizeThreshold() {
    ByteSizeValue translogFlushThresholdSize = new ByteSizeValue(Math.abs(randomInt()));
    ByteSizeValue actualValue = ByteSizeValue.parseBytesSizeValue(translogFlushThresholdSize.toString(), IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey());
    IndexMetaData metaData = newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(), translogFlushThresholdSize.toString()).build());
    IndexSettings settings = new IndexSettings(metaData, Settings.EMPTY);
    assertEquals(actualValue, settings.getFlushThresholdSize());
    ByteSizeValue newTranslogFlushThresholdSize = new ByteSizeValue(Math.abs(randomInt()));
    ByteSizeValue actualNewTranslogFlushThresholdSize = ByteSizeValue.parseBytesSizeValue(newTranslogFlushThresholdSize.toString(), IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey());
    settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(), newTranslogFlushThresholdSize.toString()).build()));
    assertEquals(actualNewTranslogFlushThresholdSize, settings.getFlushThresholdSize());
}
Also used : ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 92 with ByteSizeValue

use of org.elasticsearch.common.unit.ByteSizeValue in project elasticsearch by elastic.

the class NodeInfoStreamingTests method createNodeInfo.

private static NodeInfo createNodeInfo() {
    Build build = Build.CURRENT;
    DiscoveryNode node = new DiscoveryNode("test_node", buildNewFakeTransportAddress(), emptyMap(), emptySet(), VersionUtils.randomVersion(random()));
    Settings settings = randomBoolean() ? null : Settings.builder().put("test", "setting").build();
    OsInfo osInfo = null;
    if (randomBoolean()) {
        int availableProcessors = randomIntBetween(1, 64);
        int allocatedProcessors = randomIntBetween(1, availableProcessors);
        long refreshInterval = randomBoolean() ? -1 : randomNonNegativeLong();
        String name = randomAsciiOfLengthBetween(3, 10);
        String arch = randomAsciiOfLengthBetween(3, 10);
        String version = randomAsciiOfLengthBetween(3, 10);
        osInfo = new OsInfo(refreshInterval, availableProcessors, allocatedProcessors, name, arch, version);
    }
    ProcessInfo process = randomBoolean() ? null : new ProcessInfo(randomInt(), randomBoolean(), randomNonNegativeLong());
    JvmInfo jvm = randomBoolean() ? null : JvmInfo.jvmInfo();
    ThreadPoolInfo threadPoolInfo = null;
    if (randomBoolean()) {
        int numThreadPools = randomIntBetween(1, 10);
        List<ThreadPool.Info> threadPoolInfos = new ArrayList<>(numThreadPools);
        for (int i = 0; i < numThreadPools; i++) {
            threadPoolInfos.add(new ThreadPool.Info(randomAsciiOfLengthBetween(3, 10), randomFrom(ThreadPool.ThreadPoolType.values()), randomInt()));
        }
        threadPoolInfo = new ThreadPoolInfo(threadPoolInfos);
    }
    Map<String, BoundTransportAddress> profileAddresses = new HashMap<>();
    BoundTransportAddress dummyBoundTransportAddress = new BoundTransportAddress(new TransportAddress[] { buildNewFakeTransportAddress() }, buildNewFakeTransportAddress());
    profileAddresses.put("test_address", dummyBoundTransportAddress);
    TransportInfo transport = randomBoolean() ? null : new TransportInfo(dummyBoundTransportAddress, profileAddresses);
    HttpInfo httpInfo = randomBoolean() ? null : new HttpInfo(dummyBoundTransportAddress, randomLong());
    PluginsAndModules pluginsAndModules = null;
    if (randomBoolean()) {
        int numPlugins = randomIntBetween(0, 5);
        List<PluginInfo> plugins = new ArrayList<>();
        for (int i = 0; i < numPlugins; i++) {
            plugins.add(new PluginInfo(randomAsciiOfLengthBetween(3, 10), randomAsciiOfLengthBetween(3, 10), randomAsciiOfLengthBetween(3, 10), randomAsciiOfLengthBetween(3, 10)));
        }
        int numModules = randomIntBetween(0, 5);
        List<PluginInfo> modules = new ArrayList<>();
        for (int i = 0; i < numModules; i++) {
            modules.add(new PluginInfo(randomAsciiOfLengthBetween(3, 10), randomAsciiOfLengthBetween(3, 10), randomAsciiOfLengthBetween(3, 10), randomAsciiOfLengthBetween(3, 10)));
        }
        pluginsAndModules = new PluginsAndModules(plugins, modules);
    }
    IngestInfo ingestInfo = null;
    if (randomBoolean()) {
        int numProcessors = randomIntBetween(0, 5);
        List<ProcessorInfo> processors = new ArrayList<>(numProcessors);
        for (int i = 0; i < numProcessors; i++) {
            processors.add(new ProcessorInfo(randomAsciiOfLengthBetween(3, 10)));
        }
        ingestInfo = new IngestInfo(processors);
    }
    ByteSizeValue indexingBuffer = null;
    if (randomBoolean()) {
        // pick a random long that sometimes exceeds an int:
        indexingBuffer = new ByteSizeValue(random().nextLong() & ((1L << 40) - 1));
    }
    return new NodeInfo(VersionUtils.randomVersion(random()), build, node, settings, osInfo, process, jvm, threadPoolInfo, transport, httpInfo, pluginsAndModules, ingestInfo, indexingBuffer);
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) JvmInfo(org.elasticsearch.monitor.jvm.JvmInfo) ProcessorInfo(org.elasticsearch.ingest.ProcessorInfo) HashMap(java.util.HashMap) PluginsAndModules(org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules) ArrayList(java.util.ArrayList) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) HttpInfo(org.elasticsearch.http.HttpInfo) OsInfo(org.elasticsearch.monitor.os.OsInfo) Build(org.elasticsearch.Build) IngestInfo(org.elasticsearch.ingest.IngestInfo) PluginInfo(org.elasticsearch.plugins.PluginInfo) Settings(org.elasticsearch.common.settings.Settings) ThreadPoolInfo(org.elasticsearch.threadpool.ThreadPoolInfo) TransportInfo(org.elasticsearch.transport.TransportInfo) ProcessInfo(org.elasticsearch.monitor.process.ProcessInfo) PluginInfo(org.elasticsearch.plugins.PluginInfo) OsInfo(org.elasticsearch.monitor.os.OsInfo) ThreadPoolInfo(org.elasticsearch.threadpool.ThreadPoolInfo) ProcessInfo(org.elasticsearch.monitor.process.ProcessInfo) IngestInfo(org.elasticsearch.ingest.IngestInfo) JvmInfo(org.elasticsearch.monitor.jvm.JvmInfo) ProcessorInfo(org.elasticsearch.ingest.ProcessorInfo) HttpInfo(org.elasticsearch.http.HttpInfo) TransportInfo(org.elasticsearch.transport.TransportInfo) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress)

Example 93 with ByteSizeValue

use of org.elasticsearch.common.unit.ByteSizeValue in project elasticsearch by elastic.

the class Netty4Transport method createBootstrap.

private Bootstrap createBootstrap() {
    final Bootstrap bootstrap = new Bootstrap();
    bootstrap.group(new NioEventLoopGroup(workerCount, daemonThreadFactory(settings, TRANSPORT_CLIENT_BOSS_THREAD_NAME_PREFIX)));
    bootstrap.channel(NioSocketChannel.class);
    bootstrap.handler(getClientChannelInitializer());
    bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, Math.toIntExact(defaultConnectionProfile.getConnectTimeout().millis()));
    bootstrap.option(ChannelOption.TCP_NODELAY, TCP_NO_DELAY.get(settings));
    bootstrap.option(ChannelOption.SO_KEEPALIVE, TCP_KEEP_ALIVE.get(settings));
    final ByteSizeValue tcpSendBufferSize = TCP_SEND_BUFFER_SIZE.get(settings);
    if (tcpSendBufferSize.getBytes() > 0) {
        bootstrap.option(ChannelOption.SO_SNDBUF, Math.toIntExact(tcpSendBufferSize.getBytes()));
    }
    final ByteSizeValue tcpReceiveBufferSize = TCP_RECEIVE_BUFFER_SIZE.get(settings);
    if (tcpReceiveBufferSize.getBytes() > 0) {
        bootstrap.option(ChannelOption.SO_RCVBUF, Math.toIntExact(tcpReceiveBufferSize.getBytes()));
    }
    bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, recvByteBufAllocator);
    final boolean reuseAddress = TCP_REUSE_ADDRESS.get(settings);
    bootstrap.option(ChannelOption.SO_REUSEADDR, reuseAddress);
    bootstrap.validate();
    return bootstrap;
}
Also used : ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) Bootstrap(io.netty.bootstrap.Bootstrap) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 94 with ByteSizeValue

use of org.elasticsearch.common.unit.ByteSizeValue in project elasticsearch by elastic.

the class Netty4Transport method createFallbackSettings.

private Settings createFallbackSettings() {
    Settings.Builder fallbackSettingsBuilder = Settings.builder();
    List<String> fallbackBindHost = TransportSettings.BIND_HOST.get(settings);
    if (fallbackBindHost.isEmpty() == false) {
        fallbackSettingsBuilder.putArray("bind_host", fallbackBindHost);
    }
    List<String> fallbackPublishHost = TransportSettings.PUBLISH_HOST.get(settings);
    if (fallbackPublishHost.isEmpty() == false) {
        fallbackSettingsBuilder.putArray("publish_host", fallbackPublishHost);
    }
    boolean fallbackTcpNoDelay = settings.getAsBoolean("transport.netty.tcp_no_delay", TcpSettings.TCP_NO_DELAY.get(settings));
    fallbackSettingsBuilder.put("tcp_no_delay", fallbackTcpNoDelay);
    boolean fallbackTcpKeepAlive = settings.getAsBoolean("transport.netty.tcp_keep_alive", TcpSettings.TCP_KEEP_ALIVE.get(settings));
    fallbackSettingsBuilder.put("tcp_keep_alive", fallbackTcpKeepAlive);
    boolean fallbackReuseAddress = settings.getAsBoolean("transport.netty.reuse_address", TcpSettings.TCP_REUSE_ADDRESS.get(settings));
    fallbackSettingsBuilder.put("reuse_address", fallbackReuseAddress);
    ByteSizeValue fallbackTcpSendBufferSize = settings.getAsBytesSize("transport.netty.tcp_send_buffer_size", TCP_SEND_BUFFER_SIZE.get(settings));
    if (fallbackTcpSendBufferSize.getBytes() >= 0) {
        fallbackSettingsBuilder.put("tcp_send_buffer_size", fallbackTcpSendBufferSize);
    }
    ByteSizeValue fallbackTcpBufferSize = settings.getAsBytesSize("transport.netty.tcp_receive_buffer_size", TCP_RECEIVE_BUFFER_SIZE.get(settings));
    if (fallbackTcpBufferSize.getBytes() >= 0) {
        fallbackSettingsBuilder.put("tcp_receive_buffer_size", fallbackTcpBufferSize);
    }
    return fallbackSettingsBuilder.build();
}
Also used : ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) Settings(org.elasticsearch.common.settings.Settings) TransportSettings(org.elasticsearch.transport.TransportSettings) TcpSettings(org.elasticsearch.common.network.NetworkService.TcpSettings)

Example 95 with ByteSizeValue

use of org.elasticsearch.common.unit.ByteSizeValue in project elasticsearch by elastic.

the class Netty4Transport method createServerBootstrap.

private void createServerBootstrap(String name, Settings settings) {
    if (logger.isDebugEnabled()) {
        logger.debug("using profile[{}], worker_count[{}], port[{}], bind_host[{}], publish_host[{}], compress[{}], " + "connect_timeout[{}], connections_per_node[{}/{}/{}/{}/{}], receive_predictor[{}->{}]", name, workerCount, settings.get("port"), settings.get("bind_host"), settings.get("publish_host"), compress, defaultConnectionProfile.getConnectTimeout(), defaultConnectionProfile.getNumConnectionsPerType(TransportRequestOptions.Type.RECOVERY), defaultConnectionProfile.getNumConnectionsPerType(TransportRequestOptions.Type.BULK), defaultConnectionProfile.getNumConnectionsPerType(TransportRequestOptions.Type.REG), defaultConnectionProfile.getNumConnectionsPerType(TransportRequestOptions.Type.STATE), defaultConnectionProfile.getNumConnectionsPerType(TransportRequestOptions.Type.PING), receivePredictorMin, receivePredictorMax);
    }
    final ThreadFactory workerFactory = daemonThreadFactory(this.settings, TRANSPORT_SERVER_WORKER_THREAD_NAME_PREFIX, name);
    final ServerBootstrap serverBootstrap = new ServerBootstrap();
    serverBootstrap.group(new NioEventLoopGroup(workerCount, workerFactory));
    serverBootstrap.channel(NioServerSocketChannel.class);
    serverBootstrap.childHandler(getServerChannelInitializer(name, settings));
    serverBootstrap.childOption(ChannelOption.TCP_NODELAY, TCP_NO_DELAY.get(settings));
    serverBootstrap.childOption(ChannelOption.SO_KEEPALIVE, TCP_KEEP_ALIVE.get(settings));
    final ByteSizeValue tcpSendBufferSize = TCP_SEND_BUFFER_SIZE.getDefault(settings);
    if (tcpSendBufferSize != null && tcpSendBufferSize.getBytes() > 0) {
        serverBootstrap.childOption(ChannelOption.SO_SNDBUF, Math.toIntExact(tcpSendBufferSize.getBytes()));
    }
    final ByteSizeValue tcpReceiveBufferSize = TCP_RECEIVE_BUFFER_SIZE.getDefault(settings);
    if (tcpReceiveBufferSize != null && tcpReceiveBufferSize.getBytes() > 0) {
        serverBootstrap.childOption(ChannelOption.SO_RCVBUF, Math.toIntExact(tcpReceiveBufferSize.bytesAsInt()));
    }
    serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, recvByteBufAllocator);
    serverBootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, recvByteBufAllocator);
    final boolean reuseAddress = TCP_REUSE_ADDRESS.get(settings);
    serverBootstrap.option(ChannelOption.SO_REUSEADDR, reuseAddress);
    serverBootstrap.childOption(ChannelOption.SO_REUSEADDR, reuseAddress);
    serverBootstrap.validate();
    serverBootstraps.put(name, serverBootstrap);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) EsExecutors.daemonThreadFactory(org.elasticsearch.common.util.concurrent.EsExecutors.daemonThreadFactory) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Aggregations

ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)145 Settings (org.elasticsearch.common.settings.Settings)23 Test (org.junit.Test)21 IOException (java.io.IOException)16 CountDownLatch (java.util.concurrent.CountDownLatch)13 ArrayList (java.util.ArrayList)11 TimeValue (org.elasticsearch.common.unit.TimeValue)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 List (java.util.List)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 Path (java.nio.file.Path)7 Translog (org.elasticsearch.index.translog.Translog)7 Arrays (java.util.Arrays)6 Collections (java.util.Collections)6 Collectors (java.util.stream.Collectors)6 BulkProcessor (org.elasticsearch.action.bulk.BulkProcessor)6 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)6 BytesArray (org.elasticsearch.common.bytes.BytesArray)6 Matchers.equalTo (org.hamcrest.Matchers.equalTo)6