Skip to content

Commit 3cfd090

Browse files
committed
Bug 38434644 - [36166441->25.09] Using Long.MAX_VALUE as a ttl to a NamedCache put results in error
(merge main -> ce/main 118592) [git-p4: depot-paths = "//dev/coherence-ce/main/": change = 118603]
1 parent 8fbfafb commit 3cfd090

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;
@@ -737,6 +738,12 @@ public class Storage
737738

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

741+
/**
742+
* The maximum accepted value used in {#link {@link #scheduleEviction(long)}}.
743+
* This equals {@link Long#MAX_VALUE} minus millis in one day
744+
*/
745+
private static final long MAX_EXPIRY = Long.MAX_VALUE - TimeUnit.DAYS.toMillis(1);
746+
740747
// Static initializer
741748
static
742749
{
@@ -9100,15 +9107,12 @@ protected static void rethrow(Throwable e)
91009107
* Schedule to run the eviction task at specified expiry delay
91019108
* (cExpiryMillis) if no task is currently scheduled. Cancel the
91029109
* existing task and create a new one if new expiry time is sooner than
9103-
* previosely scheduled one.
9110+
* previously scheduled one.
91049111
*
91059112
* @param cExpiryMillis expiry delay in millis
91069113
*/
91079114
public synchronized void scheduleEviction(long cExpiryMillis)
91089115
{
9109-
// import Component.Util.DaemonPool as com.tangosol.coherence.component.util.DaemonPool;
9110-
// import com.tangosol.util.Base;
9111-
91129116
com.tangosol.coherence.component.util.DaemonPool pool = getService().getDaemonPool();
91139117

91149118
if (!pool.isStarted())
@@ -9126,7 +9130,22 @@ public synchronized void scheduleEviction(long cExpiryMillis)
91269130
}
91279131

91289132
long ldtOldNext = task.getEvictionTime();
9129-
long ldtNewNext = Base.getSafeTimeMillis() + cExpiryMillis;
9133+
long ldtNow = TimeHelper.getSafeTimeMillis();
9134+
long ldtMax = MAX_EXPIRY - ldtNow;
9135+
9136+
long ldtNewNext;
9137+
long ldtSchedule;
9138+
9139+
if (cExpiryMillis < ldtMax)
9140+
{
9141+
ldtNewNext = ldtNow + cExpiryMillis;
9142+
ldtSchedule = cExpiryMillis;
9143+
}
9144+
else
9145+
{
9146+
ldtNewNext = MAX_EXPIRY;
9147+
ldtSchedule = MAX_EXPIRY - ldtNow;
9148+
}
91309149

91319150
task.setPrune(cExpiryMillis == 0L);
91329151

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)