Skip to content

Commit

Permalink
Merge branch 'main' into remove-consistent-secure-settings-hash
Browse files Browse the repository at this point in the history
  • Loading branch information
albertzaharovits committed Jul 16, 2024
2 parents 286f650 + df15058 commit 2d2148d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
package org.elasticsearch.index.codec;

import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.FieldInfosFormat;
import org.apache.lucene.codecs.FilterCodec;
import org.apache.lucene.codecs.lucene99.Lucene99Codec;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.util.FeatureFlag;
Expand All @@ -18,6 +20,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

/**
* Since Lucene 4.0 low level index segments are read and written through a
Expand Down Expand Up @@ -65,7 +68,13 @@ public CodecService(@Nullable MapperService mapperService, BigArrays bigArrays)
for (String codec : Codec.availableCodecs()) {
codecs.put(codec, Codec.forName(codec));
}
this.codecs = Map.copyOf(codecs);
this.codecs = codecs.entrySet().stream().collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, e -> {
var codec = e.getValue();
if (codec instanceof DeduplicateFieldInfosCodec) {
return codec;
}
return new DeduplicateFieldInfosCodec(codec.getName(), codec);
}));
}

public Codec codec(String name) {
Expand All @@ -82,4 +91,20 @@ public Codec codec(String name) {
public String[] availableCodecs() {
return codecs.keySet().toArray(new String[0]);
}

public static class DeduplicateFieldInfosCodec extends FilterCodec {

private final DeduplicatingFieldInfosFormat deduplicatingFieldInfosFormat;

protected DeduplicateFieldInfosCodec(String name, Codec delegate) {
super(name, delegate);
this.deduplicatingFieldInfosFormat = new DeduplicatingFieldInfosFormat(super.fieldInfosFormat());
}

@Override
public final FieldInfosFormat fieldInfosFormat() {
return deduplicatingFieldInfosFormat;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
package org.elasticsearch.index.codec;

import org.apache.lucene.codecs.DocValuesFormat;
import org.apache.lucene.codecs.FieldInfosFormat;
import org.apache.lucene.codecs.FilterCodec;
import org.apache.lucene.codecs.KnnVectorsFormat;
import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.codecs.StoredFieldsFormat;
Expand All @@ -27,12 +25,10 @@
* Elasticsearch codec as of 8.14. This extends the Lucene 9.9 codec to compressed stored fields with ZSTD instead of LZ4/DEFLATE. See
* {@link Zstd814StoredFieldsFormat}.
*/
public class Elasticsearch814Codec extends FilterCodec {
public class Elasticsearch814Codec extends CodecService.DeduplicateFieldInfosCodec {

private final StoredFieldsFormat storedFieldsFormat;

private final FieldInfosFormat fieldInfosFormat;

private final PostingsFormat defaultPostingsFormat;
private final PostingsFormat postingsFormat = new PerFieldPostingsFormat() {
@Override
Expand Down Expand Up @@ -72,7 +68,6 @@ public Elasticsearch814Codec(Zstd814StoredFieldsFormat.Mode mode) {
this.defaultPostingsFormat = new Lucene99PostingsFormat();
this.defaultDVFormat = new Lucene90DocValuesFormat();
this.defaultKnnVectorsFormat = new Lucene99HnswVectorsFormat();
this.fieldInfosFormat = new DeduplicatingFieldInfosFormat(delegate.fieldInfosFormat());
}

@Override
Expand Down Expand Up @@ -132,8 +127,4 @@ public KnnVectorsFormat getKnnVectorsFormatForField(String field) {
return defaultKnnVectorsFormat;
}

@Override
public FieldInfosFormat fieldInfosFormat() {
return fieldInfosFormat;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.lucene90.Lucene90StoredFieldsFormat;
import org.apache.lucene.codecs.lucene99.Lucene99Codec;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.IntField;
Expand Down Expand Up @@ -73,7 +72,6 @@ public void testBestCompression() throws Exception {

public void testLegacyDefault() throws Exception {
Codec codec = createCodecService().codec("legacy_default");
assertThat(codec, Matchers.instanceOf(Lucene99Codec.class));
assertThat(codec.storedFieldsFormat(), Matchers.instanceOf(Lucene90StoredFieldsFormat.class));
// Make sure the legacy codec is writable
try (Directory dir = newDirectory(); IndexWriter w = new IndexWriter(dir, newIndexWriterConfig().setCodec(codec))) {
Expand All @@ -87,7 +85,6 @@ public void testLegacyDefault() throws Exception {

public void testLegacyBestCompression() throws Exception {
Codec codec = createCodecService().codec("legacy_best_compression");
assertThat(codec, Matchers.instanceOf(Lucene99Codec.class));
assertThat(codec.storedFieldsFormat(), Matchers.instanceOf(Lucene90StoredFieldsFormat.class));
// Make sure the legacy codec is writable
try (Directory dir = newDirectory(); IndexWriter w = new IndexWriter(dir, newIndexWriterConfig().setCodec(codec))) {
Expand Down

0 comments on commit 2d2148d

Please sign in to comment.