Skip to content

Commit

Permalink
Merge branch 'main' of github.com:opensearch-project/OpenSearch into …
Browse files Browse the repository at this point in the history
…startreemapping
  • Loading branch information
bharath-techie committed Jul 1, 2024
2 parents 8263b0b + c71fd4a commit ed03900
Show file tree
Hide file tree
Showing 10 changed files with 562 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 3. Use the command palette to run the CODEOWNERS: Show owners of current file command, which will display all code owners for the current file.

# Default ownership for all repo files
* @anasalkouz @andrross @Bukhtawar @CEHENKLE @dblock @dbwiddis @gbbafna @kotwanikunal @mch2 @msfroh @nknize @owaiskazi19 @reta @Rishikesh1159 @sachinpkale @saratvemulapalli @shwetathareja @sohami @VachaShah
* @anasalkouz @andrross @ashking94 @Bukhtawar @CEHENKLE @dblock @dbwiddis @gbbafna @kotwanikunal @mch2 @msfroh @nknize @owaiskazi19 @reta @Rishikesh1159 @sachinpkale @saratvemulapalli @shwetathareja @sohami @VachaShah

/modules/transport-netty4/ @peternied

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- [Remote Store] Rate limiter for remote store low priority uploads ([#14374](https://github.com/opensearch-project/OpenSearch/pull/14374/))
- Apply the date histogram rewrite optimization to range aggregation ([#13865](https://github.com/opensearch-project/OpenSearch/pull/13865))
- [Writable Warm] Add composite directory implementation and integrate it with FileCache ([12782](https://github.com/opensearch-project/OpenSearch/pull/12782))
- Add batching supported processor base type AbstractBatchingProcessor ([#14554](https://github.com/opensearch-project/OpenSearch/pull/14554))
- Fix race condition while parsing derived fields from search definition ([14445](https://github.com/opensearch-project/OpenSearch/pull/14445))
- Add allowlist setting for ingest-common and search-pipeline-common processors ([#14439](https://github.com/opensearch-project/OpenSearch/issues/14439))

Expand All @@ -33,6 +34,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Updated the `indices.query.bool.max_clause_count` setting from being static to dynamically updateable ([#13568](https://github.com/opensearch-project/OpenSearch/pull/13568))
- Make the class CommunityIdProcessor final ([#14448](https://github.com/opensearch-project/OpenSearch/pull/14448))
- Allow @InternalApi annotation on classes not meant to be constructed outside of the OpenSearch core ([#14575](https://github.com/opensearch-project/OpenSearch/pull/14575))
- Add @InternalApi annotation to japicmp exclusions ([#14597](https://github.com/opensearch-project/OpenSearch/pull/14597))

### Deprecated

Expand All @@ -50,6 +52,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add ListPitInfo::getKeepAlive() getter ([#14495](https://github.com/opensearch-project/OpenSearch/pull/14495))
- Fix FuzzyQuery in keyword field will use IndexOrDocValuesQuery when both of index and doc_value are true ([#14378](https://github.com/opensearch-project/OpenSearch/pull/14378))
- Fix file cache initialization ([#14004](https://github.com/opensearch-project/OpenSearch/pull/14004))
- Handle NPE in GetResult if "found" field is missing ([#14552](https://github.com/opensearch-project/OpenSearch/pull/14552))

### Security

Expand Down
1 change: 1 addition & 0 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ tasks.register("japicmp", me.champeau.gradle.japicmp.JapicmpTask) {
failOnModification = true
ignoreMissingClasses = true
annotationIncludes = ['@org.opensearch.common.annotation.PublicApi', '@org.opensearch.common.annotation.DeprecatedApi']
annotationExcludes = ['@org.opensearch.common.annotation.InternalApi']
txtOutputFile = layout.buildDirectory.file("reports/java-compatibility/report.txt")
htmlOutputFile = layout.buildDirectory.file("reports/java-compatibility/report.html")
dependsOn downloadJapicmpCompareTarget
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
*/
public class RemoteClusterStateCustoms extends AbstractRemoteWritableBlobEntity<Custom> {
public static final String CLUSTER_STATE_CUSTOM = "cluster-state-custom";
public final ChecksumWritableBlobStoreFormat<ClusterState.Custom> clusterStateCustomsFormat;

private long stateVersion;
private final String customType;
private ClusterState.Custom custom;
private final NamedWriteableRegistry namedWriteableRegistry;
private final ChecksumWritableBlobStoreFormat<ClusterState.Custom> clusterStateCustomsFormat;

public RemoteClusterStateCustoms(
final ClusterState.Custom custom,
Expand Down
10 changes: 10 additions & 0 deletions server/src/main/java/org/opensearch/index/get/GetResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.common.document.DocumentField;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.core.common.ParsingException;
import org.opensearch.core.common.Strings;
import org.opensearch.core.common.bytes.BytesReference;
import org.opensearch.core.common.io.stream.StreamInput;
Expand All @@ -56,6 +57,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

Expand Down Expand Up @@ -398,6 +400,14 @@ public static GetResult fromXContentEmbedded(XContentParser parser, String index
}
}
}

if (found == null) {
throw new ParsingException(
parser.getTokenLocation(),
String.format(Locale.ROOT, "Missing required field [%s]", GetResult.FOUND)
);
}

return new GetResult(index, id, seqNo, primaryTerm, version, found, source, documentFields, metaFields);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.ingest;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;

import static org.opensearch.ingest.ConfigurationUtils.newConfigurationException;

/**
* Abstract base class for batch processors.
*
* @opensearch.internal
*/
public abstract class AbstractBatchingProcessor extends AbstractProcessor {

public static final String BATCH_SIZE_FIELD = "batch_size";
private static final int DEFAULT_BATCH_SIZE = 1;
protected final int batchSize;

protected AbstractBatchingProcessor(String tag, String description, int batchSize) {
super(tag, description);
this.batchSize = batchSize;
}

/**
* Internal logic to process batched documents, must be implemented by concrete batch processors.
*
* @param ingestDocumentWrappers {@link List} of {@link IngestDocumentWrapper} to be processed.
* @param handler {@link Consumer} to be called with the results of the processing.
*/
protected abstract void subBatchExecute(
List<IngestDocumentWrapper> ingestDocumentWrappers,
Consumer<List<IngestDocumentWrapper>> handler
);

@Override
public void batchExecute(List<IngestDocumentWrapper> ingestDocumentWrappers, Consumer<List<IngestDocumentWrapper>> handler) {
if (ingestDocumentWrappers.isEmpty()) {
handler.accept(Collections.emptyList());
return;
}

// if batch size is larger than document size, send one batch
if (this.batchSize >= ingestDocumentWrappers.size()) {
subBatchExecute(ingestDocumentWrappers, handler);
return;
}

// split documents into multiple batches and send each batch to batch processors
List<List<IngestDocumentWrapper>> batches = cutBatches(ingestDocumentWrappers);
int size = ingestDocumentWrappers.size();
AtomicInteger counter = new AtomicInteger(size);
List<IngestDocumentWrapper> allResults = Collections.synchronizedList(new ArrayList<>());
for (List<IngestDocumentWrapper> batch : batches) {
this.subBatchExecute(batch, batchResults -> {
allResults.addAll(batchResults);
if (counter.addAndGet(-batchResults.size()) == 0) {
handler.accept(allResults);
}
assert counter.get() >= 0 : "counter is negative";
});
}
}

private List<List<IngestDocumentWrapper>> cutBatches(List<IngestDocumentWrapper> ingestDocumentWrappers) {
List<List<IngestDocumentWrapper>> batches = new ArrayList<>();
for (int i = 0; i < ingestDocumentWrappers.size(); i += this.batchSize) {
batches.add(ingestDocumentWrappers.subList(i, Math.min(i + this.batchSize, ingestDocumentWrappers.size())));
}
return batches;
}

/**
* Factory class for creating {@link AbstractBatchingProcessor} instances.
*
* @opensearch.internal
*/
public abstract static class Factory implements Processor.Factory {
final String processorType;

protected Factory(String processorType) {
this.processorType = processorType;
}

/**
* Creates a new processor instance.
*
* @param processorFactories The processor factories.
* @param tag The processor tag.
* @param description The processor description.
* @param config The processor configuration.
* @return The new AbstractBatchProcessor instance.
* @throws Exception If the processor could not be created.
*/
@Override
public AbstractBatchingProcessor create(
Map<String, Processor.Factory> processorFactories,
String tag,
String description,
Map<String, Object> config
) throws Exception {
int batchSize = ConfigurationUtils.readIntProperty(this.processorType, tag, config, BATCH_SIZE_FIELD, DEFAULT_BATCH_SIZE);
if (batchSize < 1) {
throw newConfigurationException(this.processorType, tag, BATCH_SIZE_FIELD, "batch size must be a positive integer");
}
return newProcessor(tag, description, batchSize, config);
}

/**
* Returns a new processor instance.
*
* @param tag tag of the processor
* @param description description of the processor
* @param batchSize batch size of the processor
* @param config configuration of the processor
* @return a new batch processor instance
*/
protected abstract AbstractBatchingProcessor newProcessor(
String tag,
String description,
int batchSize,
Map<String, Object> config
);
}
}
Loading

0 comments on commit ed03900

Please sign in to comment.