Skip to content

Let the OpenSearch worker clear its delete-by-query scrolls - #600

Merged
suguanYang merged 1 commit into
mainfrom
fix/wangbinqi/worker-scroll-clear-permission
Dec 1, 2026
Merged

suguanYang merged 1 commit into
mainfrom
fix/wangbinqi/worker-scroll-clear-permission

Conversation

@suguanYang

Copy link
Copy Markdown
Contributor

Summary

Lexical build cleanup runs _delete_by_query. OpenSearch opens a scroll for it and clears that scroll when the delete finishes. The rendered worker role could open the scroll but could not clear it:

hourly maintenance sweep
  LexicalCleanup.collect(build)            # one per lexical build
    _delete_by_query?refresh=true
      open scroll                          # allowed
      bulk delete, refresh                 # allowed
      clear scroll                         # denied → scroll stays open 5 min
...after ~500 builds
  open scroll → rejected (500 open scroll limit), retried ~30 s
  worker request → httpx.ReadTimeout
 knowhere_worker
   cluster_permissions
     indices:data/read/scroll
+    indices:data/read/scroll/clear
   namespace index actions
     ... delete/byquery, delete, refresh
+    indices:data/read/scroll
+    indices:data/read/scroll/clear

OpenSearch's permissions reference says both scroll actions must be granted at cluster and index level.

This PR changes the rendered role and the role check only. The live roles on the shared node are maintained by hand, so knowhere_prod_worker and knowhere_worker need the same actions added with the admin certificate (see deploy/opensearch/README.md, "Two-release rehearsal and cutover"). Use a role PATCH, not PUT, because PUT replaces the whole role.

Evidence

  • Before: in production, each hourly sweep cleaned about 500 lexical builds and then hit about 10 timeouts. The node log showed no permissions for [indices:data/read/scroll/clear] for the worker identity, followed by Trying to create too many scroll contexts. Must be less than or equal to: [500]. Node stats right after a sweep showed scroll_current: 500, and scrolls lived about 5.4 minutes on average, their full keep-alive.
    After: the rendered worker role grants the clear action. For a live role without it, manage.py application-roles now reports cluster indices:data/read/scroll/clear and exits 1.
test_application_role_check_detects_worker_unable_to_clear_scrolls
  worker role without indices:data/read/scroll/clear
  → check fails, missing == ["cluster indices:data/read/scroll/clear"]   # new, passes

deploy/opensearch/tests/test_operations.py passes on Python 3.12. Ruff passes on the changed files.

Merge Danger

Door: two-way

Only the rendered role definition, its tests and the README change. Reverting restores the previous rendering. The live role change is a separate operator step and can be undone with a PATCH remove.

Blast Radius: worker-role

After the live roles are updated, the worker can clear scroll contexts. It needs this action for every _delete_by_query it already runs. Until then, the role check reports the gap for both environments.

🤖 Generated with Claude Code

Build cleanup runs _delete_by_query, which opens a scroll and clears it when
the delete finishes. The worker role granted indices:data/read/scroll but not
indices:data/read/scroll/clear, so every clear was denied and each scroll
stayed open for its 5-minute keep-alive. Once the hourly maintenance sweep had
opened 500 scrolls, the node rejected every later delete and the worker
request timed out after 30 seconds.

Grant both scroll actions at cluster and index level, as OpenSearch requires,
and add a role-check test for a worker role that cannot clear scrolls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@suguanYang
suguanYang merged commit 5db63f8 into main Dec 1, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant