-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an erorr store to record the errors encountered by DLM (#94391)
DLM can encounter errors when attempting to execupte the needed operations in order to implement the lifecycle configuration for a data stream. This adds an in-memory error store to record these errors.
- Loading branch information
Showing
6 changed files
with
607 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
modules/dlm/src/main/java/org/elasticsearch/dlm/DataLifecycleErrorStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.dlm; | ||
|
||
import org.elasticsearch.ElasticsearchException; | ||
import org.elasticsearch.core.Nullable; | ||
|
||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
import static org.elasticsearch.xcontent.ToXContent.EMPTY_PARAMS; | ||
|
||
/** | ||
* Provides a store for the errors DLM encounters. | ||
* It offers the functionality to record, retrieve, and clear errors for a specified target. | ||
* This class is thread safe. | ||
*/ | ||
public class DataLifecycleErrorStore { | ||
|
||
private final ConcurrentMap<String, String> targetToError = new ConcurrentHashMap<>(); | ||
|
||
/** | ||
* Records a string representation of the provided exception for the provided target. | ||
* If an error was already recorded for the provided target this will override that error. | ||
*/ | ||
public void recordError(String target, Exception e) { | ||
targetToError.put(target, org.elasticsearch.common.Strings.toString(((builder, params) -> { | ||
ElasticsearchException.generateThrowableXContent(builder, EMPTY_PARAMS, e); | ||
return builder; | ||
}))); | ||
} | ||
|
||
/** | ||
* Clears the recorded error for the provided target (if any exists) | ||
*/ | ||
public void clearRecordedError(String target) { | ||
targetToError.remove(target); | ||
} | ||
|
||
/** | ||
* Clears all the errors recorded in the store. | ||
*/ | ||
public void clearStore() { | ||
targetToError.clear(); | ||
} | ||
|
||
/** | ||
* Retrieves the recorderd error for the provided target. | ||
*/ | ||
@Nullable | ||
public String getError(String target) { | ||
return targetToError.get(target); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.