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

HACK: Tweak schema_updates to allow adding/removing non-unique indices #1434

Merged
merged 1 commit into from
Jun 14, 2024

Conversation

Centril
Copy link
Contributor

@Centril Centril commented Jun 13, 2024

Description of Changes

You can now add and remove non-generated indices.
That is, the indices that you actually define with #[spacetimedb(index(...))].

API and ABI breaking changes

None

Expected complexity level and risk

3, some questions re. transactionality...

Testing

Review notes

  • Hide whitespace changes on github.

@Centril Centril requested a review from kim June 14, 2024 09:47
@Centril
Copy link
Contributor Author

Centril commented Jun 14, 2024

I confirmed that this works with the following module I called foo:

use spacetimedb::{println, spacetimedb};

#[spacetimedb(table)]
pub struct Table {
    field: u64,
}

#[spacetimedb(init)]
pub fn init() {
    for i in 0..1_000 {
        Table::insert(Table { field: i });
    }
}

#[spacetimedb(reducer)]
pub fn contains(x: u64) {
    if Table::filter_by_field(&x).next().is_some() {
        println!("Found {x}");
    } else {
        println!("Didn't find {x}");
    }
}

While running spacetime start --in-memory, I did:

  1. spacetime publish foo
  2. spacetime call foo contains 500 ==> WARN iter_by_col_range without index: table Table has 1000 rows;
  3. added #[spacetimedb(index(btree, name = "field", field))]
  4. spacetime call foo contains 500 ==> no warning
  5. removed #[spacetimedb(index(btree, name = "field", field))]
  6. spacetime call foo contains 500 ==> WARN iter_by_col_range without index: table Table has 1000 rows;

Copy link
Contributor

@kim kim left a comment

Choose a reason for hiding this comment

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

Seems to do the right things.

Maybe the smoke tests could be extended to cover what is accepted as an update and what is not (I don't think we can test that an index is present or absent).

Note that adding or dropping an index is not transactional. However, the modifications of the system tables are, so re-publishing a failed update should converge to the correct state.

@Centril
Copy link
Contributor Author

Centril commented Jun 14, 2024

Maybe the smoke tests could be extended to cover what is accepted as an update and what is not (I don't think we can test that an index is present or absent).

Filed #1438 for the smoketest.

@Centril Centril added this pull request to the merge queue Jun 14, 2024
Merged via the queue into master with commit b1442fc Jun 14, 2024
10 checks passed
@Centril Centril deleted the centril/index-hack-add-rem branch June 14, 2024 15:07
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.

2 participants