Skip to content

Add explicit isNoOpUpdate() method to MapperService#144113

Merged
elasticsearchmachine merged 7 commits intoelastic:mainfrom
romseygeek:mapping/preflight-checks-method
Mar 16, 2026
Merged

Add explicit isNoOpUpdate() method to MapperService#144113
elasticsearchmachine merged 7 commits intoelastic:mainfrom
romseygeek:mapping/preflight-checks-method

Conversation

@romseygeek
Copy link
Copy Markdown
Contributor

We currently check that a mapping update will be applied and that it is not a no-op by calling MapperService.merge() with a special merge reason. All other calls to merge() will update the state of the MapperService, but this just does preflight checks. This can be confusing when reading code - it's not necessarily obvious if a call to merge() is going to change state or not. To make this clearer, we separate preflight checks that don't change state, and real merges that do change state, into separate method calls.

We currently check that a mapping update will be applied and that it is
not a no-op by calling MapperService.merge() with a special merge
reason.  All other calls to merge() will update the state of the
MapperService, but this just does preflight checks. This can be
confusing when reading code - it's not necessarily obvious if a call
to merge() is going to change state or not. To make this clearer,
we separate preflight checks that don't change state, and real
merges that do change state, into separate method calls.
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

Copy link
Copy Markdown
Member

@martijnvg martijnvg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, LGTM 👍

@romseygeek romseygeek requested a review from drempapis March 13, 2026 12:03
@romseygeek
Copy link
Copy Markdown
Contributor Author

@drempapis would appreciate your eyes on this, given the fix you merged this morning!

}

private DocumentMapper doMerge(String type, MergeReason reason, Map<String, Object> mappingSourceAsMap) {
assert reason != MergeReason.MAPPING_AUTO_UPDATE_PREFLIGHT;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this assert enough? Should it be replaced by a runtime check, throwing an exception?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An assertion should be fine I think, MergeReason is entirely internal.

// returning the current document mapper as the merge result to simulate a noop mapping update
when(mapperService.documentMapper()).thenReturn(documentMapper);
when(mapperService.merge(any(), any(CompressedXContent.class), any())).thenReturn(documentMapper);
when(mapperService.isNoOpUpdate(any())).thenReturn(true);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That behavior already existed, but I think we should remove the mockito framework.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, good idea. There are several tests in here that use Mockito so I think probably it's best done as a follow-up covering all of them, to keep things separate?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this should be done in a follow-up pr

Copy link
Copy Markdown
Contributor

@drempapis drempapis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@romseygeek romseygeek added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Mar 13, 2026
@elasticsearchmachine elasticsearchmachine merged commit 4bbbe70 into elastic:main Mar 16, 2026
36 checks passed
@romseygeek romseygeek deleted the mapping/preflight-checks-method branch March 16, 2026 11:23
szybia added a commit to szybia/elasticsearch that referenced this pull request Mar 16, 2026
…elocations

* upstream/main: (33 commits)
  Unmute InferenceRestIT and DefaultEndPointsIT (elastic#144217)
  feat: add keep_alive to async task status (elastic#144010)
  Add explicit isNoOpUpdate() method to MapperService (elastic#144113)
  Always attach APM Agent (elastic#144120)
  Fix random_score nightly tests (elastic#144176)
  Add nested query checks for disabled sequence numbers (elastic#144185)
  Return sentinel values from Fetch when sequence numbers are disabled (elastic#144212)
  [Test] Test peer-recovery with sequence numbers pruning (elastic#144116)
  Remove `scaled-*` field assertions from mixed cluster downsampling test (elastic#144295)
  Refactor: Use range syntax in ES|QL exponential histogram tests (elastic#144110)
  Move resolve aliases to IndexAbstractionOptions (elastic#143953)
  unmute test (elastic#144299)
  Fix approximation csvtests (elastic#144233)
  fix test (elastic#144171)
  Add int4 vector scoring benchmarks (elastic#144105)
  Mute org.elasticsearch.xpack.esql.qa.single_node.GenerativeIT test elastic#143023
  Mute org.elasticsearch.test.apmintegration.MetricsApmIT testApmIntegration {withOTel=false} elastic#144282
  Native cli launcher (elastic#143712)
  Mute org.elasticsearch.xpack.esql.qa.multi_node.GenerativeIT test elastic#143023
  Mute org.elasticsearch.xpack.esql.heap_attack.HeapAttackSubqueryIT testManyRandomKeywordFieldsInSubqueryIntermediateResults elastic#144274
  ...
michalborek pushed a commit to michalborek/elasticsearch that referenced this pull request Mar 23, 2026
We currently check that a mapping update will be applied and that it is
not a no-op by calling MapperService.merge() with a special merge
reason.  All other calls to merge() will update the state of the
MapperService, but this just does preflight checks. This can be
confusing when reading code - it's not necessarily obvious if a call to
merge() is going to change state or not. To make this clearer, we
separate preflight checks that don't change state, and real merges that
do change state, into separate method calls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) >non-issue :StorageEngine/Mapping The storage related side of mappings Team:StorageEngine v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants