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

refactor(VirtualFile::crashsafe_overwrite): avoid Handle::block_on in callers #6731

Conversation

problame
Copy link
Contributor

@problame problame commented Feb 12, 2024

Some callers of VirtualFile::crashsafe_overwrite call it on the executor thread, thereby potentially stalling it.

Others are more diligent and wrap it in spawn_blocking(..., Handle::block_on, ... ) to avoid stalling the executor thread.

However, because crashsafe_overwrite uses VirtualFile::open_with_options internally, we spawn a new thread-local tokio-epoll-uring::System in the blocking pool thread that's used for the spawn_blocking call.

This PR refactors the situation such that we do the spawn_blocking inside VirtualFile::crashsafe_overwrite. This unifies the situation for the better:

  1. Callers who didn't wrap in spawn_blocking(..., Handle::block_on, ...) before no longer stall the executor.
  2. Callers who did it before now can avoid the block_on, resolving the problem with the short-lived tokio-epoll-uring::Systems in the blocking pool threads.

A future PR will build on top of this and divert to tokio-epoll-uring if it's configures as the IO engine.

Changes

  • Convert implementation to std::fs and move it into crashsafe.rs

    • Yes, I know, Safekeepers (cc @arssher ) added durable_rename and fsync_async_opt recently. However, crashsafe_overwrite is different in the sense that it's higher level, i.e., it's more like std::fs::write and the Safekeeper team's code is more building block style.
    • The consequence is that we don't use the VirtualFile file descriptor cache anymore.
    • I don't think it's a big deal because we have plenty of slack wrt production file descriptor limit rlimit (see this dashboard)
  • Use tokio::task::spawn_blocking in VirtualFile::crashsafe_overwrite to call the new crashsafe::overwrite API.

  • Inspect all callers to remove any double-spawn_blocking

  • spawn_blocking requires the captures data to be 'static + Send. So, refactor the callers. We'll need this for future tokio-epoll-uring support anyway, because tokio-epoll-uring requires owned buffers.

Related Issues

Copy link

github-actions bot commented Feb 12, 2024

2436 tests run: 2319 passed, 0 failed, 117 skipped (full report)


Flaky tests (4)

Postgres 15

  • test_create_snapshot: debug, release
  • test_empty_tenant_size: release
  • test_delete_timeline_exercise_crash_safety_failpoints[Check.RETRY_WITH_RESTART-timeline-delete-before-rm]: release

Code coverage (full report)

  • functions: 55.9% (12848 of 22966 functions)
  • lines: 82.5% (69298 of 83998 lines)

The comment gets automatically updated with the latest test results
d0f2ab3 at 2024-02-14T14:25:41.325Z :recycle:

@problame problame requested review from jcsp and koivunej February 12, 2024 17:35
@problame problame marked this pull request as ready for review February 12, 2024 17:35
@problame problame requested a review from a team as a code owner February 12, 2024 17:35
Copy link
Member

@koivunej koivunej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove the REVIEW: tags. I see no issues apart from the cutpasted comment.

@problame
Copy link
Contributor Author

Need to remove the REVIEW: tags. I

Ok, so, you don't see a problem with us now doing spawn_blocking in those places?

…ath/crashsafe_overwrite/switch-to-spawn-blocking
Copy link
Collaborator

@jcsp jcsp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. In hindsight, we should have done this way back when the prototype of crashsafe_overwrite was changed to async.

@koivunej
Copy link
Member

Ok, so, you don't see a problem with us now doing spawn_blocking in those places?

No issues.

@problame problame enabled auto-merge (squash) February 14, 2024 12:42
@problame problame merged commit df5d588 into main Feb 14, 2024
49 of 50 checks passed
@problame problame deleted the problame/integrate-tokio-epoll-uring/write-path/crashsafe_overwrite/switch-to-spawn-blocking branch February 14, 2024 14:22
jcsp pushed a commit that referenced this pull request Feb 14, 2024
…ck_on in callers" (#6765)

Reverts #6731

On high tenant count Pageservers in staging, memory and CPU usage shoots
to 100% with this change. (NB: staging currently has tokio-epoll-uring
enabled)

Will analyze tomorrow.


https://neondb.slack.com/archives/C03H1K0PGKH/p1707933875639379?thread_ts=1707929541.125329&cid=C03H1K0PGKH
problame added a commit that referenced this pull request Feb 23, 2024
…dle::block_on in callers"" (#6775)

Reverts #6765 , bringing back #6731

We concluded that #6731 never was the root cause for the instability in
staging.
More details:
https://neondb.slack.com/archives/C033RQ5SPDH/p1708011674755319

However, the massive amount of concurrent `spawn_blocking` calls from
the `save_metadata` calls during startups might cause a performance
regression.
So, we'll merge this PR here after we've stopped writing the metadata
#6769).
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.

3 participants