Skip to content

Commit b3c93c4

Browse files
committed
[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 11ca95b commit b3c93c4

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
@@ -108,15 +108,7 @@ public JobDataDeleter(Client client, String jobId, boolean deleteUserAnnotations
108108
*/
109109
public void deleteModelSnapshots(List<ModelSnapshot> modelSnapshots, ActionListener<BulkByScrollResponse> listener) {
110110
if (modelSnapshots.isEmpty()) {
111-
listener.onResponse(
112-
new BulkByScrollResponse(
113-
TimeValue.ZERO,
114-
new BulkByScrollTask.Status(Collections.emptyList(), null),
115-
Collections.emptyList(),
116-
Collections.emptyList(),
117-
false
118-
)
119-
);
111+
listener.onResponse(emptyBulkByScrollResponse());
120112
return;
121113
}
122114

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

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

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

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

0 commit comments

Comments
 (0)