Skip to content

Commit 624a365

Browse files
committed
Logsdb and source only snapshots.
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. * Avoid initializing _source.mode, because otherwise an empty _source:{} gets serialized in the restored mapping. Also added a few more tests that snapshot and restore logsdb data streams.
1 parent 7bea3a5 commit 624a365

File tree

5 files changed

+359
-3
lines changed

5 files changed

+359
-3
lines changed

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

Lines changed: 12 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,24 @@ public static SegmentInfos pruneUnreferencedFiles(String segmentsFileName, Direc
190192
throw new IllegalStateException("no commit found in the directory");
191193
}
192194
}
195+
String parentField = null;
193196
final IndexCommit cp = getIndexCommit(si, directory);
197+
try (var reader = DirectoryReader.open(cp)) {
198+
var topLevelFieldInfos = FieldInfos.getMergedFieldInfos(reader);
199+
for (FieldInfo fieldInfo : topLevelFieldInfos) {
200+
if (fieldInfo.isParentField()) {
201+
parentField = fieldInfo.getName();
202+
}
203+
}
204+
}
194205
try (
195206
IndexWriter writer = new IndexWriter(
196207
directory,
197208
indexWriterConfigWithNoMerging(Lucene.STANDARD_ANALYZER).setSoftDeletesField(Lucene.SOFT_DELETES_FIELD)
198209
.setIndexCommit(cp)
199210
.setCommitOnClose(false)
200211
.setOpenMode(IndexWriterConfig.OpenMode.APPEND)
212+
.setParentField(parentField)
201213
)
202214
) {
203215
// 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()

server/src/main/java/org/elasticsearch/index/mapper/SourceFieldMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ public Builder(
176176
true,
177177
() -> null,
178178
(n, c, o) -> Mode.valueOf(o.toString().toUpperCase(Locale.ROOT)),
179-
m -> toType(m).enabled.explicit() ? null : toType(m).mode,
179+
// Avoid initializing _source.mode if it doesn't need to be serialized:
180+
m -> toType(m).enabled.explicit() ? null : toType(m).serializeMode ? toType(m).mode : null,
180181
(b, n, v) -> b.field(n, v.toString().toLowerCase(Locale.ROOT)),
181182
v -> v.toString().toLowerCase(Locale.ROOT)
182183
).setMergeValidator((previous, current, conflicts) -> (previous == current) || current != Mode.STORED)

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)