Skip to content

Commit ea9c861

Browse files
committed
Add a javadoc and an explanatory comment
1 parent c42995b commit ea9c861

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

  • server/src/main/java/org/elasticsearch/cluster/metadata

server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,17 @@ public Metadata withIncrementedVersion() {
300300
);
301301
}
302302

303+
/**
304+
* Given an index and lifecycle state, returns a metadata where the lifecycle state will be
305+
* associated with the given index.
306+
*
307+
* The passed-in index must already be present in the cluster state, this method cannot
308+
* be used to add an index.
309+
*
310+
* @param index A non-null index
311+
* @param lifecycleState A non-null lifecycle execution state
312+
* @return a <code>Metadata</code> instance where the index has the provided lifecycle state
313+
*/
303314
public Metadata withLifecycleState(final Index index, final LifecycleExecutionState lifecycleState) {
304315
Objects.requireNonNull(index, "index must not be null");
305316
Objects.requireNonNull(lifecycleState, "lifecycleState must not be null");
@@ -318,6 +329,10 @@ public Metadata withLifecycleState(final Index index, final LifecycleExecutionSt
318329
final ImmutableOpenMap.Builder<String, IndexMetadata> builder = ImmutableOpenMap.builder(indices);
319330
builder.put(index.getName(), indexMetadataBuilder.build());
320331

332+
// construct a new Metadata object directly rather than using Metadata.builder(this).[...].build().
333+
// the Metadata.Builder validation needs to handle the general case where anything at all could
334+
// have changed, and hence it is expensive -- since we are changing so little about the metadata
335+
// (and at a leaf in the object tree), we can bypass that validation for efficiency's sake
321336
return new Metadata(
322337
clusterUUID,
323338
clusterUUIDCommitted,

0 commit comments

Comments
 (0)