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

pageserver: generation number fetch on startup and use in /attach #5163

Merged
merged 46 commits into from
Sep 6, 2023

Conversation

jcsp
Copy link
Collaborator

@jcsp jcsp commented Aug 31, 2023

Problem

Closes: #5136

Summary of changes

  • A new configuration property control_plane_api controls other functionality in this PR: if it is unset (default) then everything still works as it does today.
  • If control_plane_api is set, then on startup we call out to control plane /re-attach endpoint to discover our attachments and their generations. If an attachment is missing from the response we implicitly detach the tenant.
  • Calls to pageserver /attach API may include a generation parameter. If control_plane_api is set, then this parameter is mandatory.
  • RemoteTimelineClient's loading of index_part.json is generation-aware, and will try to load the index_part with the most recent generation <= its own generation.
  • The neon_local testing environment now includes a new binary attachment_service which implements the endpoints that the pageserver requires to operate. This is on by default if running cargo neon by hand. In test_runner/ tests, it is off by default: existing tests continue to run with in the legacy generation-less mode.

Caveats:

  • The re-attachment during startup assumes that we are only re-attaching tenants that have previously been attached, and not totally new tenants -- this relies on the control plane's attachment logic to keep retrying so that we should eventually see the attach API call. That's important because the /re-attach API doesn't tell us which timelines we should attach -- we still use local disk state for that. Ref: pageserver: enable arbitrary attachments during /re-attach #5173
  • Testing: generations are only enabled for one integration test right now (test_pageserver_restart), as a smoke test that all the machinery basically works. Writing fuller tests that stress tenant migration will come later, and involve extending our test fixtures to deal with multiple pageservers.
  • I'm not in love with "attachment_service" as a name for the neon_local component, but it's not very important because we can easily rename these test bits whenever we want.
  • Limited observability when in re-attach on startup: when I add generation validation for deletions in a later PR, I want to wrap up the control plane API calls in some small client class that will expose metrics for things like errors calling the control plane API, which will act as a strong red signal that something is not right.

Checklist before requesting a review

  • I have performed a self-review of my code.
  • If it is a core feature, I have added thorough tests.
  • Do we need to implement analytics? if so did you add the relevant metrics to the dashboard?
  • If this PR requires public announcement, mark it with /release-notes label and add several sentences in this section.

Checklist before merging

  • Do not forget to reformat commit message to not include the above checklist

@github-actions
Copy link

github-actions bot commented Aug 31, 2023

1640 tests run: 1567 passed, 0 failed, 73 skipped (full report)


Code coverage full report

  • functions: 52.6% (7530 of 14318 functions)
  • lines: 81.3% (44427 of 54629 lines)

The comment gets automatically updated with the latest test results
562e47e at 2023-09-06T13:41:27.664Z :recycle:

@jcsp jcsp force-pushed the jcsp/generation-numbers-pt2 branch from 4443dc9 to 6a952e4 Compare August 31, 2023 14:34
@jcsp jcsp force-pushed the jcsp/generation-numbers-pt2 branch from 6a952e4 to acce508 Compare August 31, 2023 18:10
@jcsp jcsp marked this pull request as ready for review August 31, 2023 18:12
@jcsp jcsp requested review from a team as code owners August 31, 2023 18:12
@jcsp jcsp requested review from lubennikovaav, problame and koivunej and removed request for a team and lubennikovaav August 31, 2023 18:12
@jcsp jcsp added t/feature Issue type: feature, for new features or requests c/storage/pageserver Component: storage: pageserver labels Aug 31, 2023
@jcsp
Copy link
Collaborator Author

jcsp commented Sep 1, 2023

Please create a separate type and .rs file for the control_plane_api client (currently it's in mgr.rs).

Was going to do that later with the validation bits, but there's no time like the present :-) This is now control_plane_client.rs

Have you tried to introduce global parametrization for generation enabled/disabled, like we do with DEFAULT_PG_VERSION v14 and v15?

Right now what I care most about is not breaking the legacy mode (so still running all tests without generations). When it's time to check everything works in the new mode (i.e. before we think about cutting over in staging, then prod), it'll make sense to flip it back and forth globally.

control_plane/src/bin/attachment_service.rs Outdated Show resolved Hide resolved
control_plane/src/bin/attachment_service.rs Show resolved Hide resolved
pageserver/src/tenant/mgr.rs Outdated Show resolved Hide resolved
pageserver/src/tenant/remote_timeline_client.rs Outdated Show resolved Hide resolved
pageserver/src/tenant/remote_timeline_client.rs Outdated Show resolved Hide resolved
control_plane/src/bin/attachment_service.rs Outdated Show resolved Hide resolved
pageserver/src/control_plane_client.rs Outdated Show resolved Hide resolved
pageserver/src/tenant/remote_timeline_client/download.rs Outdated Show resolved Hide resolved
pageserver/src/tenant/remote_timeline_client/download.rs Outdated Show resolved Hide resolved
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.

Few more nites nats, but this is looking good. Would like to focus on the filter_map vs. keeping the error, sounds like this should never happen and if there was a parsing error feels like we should not continue.

I don't see how that would be safe to continue.

control_plane/src/bin/attachment_service.rs Outdated Show resolved Hide resolved
control_plane/src/bin/attachment_service.rs Outdated Show resolved Hide resolved
control_plane/src/bin/neon_local.rs Outdated Show resolved Hide resolved
pageserver/src/tenant/mgr.rs Outdated Show resolved Hide resolved
pageserver/src/tenant/mgr.rs Outdated Show resolved Hide resolved
pageserver/src/tenant/remote_timeline_client.rs Outdated Show resolved Hide resolved
pageserver/src/tenant/timeline.rs Show resolved Hide resolved
@jcsp jcsp merged commit 61d661a into main Sep 6, 2023
@jcsp jcsp deleted the jcsp/generation-numbers-pt2 branch September 6, 2023 13:44
jcsp added a commit that referenced this pull request Sep 26, 2023
## Problem

Pageservers must not delete objects or advertise updates to
remote_consistent_lsn without checking that they hold the latest
generation for the tenant in question (see [the RFC](
https://github.com/neondatabase/neon/blob/main/docs/rfcs/025-generation-numbers.md))

In this PR:
- A new "deletion queue" subsystem is introduced, through which
deletions flow
- `RemoteTimelineClient` is modified to send deletions through the
deletion queue:
- For GC & compaction, deletions flow through the full generation
verifying process
- For timeline deletions, deletions take a fast path that bypasses
generation verification
- The `last_uploaded_consistent_lsn` value in `UploadQueue` is replaced
with a mechanism that maintains a "projected" lsn (equivalent to the
previous property), and a "visible" LSN (which is the one that we may
share with safekeepers).
- Until `control_plane_api` is set, all deletions skip generation
validation
- Tests are introduced for the new functionality in
`test_pageserver_generations.py`

Once this lands, if a pageserver is configured with the
`control_plane_api` configuration added in
#5163, it becomes safe to
attach a tenant to multiple pageservers concurrently.

---------

Co-authored-by: Joonas Koivunen <[email protected]>
Co-authored-by: Christian Schwarz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c/storage/pageserver Component: storage: pageserver t/feature Issue type: feature, for new features or requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pageserver: include generations in attachment, re-attach on startup
3 participants