-
Notifications
You must be signed in to change notification settings - Fork 1
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
Flesh out the slice API for the user code #9
Conversation
An EventEnvelope specifically for the commit log has been introduced, along with the start of one for gRPC. The commit log adapter for persistence will adapt between the entity manager's envelope and its own.
Sets up the source provider using slices.
2a2a3e3
to
fa76297
Compare
assert_eq!(jdk_string_hashcode(""), 0); | ||
assert_eq!(jdk_string_hashcode("howtodoinjava.com"), 1894145264); | ||
assert_eq!(jdk_string_hashcode("hello world"), 1794106052); | ||
} |
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.
These were taken from a JDK example.
#[test] | ||
fn test_slice_ranges() { | ||
assert_eq!(slice_ranges(4), vec![0..256, 256..512, 512..768, 768..1024]); | ||
} |
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.
Note that Range
is non-inclusive in terms of its max i.e. it is "upto". I could've used RangeInclusive
instead, but then I'd have do an additional subtraction when constructing each range. :-)
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.
looking good
akka-persistence-rs/src/lib.rs
Outdated
Self::with_separator(entity_type, entity_id, '|') | ||
} | ||
|
||
pub fn with_separator(entity_type: EntityType, entity_id: EntityId, separator: char) -> Self { |
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.
In practise we only support the |
separator on the jvm side. I think we should remove the option to use another separator since we would anyway have to translate it to |
in all persistenceIds sent to jvm.
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.
Removed in commit 045b1e9
akka-persistence-rs/src/lib.rs
Outdated
/// evenly distribute all persistence ids over the slices and be able to query the | ||
/// events for a range of slices. | ||
pub fn slice_for_persistence_id(persistence_id: &PersistenceId) -> u32 { | ||
jdk_string_hashcode(&persistence_id.to_string()) % NUMBER_OF_SLICES |
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.
note that hashCode can be negative and to be compatible with jvm this should correspond to:
math.abs(persistenceId.hashCode % numberOfSlices)
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.
Now using an i32 per commit 6a1febf
akka-persistence-rs/src/lib.rs
Outdated
|
||
// Implementation of the JDK8 string hashcode: | ||
// https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#hashCode | ||
fn jdk_string_hashcode(s: &str) -> u32 { |
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.
good, important that we use the same
As per PR feedback
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.
LGTM
SmolStr::from("some-entity-type"), | ||
SmolStr::from("some-entity-id") | ||
)), | ||
451 |
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.
I have verified that it's the same slice in jvm
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.
Excellent!
This PR fleshes out the slice API from a user code perspective. While the source provider is presently sourcing a local commit log, it doesn't make sense to have multiple projection instances i.e. there's no cluster. However, we have this API so that we can start up projection instances on the cloud side when communicating over gRPC.
An EventEnvelope specifically for the commit log has also been introduced, along with the start of one for gRPC. The commit log adapter for persistence will adapt between the entity manager's envelope and its own.
Finally, I had fun implementing some partition id functions, particularly the JDK string hashing one. :-)