Skip to content

Commit 96e285d

Browse files
authored
[ML] Fix timeout bug in DBQ deletion of unused and orphan ML data (#130083) (#130103)
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 95f84bb commit 96e285d

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

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

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

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

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

0 commit comments

Comments
 (0)