Skip to content

Commit

Permalink
[9.0] Logsdb and source only snapshots. (elastic#122574)
Browse files Browse the repository at this point in the history
Backporting elastic#122199 to 9.0 branch.

Addresses a few issues with logsdb and source only snapshots:
* Avoid initializing index sorting, because sort fields will not have doc values.
* Also disable doc value skippers when doc values get disabled.
* As part of source only validation figure out what the nested parent field is.

Also added a few more tests that snapshot and restore logsdb data streams.
  • Loading branch information
martijnvg authored Feb 14, 2025
1 parent c2e632a commit 8418b85
Show file tree
Hide file tree
Showing 5 changed files with 395 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/122199.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 122199
summary: Fix issues that prevents using search only snapshots for indices that use index sorting. This is includes Logsdb and time series indices.
area: Logs
type: bug
issues: []
14 changes: 14 additions & 0 deletions server/src/main/java/org/elasticsearch/common/lucene/Lucene.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.apache.lucene.index.ConcurrentMergeScheduler;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.FieldInfos;
import org.apache.lucene.index.FilterCodecReader;
import org.apache.lucene.index.FilterDirectoryReader;
import org.apache.lucene.index.FilterLeafReader;
Expand Down Expand Up @@ -190,14 +192,26 @@ public static SegmentInfos pruneUnreferencedFiles(String segmentsFileName, Direc
throw new IllegalStateException("no commit found in the directory");
}
}
// Need to figure out what the parent field is that, so that validation in IndexWriter doesn't fail
// if no parent field is configured, but FieldInfo says there is a parent field.
String parentField = null;
final IndexCommit cp = getIndexCommit(si, directory);
try (var reader = DirectoryReader.open(cp)) {
var topLevelFieldInfos = FieldInfos.getMergedFieldInfos(reader);
for (FieldInfo fieldInfo : topLevelFieldInfos) {
if (fieldInfo.isParentField()) {
parentField = fieldInfo.getName();
}
}
}
try (
IndexWriter writer = new IndexWriter(
directory,
indexWriterConfigWithNoMerging(Lucene.STANDARD_ANALYZER).setSoftDeletesField(Lucene.SOFT_DELETES_FIELD)
.setIndexCommit(cp)
.setCommitOnClose(false)
.setOpenMode(IndexWriterConfig.OpenMode.APPEND)
.setParentField(parentField)
)
) {
// do nothing and close this will kick off IndexFileDeleter which will remove all pending files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ public IndexService(
mapperMetrics
);
this.indexFieldData = new IndexFieldDataService(indexSettings, indicesFieldDataCache, circuitBreakerService);
if (indexSettings.getIndexSortConfig().hasIndexSort()) {
boolean sourceOnly = Boolean.parseBoolean(indexSettings.getSettings().get("index.source_only"));
if (indexSettings.getIndexSortConfig().hasIndexSort() && sourceOnly == false) {
// we delay the actual creation of the sort order for this index because the mapping has not been merged yet.
// The sort order is validated right after the merge of the mapping later in the process.
this.indexSortSupplier = () -> indexSettings.getIndexSortConfig()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.index.CheckIndex;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.DocValuesSkipIndexType;
import org.apache.lucene.index.DocValuesType;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.FieldInfos;
Expand Down Expand Up @@ -252,7 +253,7 @@ private SegmentCommitInfo syncSegment(
false,
IndexOptions.NONE,
DocValuesType.NONE,
fieldInfo.docValuesSkipIndexType(),
DocValuesSkipIndexType.NONE,
-1,
fieldInfo.attributes(),
0,
Expand Down
Loading

0 comments on commit 8418b85

Please sign in to comment.