Skip to content

Commit b666de2

Browse files
Merge branch 'main' into hybrid-collector
Signed-off-by: Anand Patel <[email protected]>
2 parents 522a92b + d3ad5b8 commit b666de2

File tree

6 files changed

+114
-18
lines changed

6 files changed

+114
-18
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5353
- Query planning to determine flush mode for streaming aggregations ([#19488](https://github.com/opensearch-project/OpenSearch/pull/19488))
5454
- Harden the circuit breaker and failure handle logic in query result consumer ([#19396](https://github.com/opensearch-project/OpenSearch/pull/19396))
5555
- Add streaming cardinality aggregator ([#19484](https://github.com/opensearch-project/OpenSearch/pull/19484))
56-
- Add Hybrid Cardinality collector to prioritize Ordinals Collector ([#19524](https://github.com/opensearch-project/OpenSearch/pull/19524))
56+
- Add Hybrid Cardinality collector to prioritize Ordinals Collector ([#19524](https://github.com/opensearch-project/OpenSearch/pull/19524)).
57+
- Use Lucene `pack` method for `half_float` and `usigned_long` when using `ApproximatePointRangeQuery`.
5758

5859
### Changed
60+
- Refactor to move prepareIndex and prepareDelete methods to Engine class ([#19551](https://github.com/opensearch-project/OpenSearch/pull/19551))
5961

6062
### Fixed
6163

MAINTAINERS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ This document contains a list of maintainers in this repo. See [opensearch-proje
3737
| Sarat Vemulapalli | [saratvemulapalli](https://github.com/saratvemulapalli) | Amazon |
3838
| Shweta Thareja | [shwetathareja](https://github.com/shwetathareja) | Amazon |
3939
| Sorabh Hamirwasia | [sohami](https://github.com/sohami) | Amazon |
40+
| Varun Bharadwaj | [varunbharadwaj](https://github.com/varunbharadwaj) | Uber |
4041
| Yupeng Fu | [yupeng9](https://github.com/yupeng9) | Uber |
4142

4243
## Emeritus

server/src/main/java/org/opensearch/index/engine/Engine.java

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,14 @@
7979
import org.opensearch.core.common.unit.ByteSizeValue;
8080
import org.opensearch.core.index.shard.ShardId;
8181
import org.opensearch.index.VersionType;
82+
import org.opensearch.index.mapper.DocumentMapperForType;
8283
import org.opensearch.index.mapper.IdFieldMapper;
8384
import org.opensearch.index.mapper.Mapping;
8485
import org.opensearch.index.mapper.ParseContext.Document;
8586
import org.opensearch.index.mapper.ParsedDocument;
8687
import org.opensearch.index.mapper.SeqNoFieldMapper;
88+
import org.opensearch.index.mapper.SourceToParse;
89+
import org.opensearch.index.mapper.Uid;
8790
import org.opensearch.index.merge.MergeStats;
8891
import org.opensearch.index.seqno.SeqNoStats;
8992
import org.opensearch.index.seqno.SequenceNumbers;
@@ -1594,6 +1597,85 @@ public long startTime() {
15941597
public abstract TYPE operationType();
15951598
}
15961599

1600+
/**
1601+
* Prepares an index operation by parsing the source document and creating an Engine.Index operation.
1602+
*
1603+
* @param docMapper the document mapper instance
1604+
* @param source the source to parse
1605+
* @param seqNo the sequence number
1606+
* @param primaryTerm the primary term
1607+
* @param version the version
1608+
* @param versionType the version type
1609+
* @param origin the operation origin
1610+
* @param autoGeneratedIdTimestamp the timestamp for auto-generated IDs
1611+
* @param isRetry whether this is a retry
1612+
* @param ifSeqNo the ifSeqNo
1613+
* @param ifPrimaryTerm the ifPrimaryTerm
1614+
* @return the prepared index operation
1615+
*/
1616+
public Engine.Index prepareIndex(
1617+
DocumentMapperForType docMapper,
1618+
SourceToParse source,
1619+
long seqNo,
1620+
long primaryTerm,
1621+
long version,
1622+
VersionType versionType,
1623+
Engine.Operation.Origin origin,
1624+
long autoGeneratedIdTimestamp,
1625+
boolean isRetry,
1626+
long ifSeqNo,
1627+
long ifPrimaryTerm
1628+
) {
1629+
long startTime = System.nanoTime();
1630+
ParsedDocument doc = docMapper.getDocumentMapper().parse(source);
1631+
if (docMapper.getMapping() != null) {
1632+
doc.addDynamicMappingsUpdate(docMapper.getMapping());
1633+
}
1634+
Term uid = new Term(IdFieldMapper.NAME, Uid.encodeId(doc.id()));
1635+
return new Engine.Index(
1636+
uid,
1637+
doc,
1638+
seqNo,
1639+
primaryTerm,
1640+
version,
1641+
versionType,
1642+
origin,
1643+
startTime,
1644+
autoGeneratedIdTimestamp,
1645+
isRetry,
1646+
ifSeqNo,
1647+
ifPrimaryTerm
1648+
);
1649+
}
1650+
1651+
/**
1652+
* Prepares a delete operation by creating an Engine.Delete operation.
1653+
*
1654+
* @param id the document id
1655+
* @param seqNo the sequence number
1656+
* @param primaryTerm the primary term
1657+
* @param version the version
1658+
* @param versionType the version type
1659+
* @param origin the operation origin
1660+
* @param ifSeqNo the ifSeqNo
1661+
* @param ifPrimaryTerm the ifPrimaryTerm
1662+
* @return the prepared delete operation
1663+
*/
1664+
public Engine.Delete prepareDelete(
1665+
String id,
1666+
long seqNo,
1667+
long primaryTerm,
1668+
long version,
1669+
VersionType versionType,
1670+
Engine.Operation.Origin origin,
1671+
long ifSeqNo,
1672+
long ifPrimaryTerm
1673+
) {
1674+
long startTime = System.nanoTime();
1675+
final Term uid = new Term(IdFieldMapper.NAME, Uid.encodeId(id));
1676+
return new Engine.Delete(id, uid, seqNo, primaryTerm, version, versionType, origin, startTime, ifSeqNo, ifPrimaryTerm);
1677+
}
1678+
15971679
/**
15981680
* Index operation
15991681
*

server/src/main/java/org/opensearch/index/mapper/NumberFieldMapper.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,8 @@ public Query rangeQuery(
405405
query,
406406
new ApproximatePointRangeQuery(
407407
field,
408-
NumberType.HALF_FLOAT.encodePoint(l),
409-
NumberType.HALF_FLOAT.encodePoint(u),
408+
HalfFloatPoint.pack(l).bytes,
409+
HalfFloatPoint.pack(u).bytes,
410410
APPROX_QUERY_NUMERIC_DIMS,
411411
ApproximatePointRangeQuery.HALF_FLOAT_FORMAT
412412
)
@@ -604,8 +604,8 @@ public Query rangeQuery(
604604
query,
605605
new ApproximatePointRangeQuery(
606606
field,
607-
FloatPoint.pack(new float[] { l }).bytes,
608-
FloatPoint.pack(new float[] { u }).bytes,
607+
FloatPoint.pack(l).bytes,
608+
FloatPoint.pack(u).bytes,
609609
APPROX_QUERY_NUMERIC_DIMS,
610610
ApproximatePointRangeQuery.FLOAT_FORMAT
611611
)
@@ -778,8 +778,8 @@ public Query rangeQuery(
778778
query,
779779
new ApproximatePointRangeQuery(
780780
field,
781-
DoublePoint.pack(new double[] { l }).bytes,
782-
DoublePoint.pack(new double[] { u }).bytes,
781+
DoublePoint.pack(l).bytes,
782+
DoublePoint.pack(u).bytes,
783783
APPROX_QUERY_NUMERIC_DIMS,
784784
ApproximatePointRangeQuery.DOUBLE_FORMAT
785785
)
@@ -1228,8 +1228,8 @@ public Query rangeQuery(
12281228
query,
12291229
new ApproximatePointRangeQuery(
12301230
field,
1231-
IntPoint.pack(new int[] { l }).bytes,
1232-
IntPoint.pack(new int[] { u }).bytes,
1231+
IntPoint.pack(l).bytes,
1232+
IntPoint.pack(u).bytes,
12331233
APPROX_QUERY_NUMERIC_DIMS,
12341234
ApproximatePointRangeQuery.INT_FORMAT
12351235
)
@@ -1396,8 +1396,8 @@ public Query rangeQuery(
13961396
query,
13971397
new ApproximatePointRangeQuery(
13981398
field,
1399-
LongPoint.pack(new long[] { l }).bytes,
1400-
LongPoint.pack(new long[] { u }).bytes,
1399+
LongPoint.pack(l).bytes,
1400+
LongPoint.pack(u).bytes,
14011401
APPROX_QUERY_NUMERIC_DIMS,
14021402
ApproximatePointRangeQuery.LONG_FORMAT
14031403
)
@@ -1555,8 +1555,8 @@ public Query rangeQuery(
15551555
query,
15561556
new ApproximatePointRangeQuery(
15571557
field,
1558-
NumberType.UNSIGNED_LONG.encodePoint(l),
1559-
NumberType.UNSIGNED_LONG.encodePoint(u),
1558+
BigIntegerPoint.pack(l).bytes,
1559+
BigIntegerPoint.pack(u).bytes,
15601560
APPROX_QUERY_NUMERIC_DIMS,
15611561
ApproximatePointRangeQuery.UNSIGNED_LONG_FORMAT
15621562
)

server/src/main/java/org/opensearch/index/shard/IndexShard.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ private Engine.IndexResult applyIndexOperation(
11991199
ensureWriteAllowed(origin);
12001200
Engine.Index operation;
12011201
try {
1202-
operation = prepareIndex(
1202+
operation = engine.prepareIndex(
12031203
docMapper(),
12041204
sourceToParse,
12051205
seqNo,
@@ -1228,6 +1228,12 @@ private Engine.IndexResult applyIndexOperation(
12281228
return index(engine, operation);
12291229
}
12301230

1231+
/**
1232+
* Prepares an index operation by parsing the source document and creating an Engine.Index operation.
1233+
*
1234+
* @deprecated This static method has been moved to {@link Engine#prepareIndex} as an instance method.
1235+
*/
1236+
@Deprecated(since = "3.4.0", forRemoval = true)
12311237
public static Engine.Index prepareIndex(
12321238
DocumentMapperForType docMapper,
12331239
SourceToParse source,
@@ -1418,10 +1424,16 @@ private Engine.DeleteResult applyDeleteOperation(
14181424
+ getOperationPrimaryTerm()
14191425
+ "]";
14201426
ensureWriteAllowed(origin);
1421-
final Engine.Delete delete = prepareDelete(id, seqNo, opPrimaryTerm, version, versionType, origin, ifSeqNo, ifPrimaryTerm);
1427+
final Engine.Delete delete = engine.prepareDelete(id, seqNo, opPrimaryTerm, version, versionType, origin, ifSeqNo, ifPrimaryTerm);
14221428
return delete(engine, delete);
14231429
}
14241430

1431+
/**
1432+
* Prepares a delete operation by creating an Engine.Delete operation.
1433+
*
1434+
* @deprecated This static method has been moved to {@link Engine#prepareDelete} as an instance method.
1435+
*/
1436+
@Deprecated(since = "3.4.0", forRemoval = true)
14251437
public static Engine.Delete prepareDelete(
14261438
String id,
14271439
long seqNo,

test/framework/src/main/java/org/opensearch/index/engine/TranslogHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import org.opensearch.index.mapper.RootObjectMapper;
4848
import org.opensearch.index.mapper.SourceToParse;
4949
import org.opensearch.index.seqno.SequenceNumbers;
50-
import org.opensearch.index.shard.IndexShard;
5150
import org.opensearch.index.similarity.SimilarityService;
5251
import org.opensearch.index.translog.Translog;
5352
import org.opensearch.index.translog.TranslogRecoveryRunner;
@@ -135,7 +134,7 @@ public Engine.Operation convertToEngineOp(Translog.Operation operation, Engine.O
135134
case INDEX:
136135
final Translog.Index index = (Translog.Index) operation;
137136
final String indexName = mapperService.index().getName();
138-
final Engine.Index engineIndex = IndexShard.prepareIndex(
137+
final Engine.Index engineIndex = engine.prepareIndex(
139138
docMapper(MapperService.SINGLE_MAPPING_NAME),
140139
new SourceToParse(
141140
indexName,
@@ -157,7 +156,7 @@ public Engine.Operation convertToEngineOp(Translog.Operation operation, Engine.O
157156
return engineIndex;
158157
case DELETE:
159158
final Translog.Delete delete = (Translog.Delete) operation;
160-
return IndexShard.prepareDelete(
159+
return engine.prepareDelete(
161160
delete.id(),
162161
delete.seqNo(),
163162
delete.primaryTerm(),

0 commit comments

Comments
 (0)