-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
Signed-off-by: Bharathwaj G <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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.index.codec.composite; | ||
|
||
import org.apache.lucene.codecs.DocValuesConsumer; | ||
import org.apache.lucene.codecs.DocValuesFormat; | ||
import org.apache.lucene.codecs.DocValuesProducer; | ||
import org.apache.lucene.codecs.lucene90.Lucene90DocValuesFormat; | ||
import org.apache.lucene.index.SegmentReadState; | ||
import org.apache.lucene.index.SegmentWriteState; | ||
import org.opensearch.common.annotation.ExperimentalApi; | ||
import org.opensearch.index.mapper.MapperService; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* DocValues format to handle composite indices | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
@ExperimentalApi | ||
public class Composite90DocValuesFormat extends DocValuesFormat { | ||
/** | ||
* Creates a new docvalues format. | ||
* | ||
* <p>The provided name will be written into the index segment in some configurations (such as | ||
* when using {@code PerFieldDocValuesFormat}): in such configurations, for the segment to be read | ||
* this class should be registered with Java's SPI mechanism (registered in META-INF/ of your jar | ||
* file, etc). | ||
*/ | ||
private final DocValuesFormat delegate; | ||
private final MapperService mapperService; | ||
|
||
// needed for SPI | ||
public Composite90DocValuesFormat() { | ||
this(new Lucene90DocValuesFormat(), null); | ||
} | ||
Check warning on line 43 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesFormat.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesFormat.java#L42-L43
|
||
|
||
public Composite90DocValuesFormat(MapperService mapperService) { | ||
this(new Lucene90DocValuesFormat(), mapperService); | ||
} | ||
Check warning on line 47 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesFormat.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesFormat.java#L46-L47
|
||
|
||
public Composite90DocValuesFormat(DocValuesFormat delegate, MapperService mapperService) { | ||
super(delegate.getName()); | ||
this.delegate = delegate; | ||
this.mapperService = mapperService; | ||
} | ||
Check warning on line 53 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesFormat.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesFormat.java#L50-L53
|
||
|
||
@Override | ||
public DocValuesConsumer fieldsConsumer(SegmentWriteState state) throws IOException { | ||
return new Composite90DocValuesWriter(delegate.fieldsConsumer(state), state, mapperService); | ||
Check warning on line 57 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesFormat.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesFormat.java#L57
|
||
} | ||
|
||
@Override | ||
public DocValuesProducer fieldsProducer(SegmentReadState state) throws IOException { | ||
return new Composite90DocValuesReader(delegate.fieldsProducer(state), state, mapperService); | ||
Check warning on line 62 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesFormat.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesFormat.java#L62
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* 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.index.codec.composite; | ||
|
||
import org.apache.lucene.codecs.DocValuesProducer; | ||
import org.apache.lucene.index.BinaryDocValues; | ||
import org.apache.lucene.index.FieldInfo; | ||
import org.apache.lucene.index.NumericDocValues; | ||
import org.apache.lucene.index.SegmentReadState; | ||
import org.apache.lucene.index.SortedDocValues; | ||
import org.apache.lucene.index.SortedNumericDocValues; | ||
import org.apache.lucene.index.SortedSetDocValues; | ||
import org.opensearch.common.annotation.ExperimentalApi; | ||
import org.opensearch.index.mapper.CompositeMappedFieldType; | ||
import org.opensearch.index.mapper.MapperService; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** | ||
* Reader for star tree index and star tree doc values from the segments | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
@ExperimentalApi | ||
public class Composite90DocValuesReader extends DocValuesProducer implements CompositeIndexReader { | ||
private DocValuesProducer delegate; | ||
Set<CompositeMappedFieldType> compositeMappedFieldTypes; | ||
MapperService mapperService; | ||
|
||
public Composite90DocValuesReader(DocValuesProducer producer, SegmentReadState state, MapperService mapperService) throws IOException { | ||
this.delegate = producer; | ||
this.mapperService = mapperService; | ||
this.compositeMappedFieldTypes = mapperService.getCompositeFieldTypes(); | ||
Check warning on line 41 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java#L38-L41
|
||
// TODO : read star tree files | ||
} | ||
Check warning on line 43 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java#L43
|
||
|
||
@Override | ||
public NumericDocValues getNumeric(FieldInfo field) throws IOException { | ||
return delegate.getNumeric(field); | ||
Check warning on line 47 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java#L47
|
||
} | ||
|
||
@Override | ||
public BinaryDocValues getBinary(FieldInfo field) throws IOException { | ||
return delegate.getBinary(field); | ||
Check warning on line 52 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java#L52
|
||
} | ||
|
||
@Override | ||
public SortedDocValues getSorted(FieldInfo field) throws IOException { | ||
return delegate.getSorted(field); | ||
Check warning on line 57 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java#L57
|
||
} | ||
|
||
@Override | ||
public SortedNumericDocValues getSortedNumeric(FieldInfo field) throws IOException { | ||
return delegate.getSortedNumeric(field); | ||
Check warning on line 62 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java#L62
|
||
} | ||
|
||
@Override | ||
public SortedSetDocValues getSortedSet(FieldInfo field) throws IOException { | ||
return delegate.getSortedSet(field); | ||
Check warning on line 67 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java#L67
|
||
} | ||
|
||
@Override | ||
public void checkIntegrity() throws IOException { | ||
delegate.checkIntegrity(); | ||
Check warning on line 72 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java#L72
|
||
// Todo : check integrity of composite index related [star tree] files | ||
} | ||
Check warning on line 74 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java#L74
|
||
|
||
@Override | ||
public void close() throws IOException { | ||
delegate.close(); | ||
Check warning on line 78 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java#L78
|
||
// Todo: close composite index related files [star tree] files | ||
} | ||
Check warning on line 80 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java#L80
|
||
|
||
@Override | ||
public List<String> getCompositeIndexFields() { | ||
// todo : read from file formats and get the field names. | ||
return null; | ||
Check warning on line 85 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java#L85
|
||
} | ||
|
||
@Override | ||
public CompositeIndexValues getCompositeIndexValues(String field, CompositeMappedFieldType.CompositeFieldType fieldType) | ||
throws IOException { | ||
// TODO : read compositeIndexValues [starTreeValues] from star tree files | ||
return null; | ||
Check warning on line 92 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesReader.java#L92
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* 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.index.codec.composite; | ||
|
||
import org.apache.lucene.codecs.DocValuesConsumer; | ||
import org.apache.lucene.codecs.DocValuesProducer; | ||
import org.apache.lucene.index.FieldInfo; | ||
import org.apache.lucene.index.MergeState; | ||
import org.apache.lucene.index.SegmentWriteState; | ||
import org.opensearch.common.annotation.ExperimentalApi; | ||
import org.opensearch.index.mapper.CompositeMappedFieldType; | ||
import org.opensearch.index.mapper.MapperService; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* This class write the star tree index and star tree doc values | ||
* based on the doc values structures of the original index | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
@ExperimentalApi | ||
public class Composite90DocValuesWriter extends DocValuesConsumer { | ||
private final DocValuesConsumer delegate; | ||
private final SegmentWriteState state; | ||
private final MapperService mapperService; | ||
private MergeState mergeState = null; | ||
Check warning on line 37 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java#L37
|
||
private final Set<CompositeMappedFieldType> compositeMappedFieldTypes; | ||
private final Set<String> compositeFieldSet; | ||
|
||
private final Map<String, DocValuesProducer> fieldProducerMap = new HashMap<>(); | ||
private final Map<String, FieldInfo> fieldToFieldInfoMap = new HashMap<>(); | ||
Check warning on line 42 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java#L41-L42
|
||
|
||
public Composite90DocValuesWriter(DocValuesConsumer delegate, SegmentWriteState segmentWriteState, MapperService mapperService) | ||
throws IOException { | ||
Check warning on line 45 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java#L45
|
||
|
||
this.delegate = delegate; | ||
this.state = segmentWriteState; | ||
this.mapperService = mapperService; | ||
this.compositeMappedFieldTypes = mapperService.getCompositeFieldTypes(); | ||
compositeFieldSet = new HashSet<>(); | ||
Check warning on line 51 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java#L47-L51
|
||
for (CompositeMappedFieldType type : compositeMappedFieldTypes) { | ||
compositeFieldSet.add(type.name()); | ||
} | ||
} | ||
Check warning on line 55 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java#L53-L55
|
||
|
||
@Override | ||
public void addNumericField(FieldInfo field, DocValuesProducer valuesProducer) throws IOException { | ||
delegate.addNumericField(field, valuesProducer); | ||
} | ||
Check warning on line 60 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java#L59-L60
|
||
|
||
@Override | ||
public void addBinaryField(FieldInfo field, DocValuesProducer valuesProducer) throws IOException { | ||
delegate.addBinaryField(field, valuesProducer); | ||
} | ||
Check warning on line 65 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java#L64-L65
|
||
|
||
@Override | ||
public void addSortedField(FieldInfo field, DocValuesProducer valuesProducer) throws IOException { | ||
delegate.addSortedField(field, valuesProducer); | ||
} | ||
Check warning on line 70 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java#L69-L70
|
||
|
||
@Override | ||
public void addSortedNumericField(FieldInfo field, DocValuesProducer valuesProducer) throws IOException { | ||
delegate.addSortedNumericField(field, valuesProducer); | ||
Check warning on line 74 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java#L74
|
||
// Perform this only during flush flow | ||
if (mergeState == null) { | ||
createCompositeIndicesIfPossible(valuesProducer, field); | ||
Check warning on line 77 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java#L77
|
||
} | ||
} | ||
Check warning on line 79 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java#L79
|
||
|
||
@Override | ||
public void addSortedSetField(FieldInfo field, DocValuesProducer valuesProducer) throws IOException { | ||
delegate.addSortedSetField(field, valuesProducer); | ||
} | ||
Check warning on line 84 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java#L83-L84
|
||
|
||
@Override | ||
public void close() throws IOException { | ||
|
||
} | ||
Check warning on line 89 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java#L89
|
||
|
||
private void createCompositeIndicesIfPossible(DocValuesProducer valuesProducer, FieldInfo field) throws IOException { | ||
if (compositeFieldSet.isEmpty()) return; | ||
if (compositeFieldSet.contains(field.name)) { | ||
fieldProducerMap.put(field.name, valuesProducer); | ||
fieldToFieldInfoMap.put(field.name, field); | ||
compositeFieldSet.remove(field.name); | ||
Check warning on line 96 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java#L94-L96
|
||
} | ||
// we have all the required fields to build composite fields | ||
if (compositeFieldSet.isEmpty()) { | ||
for (CompositeMappedFieldType mappedType : compositeMappedFieldTypes) { | ||
if (mappedType.getCompositeIndexType().equals(CompositeMappedFieldType.CompositeFieldType.STAR_TREE)) { | ||
// TODO : Call StarTree builder | ||
} | ||
} | ||
Check warning on line 104 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java#L104
|
||
} | ||
} | ||
Check warning on line 106 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java#L106
|
||
|
||
@Override | ||
public void merge(MergeState mergeState) throws IOException { | ||
// TODO : check if class variable will cause concurrency issues | ||
this.mergeState = mergeState; | ||
super.merge(mergeState); | ||
Check warning on line 112 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java#L111-L112
|
||
// TODO : handle merge star tree | ||
// mergeStarTreeFields(mergeState); | ||
} | ||
Check warning on line 115 in server/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite90DocValuesWriter.java#L115
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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.index.codec.composite; | ||
|
||
import org.apache.logging.log4j.Logger; | ||
import org.apache.lucene.codecs.Codec; | ||
import org.apache.lucene.codecs.DocValuesFormat; | ||
import org.apache.lucene.codecs.FilterCodec; | ||
import org.apache.lucene.codecs.lucene99.Lucene99Codec; | ||
import org.opensearch.common.annotation.ExperimentalApi; | ||
import org.opensearch.index.codec.PerFieldMappingPostingFormatCodec; | ||
import org.opensearch.index.mapper.MapperService; | ||
|
||
/** | ||
* Extends the Codec to support new file formats for composite indices eg: star tree index | ||
* based on the mappings. | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
@ExperimentalApi | ||
public class Composite99Codec extends FilterCodec { | ||
public static final String COMPOSITE_INDEX_CODEC_NAME = "Composite99Codec"; | ||
private final MapperService mapperService; | ||
|
||
public Composite99Codec() { | ||
this(COMPOSITE_INDEX_CODEC_NAME, new Lucene99Codec(), null); | ||
} | ||
Check warning on line 33 in server/src/main/java/org/opensearch/index/codec/composite/Composite99Codec.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite99Codec.java#L32-L33
|
||
|
||
public Composite99Codec(Lucene99Codec.Mode compressionMode, MapperService mapperService, Logger logger) { | ||
this(COMPOSITE_INDEX_CODEC_NAME, new PerFieldMappingPostingFormatCodec(compressionMode, mapperService, logger), mapperService); | ||
} | ||
Check warning on line 37 in server/src/main/java/org/opensearch/index/codec/composite/Composite99Codec.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite99Codec.java#L36-L37
|
||
|
||
/** | ||
* Sole constructor. When subclassing this codec, create a no-arg ctor and pass the delegate codec and a unique name to | ||
* this ctor. | ||
* | ||
* @param name | ||
* @param delegate | ||
*/ | ||
protected Composite99Codec(String name, Codec delegate, MapperService mapperService) { | ||
super(name, delegate); | ||
this.mapperService = mapperService; | ||
} | ||
Check warning on line 49 in server/src/main/java/org/opensearch/index/codec/composite/Composite99Codec.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/codec/composite/Composite99Codec.java#L47-L49
|
||
|
||
@Override | ||
public DocValuesFormat docValuesFormat() { | ||
return new Composite90DocValuesFormat(mapperService); | ||
} | ||
} |