Skip to content

Commit 7ebfd68

Browse files
committed
Bug 38434643 - [36166441->22.06.15] Using Long.MAX_VALUE as a ttl to a NamedCache put results in error
(merge 14.1.1-2206 -> ce/22.06 118608) [git-p4: depot-paths = "//dev/coherence-ce/release/coherence-ce-v22.06/": change = 118610]
1 parent 9ac09d7 commit 7ebfd68

File tree

2 files changed

+70
-5
lines changed
  • prj
    • coherence-core-components/src/main/java/com/tangosol/coherence/component/util/daemon/queueProcessor/service/grid/partitionedService/partitionedCache
    • test/functional/cache/src/main/java/cache

2 files changed

+70
-5
lines changed

prj/coherence-core-components/src/main/java/com/tangosol/coherence/component/util/daemon/queueProcessor/service/grid/partitionedService/partitionedCache/Storage.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.partitionedService.partitionedCache;
99

1010
import com.oracle.coherence.common.base.Blocking;
11+
import com.oracle.coherence.common.base.TimeHelper;
1112
import com.oracle.coherence.persistence.PersistentStore;
1213
import com.tangosol.coherence.component.net.Lease;
1314
import com.tangosol.coherence.component.net.MemberSet;
@@ -736,6 +737,12 @@ public class Storage
736737

737738
private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
738739

740+
/**
741+
* The maximum accepted value used in {#link {@link #scheduleEviction(long)}}.
742+
* This equals {@link Long#MAX_VALUE} minus millis in one day
743+
*/
744+
private static final long MAX_EXPIRY = Long.MAX_VALUE - TimeUnit.DAYS.toMillis(1);
745+
739746
// Static initializer
740747
static
741748
{
@@ -9065,15 +9072,12 @@ protected static void rethrow(Throwable e)
90659072
* Schedule to run the eviction task at specified expiry delay
90669073
* (cExpiryMillis) if no task is currently scheduled. Cancel the
90679074
* existing task and create a new one if new expiry time is sooner than
9068-
* previosely scheduled one.
9075+
* previously scheduled one.
90699076
*
90709077
* @param cExpiryMillis expiry delay in millis
90719078
*/
90729079
public synchronized void scheduleEviction(long cExpiryMillis)
90739080
{
9074-
// import Component.Util.DaemonPool as com.tangosol.coherence.component.util.DaemonPool;
9075-
// import com.tangosol.util.Base;
9076-
90779081
com.tangosol.coherence.component.util.DaemonPool pool = getService().getDaemonPool();
90789082

90799083
if (!pool.isStarted())
@@ -9091,7 +9095,22 @@ public synchronized void scheduleEviction(long cExpiryMillis)
90919095
}
90929096

90939097
long ldtOldNext = task.getEvictionTime();
9094-
long ldtNewNext = Base.getSafeTimeMillis() + cExpiryMillis;
9098+
long ldtNow = TimeHelper.getSafeTimeMillis();
9099+
long ldtMax = MAX_EXPIRY - ldtNow;
9100+
9101+
long ldtNewNext;
9102+
long ldtSchedule;
9103+
9104+
if (cExpiryMillis < ldtMax)
9105+
{
9106+
ldtNewNext = ldtNow + cExpiryMillis;
9107+
ldtSchedule = cExpiryMillis;
9108+
}
9109+
else
9110+
{
9111+
ldtNewNext = MAX_EXPIRY;
9112+
ldtSchedule = MAX_EXPIRY - ldtNow;
9113+
}
90959114

90969115
task.setPrune(cExpiryMillis == 0L);
90979116

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Universal Permissive License v 1.0 as shown at
5+
* https://oss.oracle.com/licenses/upl.
6+
*/
7+
8+
package cache;
9+
10+
import com.oracle.coherence.common.base.TimeHelper;
11+
import com.tangosol.net.Coherence;
12+
import com.tangosol.net.NamedCache;
13+
import com.tangosol.net.Session;
14+
import org.junit.BeforeClass;
15+
import org.junit.Test;
16+
17+
import java.util.concurrent.TimeUnit;
18+
19+
public class PutWithExpiryTests
20+
{
21+
@BeforeClass
22+
public static void setup() throws Exception
23+
{
24+
session = Coherence.clusterMember().startAndWait().getSession();
25+
}
26+
27+
@Test
28+
public void shouldPutWithLongMaxValueExpiry() throws Exception
29+
{
30+
NamedCache<String, String> cache = session.getCache("test");
31+
cache.put("key", "value", Long.MAX_VALUE);
32+
}
33+
34+
@Test
35+
public void shouldPutWithExpiryPastUnixEpochEnd() throws Exception
36+
{
37+
long epochEnd = Long.MAX_VALUE;
38+
long now = TimeHelper.getSafeTimeMillis();
39+
long expiry = epochEnd - now + TimeUnit.DAYS.toMillis(1);
40+
// expiry delay would be one day past epoch end
41+
NamedCache<String, String> cache = session.getCache("test");
42+
cache.put("key", "value", expiry);
43+
}
44+
45+
public static Session session;
46+
}

0 commit comments

Comments
 (0)