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

Protobufectomy #1077

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Protobufectomy #1077

wants to merge 5 commits into from

Conversation

coolreader18
Copy link
Collaborator

Description of Changes

Replace protobuf with bsatn.

API and ABI breaking changes

API breaking for binary clients.

Expected complexity level and risk

3 (lotsa churn)

Testing

This is dependent on the C# sdk getting updated. I feel confident that CI + a botstest with the updated sdk would get everything.

Copy link
Contributor

@gefjon gefjon left a comment

Choose a reason for hiding this comment

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

So far I've only reviewed changes to client-api-messages, the Rust SDK and its codegen. Those look excellent. I've left a few low-priority questions and doc-related suggestions.

/// It also will not check for duplicate IDs. They are just a way to match responses to messages.
#[derive(Deserialize, Serialize, serde::Deserialize)]
pub struct OneOffQuery {
pub message_id: Vec<u8>,
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 this a Vec<u8> rather than a u32 or something?

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 like that on older proto schema, we have a ticket to fix this - #927 waiting for breaking release. May be, this is a correct time to do it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, that'd be great, I'd been wondering about that as well.

Comment on lines +80 to +88
/// Query should be a "SELECT * FROM Table WHERE ...". Other types of queries will be rejected.
/// Multiple such semicolon-delimited queries are allowed.
///
/// One-off queries are identified by a client-generated messageID.
/// To avoid data leaks, the server will NOT cache responses to messages based on UUID!
/// It also will not check for duplicate IDs. They are just a way to match responses to messages.
Copy link
Contributor

Choose a reason for hiding this comment

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

Doc comments should be moved to fields.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ya - I tried to do that for the most part; most/all of the comments are copied from the protobuf, which tended to put field docs on the outer type.

pub struct Subscribe {
/// A sequence of SQL queries.
pub query_strings: Vec<String>,
pub request_id: u32,
Copy link
Contributor

Choose a reason for hiding this comment

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

Doc comment please.

Comment on lines +53 to +56
// /// A reducer specified by its numerical ID.
// Id(u32),
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 this in here?

pub struct CallReducer<Args> {
/// The name or id of the reducer to call.
pub reducer: ReducerId,
/// The arguments to the reducer, encoded as ????.
Copy link
Contributor

Choose a reason for hiding this comment

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

????

use crate::timestamp::Timestamp;

#[derive(Deserialize, Serialize, serde::Deserialize)]
pub enum ClientMessage<Args = Row> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub enum ClientMessage<Args = Row> {
/// A message sent by the client to the server.
pub enum ClientMessage<Args = Row> {

}

#[derive(Serialize, Deserialize, derive_more::From)]
pub enum ServerMessage {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub enum ServerMessage {
/// A message sent by the server to the client.
pub enum ServerMessage {

}
}
}
pub use spacetimedb_lib::Identity;
Copy link
Contributor

Choose a reason for hiding this comment

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

This closes an outstanding ticket I had. You're my hero.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Lol - it was breaking something with a type mismatch and I didn't wanna do a from_bytes(to_bytes()) thing to convert it so this seemed simple enough lol.

@gefjon
Copy link
Contributor

gefjon commented Apr 11, 2024

Outstanding TODOs:

  • C# SDK.
  • Unity package of C# SDK.
  • Typescript SDK.
  • Tests of above.
  • Minor updates to Rust SDK docs now that Identity has been changed to use the actual spacetimedb_lib::Identity type.

(Plus make the tests and lints pass, obviously.)

Copy link
Contributor

@kazimuth kazimuth left a comment

Choose a reason for hiding this comment

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

This all seems straightforward enough, I don't have any particular commentary. Thanks for getting it in!

I wonder if I can auto-generate the C# side of this interface...

@@ -45,6 +45,9 @@ mod sym {
/// Matches `sats`.
pub const SATS: Symbol = Symbol("sats");

/// Matches `transparent`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this used on stuff in this PR? Just curious

Copy link
Contributor

@kazimuth kazimuth left a comment

Choose a reason for hiding this comment

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

Additional question: how do we negotiate protocol version now? I believe protobuf transparently supports changing schemas for the most part by making everything optional, but I don't think bsatn has anything like that. We should at minimum send a version number I think, either once per session or once per message...

@@ -0,0 +1,266 @@
use bytes::Bytes;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would like a module doc comment, also a crate doc comment.

use crate::timestamp::Timestamp;

#[derive(Deserialize, Serialize, serde::Deserialize)]
pub enum ClientMessage<Args = Row> {
Copy link
Contributor

@kazimuth kazimuth Apr 11, 2024

Choose a reason for hiding this comment

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

Do we need to add additional messages here for protocol version negotiation?

pub inserts: Vec<Row>,
}

#[derive(Debug, Clone)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#[derive(Debug, Clone)]
#[derive(Debug, Clone, From)]

Comment on lines 236 to 240
impl From<Bytes> for Row {
fn from(b: Bytes) -> Self {
Row(b)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
impl From<Bytes> for Row {
fn from(b: Bytes) -> Self {
Row(b)
}
}

pub mod name;
pub mod recovery;
pub mod timestamp;
pub mod ws;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub mod ws;
pub mod web_socket;

@@ -21,17 +21,28 @@ pub(crate) struct SatsType<'a> {
pub(crate) enum SatsTypeData<'a> {
Product(Vec<SatsField<'a>>),
Sum(Vec<SatsVariant<'a>>),
Transparent(SatsField<'a>),
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add some docs here?

@@ -642,6 +618,11 @@ impl ModuleHost {
&self.info.subscriptions
}

/// internal method to access the DatabaseInstanceContext for the module. don't make this public.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be reflected in the method name?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to request that the method becomes public API.

The lifetimes of dbic and module should become coupled anyway.

@@ -2,3 +2,6 @@ pub mod control_db;
pub mod control_worker_api;
pub mod instance_db_trace_log;
pub mod worker_db;
pub mod ws {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub mod ws {
pub mod web_socket {

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-1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants