-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move IndexLifecycleMetadata installation to put-lifecycle-action #31346
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,8 @@ Map<String, Map<Step.StepKey, Step>> getStepMap() { | |
@SuppressWarnings({ "unchecked", "rawtypes" }) | ||
public void update(ClusterState currentState, Client client, LongSupplier nowSupplier) { | ||
IndexLifecycleMetadata meta = currentState.metaData().custom(IndexLifecycleMetadata.TYPE); | ||
assert meta != null : "IndexLifecycleMetadata cannot be null when updating the policy steps registry"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've seen this pattern of assertion elsewhere in the codebase. I am not sure how I feel about it, but I chose to try it out here to be self-documenting. Currently this method is only ever called once, and it is behind a null check |
||
|
||
Diff<Map<String, LifecyclePolicyMetadata>> diff = DiffableUtils.diff(lifecyclePolicyMap, meta.getPolicyMetadatas(), | ||
DiffableUtils.getStringKeySerializer()); | ||
DiffableUtils.MapDiff<String, LifecyclePolicyMetadata, DiffableUtils.KeySerializer<String>> mapDiff = (DiffableUtils.MapDiff) diff; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,11 +32,12 @@ | |
import java.util.SortedMap; | ||
import java.util.TreeMap; | ||
|
||
public class TransportDeleteLifcycleAction extends TransportMasterNodeAction<Request, Response> { | ||
public class TransportDeleteLifecycleAction extends TransportMasterNodeAction<Request, Response> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missed an existing typo |
||
|
||
@Inject | ||
public TransportDeleteLifcycleAction(Settings settings, TransportService transportService, ClusterService clusterService, | ||
ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { | ||
public TransportDeleteLifecycleAction(Settings settings, TransportService transportService, ClusterService clusterService, | ||
ThreadPool threadPool, ActionFilters actionFilters, | ||
IndexNameExpressionResolver indexNameExpressionResolver) { | ||
super(settings, DeleteLifecycleAction.NAME, transportService, clusterService, threadPool, actionFilters, | ||
indexNameExpressionResolver, Request::new); | ||
} | ||
|
@@ -74,7 +75,8 @@ public ClusterState execute(ClusterState currentState) { | |
} | ||
ClusterState.Builder newState = ClusterState.builder(currentState); | ||
IndexLifecycleMetadata currentMetadata = currentState.metaData().custom(IndexLifecycleMetadata.TYPE); | ||
if (currentMetadata.getPolicyMetadatas().containsKey(request.getPolicyName()) == false) { | ||
if (currentMetadata == null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this is an anonymous class, we do not have good unit test coverage, so I've added a yaml test to walk this branch |
||
|| currentMetadata.getPolicyMetadatas().containsKey(request.getPolicyName()) == false) { | ||
throw new ResourceNotFoundException("Lifecycle policy not found: {}", request.getPolicyName()); | ||
} | ||
SortedMap<String, LifecyclePolicyMetadata> newPolicies = new TreeMap<>(currentMetadata.getPolicyMetadatas()); | ||
|
@@ -91,4 +93,4 @@ public ClusterState execute(ClusterState currentState) { | |
protected ClusterBlockException checkBlock(Request request, ClusterState state) { | ||
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,10 @@ | |
import java.util.TreeMap; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* This class is responsible for bootstrapping {@link IndexLifecycleMetadata} into the cluster-state, as well | ||
* as adding the desired new policy to be inserted. | ||
*/ | ||
public class TransportPutLifecycleAction extends TransportMasterNodeAction<Request, Response> { | ||
|
||
@Inject | ||
|
@@ -64,6 +68,9 @@ protected Response newResponse(boolean acknowledged) { | |
public ClusterState execute(ClusterState currentState) throws Exception { | ||
ClusterState.Builder newState = ClusterState.builder(currentState); | ||
IndexLifecycleMetadata currentMetadata = currentState.metaData().custom(IndexLifecycleMetadata.TYPE); | ||
if (currentMetadata == null) { // first time using index-lifecycle feature, bootstrap metadata | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. existing yaml tests should walk this branch |
||
currentMetadata = IndexLifecycleMetadata.EMPTY; | ||
} | ||
if (currentMetadata.getPolicyMetadatas().containsKey(request.getPolicy().getName())) { | ||
throw new ResourceAlreadyExistsException("Lifecycle policy already exists: {}", | ||
request.getPolicy().getName()); | ||
|
@@ -87,4 +94,4 @@ public ClusterState execute(ClusterState currentState) throws Exception { | |
protected ClusterBlockException checkBlock(Request request, ClusterState state) { | ||
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ThreadPool is no longer used since the service does not issue a cluster-state-update to install metadata anymore