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

Update TableSchema & system tables to resemble ABI V9 #1697

Merged
merged 31 commits into from
Sep 25, 2024

Conversation

kazimuth
Copy link
Contributor

@kazimuth kazimuth commented Sep 11, 2024

Description of Changes

This gets rid of most of the usages of RawModuleDefV8 in core. It replaces it with ModuleDef, which means that the new validation path is used consistently throughout the codebase. It also refactors the system tables & TableSchema types to match the new ModuleDef, the update functionality to use the new auto-migration functionality based on ModuleDef, and does a little bit of other cleanup.

The major user-visible changes from this PR are:

  • Some modules that used to be allowed may be rejected by the new, intensive validation rules.
  • The describe endpoint now returns a json-serialized RawModuleDefV9 rather than RawModuleDefV8.

The major logical changes are:

  • ConstraintSchema and IndexSchema (and their corresponding system tables) no longer store redundant information. Constraints are completely separate from indices; to determine if an index is unique, look up a constraint with its columns. (This is not quite true in mut_tx.rs and the table crate, see my discussion with tyler below, but this is now true throughout more of the codebase.)
  • Also note that IndexSchema stores a ColList, to keep track of field ordering, whereas ConstraintSchema stores a ColSet, which discards ordering, but can be cheaply constructed from a ColList.
  • The Constraints type is now constructed on-demand from TableSchema, rather than being stored directly in TableSchema. This means we have a single source of truth for the data in Constraints and are less likely to muck it up. Constraints is still used in the vm and sql modules.

API and ABI breaking changes

ABI break in the system tables, API break at the describe endpoint.

Expected complexity level and risk

4, this is a system table update and touches things all over core.

Testing

Updated all tests and added some. See also #1737

@kazimuth kazimuth added the abi-break A PR that makes an ABI breaking change label Sep 11, 2024
Base automatically changed from jgilles/algebraic_type_for_generate to master September 11, 2024 20:44
crates/core/src/db/relational_db.rs Outdated Show resolved Hide resolved
crates/core/src/sql/compiler.rs Show resolved Hide resolved
crates/lib/src/relation.rs Outdated Show resolved Hide resolved
crates/schema/src/schema.rs Show resolved Hide resolved
@kazimuth kazimuth force-pushed the jgilles/newschema_real branch 2 times, most recently from 2553709 to 63cda1f Compare September 23, 2024 18:12
Get  compiling, fix birdbrained API

System table rewrite done

More progress

Get rid of useless generic args

WIP

module_host.rs errorless

Lots more compilation successes

Finish update.rs

A bunch of easy fixes

.

CORE COMPILING BABY

Core and planner tests compiling

Everything but CLI compiling
@kazimuth
Copy link
Contributor Author

kazimuth commented Sep 24, 2024

There's now a fix for the internal tests in private, so this is all ready. Together with #1370, update is broken but that shouldn't be a problem.

use enum_as_inner::EnumAsInner;
use itertools::Itertools;
use similar::{Algorithm, TextDiff};
use crate::execution_context::ExecutionContext;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file was completely rewritten so should probably not be reviewed in diff view.

@@ -541,39 +540,6 @@ impl<'db, 'tx> DbProgram<'db, 'tx> {
}
}

fn _create_table(&mut self, table: RawTableDefV8) -> Result<Code, ErrorVm> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code was dead and now out-of-date so I buried it.

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 scanned the whole PR. I left a few small nits. AFAICT, this looks really good. Very nice job here @kazimuth.

I am approving this PR from a traits.rs perspective and no major objection to the rest, but would probably be good to get another approval as well.

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.

Looks good.

Error propagation needs another pass.

crates/core/src/db/relational_db.rs Show resolved Hide resolved
/// It's fine to call this on system table types, because `validate_system_table` checks that
/// they are `ProductType`s.
///
/// TODO: this performs some unnecessary allocation. We may want to reimplement the conversions manually for
Copy link
Contributor

Choose a reason for hiding this comment

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

🤷

crates/core/src/host/host_controller.rs Outdated Show resolved Hide resolved
Comment on lines +342 to +343
log::warn!("Database update failed: {} @ {}", e, stdb.address());
self.system_logger().warn(&format!("Database update failed: {e}"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Seen this so many times that I feel like there should be a tee logger which can log to more than one sink.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would be a good idea to just log everything that goes through the system loggers yeah. I'll make that a separate issue tho

crates/core/src/db/update.rs Show resolved Hide resolved
@kazimuth kazimuth added this pull request to the merge queue Sep 25, 2024
Merged via the queue into master with commit c32f297 Sep 25, 2024
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
abi-break A PR that makes an ABI breaking change release-0.12
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants