Skip to content

Conversation

muhamadazmy
Copy link
Contributor

@muhamadazmy muhamadazmy commented Oct 3, 2025

Consistent schema across partitions

Summary:
This PR make sure that PPs have a consistent service schema by writing
and upsert-schema record to bifrost. The leader processor makes sure
to write this record to bifrost when schema changes are detected

@muhamadazmy muhamadazmy force-pushed the pr3860 branch 2 times, most recently from ca7a790 to 057eaea Compare October 3, 2025 10:43
@muhamadazmy muhamadazmy marked this pull request as ready for review October 3, 2025 10:46
self.record_keys().matches_key_query(query)
}
}

Copy link
Contributor Author

@muhamadazmy muhamadazmy Oct 3, 2025

Choose a reason for hiding this comment

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

This is currently not used (and will never be) a new draft for envelope redesign can be checked here

@slinkydeveloper
Copy link
Contributor

Can we wait to merge this?

@muhamadazmy
Copy link
Contributor Author

@slinkydeveloper of course. Not urgent. let's discuss how we going to maintain the schema type. moving forward

Copy link
Contributor

@slinkydeveloper slinkydeveloper left a comment

Choose a reason for hiding this comment

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

LGTM, as discussed offline, we need to verify what happens with large schemas and how we want to mitigate eventual issues in that direction.

Command::InvocationResponse(response) => Keys::Single(response.partition_key()),
Command::NotifySignal(sig) => Keys::Single(sig.partition_key()),
Command::NotifyGetInvocationOutputResponse(res) => Keys::Single(res.partition_key()),
Command::UpsertSchema(_) => Keys::Single(self.partition_key()),
Copy link
Contributor

Choose a reason for hiding this comment

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

This should apply to the entire partition range. Imagine if the partition is split, would you want only one of the sub-partitions to see this upsert or both?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. I didn't take the sub-partitions scenario into consideration.

Comment on lines 150 to 152
.map(|_| {
let schema = Metadata::with_current(|m| m.schema().clone());
ActionEffect::UpsertSchema(schema)
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps it's better to check the version that was returned from Metadata instead of relying on the implicit assumption that the returned metadata will be >= last observed from the stream.

Copy link
Contributor

@AhmedSoliman AhmedSoliman left a comment

Choose a reason for hiding this comment

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

As it stands, this cannot be merged unless writes are gated with a check for restate version >= 1.7

@muhamadazmy muhamadazmy force-pushed the pr3860 branch 2 times, most recently from ccc5178 to a8ded64 Compare October 9, 2025 13:33
Copy link
Contributor

@AhmedSoliman AhmedSoliman left a comment

Choose a reason for hiding this comment

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

We are very close :)

pub modification_time: MillisSinceEpoch,
}

/// Consistency store schema across partition replicas.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Consistently

Comment on lines +72 to +75
pub struct UpsertSchema {
pub partition_key_range: Keys,
pub schema: Schema,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

A nice little optimization is to break the version from schema, and only deserialize the schema if the version is eligible for the update.

struct UpsertSchema {
  pub partition_key_range: Keys,
  pub version: Version,
  pub schema_raw: Bytes,
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a great idea

Copy link
Contributor Author

@muhamadazmy muhamadazmy Oct 10, 2025

Choose a reason for hiding this comment

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

Agreed to streamline this optimisation as part of Envelope v2

Comment on lines 310 to 322
// todo: enable on version v1.7.0
//
// self.self_proposer
// .propose(
// *self.partition_key_range.start(),
// Command::UpsertSchema(UpsertSchema {
// partition_key_range: Keys::RangeInclusive(
// self.partition_key_range.clone(),
// ),
// schema,
// }),
// )
// .await?;
Copy link
Contributor

Choose a reason for hiding this comment

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

tip: You can potentially gate this based on RestateVersion::current()

.unwrap_or_else(Version::invalid);

std::future::ready(
Some(Metadata::with_current(|m| m.schema().clone()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps check the version in the closure to avoid cloning if we are not interested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch :)

Summary:
This PR make sure that PPs have a consistent service schema by writing
and upsert-schema record to bifrost. The leader processor makes sure
to write this record to bifrost when schema changes are detected
@muhamadazmy muhamadazmy merged commit 6764649 into restatedev:main Oct 10, 2025
59 of 60 checks passed
@muhamadazmy muhamadazmy deleted the pr3860 branch October 10, 2025 13:45
@github-actions github-actions bot locked and limited conversation to collaborators Oct 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants