Skip to content

Add points metadata support for archive indices #86655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 16, 2022
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 @@ -345,6 +345,7 @@ public DateFieldMapper build(MapperBuilderContext context) {
DateFieldType ft = new DateFieldType(
context.buildFullName(name()),
index.getValue() && indexCreatedVersion.isLegacyIndexVersion() == false,
index.getValue(),
store.getValue(),
docValues.getValue(),
buildFormatter(),
Expand Down Expand Up @@ -391,10 +392,12 @@ public static final class DateFieldType extends MappedFieldType {
protected final Resolution resolution;
protected final String nullValue;
protected final FieldValues<Long> scriptValues;
private final boolean pointsMetadataAvailable;

public DateFieldType(
String name,
boolean isIndexed,
boolean pointsMetadataAvailable,
boolean isStored,
boolean hasDocValues,
DateFormatter dateTimeFormatter,
Expand All @@ -409,26 +412,52 @@ public DateFieldType(
this.resolution = resolution;
this.nullValue = nullValue;
this.scriptValues = scriptValues;
this.pointsMetadataAvailable = pointsMetadataAvailable;
}

public DateFieldType(
String name,
boolean isIndexed,
boolean isStored,
boolean hasDocValues,
DateFormatter dateTimeFormatter,
Resolution resolution,
String nullValue,
FieldValues<Long> scriptValues,
Map<String, String> meta
) {
this(name, isIndexed, isIndexed, isStored, hasDocValues, dateTimeFormatter, resolution, nullValue, scriptValues, meta);
}

public DateFieldType(String name) {
this(name, true, false, true, DEFAULT_DATE_TIME_FORMATTER, Resolution.MILLISECONDS, null, null, Collections.emptyMap());
this(name, true, true, false, true, DEFAULT_DATE_TIME_FORMATTER, Resolution.MILLISECONDS, null, null, Collections.emptyMap());
}

public DateFieldType(String name, boolean isIndexed) {
this(name, isIndexed, false, true, DEFAULT_DATE_TIME_FORMATTER, Resolution.MILLISECONDS, null, null, Collections.emptyMap());
this(
name,
isIndexed,
isIndexed,
false,
true,
DEFAULT_DATE_TIME_FORMATTER,
Resolution.MILLISECONDS,
null,
null,
Collections.emptyMap()
);
}

public DateFieldType(String name, DateFormatter dateFormatter) {
this(name, true, false, true, dateFormatter, Resolution.MILLISECONDS, null, null, Collections.emptyMap());
this(name, true, true, false, true, dateFormatter, Resolution.MILLISECONDS, null, null, Collections.emptyMap());
}

public DateFieldType(String name, Resolution resolution) {
this(name, true, false, true, DEFAULT_DATE_TIME_FORMATTER, resolution, null, null, Collections.emptyMap());
this(name, true, true, false, true, DEFAULT_DATE_TIME_FORMATTER, resolution, null, null, Collections.emptyMap());
}

public DateFieldType(String name, Resolution resolution, DateFormatter dateFormatter) {
this(name, true, false, true, dateFormatter, resolution, null, null, Collections.emptyMap());
this(name, true, true, false, true, dateFormatter, resolution, null, null, Collections.emptyMap());
}

@Override
Expand Down Expand Up @@ -650,7 +679,7 @@ public Relation isFieldWithinQuery(
DateMathParser dateParser,
QueryRewriteContext context
) throws IOException {
if (isIndexed() == false && hasDocValues()) {
if (isIndexed() == false && pointsMetadataAvailable == false && hasDocValues()) {
// we don't have a quick way to run this check on doc values, so fall back to default assuming we are within bounds
return Relation.INTERSECTS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
@ESIntegTestCase.ClusterScope(supportsDedicatedMasters = false, numClientNodes = 0, scope = ESIntegTestCase.Scope.TEST)
public abstract class AbstractArchiveTestCase extends AbstractSnapshotIntegTestCase {

@Override
protected boolean addMockInternalEngine() {
return false;
}

@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return Arrays.asList(LocalStateOldLuceneVersions.class, TestRepositoryPlugin.class, MockRepository.Plugin.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,29 @@
import org.elasticsearch.env.Environment;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.engine.EngineFactory;
import org.elasticsearch.index.engine.ReadOnlyEngine;
import org.elasticsearch.index.seqno.SequenceNumbers;
import org.elasticsearch.index.shard.IndexEventListener;
import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.index.translog.TranslogStats;
import org.elasticsearch.license.License;
import org.elasticsearch.license.LicenseUtils;
import org.elasticsearch.license.LicensedFeature;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.plugins.ClusterPlugin;
import org.elasticsearch.plugins.EnginePlugin;
import org.elasticsearch.plugins.IndexStorePlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.RepositoryPlugin;
import org.elasticsearch.repositories.RepositoriesService;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.snapshots.Snapshot;
import org.elasticsearch.snapshots.SnapshotRestoreException;
import org.elasticsearch.snapshots.sourceonly.SourceOnlySnapshotRepository;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.watcher.ResourceWatcherService;
import org.elasticsearch.xcontent.NamedXContentRegistry;
Expand All @@ -60,10 +66,12 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Supplier;

public class OldLuceneVersions extends Plugin implements IndexStorePlugin, ClusterPlugin, RepositoryPlugin, ActionPlugin {
public class OldLuceneVersions extends Plugin implements IndexStorePlugin, ClusterPlugin, RepositoryPlugin, ActionPlugin, EnginePlugin {

public static final LicensedFeature.Momentary ARCHIVE_FEATURE = LicensedFeature.momentary(
null,
Expand Down Expand Up @@ -226,4 +234,17 @@ private static SegmentInfos convertToNewerLuceneVersion(OldSegmentInfos oldSegme
public Map<String, DirectoryFactory> getDirectoryFactories() {
return Map.of();
}

@Override
public Optional<EngineFactory> getEngineFactory(IndexSettings indexSettings) {
if (indexSettings.getIndexVersionCreated().isLegacyIndexVersion()
&& indexSettings.getIndexMetadata().isSearchableSnapshot() == false
&& indexSettings.getValue(SourceOnlySnapshotRepository.SOURCE_ONLY) == false) {
return Optional.of(
engineConfig -> new ReadOnlyEngine(engineConfig, null, new TranslogStats(), true, Function.identity(), true, false)
);
}

return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.apache.lucene.codecs.FieldInfosFormat;
import org.apache.lucene.codecs.KnnVectorsFormat;
import org.apache.lucene.codecs.NormsFormat;
import org.apache.lucene.codecs.PointsFormat;
import org.apache.lucene.codecs.SegmentInfoFormat;
import org.apache.lucene.codecs.TermVectorsFormat;
import org.apache.lucene.index.FieldInfo;
Expand Down Expand Up @@ -45,11 +44,6 @@ public TermVectorsFormat termVectorsFormat() {
throw new UnsupportedOperationException();
}

@Override
public PointsFormat pointsFormat() {
throw new UnsupportedOperationException();
}

@Override
public KnnVectorsFormat knnVectorsFormat() {
throw new UnsupportedOperationException();
Expand Down Expand Up @@ -85,7 +79,7 @@ public void write(Directory directory, SegmentInfo segmentInfo, String segmentSu
};
}

// mark all fields as no term vectors, no norms, no payloads, no points, and no vectors.
// mark all fields as no term vectors, no norms, no payloads, and no vectors.
private static FieldInfos filterFields(FieldInfos fieldInfos) {
List<FieldInfo> fieldInfoCopy = new ArrayList<>(fieldInfos.size());
for (FieldInfo fieldInfo : fieldInfos) {
Expand All @@ -100,9 +94,9 @@ private static FieldInfos filterFields(FieldInfos fieldInfos) {
fieldInfo.getDocValuesType(),
fieldInfo.getDocValuesGen(),
fieldInfo.attributes(),
0,
0,
0,
fieldInfo.getPointDimensionCount(),
fieldInfo.getPointIndexDimensionCount(),
fieldInfo.getPointNumBytes(),
0,
fieldInfo.getVectorSimilarityFunction(),
fieldInfo.isSoftDeletesField()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.lucene.codecs.DocValuesFormat;
import org.apache.lucene.codecs.FieldInfosFormat;
import org.apache.lucene.codecs.LiveDocsFormat;
import org.apache.lucene.codecs.PointsFormat;
import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.codecs.SegmentInfoFormat;
import org.apache.lucene.codecs.StoredFieldsFormat;
Expand Down Expand Up @@ -121,4 +122,9 @@ public DocValuesFormat docValuesFormat() {
public PostingsFormat postingsFormat() {
return postingsFormat;
}

@Override
public PointsFormat pointsFormat() {
return new Lucene60MetadataOnlyPointsFormat();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* @notice
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Modifications copyright (C) 2021 Elasticsearch B.V.
*/
package org.elasticsearch.xpack.lucene.bwc.codecs.lucene60;

import org.apache.lucene.codecs.PointsFormat;
import org.apache.lucene.codecs.PointsReader;
import org.apache.lucene.codecs.PointsWriter;
import org.apache.lucene.index.SegmentReadState;
import org.apache.lucene.index.SegmentWriteState;

import java.io.IOException;

/**
* Allows reading metadata only from Lucene 6.0 point format
**/
public class Lucene60MetadataOnlyPointsFormat extends PointsFormat {

static final String DATA_CODEC_NAME = "Lucene60PointsFormatData";
static final String META_CODEC_NAME = "Lucene60PointsFormatMeta";

/** Filename extension for the leaf blocks */
public static final String DATA_EXTENSION = "dim";

/** Filename extension for the index per field */
public static final String INDEX_EXTENSION = "dii";

static final int DATA_VERSION_START = 0;
static final int DATA_VERSION_CURRENT = DATA_VERSION_START;

static final int INDEX_VERSION_START = 0;
static final int INDEX_VERSION_CURRENT = INDEX_VERSION_START;

/** Sole constructor */
public Lucene60MetadataOnlyPointsFormat() {}

@Override
public PointsWriter fieldsWriter(SegmentWriteState state) {
throw new UnsupportedOperationException("Old codecs may only be used for reading");
}

@Override
public PointsReader fieldsReader(SegmentReadState state) throws IOException {
return new Lucene60MetadataOnlyPointsReader(state);
}
}
Loading