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

Timer Table Implementation #1449

Merged
merged 3 commits into from
Jul 16, 2024
Merged

Timer Table Implementation #1449

merged 3 commits into from
Jul 16, 2024

Conversation

Shubham8287
Copy link
Contributor

@Shubham8287 Shubham8287 commented Jun 19, 2024

Description of Changes

Host side implementation of scheduled tables as per proposal - https://github.com/clockworklabs/SpacetimeDBPrivate/blob/master/proposals/0005-timers.md

API and ABI breaking changes

yes

Expected complexity level and risk

3

Testing

Tested via running through example apps.

@Shubham8287 Shubham8287 self-assigned this Jun 20, 2024
@Shubham8287 Shubham8287 force-pushed the shub/scheduler-actor branch 2 times, most recently from c0db594 to b13cf7c Compare June 20, 2024 16:45
@@ -485,6 +485,7 @@ pub struct TableSchema {
pub sequences: Vec<SequenceSchema>,
pub table_type: StTableType,
pub table_access: StAccess,
pub scheduled: Option<Box<str>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

In the PR #1448 I'm rewriting Def. My plan was to add:

struct ScheduleDef {
    reducer_name: Box<str>,
    at_column: ColId
}

And then having an Option<ScheduleDef> on TableDef.
If you don't mind restructuring this that way it would make it easier for me down the line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How do you translate this in TableSchema?

Copy link
Contributor

@kazimuth kazimuth Jul 12, 2024

Choose a reason for hiding this comment

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

I guess just assert that at_column is named "at" and convert the reducer name.

This can be changed later once TableSchema is updated.

Comment on lines +146 to +150
.map(|row| -> Result<_> {
let row = StScheduledRow::try_from(row)?;
Ok(row.reducer_name)
})
.transpose()?;
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
.map(|row| -> Result<_> {
let row = StScheduledRow::try_from(row)?;
Ok(row.reducer_name)
})
.transpose()?;
.and_then(|row| StScheduledRow::try_from(row).map(|r| r.reducer_name))?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ummm, scheduled is supposed to be an Option enum, provided suggestion does not looks to evaluates to that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Given that @Centril did not provide more context I would mark this as resolved.

@bfops bfops added the release-any To be landed in any release window label Jun 24, 2024
@Shubham8287 Shubham8287 force-pushed the shub/scheduler-actor branch from 77d405b to e951eb7 Compare June 26, 2024 09:05
@Shubham8287 Shubham8287 added abi-break A PR that makes an ABI breaking change release-0.11 and removed release-any To be landed in any release window labels Jun 26, 2024
@Shubham8287 Shubham8287 force-pushed the shub/scheduler-actor branch 5 times, most recently from 72bab7c to 15bf757 Compare June 26, 2024 14:43
@Shubham8287 Shubham8287 requested review from Centril and kim June 26, 2024 14:44
@Shubham8287 Shubham8287 force-pushed the shub/scheduler-actor branch from 15bf757 to 85a0aed Compare June 26, 2024 14:55
@Shubham8287 Shubham8287 changed the title Shub/scheduler actor scheduled tables Jun 26, 2024
@Shubham8287 Shubham8287 force-pushed the shub/scheduler-actor branch 2 times, most recently from 87f7dc6 to 1b3bbe0 Compare June 26, 2024 17:15
Comment on lines 72 to 74
// can this be shared with bindings?
const SCHEDULED_AT_FIELD: &str = "scheduled_at";
const SCHEDULED_ID_FIELD: &str = "scheduled_id";
Copy link
Contributor

@Centril Centril Jun 27, 2024

Choose a reason for hiding this comment

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

Yes, you can move them to spacetimedb_primitives, e.g., scheduling.rs.


#[derive(Copy, Clone, Eq, PartialEq, Hash)]
pub struct ScheduledReducerId(pub u64);
pub struct ScheduledReducerId {
/// Scheduled Table id, this should have a entry in `ST_SCHEDULED`
Copy link
Contributor

Choose a reason for hiding this comment

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

@Shubham8287 This hasn't been addressed.

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 overall.
I'll want to do the manual testing before approving.

db.delete(tx, id.table_id, [schedule_row_ptr]);
Ok::<(), anyhow::Error>(())
})
.map_err(|e| log::error!("deleting scheduled reducer 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.

Strangely, the types are lying -- this transaction cannot actually fail.

But if it could, we might run the scheduler again in the future, is that correct?

I think it's important to note both in the proposal and user-facing documentation that scheduled reducers have "at least once" semantics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But does that also means that there is a bug in our logic?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it means that, like in many instances in the codebase, we formulate types not to express what is the case, but what might be the case in the future.

In this case: transactions may become fallible under MVCC, if and when that is supported, but they are, in fact, not.

If we resist debating the code structure, the possibility of this particular transaction being fallible means that we may run the scheduled reducer more than once.

I think that’s fine, but we need to be diligent in documenting the behavior.

@Shubham8287 Shubham8287 force-pushed the shub/scheduler-actor branch from 92fff9f to 9f5c008 Compare June 27, 2024 13:41
@Shubham8287 Shubham8287 force-pushed the shub/scheduler-actor branch from b1c2b45 to be97bda Compare June 28, 2024 14:31
Ok(schedule_row) => schedule_row,
// if the row is not found, it means the schedule is cancelled by the user
Err(_) => {
log::info!(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we downgrade this to debug?

I created a reducer with ScheduleAt::Interval(duration!(100ms)), and then delete the the table in the first call. That yields 3x, supposedly because it was put on the queue this many times already.

It's not immediately clear what the message is trying to tell me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you put it inside init?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So it was extra noisy for you due to bug specific for this particular case - https://discord.com/channels/931210784011321394/1011381307965722774/1257812281564073996, but I think message can still be downgraded to Debug, purpose for it is for debugging only.

@Shubham8287 Shubham8287 force-pushed the shub/scheduler-actor branch 4 times, most recently from 20bc515 to 47dedc6 Compare July 3, 2024 08:49
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.

Looks like the test suite is failing for trivial reasons; with that fixed, this look good!

@joshua-spacetime joshua-spacetime changed the title scheduled tables Timer Table Implementation Jul 8, 2024
Update test snapshot

Add support for the new timer tables

Remove old scheduler ABI & API

Add implicit conversions for ScheduleAt
@Shubham8287 Shubham8287 force-pushed the shub/scheduler-actor branch 3 times, most recently from 6c2b51f to c9b9699 Compare July 15, 2024 19:18
@Shubham8287 Shubham8287 force-pushed the shub/scheduler-actor branch from c9b9699 to 7516f72 Compare July 16, 2024 08:03
@Shubham8287 Shubham8287 added this pull request to the merge queue Jul 16, 2024
Merged via the queue into master with commit 276387d Jul 16, 2024
14 checks passed
@Shubham8287
Copy link
Contributor Author

new commits after last update are

  • Few times rebasing with master.
  • merging [DO NOT MERGE] Timer tables implementation for C# #1459, which was required for smoketests to pass.
  • Simplify Timestamp usage which was conflicting with protobufectomy.
    All of them seems trivial or not to be concerned with PR main logic, hence didn't seek new approval.

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

Successfully merging this pull request may close these issues.

7 participants