Skip to content
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

Add ETA for Reindex, update_by_query, delete_by_query #89791

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

amooncake
Copy link
Contributor

Closes #76904

@github-actions
Copy link

github-actions bot commented Sep 4, 2022

Documentation preview:

@elasticsearchmachine elasticsearchmachine added v8.5.0 external-contributor Pull request authored by a developer outside the Elasticsearch team labels Sep 4, 2022
@amooncake
Copy link
Contributor Author

Add eta_millis in status, a human readable eta will also be returned when human=true in query params

{
  "node": "Xqj-2eUEQES4sqBzcX4FVA",
  "id": 172,
  "type": "transport",
  "action": "indices:data/write/delete/byquery",
  "status": {
    "slice_id": 1,
    "total": 113,
    "updated": 0,
    "created": 0,
    "deleted": 8,
    "batches": 4,
    "version_conflicts": 0,
    "noops": 0,
    "retries": {
      "bulk": 0,
      "search": 0
    },
    "throttled": "11.9s",
    "throttled_millis": 11999,
    "requests_per_second": 0.5,
    "throttled_until": "3.3s",
    "throttled_until_millis": 3325,
    "eta": "3.4m",
    "eta_millis": 209999
  },
  "description": "delete-by-query [sales]",
  "start_time": "2022-09-04T07:57:14.465Z",
  "start_time_in_millis": 1662278234465,
  "running_time": "13s",
  "running_time_in_nanos": 13015756458,
  "cancellable": true,
  "cancelled": false,
  "parent_task_id": "Xqj-2eUEQES4sqBzcX4FVA:168",
  "headers": {
    
  }
}

For reviewers: eta was calculated by rest/lastBatchRequestsPerMillis

public TimeValue throttleWaitTime(long lastBatchStartTimeNS, long nowNS, int lastBatchSize) {
long earliestNextBatchStartTime = nowNS + (long) perfectlyThrottledBatchTime(lastBatchSize);
long waitTime = min(MAX_THROTTLE_WAIT_TIME.nanos(), max(0, earliestNextBatchStartTime - System.nanoTime()));
this.lastBatchRequestsPerMillis = 1.0f * lastBatchSize / max(
1,
TimeUnit.NANOSECONDS.toMillis(earliestNextBatchStartTime - lastBatchStartTimeNS)
);
return timeValueNanos(waitTime);
}

TimeValue eta() {
if (lastBatchRequestsPerMillis > 0) {
long done = updated.get() + created.get() + deleted.get() + noops.get() + versionConflicts.get();
long rest = total.get() - done;
// `done` should be less than `total`, just in case
rest = rest < 0 ? 0 : rest;
return timeValueMillis((long) Math.floor(rest / lastBatchRequestsPerMillis));
} else {
return timeValueMillis(0);
}
}

DELETE sales

PUT sales

POST sales/_bulk?refresh
{"index":{}}
{"date": "2015/01/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "hat"}
{"index":{}}
{"date": "2015/01/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "t-shirt"}
{"index":{}}
{"date": "2015/01/01 00:00:00", "price": 150, "promoted": true, "rating": 5, "type": "bag"}
{"index":{}}
{"date": "2015/02/01 00:00:00", "price": 50, "promoted": false, "rating": 1, "type": "hat"}
{"index":{}}
{"date": "2015/02/01 00:00:00", "price": 10, "promoted": true, "rating": 4, "type": "t-shirt"}

POST sales/_delete_by_query?scroll_size=2&wait_for_completion=false&requests_per_second=1&slices=2&&conflicts=proceed
{
  "query": {
    "match_all": {}
  }
}

GET _tasks?detailed=true&actions=*/write/*&human=true&group_by=parents

@amooncake amooncake marked this pull request as ready for review September 4, 2022 08:41
@elasticsearchmachine elasticsearchmachine added the needs:triage Requires assignment of a team area label label Sep 4, 2022
@DaveCTurner DaveCTurner added :Distributed/Reindex Issues relating to reindex that are not caused by issues further down and removed needs:triage Requires assignment of a team area label labels Sep 8, 2022
@elasticsearchmachine elasticsearchmachine added the Team:Distributed Meta label for distributed team label Sep 8, 2022
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed/Reindex Issues relating to reindex that are not caused by issues further down external-contributor Pull request authored by a developer outside the Elasticsearch team Team:Distributed Meta label for distributed team v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ETA for Reindex API