-
Notifications
You must be signed in to change notification settings - Fork 24.6k
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
[ML] Delete unused data frame analytics state #50243
Changes from all commits
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 |
---|---|---|
|
@@ -10,13 +10,15 @@ | |
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; | ||
import org.elasticsearch.action.bulk.BulkRequestBuilder; | ||
import org.elasticsearch.action.bulk.BulkResponse; | ||
import org.elasticsearch.action.delete.DeleteResponse; | ||
import org.elasticsearch.action.get.GetResponse; | ||
import org.elasticsearch.action.index.IndexAction; | ||
import org.elasticsearch.action.index.IndexRequest; | ||
import org.elasticsearch.action.search.SearchResponse; | ||
import org.elasticsearch.action.support.WriteRequest; | ||
import org.elasticsearch.index.query.QueryBuilder; | ||
import org.elasticsearch.index.query.QueryBuilders; | ||
import org.elasticsearch.rest.RestStatus; | ||
import org.elasticsearch.search.SearchHit; | ||
import org.elasticsearch.xpack.core.ml.action.EvaluateDataFrameAction; | ||
import org.elasticsearch.xpack.core.ml.dataframe.DataFrameAnalyticsConfig; | ||
|
@@ -315,6 +317,38 @@ public void testTwoJobsWithSameRandomizeSeedUseSameTrainingSet() throws Exceptio | |
assertThat(secondRunTrainingRowsIds, equalTo(firstRunTrainingRowsIds)); | ||
} | ||
|
||
public void testDeleteExpiredData_RemovesUnusedState() throws Exception { | ||
initialize("classification_delete_expired_data"); | ||
indexData(sourceIndex, 100, 0, KEYWORD_FIELD); | ||
|
||
DataFrameAnalyticsConfig config = buildAnalytics(jobId, sourceIndex, destIndex, null, new Classification(KEYWORD_FIELD)); | ||
registerAnalytics(config); | ||
putAnalytics(config); | ||
startAnalytics(jobId); | ||
waitUntilAnalyticsIsStopped(jobId); | ||
|
||
assertProgress(jobId, 100, 100, 100, 100); | ||
assertThat(searchStoredProgress(jobId).getHits().getTotalHits().value, equalTo(1L)); | ||
assertModelStatePersisted(stateDocId()); | ||
assertInferenceModelPersisted(jobId); | ||
|
||
// Call _delete_expired_data API and check nothing was deleted | ||
assertThat(deleteExpiredData().isDeleted(), is(true)); | ||
assertThat(searchStoredProgress(jobId).getHits().getTotalHits().value, equalTo(1L)); | ||
assertModelStatePersisted(stateDocId()); | ||
|
||
// Delete the config straight from the config index | ||
DeleteResponse deleteResponse = client().prepareDelete(".ml-config", DataFrameAnalyticsConfig.documentId(jobId)) | ||
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. Why delete the config? Does 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. Yes, for the state to become "unused", ie. there is no job owning those state docs. |
||
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).execute().actionGet(); | ||
assertThat(deleteResponse.status(), equalTo(RestStatus.OK)); | ||
|
||
// Now calling the _delete_expired_data API should remove unused state | ||
assertThat(deleteExpiredData().isDeleted(), is(true)); | ||
|
||
SearchResponse stateIndexSearchResponse = client().prepareSearch(".ml-state").execute().actionGet(); | ||
assertThat(stateIndexSearchResponse.getHits().getTotalHits().value, equalTo(0L)); | ||
} | ||
|
||
private void initialize(String jobId) { | ||
this.jobId = jobId; | ||
this.sourceIndex = jobId + "_source_index"; | ||
|
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.
Should the suffix have the
#1
attached, it feels like thats a number that will changeThere 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.
I also thought about this. We currently handle just a single doc. But we can fix this if and when we switch to handling state split over multiple docs.