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

Refactoring IDs for system objects #439

Merged
merged 5 commits into from
Nov 15, 2023
Merged

Conversation

mamcx
Copy link
Contributor

@mamcx mamcx commented Oct 17, 2023

Description of Changes

Note: This is a multi-step set of PRs to bring constraints + multi-column indexes

Step:

This PR is to simplify the review of #267. It only have the movement of schema objects and the use of newtypes for system objects.

API and ABI

  • This is a breaking change to the module ABI
  • This is a breaking change to the module API
  • This is a breaking change to the ClientAPI
  • This is a breaking change to the SDK API

If the API is breaking, please state below what will break

Copy link
Contributor

@Centril Centril left a comment

Choose a reason for hiding this comment

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

Some more ideas on how to further split this PR.

crates/core/src/db/datastore/system_tables.rs Outdated Show resolved Hide resolved
crates/core/src/db/datastore/system_tables.rs Outdated Show resolved Hide resolved
crates/core/src/db/datastore/system_tables.rs Outdated Show resolved Hide resolved
crates/core/src/db/datastore/system_tables.rs Outdated Show resolved Hide resolved
crates/core/src/db/datastore/system_tables.rs Outdated Show resolved Hide resolved
crates/sats/src/db/mod.rs Outdated Show resolved Hide resolved
@mamcx mamcx force-pushed the mamcx/newtype_system_tables branch 3 times, most recently from c8e3f98 to 504a1ef Compare October 18, 2023 15:14
@mamcx mamcx marked this pull request as draft October 18, 2023 20:51
@mamcx mamcx force-pushed the mamcx/newtype_system_tables branch 4 times, most recently from 22a4523 to 0021da4 Compare October 20, 2023 17:07
@mamcx mamcx marked this pull request as ready for review October 20, 2023 17:07
crates/core/src/vm.rs Show resolved Hide resolved
crates/core/src/vm.rs Outdated Show resolved Hide resolved
crates/bindings-macro/src/lib.rs Outdated Show resolved Hide resolved
crates/vm/src/expr.rs Show resolved Hide resolved
crates/core/src/db/datastore/locking_tx_datastore/mod.rs Outdated Show resolved Hide resolved
crates/core/src/db/datastore/locking_tx_datastore/mod.rs Outdated Show resolved Hide resolved
crates/core/src/db/datastore/locking_tx_datastore/mod.rs Outdated Show resolved Hide resolved
crates/core/src/db/datastore/locking_tx_datastore/mod.rs Outdated Show resolved Hide resolved
crates/core/src/sql/compiler.rs Outdated Show resolved Hide resolved
crates/core/src/sql/compiler.rs Outdated Show resolved Hide resolved
crates/core/src/sql/compiler.rs Outdated Show resolved Hide resolved
crates/core/src/vm.rs Show resolved Hide resolved
crates/sats/src/product_value.rs Outdated Show resolved Hide resolved
@mamcx mamcx mentioned this pull request Oct 24, 2023
4 tasks
@Centril Centril force-pushed the mamcx/newtype_system_tables branch from 0021da4 to 7dba4dc Compare October 29, 2023 16:52
@Centril Centril force-pushed the mamcx/newtype_system_tables branch from 7dba4dc to b0d8b18 Compare October 30, 2023 16:43
@mamcx mamcx force-pushed the mamcx/newtype_system_tables branch from b0d8b18 to 1cee02c Compare November 13, 2023 18:19
@mamcx mamcx added the abi-break A PR that makes an ABI breaking change label Nov 13, 2023
@mamcx mamcx self-assigned this Nov 13, 2023
@Centril Centril self-requested a review November 13, 2023 18:39
@mamcx mamcx marked this pull request as draft November 13, 2023 18:43
@mamcx mamcx marked this pull request as ready for review November 13, 2023 19:11
@Centril Centril force-pushed the mamcx/newtype_system_tables branch 3 times, most recently from ef2f883 to 2813cef Compare November 13, 2023 19:32
@Centril Centril force-pushed the mamcx/newtype_system_tables branch 6 times, most recently from 4b04100 to aa3bdc3 Compare November 13, 2023 19:53
Copy link
Contributor

@kulakowski kulakowski left a comment

Choose a reason for hiding this comment

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

I'm worried about the number of seemingly stray kind-constraint find and replace changes.

Cargo.lock Show resolved Hide resolved
@@ -12,7 +12,7 @@ use std::{
hint::black_box,
sync::{Arc, RwLock},
};
use tempfile::TempDir;
use tempdir::TempDir;
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't change it at this point, but why did this change in this PR?

@@ -248,7 +245,7 @@ impl CommitLogView {
/// the transactions in a [`Commit`].
///
/// The iterator attempts to read each large object in turn, yielding an
/// [`io::Error`] with kind [`io::ErrorKind::NotFound`] if the object was
/// [`io::Error`] with constraints [`io::ErrorKind::NotFound`] if the object was
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this a stray find-and-replace change? It reads oddly now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. I make a wrong refactor.

@@ -223,7 +223,7 @@ pub trait MutTxDatastore: TxDatastore + MutTx {

/// Describes a programmable [`TxDatastore`].
///
/// A programmable datastore is one which has a program of some kind associated
/// A programmable datastore is one which has a program of some constraints associated
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto on the find-and-replace in a comment.

@@ -477,7 +467,7 @@ impl RelationalDB {
///
/// NOTE: It loads the data from the table into it before returning
#[tracing::instrument(skip(self, tx, index), fields(index=index.name))]
pub fn create_index(&self, tx: &mut MutTxId, index: IndexDef) -> Result<IndexId, DBError> {
pub fn create_index(&self, tx: &mut MutTxId, table_id: TableId, index: IndexDef) -> Result<IndexId, DBError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is table_id plumbed through but not used? Does it get used in #267 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. I will remove this change because if is not used is pointless here.

"table_id", TableId = 3,
"columns", Columns = 4,
});
// WARNING: For a stable schema, don't change the field names and discriminants.
st_fields_enum!(enum StModuleFields {
"program_hash", ProgramHash = 0,
"kind", Kind = 1,
"constraints", Kind = 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a bit odd that this one did not change both, but the equivalent in StConstraintsFields did. But maybe that's an artifact of the split from #267?

@@ -945,7 +941,7 @@ pub struct ModuleKind(u8);

/// The [`ModuleKind`] of WASM-based modules.
///
/// This is currently the only known kind.
/// This is currently the only known constraints.
Copy link
Contributor

Choose a reason for hiding this comment

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

Another constraint-kind doc comment change?

x.table_id,
ArrayValue::from(cols)
]
}
}

/// Indicates the kind of module the `program_hash` of a [`StModuleRow`]
/// Indicates the constraints of module the `program_hash` of a [`StModuleRow`]
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto. I'm a bit concerned about these.

@@ -503,7 +505,7 @@ impl Inner {
is_unique: false,
index_type: IndexType::BTree,
},
x => panic!("Adding constraint of kind `{x:?}` is not supported yet."),
x => panic!("Adding constraint of constraints `{x:?}` is not supported yet."),
Copy link
Contributor

Choose a reason for hiding this comment

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

Yet another.

@@ -13,22 +13,22 @@ mod timestamp;
use crate::sats::db::def::IndexType;
use spacetimedb_lib::buffer::{BufReader, BufWriter, Cursor, DecodeError};
use spacetimedb_lib::sats::{impl_deserialize, impl_serialize, impl_st};
pub use spacetimedb_lib::ser::Serialize;
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks out of place. It should at least be with the other pub use entries.

@@ -343,24 +332,118 @@ impl From<&ColumnSchema> for ProductTypeElement {
#[derive(Clone)]
pub struct ColumnDefMeta {
pub column: ProductTypeElement,
pub attr: ColumnIndexAttribute,
pub attr: Constraints,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: should this field be named constraints now?

#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord)]
pub struct ProductTypeMeta {
pub columns: ProductType,
pub attr: Vec<Constraints>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: should this field be named constraints now?

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 will be gone it the last PR, and for now attr is more correct because is for the column, not the table.

@kulakowski
Copy link
Contributor

Also, my approval is assuming the chat discussion about autoinc sematics etc is agreed to be good

@mamcx mamcx force-pushed the mamcx/newtype_system_tables branch from d678943 to 9cd06cd Compare November 14, 2023 20:58
@mamcx mamcx force-pushed the mamcx/newtype_system_tables branch from 9cd06cd to b11669d Compare November 15, 2023 14:54
@mamcx mamcx merged commit b3ccc13 into master Nov 15, 2023
5 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants