Skip to content

[BUG] SQL Join timeout isn't applied when using PIT #3820

Open

Description

@Swiddis

What is the bug?
When using a JOIN timeout hint with a PIT-enabled cluster, the PIT will get deleted before the timeout expires.

Caused by: java.lang.IllegalArgumentException: Point In Time id: [y_T7MwDnSG-rblpw9Xa6mQ] doesn't exist

This is due to a 1-minute keepalive

Used by PIT at

LocalClusterState.state().getSettingValue(SQL_CURSOR_KEEP_ALIVE), false, indices);

How can one reproduce the bug?
Steps to reproduce the behavior:

  1. Create indices that require more than 60s to join on (>5 mil records each)
  2. Configure the cluster to use PIT joins per
    "plugins.sql.pagination.api" : "true"
  3. Run a join query with a longer join timeout hint /*! JOIN_TIME_OUT(90) */
  4. See in the logs that the join failed because the PIT no longer exists (deleted by the 1m keepalive)

What is the expected behavior?
The JOIN_TIME_OUT should also update the keepalive

What is your host/environment?

  • OS: Latest

Do you have any screenshots?
N/A

Do you have any additional context?
Add any other context about the problem.

Activity

  1. added
    bug
    on Jun 24, 2025
  2. penghuo commented on Jun 25, 2025

    @penghuo
    Collaborator

    See in the logs that the join failed because the PIT no longer exists (deleted by the 1m keepalive)

    Every time you access a PIT by using the Search API, the PIT lifetime is extended by the amount of time equal to the keep_alive parameter.

    For Join, blockHash operator read one block from LeftTable, and iterate all data from rightTable. So if iterate all data from rightTable took more than keep_alive time, then the pit on LeftTable will be deleted.

    Question, Could we confirm that iterate all data from rightTable took more than keep_alive time?

  3. Swiddis commented on Jun 25, 2025

    @Swiddis
    CollaboratorAuthor

    Did some testing with @noCharger, it looks like on Serverless the PIT extension isn't automatic, so we have the right index PIT getting deleted after 60s. We'd need to add the keep_alive parameter to the PointInTimeBuilder for our batch loader to make it apply.

    Here's a trace from the join running on it, out.txt. This is the right index PIT getting deleted for this query:

    SELECT /*! JOIN_TIME_OUT(90) */ l.spanId, r.spanId, r.epoch FROM nginx_logs_left AS l LEFT JOIN nginx_logs_right AS r ON l.epoch = r.epoch LIMIT 3
    

    We can see that it creates the PIT on the logs_right index (the shards are listed at the end), paginates through the PIT (~6 pages/second), and then the PIT is dropped after 60s.

    To your point, I do see that it loads the first batch of some earlier PITs before the big scan, which also would be deleted in spite of fixing the keepalive since no new pages are fetched for those other PITs.

    2025-06-24 22:40:51.619 Created Point In Time FZuhvrtKReSRxx51Vzo3CA successfully.
    2025-06-24 22:40:51.630 Created Point In Time tkUYvb-IRcCuZgDWxsMWzw successfully.
    2025-06-24 22:40:51.631 Loading first batch of response using Point In Time
    2025-06-24 22:40:51.821 Created Point In Time y_T7MwDnSG-rblpw9Xa6mQ successfully.
    2025-06-24 22:40:51.821 Loading first batch of response using Point In Time
    2025-06-24 22:40:52.105 Loading next batch of response using Point In Time. - y_T7MwDnSG-rblpw9Xa6mQ
    2025-06-24 22:40:52.325 Loading next batch of response using Point In Time. - y_T7MwDnSG-rblpw9Xa6mQ
    2025-06-24 22:40:52.622 Loading next batch of response using Point In Time. - y_T7MwDnSG-rblpw9Xa6mQ
    2025-06-24 22:40:52.838 Loading next batch of response using Point In Time. - y_T7MwDnSG-rblpw9Xa6mQ
    ...
    

    So a robust solution I think needs to fix both: the left index PIT needs to be kept alive long enough to scan the right index, and the right index PIT also needs to be extended. (Alternatively, we can skip extending the right index and just create both PITs with the correct timing, since we need that solution for the left index anyway.)

  4. Swiddis commented on Jun 25, 2025

    @Swiddis
    CollaboratorAuthor

    Did some more debugging across environments and discussed in side channels. Action items for this:

    1. Modify the PIT creation logic to use a join timeout hint for keepalive if present; don't worry about PIT extension since it won't generalize to the left index
    2. Improve the error handling around these timeouts, guide user to using join timeout hint if the query fails due to timeout
  5. noCharger commented on Jun 26, 2025

    @noCharger
    Collaborator

    The actual issue is how this join timeout hint works with PIT keep_alive:

    1. When join timeout <= keep_alive, ResourceManager will circuit-break the query (for example, in the default case, both are 60s).
    2. When join timeout > keep_alive, if PIT doesn't auto-extend, the query will be stopped due to PIT not existing.

    The proposal makes sense to me in terms of join timeout hint control PIT keep_alive in case PIT doesn't auto-extend. That would force case 2 to go to case 1.

    However, if PIT can auto-extend, it will always go to case 1, and user can send new query with the hint as current codebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    SQLbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions