Skip to content

Commit

Permalink
Rollback "Fail-fast if max-idle-seconds is set below 2 seconds" (#14794)
Browse files Browse the repository at this point in the history
Revert "Fail-fast if max-idle-seconds is set below 2 seconds (#14727)"

This reverts commit 336bd4d and add to javadoc the MaxIdle time precision limitation
  • Loading branch information
galibey committed Mar 28, 2019
1 parent 09e9502 commit 1f6d7e3
Show file tree
Hide file tree
Showing 15 changed files with 23 additions and 395 deletions.
Expand Up @@ -126,7 +126,6 @@
import com.hazelcast.map.impl.querycache.subscriber.QueryCacheEndToEndProvider;
import com.hazelcast.map.impl.querycache.subscriber.QueryCacheRequest;
import com.hazelcast.map.impl.querycache.subscriber.SubscriberContext;
import com.hazelcast.map.impl.recordstore.RecordStore;
import com.hazelcast.map.journal.EventJournalMapEvent;
import com.hazelcast.map.listener.MapListener;
import com.hazelcast.map.listener.MapPartitionLostListener;
Expand Down Expand Up @@ -176,7 +175,6 @@
import static com.hazelcast.util.CollectionUtil.objectToDataCollection;
import static com.hazelcast.util.ExceptionUtil.rethrow;
import static com.hazelcast.util.MapUtil.createHashMap;
import static com.hazelcast.util.Preconditions.checkMinTimeIfPositive;
import static com.hazelcast.util.Preconditions.checkNotInstanceOf;
import static com.hazelcast.util.Preconditions.checkNotNull;
import static com.hazelcast.util.SortingUtil.getSortedQueryResultSet;
Expand Down Expand Up @@ -204,9 +202,6 @@ public class ClientMapProxy<K, V> extends ClientProxy
protected static final String NULL_AGGREGATOR_IS_NOT_ALLOWED = "Aggregator should not be null!";
protected static final String NULL_PROJECTION_IS_NOT_ALLOWED = "Projection should not be null!";

protected static final String MAX_IDLE_TIME_IS_TOO_SMALL = "Parameter maxIdle in seconds representation must be greater than"
+ " or equal to " + RecordStore.MIN_ALLOWED_MAX_IDLE;

@SuppressWarnings("unchecked")
protected static final ClientMessageDecoder GET_ASYNC_RESPONSE_DECODER = new ClientMessageDecoder() {
@Override
Expand Down Expand Up @@ -343,8 +338,6 @@ public V put(K key, V value) {
public V put(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
checkMinTimeIfPositive(maxIdle, maxIdleUnit, RecordStore.MIN_ALLOWED_MAX_IDLE, TimeUnit.SECONDS,
MAX_IDLE_TIME_IS_TOO_SMALL);

return putInternal(ttl, ttlUnit, maxIdle, maxIdleUnit, key, value);
}
Expand Down Expand Up @@ -454,8 +447,6 @@ public ICompletableFuture<V> putAsync(K key, V value, long ttl, TimeUnit timeuni
public ICompletableFuture<V> putAsync(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
checkMinTimeIfPositive(maxIdle, maxIdleUnit, RecordStore.MIN_ALLOWED_MAX_IDLE, TimeUnit.SECONDS,
MAX_IDLE_TIME_IS_TOO_SMALL);

return putAsyncInternal(ttl, ttlUnit, maxIdle, maxIdleUnit, key, value);
}
Expand Down Expand Up @@ -497,8 +488,6 @@ public ICompletableFuture<Void> setAsync(K key, V value, long ttl, TimeUnit time
public ICompletableFuture<Void> setAsync(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
checkMinTimeIfPositive(maxIdle, maxIdleUnit, RecordStore.MIN_ALLOWED_MAX_IDLE, TimeUnit.SECONDS,
MAX_IDLE_TIME_IS_TOO_SMALL);

return setAsyncInternal(ttl, ttlUnit, maxIdle, maxIdleUnit, key, value);
}
Expand Down Expand Up @@ -609,8 +598,6 @@ public void putTransient(K key, V value, long ttl, TimeUnit timeunit) {
public void putTransient(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
checkMinTimeIfPositive(maxIdle, maxIdleUnit, RecordStore.MIN_ALLOWED_MAX_IDLE, TimeUnit.SECONDS,
MAX_IDLE_TIME_IS_TOO_SMALL);

putTransientInternal(ttl, ttlUnit, maxIdle, maxIdleUnit, key, value);
}
Expand Down Expand Up @@ -651,8 +638,6 @@ public V putIfAbsent(K key, V value, long ttl, TimeUnit timeunit) {
public V putIfAbsent(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
checkMinTimeIfPositive(maxIdle, maxIdleUnit, RecordStore.MIN_ALLOWED_MAX_IDLE, TimeUnit.SECONDS,
MAX_IDLE_TIME_IS_TOO_SMALL);

return putIfAbsentInternal(ttl, ttlUnit, maxIdle, maxIdleUnit, key, value);
}
Expand Down Expand Up @@ -723,8 +708,6 @@ public void set(K key, V value, long ttl, TimeUnit timeunit) {
public void set(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
checkMinTimeIfPositive(maxIdle, maxIdleUnit, RecordStore.MIN_ALLOWED_MAX_IDLE, TimeUnit.SECONDS,
MAX_IDLE_TIME_IS_TOO_SMALL);

setInternal(ttl, ttlUnit, maxIdle, maxIdleUnit, key, value);
}
Expand Down
Expand Up @@ -27,7 +27,6 @@
import com.hazelcast.map.EntryProcessor;
import com.hazelcast.map.QueryResultSizeExceededException;
import com.hazelcast.map.impl.MapListenerAdapter;
import com.hazelcast.map.impl.recordstore.RecordStore;
import com.hazelcast.map.listener.MapListener;
import com.hazelcast.query.Predicate;
import com.hazelcast.query.TruePredicate;
Expand All @@ -49,7 +48,6 @@

import static java.util.Collections.emptyMap;
import static java.util.Collections.emptySet;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.Assert.assertEquals;

@RunWith(HazelcastParallelClassRunner.class)
Expand Down Expand Up @@ -615,42 +613,6 @@ public void testIssue7631_emptyKeysSupported() {
assertEquals(emptyMap(), res);
}

@Test(expected = IllegalArgumentException.class)
public void testPutAsyncWithNotAllowedMaxIdleTime() {
map.putAsync("key1", "value1", 1, TimeUnit.MINUTES,
RecordStore.MIN_ALLOWED_MAX_IDLE - 1, SECONDS);
}

@Test(expected = IllegalArgumentException.class)
public void testSetAsyncWithNotAllowedMaxIdleTime() {
map.setAsync("key1", "value1", 1, TimeUnit.MINUTES,
RecordStore.MIN_ALLOWED_MAX_IDLE - 1, SECONDS);
}

@Test(expected = IllegalArgumentException.class)
public void testPutWithNotAllowedMaxIdleTime() {
map.put("key1", "value1", 1, TimeUnit.MINUTES,
RecordStore.MIN_ALLOWED_MAX_IDLE - 1, SECONDS);
}

@Test(expected = IllegalArgumentException.class)
public void testPutTransientWithNotAllowedMaxIdleTime() {
map.putTransient("key1", "value1", 1, TimeUnit.MINUTES,
RecordStore.MIN_ALLOWED_MAX_IDLE - 1, SECONDS);
}

@Test(expected = IllegalArgumentException.class)
public void testPutIfAbsentWithNotAllowedMaxIdleTime() {
map.putIfAbsent("key1", "value1", 1, TimeUnit.MINUTES,
RecordStore.MIN_ALLOWED_MAX_IDLE - 1, SECONDS);
}

@Test(expected = IllegalArgumentException.class)
public void testSetWithNotAllowedMaxIdleTime() {
map.set("key1", "value1", 1, TimeUnit.MINUTES,
RecordStore.MIN_ALLOWED_MAX_IDLE - 1, SECONDS);
}

private static class NoOpEntryProcessor implements EntryProcessor {
@Override
public Object process(Map.Entry entry) {
Expand Down
20 changes: 3 additions & 17 deletions hazelcast/src/main/java/com/hazelcast/config/MapConfig.java
Expand Up @@ -87,11 +87,6 @@ public class MapConfig implements SplitBrainMergeTypeProvider, IdentifiedDataSer
*/
public static final int DEFAULT_MAX_IDLE_SECONDS = 0;

/**
* The number of minimum and non-zero time to wait eviction in seconds.
*/
public static final int MIN_ALLOWED_MAX_IDLE_SECONDS = 2;

/**
* Default policy for eviction.
*/
Expand Down Expand Up @@ -439,22 +434,13 @@ public int getMaxIdleSeconds() {
* Maximum number of seconds for each entry to stay idle in the map. Entries that are
* idle (not touched) for more than {@code maxIdleSeconds} will get automatically evicted from the map.
* Entry is touched if {@code get()}, {@code getAll()}, {@code put()} or {@code containsKey()} is called.
* {@code 0} and any integer between {@value #MIN_ALLOWED_MAX_IDLE_SECONDS} and {@code Integer.MAX_VALUE} (inclusive)
* are allowed.
* {@code 0} means infinite. Default is {@code 0}.
* Any integer between {@code 0} and {@code Integer.MAX_VALUE}.
* {@code 0} means infinite. Default is {@code 0}. The time precision is limited by 1 second. The MaxIdle that
* less than 1 second can lead to unexpected behaviour.
*
* @param maxIdleSeconds the maxIdleSeconds (the maximum number of seconds for each entry to stay idle in the map) to set
* @throws IllegalArgumentException if maxIdleSeconds is negative or non-zero and less
* than {@value #MIN_ALLOWED_MAX_IDLE_SECONDS}.
*/
public MapConfig setMaxIdleSeconds(int maxIdleSeconds) {
if (maxIdleSeconds < 0) {
throw new IllegalArgumentException("Parameter maxIdleSeconds can not get a negative value");
}
if (maxIdleSeconds != DEFAULT_MAX_IDLE_SECONDS && maxIdleSeconds < MIN_ALLOWED_MAX_IDLE_SECONDS) {
throw new IllegalArgumentException("Parameter maxIdleSeconds must be greater than or equal to "
+ MIN_ALLOWED_MAX_IDLE_SECONDS);
}
this.maxIdleSeconds = maxIdleSeconds;
return this;
}
Expand Down
42 changes: 13 additions & 29 deletions hazelcast/src/main/java/com/hazelcast/core/IMap.java
Expand Up @@ -776,8 +776,8 @@ public interface IMap<K, V> extends ConcurrentMap<K, V>, LegacyAsyncMap<K, V> {
* <p>
* The entry will expire and get evicted after the Max Idle time. If the MaxIdle is 0,
* then the entry lives forever. If the MaxIdle is negative, then the MaxIdle
* from the map configuration will be used (default: forever). If the MaxIdle is positive, it must not be less than
* {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent.
* from the map configuration will be used (default: forever). The time precision is limited by 1 second. The MaxIdle that
* less than 1 second can lead to unexpected behaviour.
* <pre>
* ICompletableFuture future = map.putAsync(key, value, ttl, timeunit);
* // do some other stuff, when ready get the result
Expand Down Expand Up @@ -853,8 +853,6 @@ public interface IMap<K, V> extends ConcurrentMap<K, V>, LegacyAsyncMap<K, V> {
* @param maxIdleUnit time unit for the Max-Idle
* @return ICompletableFuture from which the old value of the key can be retrieved
* @throws NullPointerException if the specified key, value, ttlUnit or maxIdleUnit are null
* @throws IllegalArgumentException if maxIdle is greater than zero and less
* than {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent
* @see ICompletableFuture
* @see #setAsync(Object, Object, long, TimeUnit)
*/
Expand Down Expand Up @@ -933,10 +931,6 @@ public interface IMap<K, V> extends ConcurrentMap<K, V>, LegacyAsyncMap<K, V> {
* The entry will expire and get evicted after the TTL. If the TTL is 0,
* then the entry lives forever. If the TTL is negative, then the TTL
* from the map configuration will be used (default: forever).
* <p>
* The entry will expire and get evicted after the Max Idle time. If the MaxIdle is 0,
* then the entry lives forever. If the MaxIdle is negative, then the MaxIdle
* from the map configuration will be used (default: forever).
* <pre>
* ICompletableFuture&lt;Void&gt; future = map.setAsync(key, value, ttl, timeunit);
* // do some other stuff, when you want to make sure set operation is complete:
Expand Down Expand Up @@ -1010,12 +1004,12 @@ public interface IMap<K, V> extends ConcurrentMap<K, V>, LegacyAsyncMap<K, V> {
* <p>
* The entry will expire and get evicted after the TTL. If the TTL is 0,
* then the entry lives forever. If the TTL is negative, then the TTL
* from the map configuration will be used (default: forever). If the MaxIdle is positive, it must not be less than
* * {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent.
* from the map configuration will be used (default: forever).
* <p>
* The entry will expire and get evicted after the Max Idle time. If the MaxIdle is 0,
* then the entry lives forever. If the MaxIdle is negative, then the MaxIdle
* from the map configuration will be used (default: forever).
* from the map configuration will be used (default: forever). The time precision is limited by 1 second. The MaxIdle that
* less than 1 second can lead to unexpected behaviour.
* <pre>
* ICompletableFuture&lt;Void&gt; future = map.setAsync(key, value, ttl, timeunit);
* // do some other stuff, when you want to make sure set operation is complete:
Expand Down Expand Up @@ -1082,8 +1076,6 @@ public interface IMap<K, V> extends ConcurrentMap<K, V>, LegacyAsyncMap<K, V> {
* @return ICompletableFuture on which client code can block waiting for the operation to complete
* or provide an {@link ExecutionCallback} to be invoked upon set operation completion
* @throws NullPointerException if the specified key, value, ttlUnit or maxIdleUnit are null
* @throws IllegalArgumentException if maxIdle is greater than zero and less
* than {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent
* @see ICompletableFuture
*/
ICompletableFuture<Void> setAsync(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit);
Expand Down Expand Up @@ -1254,8 +1246,8 @@ public interface IMap<K, V> extends ConcurrentMap<K, V>, LegacyAsyncMap<K, V> {
* <p>
* The entry will expire and get evicted after the Max Idle time. If the MaxIdle is 0,
* then the entry lives forever. If the MaxIdle is negative, then the MaxIdle
* from the map configuration will be used (default: forever). If the MaxIdle is positive, it must not be less than
* * {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent.
* from the map configuration will be used (default: forever). The time precision is limited by 1 second. The MaxIdle that
* less than 1 second can lead to unexpected behaviour.
* <p>
* <b>Warning 1:</b>
* <p>
Expand Down Expand Up @@ -1302,8 +1294,6 @@ public interface IMap<K, V> extends ConcurrentMap<K, V>, LegacyAsyncMap<K, V> {
* @param maxIdleUnit time unit for the Max-Idle
* @return old value of the entry
* @throws NullPointerException if the specified key, value, ttlUnit or maxIdleUnit are null
* @throws IllegalArgumentException if maxIdle is greater than zero and less
* than {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent
*/
V put(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit);

Expand Down Expand Up @@ -1345,8 +1335,8 @@ public interface IMap<K, V> extends ConcurrentMap<K, V>, LegacyAsyncMap<K, V> {
* <p>
* The entry will expire and get evicted after the Max Idle time. If the MaxIdle is 0,
* then the entry lives forever. If the MaxIdle is negative, then the MaxIdle
* from the map configuration will be used (default: forever). If the MaxIdle is positive, it must not be less than
* * {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent.
* from the map configuration will be used (default: forever). The time precision is limited by 1 second. The MaxIdle that
* less than 1 second can lead to unexpected behaviour.
* <p>
* <b>Warning 1:</b>
* <p>
Expand All @@ -1366,8 +1356,6 @@ public interface IMap<K, V> extends ConcurrentMap<K, V>, LegacyAsyncMap<K, V> {
* (0 means infinite, negative means map config default)
* @param maxIdleUnit time unit for the Max-Idle
* @throws NullPointerException if the specified key, value, ttlUnit or maxIdleUnit are null
* @throws IllegalArgumentException if maxIdle is greater than zero and less
* than {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent
*/
void putTransient(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit);

Expand Down Expand Up @@ -1466,8 +1454,8 @@ public interface IMap<K, V> extends ConcurrentMap<K, V>, LegacyAsyncMap<K, V> {
* <p>
* The entry will expire and get evicted after the Max Idle time. If the MaxIdle is 0,
* then the entry lives forever. If the MaxIdle is negative, then the MaxIdle
* from the map configuration will be used (default: forever). If the MaxIdle is positive, it must not be less than
* * {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent.
* from the map configuration will be used (default: forever). The time precision is limited by 1 second. The MaxIdle that
* less than 1 second can lead to unexpected behaviour.
* <p>
* <b>Warning 1:</b>
* <p>
Expand Down Expand Up @@ -1511,8 +1499,6 @@ public interface IMap<K, V> extends ConcurrentMap<K, V>, LegacyAsyncMap<K, V> {
* @param maxIdleUnit time unit for the Max-Idle
* @return old value of the entry
* @throws NullPointerException if the specified key, value, ttlUnit or maxIdleUnit are null
* @throws IllegalArgumentException if maxIdle is greater than zero and less
* than {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent
*/
V putIfAbsent(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit);
/**
Expand Down Expand Up @@ -1665,8 +1651,8 @@ public interface IMap<K, V> extends ConcurrentMap<K, V>, LegacyAsyncMap<K, V> {
* <p>
* The entry will expire and get evicted after the Max Idle time. If the MaxIdle is 0,
* then the entry lives forever. If the MaxIdle is negative, then the MaxIdle
* from the map configuration will be used (default: forever). If the MaxIdle is positive, it must not be less than
* * {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent.
* from the map configuration will be used (default: forever). The time precision is limited by 1 second. The MaxIdle that
* less than 1 second can lead to unexpected behaviour.
* <p>
* <b>Warning 1:</b>
* <p>
Expand Down Expand Up @@ -1699,8 +1685,6 @@ public interface IMap<K, V> extends ConcurrentMap<K, V>, LegacyAsyncMap<K, V> {
* (0 means infinite, negative means map config default)
* @param maxIdleUnit time unit for the Max-Idle
* @throws NullPointerException if the specified key, value, ttlUnit or maxIdleUnit are null
* @throws IllegalArgumentException if maxIdle is greater than zero and less
* than {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent
*/
void set(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit);

Expand Down

0 comments on commit 1f6d7e3

Please sign in to comment.