Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Fix PostingsFormat in KNN Codec #236

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public final class KNN86Codec extends Codec {
private final DocValuesFormat perFieldDocValuesFormat;
private final CompoundFormat compoundFormat;
private Codec lucene86Codec;
private PostingsFormat postingsFormat = null;

public static final String KNN_86 = "KNN86Codec";
public static final String LUCENE_86 = "Lucene86"; // Lucene Codec to be used
Expand Down Expand Up @@ -82,9 +83,17 @@ public DocValuesFormat docValuesFormat() {
* approach of manually overriding.
*/


public void setPostingsFormat(PostingsFormat postingsFormat) {
this.postingsFormat = postingsFormat;
}

@Override
public PostingsFormat postingsFormat() {
return getDelegatee().postingsFormat();
if (this.postingsFormat == null) {
return getDelegatee().postingsFormat();
}
return this.postingsFormat;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package com.amazon.opendistroforelasticsearch.knn.plugin;

import com.amazon.opendistroforelasticsearch.knn.index.codec.KNN86Codec.KNN86Codec;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.PostingsFormat;
import org.elasticsearch.index.codec.CodecService;

import static com.amazon.opendistroforelasticsearch.knn.index.codec.KNN86Codec.KNN86Codec.KNN_86;
Expand All @@ -35,7 +37,7 @@ class KNNCodecService extends CodecService {
* return the KNN Codec
*
* @param name dummy name
* @return KNN80Codec
* @return KNN86Codec
*/
@Override
public Codec codec(String name) {
Expand All @@ -45,4 +47,8 @@ public Codec codec(String name) {
}
return codec;
}

public void setPostingsFormat(PostingsFormat postingsFormat) {
((KNN86Codec)codec("")).setPostingsFormat(postingsFormat);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this string empty?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codec function does not use this String. We could pass any string here. Idea is to get the KNNCodec from this function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.amazon.opendistroforelasticsearch.knn.plugin;

import org.elasticsearch.index.codec.CodecService;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.engine.EngineConfig;
import org.elasticsearch.index.engine.EngineFactory;
Expand All @@ -27,10 +26,11 @@
*/
class KNNEngineFactory implements EngineFactory {

private static CodecService codecService = new KNNCodecService();
private static KNNCodecService codecService = new KNNCodecService();

@Override
public Engine newReadWriteEngine(EngineConfig config) {
codecService.setPostingsFormat(config.getCodec().postingsFormat());
EngineConfig engineConfig = new EngineConfig(config.getShardId(), config.getAllocationId(),
config.getThreadPool(), config.getIndexSettings(), config.getWarmer(), config.getStore(),
config.getMergePolicy(), config.getAnalyzer(), config.getSimilarity(), codecService,
Expand Down