mirror of
https://github.com/google/nomulus
synced 2026-10-01 04:05:49 +00:00
Use transaction time for deletion time cache ticker (#2848)
Basically, what happened is that the cache's expireAfterWrite was being called some number of milliseconds (say, 50-100) after the transaction was started. That method used the transaction time instead of the current time, so as a result the entries were sticking around 50-100ms longer in the cache than they should have been. This fix contains two parts, each of which I believe would be sufficient on their own to fix the issue: 1. Use the currentTime passed in in Expiry::expireAfterCreate 2. Use the transaction time in the cache's Ticker. This keeps everything on the same schedule.
This commit is contained in:
@@ -26,6 +26,7 @@ import google.registry.testing.DatabaseHelper;
|
||||
import google.registry.testing.FakeClock;
|
||||
import java.util.Optional;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
@@ -67,7 +68,8 @@ public class DomainDeletionTimeCacheTest {
|
||||
Domain domain = persistActiveDomain("domain.tld");
|
||||
assertThat(getDeletionTimeFromCache("domain.tld")).hasValue(END_OF_TIME);
|
||||
persistDomainAsDeleted(domain, clock.nowUtc().plusDays(1));
|
||||
// Without intervention, the cache should have the old data
|
||||
// Without intervention, the cache should have the old data, even if a few minutes have passed
|
||||
clock.advanceBy(Duration.standardMinutes(5));
|
||||
assertThat(getDeletionTimeFromCache("domain.tld")).hasValue(END_OF_TIME);
|
||||
}
|
||||
|
||||
@@ -79,6 +81,16 @@ public class DomainDeletionTimeCacheTest {
|
||||
assertThat(getDeletionTimeFromCache("domain.tld")).hasValue(clock.nowUtc().plusDays(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCache_expires() {
|
||||
Domain domain = persistActiveDomain("domain.tld");
|
||||
assertThat(getDeletionTimeFromCache("domain.tld")).hasValue(END_OF_TIME);
|
||||
DateTime elevenMinutesFromNow = clock.nowUtc().plusMinutes(11);
|
||||
persistDomainAsDeleted(domain, elevenMinutesFromNow);
|
||||
clock.advanceBy(Duration.standardMinutes(30));
|
||||
assertThat(getDeletionTimeFromCache("domain.tld")).hasValue(elevenMinutesFromNow);
|
||||
}
|
||||
|
||||
private Optional<DateTime> getDeletionTimeFromCache(String domainName) {
|
||||
return tm().transact(() -> cache.getDeletionTimeForDomain(domainName));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user