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
[#1967] Fetch available segements only from the TokenStore #1997
Conversation
…ly returns segments that have not yet been claimed.
…ableSegments instead of TokenStore::festSegments when getting new segments to claim.
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 just got a couple of minor suggestions. Other than that, I think we've got an excellent addition here. Thank @Vermorkentech!
messaging/src/main/java/org/axonframework/eventhandling/TrackingEventProcessor.java
Show resolved
Hide resolved
messaging/src/main/java/org/axonframework/eventhandling/TrackingEventProcessor.java
Outdated
Show resolved
Hide resolved
messaging/src/main/java/org/axonframework/eventhandling/tokenstore/TokenStore.java
Outdated
Show resolved
Hide resolved
messaging/src/test/java/org/axonframework/eventhandling/tokenstore/jpa/JpaTokenStoreTest.java
Show resolved
Hide resolved
…g/tokenstore/TokenStore.java Co-authored-by: Steven van Beelen <steven.vanbeelen@axoniq.io>
… various review comments.
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.
My concerns have been addressed, hence approving.
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.
Discussed some API changes to make reduce the number of required storage-roundtrips while keeping backward compatibility.
messaging/src/main/java/org/axonframework/eventhandling/tokenstore/TokenStore.java
Outdated
Show resolved
Hide resolved
messaging/src/main/java/org/axonframework/eventhandling/tokenstore/jdbc/JdbcTokenStore.java
Outdated
Show resolved
Hide resolved
messaging/src/main/java/org/axonframework/eventhandling/tokenstore/jpa/JpaTokenStore.java
Outdated
Show resolved
Hide resolved
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.
Except for some indentation nits, I think we're good to go.
messaging/src/main/java/org/axonframework/eventhandling/TrackingEventProcessor.java
Outdated
Show resolved
Hide resolved
messaging/src/main/java/org/axonframework/eventhandling/tokenstore/jpa/JpaTokenStore.java
Show resolved
Hide resolved
…Segment instead of the segmentId only. After fetching the token, some checks are performed to prevent a race condition with a concurrent split or merge of that segment.
# Conflicts: # integrationtests/src/test/java/org/axonframework/integrationtests/eventhandling/TrackingEventProcessorTest.java # messaging/src/main/java/org/axonframework/eventhandling/TrackingEventProcessor.java
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.
Just a bunch of minor improvements to cover left, I think.
messaging/src/main/java/org/axonframework/eventhandling/TrackingEventProcessor.java
Outdated
Show resolved
Hide resolved
messaging/src/main/java/org/axonframework/eventhandling/tokenstore/jdbc/JdbcTokenStore.java
Outdated
Show resolved
Hide resolved
messaging/src/main/java/org/axonframework/eventhandling/tokenstore/jdbc/JdbcTokenStore.java
Outdated
Show resolved
Hide resolved
messaging/src/test/java/org/axonframework/eventhandling/tokenstore/jdbc/JdbcTokenStoreTest.java
Show resolved
Hide resolved
messaging/src/main/java/org/axonframework/eventhandling/tokenstore/jpa/JpaTokenStore.java
Outdated
Show resolved
Hide resolved
messaging/src/main/java/org/axonframework/eventhandling/tokenstore/jpa/JpaTokenStore.java
Outdated
Show resolved
Hide resolved
messaging/src/test/java/org/axonframework/eventhandling/tokenstore/jpa/JpaTokenStoreTest.java
Show resolved
Hide resolved
…tore/jdbc/JdbcTokenStore.java Co-authored-by: Steven van Beelen <steven.vanbeelen@axoniq.io>
…tore/jdbc/JdbcTokenStore.java Co-authored-by: Steven van Beelen <steven.vanbeelen@axoniq.io>
…tore/jpa/JpaTokenStore.java Co-authored-by: Steven van Beelen <steven.vanbeelen@axoniq.io>
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.
My concerns have been addressed, hence approving.
I would still expect the deprecation notice on the TokenStore#fetchToken(String, int)
method before merging as we've discussed, of course.
messaging/src/main/java/org/axonframework/eventhandling/TrackingEventProcessor.java
Outdated
Show resolved
Hide resolved
messaging/src/main/java/org/axonframework/eventhandling/tokenstore/jpa/JpaTokenStore.java
Outdated
Show resolved
Hide resolved
messaging/src/main/java/org/axonframework/eventhandling/tokenstore/jpa/JpaTokenStore.java
Outdated
Show resolved
Hide resolved
messaging/src/test/java/org/axonframework/eventhandling/tokenstore/jdbc/JdbcTokenStoreTest.java
Show resolved
Hide resolved
…tore/jpa/JpaTokenStore.java Co-authored-by: Steven van Beelen <steven.vanbeelen@axoniq.io>
…ngEventProcessor.java Co-authored-by: Steven van Beelen <steven.vanbeelen@axoniq.io>
Kudos, SonarCloud Quality Gate passed! |
This PR introduces a new method to the
TokenStore
;fetchAvailableSegments
to fetch the ids of unclaimed segments only. This prevents streaming event processors from attempting to claim tokens that have already been claimed by another processor.Additionally, both the
TrackingEventProcessor
and thePooledStreamingEventProccesor
have been updated to utilize this method.In order to preserve backwards compatibility, the
fetchAvailableSegments
method returns anOptional<int[]>
, where an emptyOptional
should be interpreted as this method not being implemented.UPDATE: Instead of returning an
Optional<int[]>
, I'm now returning aList<Segment>
. This avoids the need to make another call to the DB later on to construct the segments. The default implementation simply returns all Segments, not only the available ones.Additionally, instead of finding segments with a
null
owner, I'm now using themayClaim
method instead. This should now also include segments that have been claimed, but have not been updated in a while (possibly due to a node going down, etc.)UPDATE 2: A potential race condition of claiming a token while performing a split or merge operation was detected. This already existed in the
PooledStreamingEventProcessor
and would have been introduced in this PR in theTrackingEventProcessor
as well. As such, an update to theTokenStore
has been added, which allows us to claim a segment by providing the entireSegment
object, after which it will be validated. If not valid, it means a split or merge operation has just been performed concurrently and the segment's mask is no longer correct. In that case, the segment will be released again to be claimed at a later moment.This PR resolves #1967