Skip to content

Conversation

@kim
Copy link
Contributor

@kim kim commented Nov 10, 2025

So far, the --clear-database option to publish has simply dropped
and then re-created the database (if it did exist).

This will no longer work when databases can have "children": because
dropping and re-creating is not atomic, children would either become
orphans, or be dropped as well.

To solve this, reset_database is introduced as a separate action that:

  • shuts down all replicas
  • if a program_bytes is supplied, replaces the database's initial
    program
  • if a host_type is supplied, replaces the database's host type
  • starts num_replicas or the previous number of replicas, which
    initialize themselves as normal

As this could be its own CLI command, the action is provided as its own
API endpoint (undocumented).

However, since publish has no way of knowing whether the database it
operates on actually exists, the publish_database handler will just
invoke the reset_database handler if clear=true and the database
exists, and return its result. This is to avoid starting the transfer of
the program in the request body, only to receive a redirect.

Some refactoring was necessary to dissect and understand the flow.

API and ABI breaking changes

Introduces a new, undocumented API endpoint.
We may want to nest it under /unstable.

Expected complexity level and risk

2

Testing

From the outside, the observed behavior should be as before,
so smoketests should cover it.

So far, the `--clear-database` option to `publish` has simply dropped
and then re-created the database (if it did exist).

This will no longer work when databases can have "children": because
dropping and re-creating is not atomic, children would either become
orphans, or be dropped as well.

To solve this, `reset_database` is introduced as a separate action that:

- shuts down all replicas
- if a `program_bytes` is supplied, replaces the database's initial
  program
- if a `host_type` is supplied, replaces the database's host type
- starts `num_replicas` or the previous number of replicas, which
  initialize themselves as normal

As this could be its own CLI command, the action is provided as its own
API endpoint (undocumented).

However, since `publish` has no way of knowing whether the database it
operates on actually exists, the `publish_database` handler will just
invoke the `reset_database` handler if `clear=true` and the database
exists, and return its result. This is to avoid starting the transfer of
the program in the request body, only to receive a redirect.

Some refactoring was necessary to dissect and understand the flow.
Copy link
Collaborator

@bfops bfops left a comment

Choose a reason for hiding this comment

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

It looks like this is an exact copy of #3496. That was approved and merged, but we rolled back because we had some fallout that we have now fixed. So.. this LGTM!

Copy link
Contributor

@cloutiertyler cloutiertyler left a comment

Choose a reason for hiding this comment

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

I did a deeper review of this one this time around and it looks good to me. It's an elegant solution. Basically just detaches the old replicas from the database and attaches new replicas.

@kim kim enabled auto-merge November 10, 2025 20:10
@bfops bfops added the release-any To be landed in any release window label Nov 10, 2025
@kim kim added this pull request to the merge queue Nov 11, 2025
Merged via the queue into master with commit e0b8e6f Nov 11, 2025
46 of 50 checks passed
@kim kim deleted the kim/reset-database branch November 11, 2025 09:22
jdetter added a commit that referenced this pull request Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-any To be landed in any release window

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants