|
44 | 44 | * A service which runs the {@link LifecyclePolicy}s associated with indexes. |
45 | 45 | */ |
46 | 46 | public class IndexLifecycleService extends AbstractComponent |
47 | | - implements ClusterStateListener, ClusterStateApplier, SchedulerEngine.Listener, Closeable, LocalNodeMasterListener { |
| 47 | + implements ClusterStateListener, ClusterStateApplier, SchedulerEngine.Listener, Closeable, LocalNodeMasterListener { |
48 | 48 | private static final Logger logger = LogManager.getLogger(IndexLifecycleService.class); |
49 | 49 | private static final Set<String> IGNORE_ACTIONS_MAINTENANCE_REQUESTED = Collections.singleton(ShrinkAction.NAME); |
50 | 50 | private volatile boolean isMaster = false; |
@@ -111,18 +111,26 @@ public void onMaster() { |
111 | 111 | IndexMetaData idxMeta = cursor.value; |
112 | 112 | String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(idxMeta.getSettings()); |
113 | 113 | if (Strings.isNullOrEmpty(policyName) == false) { |
114 | | - StepKey stepKey = IndexLifecycleRunner.getCurrentStepKey(LifecycleExecutionState.fromIndexMetadata(idxMeta)); |
115 | | - if (OperationMode.STOPPING == currentMode && |
116 | | - stepKey != null && |
117 | | - IGNORE_ACTIONS_MAINTENANCE_REQUESTED.contains(stepKey.getAction()) == false) { |
118 | | - logger.info("skipping policy [{}] for index [{}]. stopping Index Lifecycle execution", |
119 | | - policyName, idxMeta.getIndex().getName()); |
120 | | - continue; |
| 114 | + final LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(idxMeta); |
| 115 | + StepKey stepKey = IndexLifecycleRunner.getCurrentStepKey(lifecycleState); |
| 116 | + |
| 117 | + if (OperationMode.STOPPING == currentMode) { |
| 118 | + if (stepKey != null && IGNORE_ACTIONS_MAINTENANCE_REQUESTED.contains(stepKey.getAction())) { |
| 119 | + logger.info("waiting to stop ILM because index [{}] with policy [{}] is currently in action [{}]", |
| 120 | + idxMeta.getIndex().getName(), policyName, stepKey.getAction()); |
| 121 | + lifecycleRunner.maybeRunAsyncAction(clusterState, idxMeta, policyName, stepKey); |
| 122 | + // ILM is trying to stop, but this index is in a Shrink action (or other dangerous action) so we can't stop |
| 123 | + safeToStop = false; |
| 124 | + } else { |
| 125 | + logger.info("skipping policy execution for index [{}] with policy [{}] because ILM is stopping", |
| 126 | + idxMeta.getIndex().getName(), policyName); |
| 127 | + } |
| 128 | + } else { |
| 129 | + lifecycleRunner.maybeRunAsyncAction(clusterState, idxMeta, policyName, stepKey); |
121 | 130 | } |
122 | | - lifecycleRunner.maybeRunAsyncAction(clusterState, idxMeta, policyName, stepKey); |
123 | | - safeToStop = false; // proven false! |
124 | 131 | } |
125 | 132 | } |
| 133 | + |
126 | 134 | if (safeToStop && OperationMode.STOPPING == currentMode) { |
127 | 135 | submitOperationModeUpdate(OperationMode.STOPPED); |
128 | 136 | } |
@@ -184,7 +192,7 @@ public void clusterChanged(ClusterChangedEvent event) { |
184 | 192 | @Override |
185 | 193 | public void applyClusterState(ClusterChangedEvent event) { |
186 | 194 | if (event.localNodeMaster()) { // only act if we are master, otherwise |
187 | | - // keep idle until elected |
| 195 | + // keep idle until elected |
188 | 196 | if (event.state().metaData().custom(IndexLifecycleMetadata.TYPE) != null) { |
189 | 197 | policyRegistry.update(event.state()); |
190 | 198 | } |
@@ -237,21 +245,34 @@ void triggerPolicies(ClusterState clusterState, boolean fromClusterStateChange) |
237 | 245 | IndexMetaData idxMeta = cursor.value; |
238 | 246 | String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(idxMeta.getSettings()); |
239 | 247 | if (Strings.isNullOrEmpty(policyName) == false) { |
240 | | - StepKey stepKey = IndexLifecycleRunner.getCurrentStepKey(LifecycleExecutionState.fromIndexMetadata(idxMeta)); |
241 | | - if (OperationMode.STOPPING == currentMode && stepKey != null |
242 | | - && IGNORE_ACTIONS_MAINTENANCE_REQUESTED.contains(stepKey.getAction()) == false) { |
243 | | - logger.info("skipping policy [" + policyName + "] for index [" + idxMeta.getIndex().getName() |
244 | | - + "]. stopping Index Lifecycle execution"); |
245 | | - continue; |
246 | | - } |
247 | | - if (fromClusterStateChange) { |
248 | | - lifecycleRunner.runPolicyAfterStateChange(policyName, idxMeta); |
| 248 | + final LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(idxMeta); |
| 249 | + StepKey stepKey = IndexLifecycleRunner.getCurrentStepKey(lifecycleState); |
| 250 | + |
| 251 | + if (OperationMode.STOPPING == currentMode) { |
| 252 | + if (stepKey != null && IGNORE_ACTIONS_MAINTENANCE_REQUESTED.contains(stepKey.getAction())) { |
| 253 | + logger.info("waiting to stop ILM because index [{}] with policy [{}] is currently in action [{}]", |
| 254 | + idxMeta.getIndex().getName(), policyName, stepKey.getAction()); |
| 255 | + if (fromClusterStateChange) { |
| 256 | + lifecycleRunner.runPolicyAfterStateChange(policyName, idxMeta); |
| 257 | + } else { |
| 258 | + lifecycleRunner.runPeriodicStep(policyName, idxMeta); |
| 259 | + } |
| 260 | + // ILM is trying to stop, but this index is in a Shrink action (or other dangerous action) so we can't stop |
| 261 | + safeToStop = false; |
| 262 | + } else { |
| 263 | + logger.info("skipping policy execution for index [{}] with policy [{}] because ILM is stopping", |
| 264 | + idxMeta.getIndex().getName(), policyName); |
| 265 | + } |
249 | 266 | } else { |
250 | | - lifecycleRunner.runPeriodicStep(policyName, idxMeta); |
| 267 | + if (fromClusterStateChange) { |
| 268 | + lifecycleRunner.runPolicyAfterStateChange(policyName, idxMeta); |
| 269 | + } else { |
| 270 | + lifecycleRunner.runPeriodicStep(policyName, idxMeta); |
| 271 | + } |
251 | 272 | } |
252 | | - safeToStop = false; // proven false! |
253 | 273 | } |
254 | 274 | } |
| 275 | + |
255 | 276 | if (safeToStop && OperationMode.STOPPING == currentMode) { |
256 | 277 | submitOperationModeUpdate(OperationMode.STOPPED); |
257 | 278 | } |
|
0 commit comments