Skip to content

Conversation

@ben-manes
Copy link
Contributor

Fix the calculation based on what @aseovic explained to me over slack. I had mistakenly thought this was to change the base unit of the entry's weight, e.g. from bytes to kilobytes, so that larger values could be stored. Instead it is to allow the total capacity to be reported as an int instead of a long, since that fix would be a breaking API change.

A minor cleanup was to allocate a CacheEvent instance only if it the cache will actually fire the event. Since MapListenerSupport#fireEvent is a synchronous call even if no listeners are registered (see collectListeners), the unsynchronized isEmpty() method is called as a guard. It's probably better to prefer avoiding the allocation over the convenience method as not much of a difference in readability.

@ben-manes ben-manes requested a review from a team as a code owner July 30, 2022 01:09
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Jul 30, 2022
@aseovic aseovic self-assigned this Aug 1, 2022
@aseovic aseovic added LGTM Run RQ and merge PR into P4 and removed LGTM Run RQ and merge PR into P4 labels Aug 1, 2022
@aseovic
Copy link
Member

aseovic commented Aug 1, 2022

Actually, while the existing changes look good, I think some are still missing: getHighUnits and setHighUnits also need to take unit factor into account:

 @Override public int getHighUnits() { return (int) Math.min(f_eviction.getMaximum() / m_nUnitFactor, Integer.MAX_VALUE); } @Override public synchronized void setHighUnits(int units) { f_eviction.setMaximum(units * m_nUnitFactor); }

Without that it would be impossible to set high units to anything larger than 2 GB.

@ben-manes
Copy link
Contributor Author

CaffeineCacheTest runs against both implementations (unfortunately the current unit factor test passes both with and without this pr). I think adding the high/low tests would help, and we can accumulate more for compatibility checks.

@ben-manes
Copy link
Contributor Author

Updated the implementation by using the internal / external conversion methods from OldCache and added a unit test. This way the logic stays as similar as possible. It differs slightly because Caffeine avoids long overflow by restricting the maximum size to Long.MAX_VALUE - Integer.MAX_VALUE, rather than checking for that at runtime (whereas OldCache goes negative).

@ben-manes ben-manes force-pushed the issue75 branch 2 times, most recently from e0be1d1 to e244b54 Compare August 2, 2022 03:28
@aseovic aseovic added the LGTM Run RQ and merge PR into P4 label Aug 2, 2022
@coherence-bot
Copy link
Member

Failed to process pull request
Failed to prepare P4 changelist (possibly a merge conflict).

@coherence-bot coherence-bot removed the LGTM Run RQ and merge PR into P4 label Aug 2, 2022
@aseovic aseovic assigned rlubke and unassigned rlubke and aseovic Aug 2, 2022
@aseovic
Copy link
Member

aseovic commented Aug 2, 2022

@rlubke Looks like we'll have to do a manual patch in P4. Automated PR merge still doesn't work... :-(

@thegridman This may be a good PR to use to sort out why the merge doesn't work any more. It's fairly simple, touches only 3 files that should be exactly the same in main and ce branches in P4.

@ben-manes
Copy link
Contributor Author

Please remember to merge this.

@rlubke
Copy link
Contributor

rlubke commented Aug 15, 2022

We haven't forgotten :)

We're working on it, just in the middle of some refactorings and don't want to muddy the waters at the moment. Will follow up as soon as it has been merged.

@rlubke
Copy link
Contributor

rlubke commented Aug 18, 2022

PR has been merged

@rlubke rlubke closed this Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

4 participants