Skip to content

Commit 8418b85

Browse files
authored
[9.0] Logsdb and source only snapshots. (#122574)
Backporting #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.
1 parent c2e632a commit 8418b85

File tree

5 files changed

+395
-2
lines changed

5 files changed

+395
-2
lines changed

docs/changelog/122199.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 122199
2+
summary: Fix issues that prevents using search only snapshots for indices that use index sorting. This is includes Logsdb and time series indices.
3+
area: Logs
4+
type: bug
5+
issues: []

server/src/main/java/org/elasticsearch/common/lucene/Lucene.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import org.apache.lucene.index.ConcurrentMergeScheduler;
2121
import org.apache.lucene.index.CorruptIndexException;
2222
import org.apache.lucene.index.DirectoryReader;
23+
import org.apache.lucene.index.FieldInfo;
24+
import org.apache.lucene.index.FieldInfos;
2325
import org.apache.lucene.index.FilterCodecReader;
2426
import org.apache.lucene.index.FilterDirectoryReader;
2527
import org.apache.lucene.index.FilterLeafReader;
@@ -190,14 +192,26 @@ public static SegmentInfos pruneUnreferencedFiles(String segmentsFileName, Direc
190192
throw new IllegalStateException("no commit found in the directory");
191193
}
192194
}
195+
// Need to figure out what the parent field is that, so that validation in IndexWriter doesn't fail
196+
// if no parent field is configured, but FieldInfo says there is a parent field.
197+
String parentField = null;
193198
final IndexCommit cp = getIndexCommit(si, directory);
199+
try (var reader = DirectoryReader.open(cp)) {
200+
var topLevelFieldInfos = FieldInfos.getMergedFieldInfos(reader);
201+
for (FieldInfo fieldInfo : topLevelFieldInfos) {
202+
if (fieldInfo.isParentField()) {
203+
parentField = fieldInfo.getName();
204+
}
205+
}
206+
}
194207
try (
195208
IndexWriter writer = new IndexWriter(
196209
directory,
197210
indexWriterConfigWithNoMerging(Lucene.STANDARD_ANALYZER).setSoftDeletesField(Lucene.SOFT_DELETES_FIELD)
198211
.setIndexCommit(cp)
199212
.setCommitOnClose(false)
200213
.setOpenMode(IndexWriterConfig.OpenMode.APPEND)
214+
.setParentField(parentField)
201215
)
202216
) {
203217
// do nothing and close this will kick off IndexFileDeleter which will remove all pending files

server/src/main/java/org/elasticsearch/index/IndexService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ public IndexService(
232232
mapperMetrics
233233
);
234234
this.indexFieldData = new IndexFieldDataService(indexSettings, indicesFieldDataCache, circuitBreakerService);
235-
if (indexSettings.getIndexSortConfig().hasIndexSort()) {
235+
boolean sourceOnly = Boolean.parseBoolean(indexSettings.getSettings().get("index.source_only"));
236+
if (indexSettings.getIndexSortConfig().hasIndexSort() && sourceOnly == false) {
236237
// we delay the actual creation of the sort order for this index because the mapping has not been merged yet.
237238
// The sort order is validated right after the merge of the mapping later in the process.
238239
this.indexSortSupplier = () -> indexSettings.getIndexSortConfig()

x-pack/plugin/core/src/main/java/org/elasticsearch/snapshots/sourceonly/SourceOnlySnapshot.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.apache.lucene.codecs.Codec;
1010
import org.apache.lucene.index.CheckIndex;
1111
import org.apache.lucene.index.DirectoryReader;
12+
import org.apache.lucene.index.DocValuesSkipIndexType;
1213
import org.apache.lucene.index.DocValuesType;
1314
import org.apache.lucene.index.FieldInfo;
1415
import org.apache.lucene.index.FieldInfos;
@@ -252,7 +253,7 @@ private SegmentCommitInfo syncSegment(
252253
false,
253254
IndexOptions.NONE,
254255
DocValuesType.NONE,
255-
fieldInfo.docValuesSkipIndexType(),
256+
DocValuesSkipIndexType.NONE,
256257
-1,
257258
fieldInfo.attributes(),
258259
0,

0 commit comments

Comments
 (0)