Skip to content

Commit 5845c27

Browse files
committed
Add comments and make the code more readable
1 parent 27c3a3b commit 5845c27

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -445,24 +445,25 @@ public void preParse(DocumentParserContext context) throws IOException {
445445
context.doc().add(new StoredField(fieldType().name(), ref.bytes, ref.offset, ref.length));
446446
}
447447

448-
boolean enableRecoverySource = context.indexSettings().isRecoverySourceEnabled();
449-
if (enableRecoverySource && (stored() == false || adaptedStoredSource != storedSource)) {
450-
if (context.indexSettings().isRecoverySourceSyntheticEnabled()) {
451-
assert isSynthetic() : "recovery source should not be disabled on non-synthetic source";
452-
/**
453-
* We use synthetic source for recovery, so we omit the recovery source.
454-
* Instead, we record only the size of the uncompressed source.
455-
* This size is used in {@link LuceneSyntheticSourceChangesSnapshot} to control memory
456-
* usage during the recovery process when loading a batch of synthetic sources.
457-
*/
458-
context.doc().add(new NumericDocValuesField(RECOVERY_SOURCE_SIZE_NAME, originalSource.length()));
459-
} else {
460-
// if we omitted source or modified it we add the _recovery_source to ensure we have it for ops based recovery
461-
var recoverySource = removeSyntheticVectorFields(context.mappingLookup(), originalSource, contentType).toBytesRef();
462-
context.doc()
463-
.add(new StoredField(RECOVERY_SOURCE_NAME, recoverySource.bytes, recoverySource.offset, recoverySource.length));
464-
context.doc().add(new NumericDocValuesField(RECOVERY_SOURCE_NAME, 1));
465-
}
448+
if (context.indexSettings().isRecoverySourceEnabled() == false) {
449+
// Recovery source is disabled; skip adding recovery source fields.
450+
return;
451+
}
452+
453+
if (context.indexSettings().isRecoverySourceSyntheticEnabled()) {
454+
assert isSynthetic() : "Recovery source should not be disabled for non-synthetic sources";
455+
// Synthetic source recovery is enabled; omit the full recovery source.
456+
// Instead, store only the size of the uncompressed original source.
457+
// This size is used by LuceneSyntheticSourceChangesSnapshot to manage memory usage
458+
// when loading batches of synthetic sources during recovery.
459+
context.doc().add(new NumericDocValuesField(RECOVERY_SOURCE_SIZE_NAME, originalSource.length()));
460+
} else if (stored() == false || adaptedStoredSource != storedSource) {
461+
// If the source is missing (due to synthetic source or disabled mode)
462+
// or has been altered (via source filtering), store a reduced recovery source.
463+
// This includes the original source with synthetic vector fields removed for operation-based recovery.
464+
var recoverySource = removeSyntheticVectorFields(context.mappingLookup(), originalSource, contentType).toBytesRef();
465+
context.doc().add(new StoredField(RECOVERY_SOURCE_NAME, recoverySource.bytes, recoverySource.offset, recoverySource.length));
466+
context.doc().add(new NumericDocValuesField(RECOVERY_SOURCE_NAME, 1));
466467
}
467468
}
468469

0 commit comments

Comments
 (0)