Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/130083.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 130083
summary: Fix timeout bug in DBQ deletion of unused and orphan ML data
area: Machine Learning
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,7 @@ public JobDataDeleter(Client client, String jobId, boolean deleteUserAnnotations
*/
public void deleteModelSnapshots(List<ModelSnapshot> modelSnapshots, ActionListener<BulkByScrollResponse> listener) {
if (modelSnapshots.isEmpty()) {
listener.onResponse(
new BulkByScrollResponse(
TimeValue.ZERO,
new BulkByScrollTask.Status(Collections.emptyList(), null),
Collections.emptyList(),
Collections.emptyList(),
false
)
);
listener.onResponse(emptyBulkByScrollResponse());
return;
}

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

String[] indicesToQuery = removeReadOnlyIndices(new ArrayList<>(indices), listener, "model snapshots", null);
String[] indicesToQuery = removeReadOnlyIndices(
new ArrayList<>(indices),
listener,
"model snapshots",
() -> listener.onResponse(emptyBulkByScrollResponse())
);
if (indicesToQuery.length == 0) return;

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

private static BulkByScrollResponse emptyBulkByScrollResponse() {
return new BulkByScrollResponse(
TimeValue.ZERO,
new BulkByScrollTask.Status(Collections.emptyList(), null),
Collections.emptyList(),
Collections.emptyList(),
false
);
}

/**
* Asynchronously delete the annotations
* If the deleteUserAnnotations field is set to true then all
Expand Down Expand Up @@ -309,7 +316,7 @@ public void deleteDatafeedTimingStats(ActionListener<BulkByScrollResponse> liste
List.of(AnomalyDetectorsIndex.jobResultsAliasedName(jobId)),
listener,
"datafeed timing stats",
null
() -> listener.onResponse(emptyBulkByScrollResponse())
);
if (indicesToQuery.length == 0) return;
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest(indicesToQuery).setRefresh(true)
Expand Down Expand Up @@ -502,7 +509,12 @@ private void deleteResultsByQuery(
ActionListener<BroadcastResponse> refreshListener = ActionListener.wrap(refreshResponse -> {
logger.info("[{}] running delete by query on [{}]", jobId, String.join(", ", indices));
ConstantScoreQueryBuilder query = new ConstantScoreQueryBuilder(new TermQueryBuilder(Job.ID.getPreferredName(), jobId));
String[] indicesToQuery = removeReadOnlyIndices(List.of(indices), listener, "results", null);
String[] indicesToQuery = removeReadOnlyIndices(
List.of(indices),
listener,
"results",
() -> listener.onResponse(emptyBulkByScrollResponse())
);
if (indicesToQuery.length == 0) return;
DeleteByQueryRequest request = new DeleteByQueryRequest(indicesToQuery).setQuery(query)
.setIndicesOptions(MlIndicesUtils.addIgnoreUnavailable(IndicesOptions.lenientExpandOpenHidden()))
Expand Down