org.elasticsearch.common.unit.ByteSizeUnit Java Examples

The following examples show how to use org.elasticsearch.common.unit.ByteSizeUnit. 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: BulkProcessingOptionsBuilderTest.java    From ElasticUtils with MIT License 6 votes vote down vote up
@Test
public void custom_values_set_when_custom_values_set_for_builder() {

    // Build:
    BulkProcessingOptions options = new BulkProcessingOptionsBuilder()
            .setName("Test")
            .setConcurrentRequests(3)
            .setBulkActions(10)
            .setBulkSize(new ByteSizeValue(2, ByteSizeUnit.MB))
            .setFlushInterval(new TimeValue(321))
            .setBackoffPolicy(BackoffPolicy.noBackoff())
            .build();

    // Check Values:
    Assert.assertEquals("Test", options.getName());
    Assert.assertEquals(3, options.getConcurrentRequests());
    Assert.assertEquals(10, options.getBulkActions());
    Assert.assertEquals(new ByteSizeValue(2, ByteSizeUnit.MB).bytes(), options.getBulkSize().bytes());
    Assert.assertEquals(new TimeValue(321).getMillis(), options.getFlushInterval().getMillis());
    Assert.assertEquals(BackoffPolicy.noBackoff().getClass(), options.getBackoffPolicy().getClass());
}
 
Example #2
Source File: BlobStoreRepository.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs new BlobStoreRepository
 *
 * @param metadata The metadata for this repository including name and settings
 * @param settings Settings for the node this repository object is created on
 */
protected BlobStoreRepository(RepositoryMetaData metadata,
                              Settings settings,
                              NamedXContentRegistry namedXContentRegistry,
                              ThreadPool threadPool,
                              BlobPath basePath) {
    this.settings = settings;
    this.metadata = metadata;
    this.threadPool = threadPool;
    this.compress = COMPRESS_SETTING.get(metadata.settings());
    snapshotRateLimiter = getRateLimiter(metadata.settings(), "max_snapshot_bytes_per_sec", new ByteSizeValue(40, ByteSizeUnit.MB));
    restoreRateLimiter = getRateLimiter(metadata.settings(), "max_restore_bytes_per_sec", new ByteSizeValue(40, ByteSizeUnit.MB));
    readOnly = metadata.settings().getAsBoolean("readonly", false);
    this.basePath = basePath;

    indexShardSnapshotFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_CODEC, SNAPSHOT_NAME_FORMAT,
        BlobStoreIndexShardSnapshot::fromXContent, namedXContentRegistry, compress);
    indexShardSnapshotsFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_INDEX_CODEC, SNAPSHOT_INDEX_NAME_FORMAT,
        BlobStoreIndexShardSnapshots::fromXContent, namedXContentRegistry, compress);
    globalMetaDataFormat = new ChecksumBlobStoreFormat<>(METADATA_CODEC, METADATA_NAME_FORMAT,
                                                         MetaData::fromXContent, namedXContentRegistry, compress);
    indexMetaDataFormat = new ChecksumBlobStoreFormat<>(INDEX_METADATA_CODEC, METADATA_NAME_FORMAT,
                                                        IndexMetaData::fromXContent, namedXContentRegistry, compress);
    snapshotFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_CODEC, SNAPSHOT_NAME_FORMAT,
                                                   SnapshotInfo::fromXContentInternal, namedXContentRegistry, compress);
}
 
Example #3
Source File: CaseController.java    From skywalking with Apache License 2.0 6 votes vote down vote up
private void putSettings() throws IOException {
    ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest();
    String transientSettingKey =
        RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey();
    int transientSettingValue = 10;
    Settings transientSettings = Settings.builder()
            .put(transientSettingKey, transientSettingValue, ByteSizeUnit.BYTES)
            .build();
    request.transientSettings(transientSettings);
    ClusterUpdateSettingsResponse response = client.cluster().putSettings(request, RequestOptions.DEFAULT);
    if (response == null) {
        String message = "elasticsearch put settings fail.";
        logger.error(message);
        throw new RuntimeException(message);
    }
}
 
Example #4
Source File: BulkProcessorFactory.java    From samza with Apache License 2.0 6 votes vote down vote up
public BulkProcessor getBulkProcessor(Client client, BulkProcessor.Listener listener) {
  BulkProcessor.Builder builder = BulkProcessor.builder(client, listener);

  // Concurrent requests set to 0 to ensure ordering of documents is maintained in batches.
  // This also means BulkProcessor#flush() is blocking as is also required.
  builder.setConcurrentRequests(0);

  config.getBulkFlushMaxActions().ifPresent(builder::setBulkActions);
  config.getBulkFlushMaxSizeMB().ifPresent(size ->
    builder.setBulkSize(new ByteSizeValue(size, ByteSizeUnit.MB))
  );
  config.getBulkFlushIntervalMS().ifPresent(interval ->
    builder.setFlushInterval(TimeValue.timeValueMillis(interval))
  );

  return builder.build();
}
 
Example #5
Source File: ESIntegTestCase.java    From crate with Apache License 2.0 6 votes vote down vote up
private static Settings.Builder setRandomIndexTranslogSettings(Random random, Settings.Builder builder) {
    if (random.nextBoolean()) {
        builder.put(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(),
                new ByteSizeValue(RandomNumbers.randomIntBetween(random, 1, 300), ByteSizeUnit.MB));
    }
    if (random.nextBoolean()) {
        builder.put(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(),
                new ByteSizeValue(1, ByteSizeUnit.PB)); // just don't flush
    }
    if (random.nextBoolean()) {
        builder.put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(),
                RandomPicks.randomFrom(random, Translog.Durability.values()));
    }

    if (random.nextBoolean()) {
        builder.put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(),
                RandomNumbers.randomIntBetween(random, 100, 5000), TimeUnit.MILLISECONDS);
    }

    return builder;
}
 
Example #6
Source File: RamAccountingPageIteratorTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
public void testCircuitBreaking() throws Exception {
    PagingIterator<Integer, Row> pagingIterator = PagingIterator.create(
        2,
        true,
        null,
        () -> new RowAccountingWithEstimators(
            ImmutableList.of(DataTypes.STRING, DataTypes.STRING, DataTypes.STRING),
            ConcurrentRamAccounting.forCircuitBreaker(
                "test",
                new MemoryCircuitBreaker(
                    new ByteSizeValue(197, ByteSizeUnit.BYTES),
                    1,
                    LogManager.getLogger(RowAccountingWithEstimatorsTest.class)))));

    expectedException.expect(CircuitBreakingException.class);
    expectedException.expectMessage(
        "Data too large, data for field [test] would be [288/288b], which is larger than the limit of [197/197b]");
    pagingIterator.merge(Arrays.asList(
        new KeyIterable<>(0, Collections.singletonList(TEST_ROWS[0])),
        new KeyIterable<>(1, Collections.singletonList(TEST_ROWS[1]))));
}
 
Example #7
Source File: NodeFetchResponseTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
public void testResponseCircuitBreaker() throws Exception {
    NodeFetchResponse orig = new NodeFetchResponse(fetched);
    BytesStreamOutput out = new BytesStreamOutput();
    orig.writeTo(out);
    StreamInput in = out.bytes().streamInput();

    expectedException.expect(CircuitBreakingException.class);
    new NodeFetchResponse(
        in,
        streamers,
        ConcurrentRamAccounting.forCircuitBreaker(
            "test",
            new MemoryCircuitBreaker(
                new ByteSizeValue(2, ByteSizeUnit.BYTES),
                1.0,
                LogManager.getLogger(NodeFetchResponseTest.class))));

}
 
Example #8
Source File: SortingProjectorTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
public void testUsedMemoryIsAccountedFor() throws Exception {
    MemoryCircuitBreaker circuitBreaker = new MemoryCircuitBreaker(new ByteSizeValue(30, ByteSizeUnit.BYTES),
                                                                   1,
                                                                   LogManager.getLogger(SortingProjectorTest.class)
    );
    RowCellsAccountingWithEstimators rowAccounting =
        new RowCellsAccountingWithEstimators(
            List.of(DataTypes.LONG, DataTypes.BOOLEAN),
            ConcurrentRamAccounting.forCircuitBreaker("testContext", circuitBreaker),
            0);

    Projector projector = createProjector(rowAccounting, 1, 0);
    consumer.accept(projector.apply(TestingBatchIterators.range(1, 11)), null);

    expectedException.expect(CircuitBreakingException.class);
    consumer.getResult();
}
 
Example #9
Source File: TranslogService.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Inject
public TranslogService(ShardId shardId, IndexSettingsService indexSettingsService, ThreadPool threadPool, IndexShard indexShard) {
    super(shardId, indexSettingsService.getSettings());
    this.threadPool = threadPool;
    this.indexSettingsService = indexSettingsService;
    this.indexShard = indexShard;
    this.flushThresholdOperations = indexSettings.getAsInt(INDEX_TRANSLOG_FLUSH_THRESHOLD_OPS, indexSettings.getAsInt("index.translog.flush_threshold", 50000));
    this.flushThresholdSize = indexSettings.getAsBytesSize(INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE, new ByteSizeValue(100, ByteSizeUnit.MB));
    this.flushThresholdPeriod = indexSettings.getAsTime(INDEX_TRANSLOG_FLUSH_THRESHOLD_PERIOD, TimeValue.timeValueMinutes(10));
    this.interval = indexSettings.getAsTime(INDEX_TRANSLOG_FLUSH_INTERVAL, timeValueMillis(5000));
    this.disableFlush = indexSettings.getAsBoolean(INDEX_TRANSLOG_DISABLE_FLUSH, false);
    logger.debug("interval [{}], flush_threshold_ops [{}], flush_threshold_size [{}], flush_threshold_period [{}]", interval, flushThresholdOperations, flushThresholdSize, flushThresholdPeriod);

    this.future = threadPool.schedule(interval, ThreadPool.Names.SAME, new TranslogBasedFlush());

    indexSettingsService.addListener(applySettings);
}
 
Example #10
Source File: S3BlobStoreContainerTests.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
public void testNumberOfMultiparts() {
    final ByteSizeUnit unit = randomFrom(ByteSizeUnit.BYTES, ByteSizeUnit.KB, ByteSizeUnit.MB, ByteSizeUnit.GB);
    final long size = unit.toBytes(randomIntBetween(2, 1000));
    final int factor = randomIntBetween(2, 10);

    // Fits in 1 empty part
    assertNumberOfMultiparts(1, 0L, 0L, size);

    // Fits in 1 part exactly
    assertNumberOfMultiparts(1, size, size, size);
    assertNumberOfMultiparts(1, size, size, size * factor);

    // Fits in N parts exactly
    assertNumberOfMultiparts(factor, size, size * factor, size);

    // Fits in N parts plus a bit more
    final long remaining = randomIntBetween(1, (size > Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int) size - 1);
    assertNumberOfMultiparts(factor + 1, remaining, (size * factor) + remaining, size);
}
 
Example #11
Source File: AzureRepositorySettingsTests.java    From crate with Apache License 2.0 6 votes vote down vote up
public void testChunkSize() {
    // default chunk size
    AzureRepository azureRepository = azureRepository(Settings.EMPTY);
    assertEquals(AzureStorageService.MAX_CHUNK_SIZE, azureRepository.chunkSize());

    // chunk size in settings
    int size = randomIntBetween(1, 256);
    azureRepository = azureRepository(Settings.builder().put("chunk_size", size + "mb").build());
    assertEquals(new ByteSizeValue(size, ByteSizeUnit.MB), azureRepository.chunkSize());

    // zero bytes is not allowed
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () ->
        azureRepository(Settings.builder().put("chunk_size", "0").build()));
    assertEquals("failed to parse value [0] for setting [chunk_size], must be >= [1b]", e.getMessage());

    // negative bytes not allowed
    e = expectThrows(IllegalArgumentException.class, () ->
        azureRepository(Settings.builder().put("chunk_size", "-1").build()));
    assertEquals("failed to parse value [-1] for setting [chunk_size], must be >= [1b]", e.getMessage());

    // greater than max chunk size not allowed
    e = expectThrows(IllegalArgumentException.class, () ->
        azureRepository(Settings.builder().put("chunk_size", "257mb").build()));
    assertEquals("failed to parse value [257mb] for setting [chunk_size], must be <= [256mb]", e.getMessage());
}
 
Example #12
Source File: S3BlobStoreContainerTests.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecuteSingleUploadBlobSizeTooLarge() throws IOException {
    final long blobSize = ByteSizeUnit.GB.toBytes(randomIntBetween(6, 10));
    final S3BlobStore blobStore = mock(S3BlobStore.class);
    final S3BlobContainer blobContainer = new S3BlobContainer(mock(BlobPath.class), blobStore);

    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage(containsString("can't be larger than 5gb"));
    blobContainer.executeSingleUpload(blobStore, randomAlphaOfLengthBetween(1, 10), null, blobSize);
}
 
Example #13
Source File: S3BlobStoreTests.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link S3BlobStore} with random settings.
 * <p>
 * The blobstore uses a {@link MockAmazonS3} client.
 */
public static S3BlobStore randomMockS3BlobStore() {
    String bucket = randomAlphaOfLength(randomIntBetween(1, 10)).toLowerCase(Locale.ROOT);
    ByteSizeValue bufferSize = new ByteSizeValue(randomIntBetween(5, 100), ByteSizeUnit.MB);
    boolean serverSideEncryption = randomBoolean();

    String cannedACL = null;
    if (randomBoolean()) {
        cannedACL = randomFrom(CannedAccessControlList.values()).toString();
    }

    String storageClass = null;
    if (randomBoolean()) {
        storageClass = randomValueOtherThan(
            StorageClass.Glacier,
            () -> randomFrom(StorageClass.values())).toString();
    }

    final AmazonS3 client = new MockAmazonS3(new ConcurrentHashMap<>(), bucket, serverSideEncryption, cannedACL, storageClass);
    final S3Service service = new S3Service() {
        @Override
        public synchronized AmazonS3Reference client(RepositoryMetaData metadata) {
            return new AmazonS3Reference(client);
        }
    };
    return new S3BlobStore(
        service, bucket, serverSideEncryption, bufferSize, cannedACL, storageClass,
        new RepositoryMetaData(bucket, "s3", Settings.EMPTY));
}
 
Example #14
Source File: BulkWriterCollector.java    From elasticsearch-inout-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void open() throws WriterException {

    bulkListener = new BulkListener();
    bulkProcessor = BulkProcessor.builder(getClient(),
            bulkListener).setBulkActions(1000).setBulkSize(
            new ByteSizeValue(5, ByteSizeUnit.MB)).setFlushInterval(
            TimeValue.timeValueSeconds(5)).setConcurrentRequests(
            1).build();
}
 
Example #15
Source File: S3BlobStoreContainerTests.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecuteSingleUploadBlobSizeLargerThanBufferSize() throws IOException {
    final S3BlobStore blobStore = mock(S3BlobStore.class);
    when(blobStore.bufferSizeInBytes()).thenReturn(ByteSizeUnit.MB.toBytes(1));

    final S3BlobContainer blobContainer = new S3BlobContainer(mock(BlobPath.class), blobStore);
    final String blobName = randomAlphaOfLengthBetween(1, 10);

    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage(containsString("can't be larger than buffer size"));
    blobContainer.executeSingleUpload(blobStore, blobName, new ByteArrayInputStream(new byte[0]), ByteSizeUnit.MB.toBytes(2));
}
 
Example #16
Source File: S3BlobStoreContainerTests.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecuteMultipartUploadBlobSizeTooLarge() throws IOException {
    final long blobSize = ByteSizeUnit.TB.toBytes(randomIntBetween(6, 10));
    final S3BlobStore blobStore = mock(S3BlobStore.class);
    final S3BlobContainer blobContainer = new S3BlobContainer(mock(BlobPath.class), blobStore);

    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage(containsString("can't be larger than 5tb"));
    blobContainer.executeMultipartUpload(blobStore, randomAlphaOfLengthBetween(1, 10), null, blobSize);
}
 
Example #17
Source File: RowAccountingWithEstimatorsTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testCircuitBreakingWorksWithExtraSizePerRow() throws Exception {
    RowAccountingWithEstimators rowAccounting = new RowAccountingWithEstimators(
        Collections.singletonList(DataTypes.INTEGER),
        ConcurrentRamAccounting.forCircuitBreaker(
            "test",
            new MemoryCircuitBreaker(
                new ByteSizeValue(10, ByteSizeUnit.BYTES), 1.01, LogManager.getLogger(RowAccountingWithEstimatorsTest.class))
        ),
        2);

    expectedException.expect(CircuitBreakingException.class);
    RowGenerator.range(0, 2).forEach(rowAccounting::accountForAndMaybeBreak);
}
 
Example #18
Source File: RowAccountingWithEstimatorsTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testRowCellsAccountingCircuitBreakingWorks() throws Exception {
    RowCellsAccountingWithEstimators rowAccounting = new RowCellsAccountingWithEstimators(
        Collections.singletonList(DataTypes.INTEGER),
        ConcurrentRamAccounting.forCircuitBreaker(
            "test",
            new MemoryCircuitBreaker(
                new ByteSizeValue(10, ByteSizeUnit.BYTES), 1.01, LogManager.getLogger(RowAccountingWithEstimatorsTest.class))
        ), 0);

    expectedException.expect(CircuitBreakingException.class);
    IntStream.range(0, 3).forEach(i -> rowAccounting.accountForAndMaybeBreak(new Object[]{i}));
}
 
Example #19
Source File: RowAccountingWithEstimatorsTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testCircuitBreakingWorks() throws Exception {
    RowAccountingWithEstimators rowAccounting = new RowAccountingWithEstimators(
        Collections.singletonList(DataTypes.INTEGER),
        ConcurrentRamAccounting.forCircuitBreaker(
            "test",
            new MemoryCircuitBreaker(
                new ByteSizeValue(10, ByteSizeUnit.BYTES),
                1.01,
                LogManager.getLogger(RowAccountingWithEstimatorsTest.class))
        ));

    expectedException.expect(CircuitBreakingException.class);
    RowGenerator.range(0, 3).forEach(rowAccounting::accountForAndMaybeBreak);
}
 
Example #20
Source File: S3BlobStoreContainerTests.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecuteMultipartUploadBlobSizeTooSmall() throws IOException {
    final long blobSize = ByteSizeUnit.MB.toBytes(randomIntBetween(1, 4));
    final S3BlobStore blobStore = mock(S3BlobStore.class);
    final S3BlobContainer blobContainer = new S3BlobContainer(mock(BlobPath.class), blobStore);

    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage(containsString("can't be smaller than 5mb"));
    blobContainer.executeMultipartUpload(blobStore, randomAlphaOfLengthBetween(1, 10), null, blobSize);
}
 
Example #21
Source File: S3RepositoryTests.java    From crate with Apache License 2.0 5 votes vote down vote up
private Settings bufferAndChunkSettings(long buffer, long chunk) {
    return Settings.builder()
        .put(S3RepositorySettings.BUFFER_SIZE_SETTING.getKey(),
             new ByteSizeValue(buffer, ByteSizeUnit.MB).getStringRep())
        .put(S3RepositorySettings.CHUNK_SIZE_SETTING.getKey(),
             new ByteSizeValue(chunk, ByteSizeUnit.MB).getStringRep())
        .build();
}
 
Example #22
Source File: SettingTests.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testByteSizeSettingMaxValue() {
    final Setting<ByteSizeValue> byteSizeValueSetting =
            Setting.byteSizeSetting(
                    "a.byte.size",
                    new ByteSizeValue(100, ByteSizeUnit.MB),
                    new ByteSizeValue(16, ByteSizeUnit.MB),
                    new ByteSizeValue(Integer.MAX_VALUE, ByteSizeUnit.BYTES));
    final long value = (1L << 31) - 1 + randomIntBetween(1, 1024);
    final Settings settings = Settings.builder().put("a.byte.size", value + "b").build();
    final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> byteSizeValueSetting.get(settings));
    final String expectedMessage = "failed to parse value [" + value + "b] for setting [a.byte.size], must be <= [2147483647b]";
    assertThat(e, hasToString(containsString(expectedMessage)));
}
 
Example #23
Source File: FsBlobStore.java    From crate with Apache License 2.0 5 votes vote down vote up
public FsBlobStore(Settings settings, Path path) throws IOException {
    this.path = path;
    this.readOnly = settings.getAsBoolean("readonly", false);
    if (!this.readOnly) {
        Files.createDirectories(path);
    }
    this.bufferSizeInBytes = (int) settings.getAsBytesSize("repositories.fs.buffer_size", new ByteSizeValue(100, ByteSizeUnit.KB)).getBytes();
}
 
Example #24
Source File: ElasticsearchClientRest.java    From c2mon with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public BulkProcessor getBulkProcessor(BulkProcessor.Listener listener) {
  BiConsumer<BulkRequest, ActionListener<BulkResponse>> bulkConsumer =
      (request, bulkListener) -> client.bulkAsync(request, RequestOptions.DEFAULT, bulkListener);

  return BulkProcessor.builder(bulkConsumer, listener)
      .setBulkActions(properties.getBulkActions())
      .setBulkSize(new ByteSizeValue(properties.getBulkSize(), ByteSizeUnit.MB))
      .setFlushInterval(TimeValue.timeValueSeconds(properties.getBulkFlushInterval()))
      .setConcurrentRequests(properties.getConcurrentRequests())
      .build();
}
 
Example #25
Source File: ElasticsearchSinkBase.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Build the {@link BulkProcessor}.
 *
 * <p>Note: this is exposed for testing purposes.
 */
@VisibleForTesting
protected BulkProcessor buildBulkProcessor(BulkProcessor.Listener listener) {
	checkNotNull(listener);

	BulkProcessor.Builder bulkProcessorBuilder = callBridge.createBulkProcessorBuilder(client, listener);

	// This makes flush() blocking
	bulkProcessorBuilder.setConcurrentRequests(0);

	if (bulkProcessorFlushMaxActions != null) {
		bulkProcessorBuilder.setBulkActions(bulkProcessorFlushMaxActions);
	}

	if (bulkProcessorFlushMaxSizeMb != null) {
		bulkProcessorBuilder.setBulkSize(new ByteSizeValue(bulkProcessorFlushMaxSizeMb, ByteSizeUnit.MB));
	}

	if (bulkProcessorFlushIntervalMillis != null) {
		bulkProcessorBuilder.setFlushInterval(TimeValue.timeValueMillis(bulkProcessorFlushIntervalMillis));
	}

	// if backoff retrying is disabled, bulkProcessorFlushBackoffPolicy will be null
	callBridge.configureBulkProcessorBackoff(bulkProcessorBuilder, bulkProcessorFlushBackoffPolicy);

	return bulkProcessorBuilder.build();
}
 
Example #26
Source File: BulkRequestExecutor.java    From soundwave with Apache License 2.0 5 votes vote down vote up
public BulkRequestExecutor(Client client, int bulkActions, long maxSizeMegaBytes,
                           int concurrentRequest,
                           TimeValue flushInterval) {
  processor =
      BulkProcessor.builder(client, this).setBulkActions(bulkActions)
          .setBulkSize(new ByteSizeValue(maxSizeMegaBytes, ByteSizeUnit.MB))
          .setConcurrentRequests(concurrentRequest).setFlushInterval(flushInterval).build();
}
 
Example #27
Source File: BlobStoreRepository.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs new BlobStoreRepository
 *
 * @param repositoryName       repository name
 * @param repositorySettings   repository settings
 * @param indexShardRepository an instance of IndexShardRepository
 */
protected BlobStoreRepository(String repositoryName, RepositorySettings repositorySettings, IndexShardRepository indexShardRepository) {
    super(repositorySettings.globalSettings());
    this.repositoryName = repositoryName;
    this.indexShardRepository = (BlobStoreIndexShardRepository) indexShardRepository;
    snapshotRateLimiter = getRateLimiter(repositorySettings, "max_snapshot_bytes_per_sec", new ByteSizeValue(40, ByteSizeUnit.MB));
    restoreRateLimiter = getRateLimiter(repositorySettings, "max_restore_bytes_per_sec", new ByteSizeValue(40, ByteSizeUnit.MB));
    readOnly = repositorySettings.settings().getAsBoolean("readonly", false);
}
 
Example #28
Source File: PercolatorService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public PercolatorService(Settings settings, IndexNameExpressionResolver indexNameExpressionResolver, IndicesService indicesService,
                         PageCacheRecycler pageCacheRecycler, BigArrays bigArrays,
                         HighlightPhase highlightPhase, ClusterService clusterService,
                         AggregationPhase aggregationPhase, ScriptService scriptService,
                         MappingUpdatedAction mappingUpdatedAction) {
    super(settings);
    this.indexNameExpressionResolver = indexNameExpressionResolver;
    this.parseFieldMatcher = new ParseFieldMatcher(settings);
    this.indicesService = indicesService;
    this.pageCacheRecycler = pageCacheRecycler;
    this.bigArrays = bigArrays;
    this.clusterService = clusterService;
    this.highlightPhase = highlightPhase;
    this.aggregationPhase = aggregationPhase;
    this.scriptService = scriptService;
    this.mappingUpdatedAction = mappingUpdatedAction;
    this.sortParseElement = new SortParseElement();

    final long maxReuseBytes = settings.getAsBytesSize("indices.memory.memory_index.size_per_thread", new ByteSizeValue(1, ByteSizeUnit.MB)).bytes();
    cache = new CloseableThreadLocal<MemoryIndex>() {
        @Override
        protected MemoryIndex initialValue() {
            // TODO: should we expose payloads as an option? should offsets be turned on always?
            return new ExtendedMemoryIndex(true, false, maxReuseBytes);
        }
    };
    single = new SingleDocumentPercolatorIndex(cache);
    multi = new MultiDocumentPercolatorIndex(cache);

    percolatorTypes = new IntObjectHashMap<>(6);
    percolatorTypes.put(countPercolator.id(), countPercolator);
    percolatorTypes.put(queryCountPercolator.id(), queryCountPercolator);
    percolatorTypes.put(matchPercolator.id(), matchPercolator);
    percolatorTypes.put(queryPercolator.id(), queryPercolator);
    percolatorTypes.put(scoringPercolator.id(), scoringPercolator);
    percolatorTypes.put(topMatchingPercolator.id(), topMatchingPercolator);
}
 
Example #29
Source File: BulkProcessingOptionsBuilderTest.java    From ElasticUtils with MIT License 5 votes vote down vote up
@Test
public void default_values_set_when_initializing_builder() {

    // Build:
    BulkProcessingOptions options = new BulkProcessingOptionsBuilder().build();

    // Check Values:
    Assert.assertEquals(null, options.getName());
    Assert.assertEquals(1, options.getConcurrentRequests());
    Assert.assertEquals(1000, options.getBulkActions());
    Assert.assertEquals(new ByteSizeValue(5, ByteSizeUnit.MB).bytes(), options.getBulkSize().bytes());
    Assert.assertEquals(null, options.getFlushInterval());
    Assert.assertEquals(BackoffPolicy.exponentialBackoff().getClass(), options.getBackoffPolicy().getClass());
}
 
Example #30
Source File: ElasticsearchClientTransport.java    From c2mon with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public BulkProcessor getBulkProcessor(BulkProcessor.Listener listener) {
  return BulkProcessor.builder(client, listener)
      .setBulkActions(properties.getBulkActions())
      .setBulkSize(new ByteSizeValue(properties.getBulkSize(), ByteSizeUnit.MB))
      .setFlushInterval(TimeValue.timeValueSeconds(properties.getBulkFlushInterval()))
      .setConcurrentRequests(properties.getConcurrentRequests())
      .build();
}