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

Make CachedQueryEntry to implement IDS #18238

Merged

Conversation

jerrinot
Copy link
Contributor

@jerrinot jerrinot commented Feb 18, 2021

Fixes #18131
EE: https://github.com/hazelcast/hazelcast-enterprise/pull/3973

CachedQueryEntry is an output of maxBy/minBy aggregations
when aggregating entries matching a predicate which was
evaluated by using an index.

The fix is not straightforward, there is some extra complexity
so recording here for future generations:

This changeset makes CachedQueryEntry to use the same Class ID
as LazyMapEntry which already is serializable. This means why you
serialize CachedQueryEntry and deserialize again you will get
an instance of LazyMapEntry. This is already confusing enough,
but it gets worst: LazyMapEntry is subclass of CachedQueryEntry!

So you might be asking: What is going on?
The explanation is not simple, but I will try anyway:

I could make the CachedQueryEntry to use a separate Class ID. But this means
all clients would have to be updated as well. As they would not know this new ID.

Still, this on its own would not justify using a class ID belonging to
a different class. This is the contract of LazyMapEntry: "When you serialize
and deserialize LazyMapEntry it loses its "lazy" properties." After deserialize
it behaves as if it was a plain SimpleMapEntry and that's exactly what we need.

Fixes hazelcast#18131
CachedQueryEntry is an output of maxBy/minBy aggregations
when aggregating entries matching a predicate which was
evaluated by using an index.

The fix is not straightforward, there is some extra complexity
so recording here for future generations:

This changeset makes CachedQueryEntry to use the same Class ID
as LazyMapEntry which already is serializable. This means why you
serialize CachedQueryEntry and deserialize again you will get
an instance of LazyMapEntry. This is already confusing enough,
but it gets worst: LazyMapEntry is subclass of CachedQueryEntry!

So you might be asking: What is going on?
The explanation is not simple, but I will try anyway:

I could make the CachedQueryEntry to use a separate Class ID. But this means
all clients would have to be updated as well. As they would not know this new ID.

Still, this on its own would not justify using a class ID belonging to
a different class. This is the contract of LazyMapEntry: "When you serialize
and deserialize LazyMapEntry it loses its "lazy" properties." After deserialize
it behaves as if it was a plain SimpleMapEntry and that's exactly what we need.

TODO: Write sed-de test for CacheQueryEntry
@mmedenjak mmedenjak added the Source: Internal PR or issue was opened by an employee label Feb 18, 2021
Copy link
Contributor

@sancar sancar left a comment

Choose a reason for hiding this comment

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

Looks ok given that we need to support backward compatibility.
At least, I don't have a better solution.

@ahmetmircik
Copy link
Member

Instead of having to document an unexpected situation as in here: https://github.com/hazelcast/hazelcast/pull/18238/files#diff-704432b994852652577c49594ec841d6f15265fbc703320d1a64f42c825dd905R224

What about doing something like these:

  1. Rename LazyMapEntry to EntryProcessorEntry (since the transient fields are used only in entry-processing logic)
  2. Rename CachedQueryEntry as LazyMapEntry

Gain is these classes will be aligned with their intention of usage.

@mmedenjak
Copy link
Contributor

@jerrinot what's the state of this fix? I see it's draft, there's a TODO and Ahmet posted a comment. Can you finalise the PR?

@jerrinot
Copy link
Contributor Author

jerrinot commented Mar 4, 2021

@ahmetmircik that's an interesting idea! do you want to do a change like this in a minor release? wouldnt it be better to wait for the 5.0 release? I know technically it does not break compatibility (yay, IDS!), but it still seem to be quite surprising.

@ahmetmircik
Copy link
Member

ahmetmircik commented Mar 4, 2021

@jerrinot Of course it is up to you but if no big obstacle, i prefer it to workarounds. Workarounds seem more surprising in this context.

@jerrinot jerrinot marked this pull request as ready for review March 4, 2021 10:54
@jerrinot jerrinot requested a review from a team as a code owner March 4, 2021 10:54
@hz-devops-test
Copy link

The job Hazelcast-pr-builder of your PR failed.
Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log file
--------------------------
-------TEST FAILURE-------
--------------------------
[INFO] Results:
[INFO] 
[ERROR] Failures: 
[ERROR]   CachedQueryEntryTest.testDeserialization:221 expected:<1476017569> but was:<112004910>
[INFO] 
[ERROR] Tests run: 36301, Failures: 1, Errors: 0, Skipped: 988
[INFO] 

[ERROR] There are test failures.

@jerrinot jerrinot force-pushed the fixes/cache-query-entry-ids/master branch from d0139f5 to 1842123 Compare March 4, 2021 14:46
@jerrinot jerrinot merged commit a955131 into hazelcast:master Mar 8, 2021
@jerrinot jerrinot deleted the fixes/cache-query-entry-ids/master branch March 8, 2021 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HazelcastSerializationException Failed to serialize 'com.hazelcast.query.impl.CachedQueryEntry'
6 participants