[BUG] PIT is not deleted when a Calcite query is rejected for memory at start

Open
#5,860 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
Half a day
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
java
Domain
backend, search

Research direction

Start in CalciteEnumerableIndexScan.enumerator(), where osIndex.buildRequest(...) runs as a constructor argument and creates the PIT before OpenSearchIndexEnumerator's constructor performs the memory check and may throw. Read that constructor and its close() method to see why the PIT is never deleted. Done means that a rejected query leaves no open PIT contexts, either because the memory check runs before buildRequest or because the PIT is deleted when the constructor throws, and a test covers that path.

Written by the indexing model from the issue text.

Description

bug PPL
Issue Summary:

When a query is rejected with Insufficient resources to start query, the PIT it already created is never deleted. It stays open until plugins.sql.cursor.keep_alive (1m) expires.

In CalciteEnumerableIndexScan.enumerator(), osIndex.buildRequest(...) is passed as a constructor argument, so it runs first and creates the PIT. The OpenSearchIndexEnumerator constructor then fails its memory check and throws, so no enumerator exists and close() never runs to delete the PIT.

Steps to Reproduce:
  1. Index 200k docs into a 2-shard index.
  2. Bring heap above plugins.query.memory_limit (default 85%).
  3. Run a full-scan query 20 times, e.g. source=big | eval z=concat(s, cast(k as string)) | eventstats count() as c by g | sort - z | head 5.
  4. Check point_in_time_current in _nodes/stats/indices/search.

###Expected Result:
no open PIT contexts after the queries fail.

Actual Result:

every "start query" rejection leaves 2 open PIT contexts (one per shard) until they expire. Queries rejected mid-scan ("continue processing") don't leak, and neither do successful ones.

Impact:

under memory pressure, rejected queries pile up open PIT contexts toward search.max_open_pit_context (300). New queries can keep failing for up to a minute after memory recovers. Async submits make this easier to hit.

Suggested fix:

check the resource monitor before calling buildRequest, or delete the PIT if the constructor throws.

Env Setup - OpenSearch Version:

3.10.0-SNAPSHOT, main @ 866dafcbd

Dominant language
Java
Stars
176
Forks
237
Avg merge
2d 12h
Merged PRs (30d)
34

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from opensearch-project/sql

All issues in opensearch-project/sql

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.