Skip to content
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

IGNITE-13870 #8586

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,10 @@ public final class IgniteSystemProperties {

/**
* Flag indicating whether validation of keys put to cache should be disabled.
*
* @deprecated Since 2.10 Obsolete because of common use of binary marshaller.
*/
@Deprecated
@SystemProperty("Disables validation of keys put to cache")
public static final String IGNITE_CACHE_KEY_VALIDATION_DISABLED = "IGNITE_CACHE_KEY_VALIDATION_DISABLED";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_KEY_VALIDATION_DISABLED;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_RETRIES_COUNT;
import static org.apache.ignite.internal.GridClosureCallMode.BROADCAST;
import static org.apache.ignite.internal.processors.cache.CacheOperationContext.DFLT_ALLOW_ATOMIC_OPS_IN_TX;
Expand Down Expand Up @@ -255,9 +254,6 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
}
};

/** */
protected boolean keyCheck = !Boolean.getBoolean(IGNITE_CACHE_KEY_VALIDATION_DISABLED);

/** Last asynchronous future. */
protected ThreadLocal<FutureHolder> lastFut = new ThreadLocal<FutureHolder>() {
@Override protected FutureHolder initialValue() {
Expand Down Expand Up @@ -362,10 +358,6 @@ protected GridCacheAdapter(final GridCacheContext<K, V> ctx, @Nullable GridCache
init();

aff = new GridCacheAffinityImpl<>(ctx);

// The check of methods 'equals' and 'hashCode' that they had been overrode isn't required, since BinaryMarshaller doesn't use them.
if (keyCheck && ctx.binaryMarshaller())
keyCheck = false;
}

/**
Expand Down Expand Up @@ -843,9 +835,6 @@ else if (modes.heap) {
throws IgniteCheckedException {
A.notNull(key, "key");

if (keyCheck)
validateCacheKey(key);

ctx.checkSecurity(SecurityPermission.CACHE_READ);

PeekModes modes = parsePeekModes(peekModes, false);
Expand Down Expand Up @@ -2004,9 +1993,6 @@ public final IgniteInternalFuture<Map<K, V>> getAllAsync(@Nullable final Collect
) {
ctx.checkSecurity(SecurityPermission.CACHE_READ);

if (keyCheck)
validateCacheKeys(keys);

warnIfUnordered(keys, BulkOperation.GET);

return getAllAsync0(ctx.cacheKeysView(keys),
Expand Down Expand Up @@ -2496,9 +2482,6 @@ private void clearReservationsIfNeeded(

A.notNull(key, "key", val, "val");

if (keyCheck)
validateCacheKey(key);

V prevVal = getAndPut0(key, val, filter);

if (statsEnabled)
Expand Down Expand Up @@ -2552,9 +2535,6 @@ protected final IgniteInternalFuture<V> getAndPutAsync(K key, V val, @Nullable C

A.notNull(key, "key", val, "val");

if (keyCheck)
validateCacheKey(key);

IgniteInternalFuture<V> fut = getAndPutAsync0(key, val, filter);

if (statsEnabled)
Expand Down Expand Up @@ -2613,9 +2593,6 @@ public boolean put(final K key, final V val, final CacheEntryPredicate filter)

A.notNull(key, "key", val, "val");

if (keyCheck)
validateCacheKey(key);

boolean stored = put0(key, val, filter);

if (statsEnabled && stored)
Expand Down Expand Up @@ -2725,9 +2702,6 @@ private <T> EntryProcessorResult<T> invoke0(
throws IgniteCheckedException {
A.notNull(key, "key", entryProcessor, "entryProcessor");

if (keyCheck)
validateCacheKey(key);

return syncOp(new SyncOp<EntryProcessorResult<T>>(true) {
@Override public EntryProcessorResult<T> op(GridNearTxLocal tx)
throws IgniteCheckedException {
Expand Down Expand Up @@ -2774,9 +2748,6 @@ private <T> EntryProcessorResult<T> invoke0(
final Object... args) throws IgniteCheckedException {
A.notNull(keys, "keys", entryProcessor, "entryProcessor");

if (keyCheck)
validateCacheKeys(keys);

warnIfUnordered(keys, BulkOperation.INVOKE);

final boolean statsEnabled = ctx.statisticsEnabled();
Expand Down Expand Up @@ -2817,9 +2788,6 @@ private <T> EntryProcessorResult<T> invoke0(
throws EntryProcessorException {
A.notNull(key, "key", entryProcessor, "entryProcessor");

if (keyCheck)
validateCacheKey(key);

final boolean statsEnabled = ctx.statisticsEnabled();
final boolean performanceStatsEnabled = ctx.kernalContext().performanceStatistics().enabled();

Expand Down Expand Up @@ -2873,9 +2841,6 @@ private <T> EntryProcessorResult<T> invoke0(
final Object... args) {
A.notNull(keys, "keys", entryProcessor, "entryProcessor");

if (keyCheck)
validateCacheKeys(keys);

warnIfUnordered(keys, BulkOperation.INVOKE);

final boolean statsEnabled = ctx.statisticsEnabled();
Expand Down Expand Up @@ -2929,9 +2894,6 @@ private <T> EntryProcessorResult<T> invoke0(
final Object... args) {
A.notNull(map, "map");

if (keyCheck)
validateCacheKeys(map.keySet());

warnIfUnordered(map, BulkOperation.INVOKE);

final boolean statsEnabled = ctx.statisticsEnabled();
Expand Down Expand Up @@ -2980,9 +2942,6 @@ private <T> EntryProcessorResult<T> invoke0(
final Object... args) throws IgniteCheckedException {
A.notNull(map, "map");

if (keyCheck)
validateCacheKeys(map.keySet());

warnIfUnordered(map, BulkOperation.INVOKE);

final boolean statsEnabled = ctx.statisticsEnabled();
Expand Down Expand Up @@ -3023,9 +2982,6 @@ private <T> EntryProcessorResult<T> invoke0(
public final IgniteInternalFuture<Boolean> putAsync(K key, V val, @Nullable CacheEntryPredicate filter) {
A.notNull(key, "key", val, "val");

if (keyCheck)
validateCacheKey(key);

final boolean statsEnabled = ctx.statisticsEnabled();
final boolean performanceStatsEnabled = ctx.kernalContext().performanceStatistics().enabled();

Expand Down Expand Up @@ -3136,9 +3092,6 @@ public IgniteInternalFuture<Boolean> putAsync0(final K key, final V val,

long start = statsEnabled || performanceStatsEnabled ? System.nanoTime() : 0L;

if (keyCheck)
validateCacheKeys(m.keySet());

warnIfUnordered(m, BulkOperation.PUT);

putAll0(m);
Expand Down Expand Up @@ -3177,9 +3130,6 @@ protected void putAll0(final Map<? extends K, ? extends V> m) throws IgniteCheck

long start = statsEnabled || performanceStatsEnabled ? System.nanoTime() : 0L;

if (keyCheck)
validateCacheKeys(m.keySet());

warnIfUnordered(m, BulkOperation.PUT);

IgniteInternalFuture<?> fut = putAllAsync0(m);
Expand Down Expand Up @@ -3222,9 +3172,6 @@ protected IgniteInternalFuture<?> putAllAsync0(final Map<? extends K, ? extends

A.notNull(key, "key");

if (keyCheck)
validateCacheKey(key);

V prevVal = getAndRemove0(key);

if (statsEnabled)
Expand Down Expand Up @@ -3282,9 +3229,6 @@ protected V getAndRemove0(final K key) throws IgniteCheckedException {

A.notNull(key, "key");

if (keyCheck)
validateCacheKey(key);

IgniteInternalFuture<V> fut = getAndRemoveAsync0(key);

if (statsEnabled)
Expand Down Expand Up @@ -3353,9 +3297,6 @@ protected IgniteInternalFuture<V> getAndRemoveAsync0(final K key) {
if (F.isEmpty(keys))
return;

if (keyCheck)
validateCacheKeys(keys);

warnIfUnordered(keys, BulkOperation.REMOVE);

removeAll0(keys);
Expand Down Expand Up @@ -3399,9 +3340,6 @@ protected void removeAll0(final Collection<? extends K> keys) throws IgniteCheck

final long start = statsEnabled || performanceStatsEnabled ? System.nanoTime() : 0L;

if (keyCheck)
validateCacheKeys(keys);

warnIfUnordered(keys, BulkOperation.REMOVE);

IgniteInternalFuture<Object> fut = removeAllAsync0(keys);
Expand Down Expand Up @@ -3456,9 +3394,6 @@ public boolean remove(final K key, @Nullable CacheEntryPredicate filter) throws

A.notNull(key, "key");

if (keyCheck)
validateCacheKey(key);

boolean rmv = remove0(key, filter);

if (statsEnabled && rmv)
Expand Down Expand Up @@ -3518,9 +3453,6 @@ public IgniteInternalFuture<Boolean> removeAsync(final K key, @Nullable final Ca

A.notNull(key, "key");

if (keyCheck)
validateCacheKey(key);

IgniteInternalFuture<Boolean> fut = removeAsync0(key, filter);

if (statsEnabled)
Expand Down Expand Up @@ -3683,9 +3615,6 @@ public CacheMetricsImpl metrics0() {
if (F.isEmpty(keys))
return true;

if (keyCheck)
validateCacheKeys(keys);

//TODO: IGNITE-9324: add explicit locks support.
MvccUtils.verifyMvccOperationSupport(ctx, "Lock");

Expand Down Expand Up @@ -3730,9 +3659,6 @@ public CacheMetricsImpl metrics0() {
@Override public IgniteInternalFuture<Boolean> lockAsync(K key, long timeout) {
A.notNull(key, "key");

if (keyCheck)
validateCacheKey(key);

//TODO: IGNITE-9324: add explicit locks support.
MvccUtils.verifyMvccOperationSupport(ctx, "Lock");

Expand All @@ -3744,19 +3670,13 @@ public CacheMetricsImpl metrics0() {
throws IgniteCheckedException {
A.notNull(key, "key");

if (keyCheck)
validateCacheKey(key);

unlockAll(Collections.singletonList(key));
}

/** {@inheritDoc} */
@Override public boolean isLocked(K key) {
A.notNull(key, "key");

if (keyCheck)
validateCacheKey(key);

KeyCacheObject cacheKey = ctx.toCacheKeyObject(key);

while (true) {
Expand All @@ -3775,9 +3695,6 @@ public CacheMetricsImpl metrics0() {
@Override public boolean isLockedByThread(K key) {
A.notNull(key, "key");

if (keyCheck)
validateCacheKey(key);

try {
KeyCacheObject cacheKey = ctx.toCacheKeyObject(key);

Expand Down Expand Up @@ -4855,9 +4772,6 @@ private boolean clearLocally0(K key, boolean readers) {

ctx.checkSecurity(SecurityPermission.CACHE_REMOVE);

if (keyCheck)
validateCacheKey(key);

GridCacheVersion obsoleteVer = nextVersion();

ctx.shared().database().checkpointReadLock();
Expand Down Expand Up @@ -4887,9 +4801,6 @@ private boolean clearLocally0(K key, boolean readers) {
@Override public boolean evict(K key) {
A.notNull(key, "key");

if (keyCheck)
validateCacheKey(key);

//TODO IGNITE-7956
MvccUtils.verifyMvccOperationSupport(ctx, "Evict");

Expand All @@ -4903,9 +4814,6 @@ private boolean clearLocally0(K key, boolean readers) {
if (F.isEmpty(keys))
return;

if (keyCheck)
validateCacheKey(keys);

//TODO IGNITE-7956
MvccUtils.verifyMvccOperationSupport(ctx, "Evict");

Expand Down Expand Up @@ -5266,51 +5174,6 @@ public void onReconnected() {
// No-op.
}

/**
* For tests only.
*/
public void forceKeyCheck() {
keyCheck = true;
}

/**
* Validates that given cache key has overridden equals and hashCode methods and
* implements {@link Externalizable}.
*
* @param key Cache key.
* @throws IllegalArgumentException If validation fails.
*/
protected final void validateCacheKey(Object key) {
if (keyCheck) {
CU.validateCacheKey(key);

keyCheck = false;
}
}

/**
* Validates that given cache keys have overridden equals and hashCode methods and
* implement {@link Externalizable}.
*
* @param keys Cache keys.
* @throws IgniteException If validation fails.
*/
protected final void validateCacheKeys(Iterable<?> keys) {
if (keys == null)
return;

if (keyCheck) {
for (Object key : keys) {
if (key == null || key instanceof GridCacheInternal)
continue;

CU.validateCacheKey(key);

keyCheck = false;
}
}
}

/**
* Checks that given map is sorted or otherwise constant order, or processed inside deadlock-detecting transaction.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1051,22 +1051,6 @@ private static String capitalize(String str) {
return Character.toUpperCase(str.charAt(0)) + str.substring(1);
}

/**
* Validates that cache key object has overridden equals and hashCode methods.
* Will also check that a BinaryObject has a hash code set.
*
* @param key Key.
* @throws IllegalArgumentException If equals or hashCode is not implemented.
*/
public static void validateCacheKey(@Nullable Object key) {
if (key == null)
return;

if (!U.overridesEqualsAndHashCode(key))
throw new IllegalArgumentException("Cache key must override hashCode() and equals() methods: " +
key.getClass().getName());
}

/**
* @param cacheName Cache name.
* @return {@code True} if this is utility system cache.
Expand Down
Loading