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
Fix LRU comparison algorithm #18624
Fix LRU comparison algorithm #18624
Conversation
303b56f
to
f8cb33f
Compare
The job Click to expand the log file-------------------------- -------TEST FAILURE------- -------------------------- [INFO] Results: [INFO] [ERROR] Failures: [ERROR] ExpirationTimeTest.last_access_time_updated_on_primary_when_read_backup_data_enabled:451 lastAccessTimeBefore:1620075212000, lastAccessTimeAfter:1620075212000 [ERROR] ExpirationTimeTest.testExpirationTime_whenMaxIdleTime_isSmallerThan_TTL:352 expected:<3240150432000> but was:<1620075221000> [ERROR] ExpirationTimeTest.testLastAccessTime_isZero_afterFirstPut:377 expected:<0> but was:<1620075212000> [INFO] [ERROR] Tests run: 36328, Failures: 3, Errors: 0, Skipped: 988 [INFO] |
@@ -344,8 +344,7 @@ public void testExpirationTime_whenMaxIdleTime_isSmallerThan_TTL() { | |||
map.put(1, 1, 100, TimeUnit.SECONDS); | |||
|
|||
EntryView<Integer, Integer> entryView = map.getEntryView(1); | |||
long lastAccessTime = entryView.getLastAccessTime(); | |||
long delayToExpiration = lastAccessTime + TimeUnit.SECONDS.toMillis(10); | |||
long delayToExpiration = TimeUnit.SECONDS.toMillis(10); | |||
|
|||
// lastAccessTime is zero after put, we can find expiration by this calculation |
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.
This comment is stale. Could you update it?
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.
long time1 = Math.max(e1.getCreationTime(), e1.getLastAccessTime()); | ||
long time2 = Math.max(e2.getCreationTime(), e2.getLastAccessTime()); |
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.
Do we need these comparisons after the change in AbstractRecordStore
? I don't know exactly where the last access times can be changed, so it's just a question to learn the cases that need them.
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.
This comparator is a common one used by multiple data structures, it is not specific to IMap, i have also fixed it here.
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 think it would be better if we also apply the change made in AbstractRecordStore
to AbstractCacheRecordStore
(and all others) to have a convenience on these last access times.
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.
There is no issue in the context of icache. Setting last-access-time is a missing requirement for imap after 4.2 improvements. No need for others now.
d8a3a41
to
b911cdf
Compare
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.
Even though setting the initial last access times in cache and map entries in different ways seems rough to me, I leave this discussion to other reviewers. Other than that it looks good to me.
for (int i = 0; i < recordCount; i++) { | ||
long creationTime = baseTime + (i * 100); | ||
minCreationTime = minCreationTime == -1 ? creationTime : Math.min(creationTime, minCreationTime); |
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.
nit: could also initialize minCreationTime = Long.MAX_VALUE
and just use minCreationTime = Math.min(creationTime, minCreationTime);
here instead of the ternary operator.
closes #18614
For lru sorting, when last-access-time is zero, we will use creation-time of the entry. This is to prevent premature removal of lately added but not yet accessed entries.
Backport: #18632
Forward-port: #18909