-
Notifications
You must be signed in to change notification settings - Fork 101
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
Jeremie/notify sql #1198
Jeremie/notify sql #1198
Conversation
crates/core/src/sql/execute.rs
Outdated
collect_result(&mut tables, &mut updates, code?.into())?; | ||
|
||
if !reads && !updates.is_empty() { | ||
let event = ModuleEvent { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left most of the values to defaults here, assuming these relate to reflecting the state of a reducer/client which aren't present in this case.
Only handling the committed case, as collect_result short-circuits the function on error.
crates/core/src/vm.rs
Outdated
@@ -447,10 +447,17 @@ impl<'db, 'tx> DbProgram<'db, 'tx> { | |||
// TODO: How do we deal with mutating values? | |||
Table::MemTable(_) => Err(ErrorVm::Other(anyhow::anyhow!("How deal with mutating values?"))), | |||
Table::DbTable(x) => { | |||
let inserts = rows.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would prefer not to clone here, but db.insert wants a row, not a &row. Is it worth extending the refactor in there too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's leave a todo for now. This code shouldn't be hot.
crates/core/src/vm.rs
Outdated
@@ -518,15 +533,15 @@ impl<'db, 'tx> DbProgram<'db, 'tx> { | |||
} | |||
} | |||
} | |||
Ok(Code::Pass) | |||
Ok(Code::Pass(None)) // TODO going to assume dropping a table doesn't need to broadcast its entire contents as a notify |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assumption here is deleting a table a reducer/subscriber depends on is either undefined behavior or breaking things up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct; modifying the schema which clients depend on is unsupported.
crates/core/src/vm.rs
Outdated
} | ||
TxMode::Tx(_) => unreachable!("mutable operation is invalid with read tx"), | ||
} | ||
} | ||
|
||
fn _set_config(&mut self, name: String, value: AlgebraicValue) -> Result<Code, ErrorVm> { | ||
self.db.set_config(&name, value)?; | ||
Ok(Code::Pass) | ||
Ok(Code::Pass(None)) // TODO can subscriptions watch config values? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsure how to broadcast these, as there's no "sql update" happening here. Is there a path to notify config changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clients should only care about inserts and deletes in non-system tables; anything else doesn't need to be broadcast.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good with the latest changes.
(Needs a rebase though) |
faa5b54
to
3e48c7d
Compare
let host = worker_ctx.host_controller(); | ||
let module_host = host.get_or_launch_module_host(database.clone(), instance_id).await.map_err(|e| { | ||
log::warn!("{}", e); | ||
(StatusCode::INTERNAL_SERVER_ERROR, "Internal Server Error") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay this is a bit aggressive, but I think this is the wanted behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why warn!
and not use log_and_500
here?
3e48c7d
to
bbfdfc2
Compare
Looks like you need to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but please also consider #1198 (comment) before deciding to merge. But I'm happy for this to merge either way.
a71a270
to
96884d1
Compare
(From another PR, but helps tests to pass)
96884d1
to
326e156
Compare
Description of Changes
Expected complexity level and risk
2? Still a few things I'm unsure of:
Testing
Still need to add tests to validate that changes broadcast correctly.