Skip to content

Nexus holds on to specific service backends of crdb and crucible-pantry for too long #3763

Closed

Description

@askfongjojo

While testing service failover on rack2, I noticed that nexus held on to the same cockroachdb backend without attempting to use any of the other nodes in the 5-node database cluster, causing requests to fail until the one it favored came back.

The same happened with pantry requests for disk import blocks / bulk writes. I haven't got to the point of seeing the TTL being exhausted. I tried waiting for up to 5 minutes and the request still couldn't succeed until the pantry zone Nexus has been using prior to its outage came up again.

Activity

  1. smklein commented on Jul 25, 2023

    @smklein
    Collaborator

    I think ignoring the TTL makes sense (not that it's right, just that it makes sense) in the context of this code:

    let url = match &config.deployment.database {
    nexus_config::Database::FromUrl { url } => url.clone(),
    nexus_config::Database::FromDns => {
    info!(log, "Accessing DB url from DNS");
    let address = loop {
    match resolver
    .lookup_socket_v6(ServiceName::Cockroach)
    .await
    {
    Ok(address) => break address,
    Err(e) => {
    warn!(
    log,
    "Failed to lookup cockroach address: {e}"
    );
    tokio::time::sleep(std::time::Duration::from_secs(
    1,
    ))
    .await;
    }
    }
    };
    info!(log, "DB address: {}", address);
    PostgresConfigWithUrl::from_str(&format!(
    "postgresql://root@{address}/omicron?sslmode=disable",
    ))
    .map_err(|e| format!("Cannot parse Postgres URL: {}", e))?
    }
    };

    Our API to interface with CockroachDB from Nexus involves "constructing a URL", and right now, we embed a single point-in-time address of CockroachDB into this URL.

    We should probably avoid doing this, and embed the service name into the URL, so it actually use DNS during later lookups.

  2. askfongjojo commented on Jul 25, 2023

    @askfongjojo
    Author

    Understood. The current behavior, in conjunction with #3613, results in an 1 in 15 probability that a user will not be able to use the system at all. I happened to be in this situation when my workstation always used the one nexus that had the first CRDB backend I brought down to test failover. :(

  3. added this to the 1.0.1 milestone on Jul 25, 2023
  4. jmpesp commented on Jul 26, 2023

    @jmpesp
    Contributor

    The same happened with pantry requests for disk import blocks / bulk writes. I haven't got to the point of seeing the TTL being exhausted. I tried waiting for up to 5 minutes and the request still couldn't succeed until the pantry zone Nexus has been using prior to its outage came up again.

    In this case, there's no TTL: a specific pantry from the list of available ones is selected once and used for a disk until that disk is finalized.

    One thing that could be done is to check of the selected pantry is still responsive and choose another one if not, but it was important not keep as much code out of the import chunk hot-path as possible, as any checks there will be multiplied by the number of chunks to import and slow down imports. That being said, slow imports are better than non-working imports :) I'll give this some thought.

  5. askfongjojo commented on Jul 26, 2023

    @askfongjojo
    Author

    Sorry for not being clear in pantry's case. I understand the need to stay with the same pantry for the same disk snapshot. But the issue I ran into is with new/separate snapshot requests still holding on to the unresponsive one.

  6. changed the title [-]Nexus holds on to a specific service backends of crdb and crucible-pantry for too long[/-] [+]Nexus holds on to specific service backends of crdb and crucible-pantry for too long[/+] on Jul 27, 2023
  7. modified the milestones: 1.0.1, 1.0.2 on Jul 28, 2023
  8. luqmana commented on Jul 31, 2023

    @luqmana
    Contributor

    #3783 partially addresses this for crdb. We now, grab all the cockroachdb hosts via internal dns at nexus startup and add them all to the connection string. Whenever a new connection is established it'll try the listed hosts in order and use the first one that successfully connects. While that's an improvement in that Nexus won't fail to serve requests if one crdb instance goes down, there are still some issues:

    1. The list of hosts used are resolved and get fixed at Nexus startup. If new cockroachdb zones get spun up, it'll take a restart of Nexus for it to pick them up. As-is, I don't think we're yet dynamically spinning up new services and instead just creating the service plan during RSS.
    2. Internal DNS returns records in the same order everytime (couldn't find existing issue so created one: Internal DNS should permute the order in which it responds for entries with multiple records. #3805). This means every Nexus zone tries to connect to the set of CRDB hosts in the same order.
  9. modified the milestones: 1.0.2, 1.0.3 on Aug 22, 2023
  10. modified the milestones: 1.0.3, 3 on Sep 1, 2023
  11. removed this from the 3 milestone on Oct 4, 2023
  12. 14 remaining items

  13. askfongjojo commented on Jun 21, 2024

    @askfongjojo
    Author

    In my most recent testing, the behavior for CRDB connection failures has changed (or might be expected?). When the crdb node in use has gone down, I saw messages like this in nexus logs:

    17:42:35.701Z ERRO 2898657e-4141-4c05-851b-147bffc6bbbd (ServerContext): database connection error
        database_url = postgresql://root@[fd00:1122:3344:109::3]:32221,[fd00:1122:3344:105::3]:32221,[fd00:1122:3344:10b::3]:32221,[fd00:1122:3344:107::3]:32221,[fd00:1122:3344:108::3]:32221/omicron?sslmode=disable
        error_message = Connection error: server is shutting down
        file = nexus/db-queries/src/db/pool.rs:100
    

    (Note: The crdb instance in use is not necessarily the first one listed; in my case, disabling the 105 instance is what triggered the error.)

    Nexus was able to continue serving both read and update API requests in spite of the above error. It's possible that any ongoing requests against the crdb node right at the moment it's going down could have failed but all requests I made afterwards succeeded.

    @davepacheco took a look at the code to understand what changed the behavior. Here are his comments:

    I didn't think we'd changed anything here since #3763 was filed, but I see there was #3763 (comment), which maybe fixed this? Although subsequent comments suggested it might not have, but it seems like it should have. Anyway, it's good that it worked.

  14. smklein commented on Jun 25, 2024

    @smklein
    Collaborator

    Just to be explicit: #5876 will fix this issue for CockroachDB -- in that PR, we use https://github.com/oxidecomputer/qorb to access each CRDB node individually, and create a pool of connections for each one.

    • If a CRDB node starts returning errors, we reduce our usage of it until it looks healthy
    • If a CRDB node is removed from DNS, we stop using it
    • If a new CRDB node shows up in DNS, we start using it
  15. modified the milestones: MVP, 10 on Jul 2, 2024
  16. modified the milestones: 10, 11 on Aug 12, 2024
  17. removed this from the 11 milestone on Aug 21, 2024
  18. added this to the 12 milestone on Oct 4, 2024
  19. added
    qorb
    on Oct 8, 2024
  20. jgallagher commented on Nov 18, 2024

    @jgallagher
    Contributor

    Sorry for not being clear in pantry's case. I understand the need to stay with the same pantry for the same disk snapshot. But the issue I ran into is with new/separate snapshot requests still holding on to the unresponsive one.

    I believe this is now fixed for the pantry too:

    Given CRDB and the pantry are both addressed, I'm going to close this. If we run into stale handles to services now that the qorb integration is done, we should file new issues.

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

Metadata

Metadata

Assignees

Labels

qorb

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions