Skip to content

Commit 4c7d922

Browse files
authored
[ML] Fix timeout bug in DBQ deletion of unused and orphan ML data (#130083)
There was a bug in the code for deleting unused and orphan ML data. When deletion using DBQ occurred, the bug caused the request to time out. This PR resolves the issue.
1 parent a6004a6 commit 4c7d922

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

docs/changelog/130083.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 130083
2+
summary: Fix timeout bug in DBQ deletion of unused and orphan ML data
3+
area: Machine Learning
4+
type: bug
5+
issues: []

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobDataDeleter.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,7 @@ public JobDataDeleter(Client client, String jobId, boolean deleteUserAnnotations
109109
*/
110110
public void deleteModelSnapshots(List<ModelSnapshot> modelSnapshots, ActionListener<BulkByScrollResponse> listener) {
111111
if (modelSnapshots.isEmpty()) {
112-
listener.onResponse(
113-
new BulkByScrollResponse(
114-
TimeValue.ZERO,
115-
new BulkByScrollTask.Status(Collections.emptyList(), null),
116-
Collections.emptyList(),
117-
Collections.emptyList(),
118-
false
119-
)
120-
);
112+
listener.onResponse(emptyBulkByScrollResponse());
121113
return;
122114
}
123115

@@ -134,7 +126,12 @@ public void deleteModelSnapshots(List<ModelSnapshot> modelSnapshots, ActionListe
134126
indices.add(AnomalyDetectorsIndex.jobResultsAliasedName(modelSnapshot.getJobId()));
135127
}
136128

137-
String[] indicesToQuery = removeReadOnlyIndices(new ArrayList<>(indices), listener, "model snapshots", null);
129+
String[] indicesToQuery = removeReadOnlyIndices(
130+
new ArrayList<>(indices),
131+
listener,
132+
"model snapshots",
133+
() -> listener.onResponse(emptyBulkByScrollResponse())
134+
);
138135
if (indicesToQuery.length == 0) return;
139136

140137
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest(indicesToQuery).setRefresh(true)
@@ -147,6 +144,16 @@ public void deleteModelSnapshots(List<ModelSnapshot> modelSnapshots, ActionListe
147144
executeAsyncWithOrigin(client, ML_ORIGIN, DeleteByQueryAction.INSTANCE, deleteByQueryRequest, listener);
148145
}
149146

147+
private static BulkByScrollResponse emptyBulkByScrollResponse() {
148+
return new BulkByScrollResponse(
149+
TimeValue.ZERO,
150+
new BulkByScrollTask.Status(Collections.emptyList(), null),
151+
Collections.emptyList(),
152+
Collections.emptyList(),
153+
false
154+
);
155+
}
156+
150157
/**
151158
* Asynchronously delete the annotations
152159
* If the deleteUserAnnotations field is set to true then all
@@ -311,7 +318,7 @@ public void deleteDatafeedTimingStats(ActionListener<BulkByScrollResponse> liste
311318
List.of(AnomalyDetectorsIndex.jobResultsAliasedName(jobId)),
312319
listener,
313320
"datafeed timing stats",
314-
null
321+
() -> listener.onResponse(emptyBulkByScrollResponse())
315322
);
316323
if (indicesToQuery.length == 0) return;
317324
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest(indicesToQuery).setRefresh(true)
@@ -504,7 +511,12 @@ private void deleteResultsByQuery(
504511
ActionListener<BroadcastResponse> refreshListener = ActionListener.wrap(refreshResponse -> {
505512
logger.info("[{}] running delete by query on [{}]", jobId, String.join(", ", indices));
506513
ConstantScoreQueryBuilder query = new ConstantScoreQueryBuilder(new TermQueryBuilder(Job.ID.getPreferredName(), jobId));
507-
String[] indicesToQuery = removeReadOnlyIndices(List.of(indices), listener, "results", null);
514+
String[] indicesToQuery = removeReadOnlyIndices(
515+
List.of(indices),
516+
listener,
517+
"results",
518+
() -> listener.onResponse(emptyBulkByScrollResponse())
519+
);
508520
if (indicesToQuery.length == 0) return;
509521
DeleteByQueryRequest request = new DeleteByQueryRequest(indicesToQuery).setQuery(query)
510522
.setIndicesOptions(MlIndicesUtils.addIgnoreUnavailable(IndicesOptions.lenientExpandOpenHidden()))

0 commit comments

Comments
 (0)