Skip to content

Commit

Permalink
#ignite-629: Remove CacheFlag.Local
Browse files Browse the repository at this point in the history
  • Loading branch information
ivasilinets committed Mar 27, 2015
1 parent 71ecef2 commit 4bc5b22
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 101 deletions.
Expand Up @@ -30,19 +30,11 @@
* <li>{@link CacheProjection#flagsOn(CacheFlag...)}</li> * <li>{@link CacheProjection#flagsOn(CacheFlag...)}</li>
* <li>{@link CacheProjection#flagsOff(CacheFlag...)}</li> * <li>{@link CacheProjection#flagsOff(CacheFlag...)}</li>
* </ul> * </ul>
* Also, some flags, like {@link #LOCAL}, or {@link #READ} may be implicitly set whenever * Also, some flags, like {@link #READ} may be implicitly set whenever
* creating new projections and passing entries to predicate filters. * creating new projections and passing entries to predicate filters.
*/ */
public enum CacheFlag { public enum CacheFlag {
/**
* Only operations that don't require any communication with
* other cache nodes are allowed. This flag is automatically set
* on underlying projection for all the entries that are given to
* predicate filters to make sure that no distribution happens
* from inside of predicate evaluation.
*/
LOCAL, LOCAL,

/** /**
* Only operations that don't change cached data are allowed. * Only operations that don't change cached data are allowed.
* This flag is automatically set on underlying projection for * This flag is automatically set on underlying projection for
Expand Down

Large diffs are not rendered by default.

Expand Up @@ -1597,8 +1597,6 @@ private boolean evictx(K key, GridCacheVersion ver,


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override public V getForcePrimary(K key) throws IgniteCheckedException { @Override public V getForcePrimary(K key) throws IgniteCheckedException {
ctx.denyOnFlag(LOCAL);

String taskName = ctx.kernalContext().job().currentTaskName(); String taskName = ctx.kernalContext().job().currentTaskName();


return getAllAsync(F.asList(key), /*force primary*/true, /*skip tx*/false, null, null, taskName, true, false) return getAllAsync(F.asList(key), /*force primary*/true, /*skip tx*/false, null, null, taskName, true, false)
Expand All @@ -1607,8 +1605,6 @@ private boolean evictx(K key, GridCacheVersion ver,


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override public IgniteInternalFuture<V> getForcePrimaryAsync(final K key) { @Override public IgniteInternalFuture<V> getForcePrimaryAsync(final K key) {
ctx.denyOnFlag(LOCAL);

String taskName = ctx.kernalContext().job().currentTaskName(); String taskName = ctx.kernalContext().job().currentTaskName();


return getAllAsync(Collections.singletonList(key), /*force primary*/true, /*skip tx*/false, null, null, return getAllAsync(Collections.singletonList(key), /*force primary*/true, /*skip tx*/false, null, null,
Expand Down Expand Up @@ -2040,9 +2036,7 @@ public IgniteInternalFuture<Map<K, V>> getAllAsync(@Nullable final Collection<?
) { ) {
ctx.checkSecurity(GridSecurityPermission.CACHE_READ); ctx.checkSecurity(GridSecurityPermission.CACHE_READ);


ctx.denyOnFlag(LOCAL); if (keyCheck)

if (keyCheck)
validateCacheKeys(keys); validateCacheKeys(keys);


return getAllAsync0(ctx.cacheKeysView(keys), return getAllAsync0(ctx.cacheKeysView(keys),
Expand Down Expand Up @@ -5023,8 +5017,6 @@ public Collection<V> primaryValues(@Nullable CacheEntryPredicate... filter) {
* @return Read operation future. * @return Read operation future.
*/ */
public final IgniteInternalFuture<V> getAsync(final K key, boolean deserializePortable) { public final IgniteInternalFuture<V> getAsync(final K key, boolean deserializePortable) {
ctx.denyOnFlag(LOCAL);

try { try {
checkJta(); checkJta();
} }
Expand All @@ -5051,8 +5043,6 @@ public final IgniteInternalFuture<V> getAsync(final K key, boolean deserializePo
* @throws IgniteCheckedException If read failed. * @throws IgniteCheckedException If read failed.
*/ */
public Map<K, V> getAll(Collection<? extends K> keys, boolean deserializePortable) throws IgniteCheckedException { public Map<K, V> getAll(Collection<? extends K> keys, boolean deserializePortable) throws IgniteCheckedException {
ctx.denyOnFlag(LOCAL);

checkJta(); checkJta();


return getAllAsync(keys, deserializePortable).get(); return getAllAsync(keys, deserializePortable).get();
Expand All @@ -5064,7 +5054,7 @@ public Map<K, V> getAll(Collection<? extends K> keys, boolean deserializePortabl
* @throws IgniteCheckedException If failed. * @throws IgniteCheckedException If failed.
*/ */
@Override @Nullable public V reload(K key) throws IgniteCheckedException { @Override @Nullable public V reload(K key) throws IgniteCheckedException {
ctx.denyOnFlags(F.asList(LOCAL, READ)); ctx.denyOnFlags(F.asList(READ));


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


Expand Down Expand Up @@ -5097,7 +5087,7 @@ public Map<K, V> getAll(Collection<? extends K> keys, boolean deserializePortabl
* @return Reload future. * @return Reload future.
*/ */
@Override public IgniteInternalFuture<V> reloadAsync(final K key) { @Override public IgniteInternalFuture<V> reloadAsync(final K key) {
ctx.denyOnFlags(F.asList(LOCAL, READ)); ctx.denyOnFlags(F.asList(READ));


return ctx.closures().callLocalSafe(ctx.projectSafe(new Callable<V>() { return ctx.closures().callLocalSafe(ctx.projectSafe(new Callable<V>() {
@Nullable @Override public V call() throws IgniteCheckedException { @Nullable @Override public V call() throws IgniteCheckedException {
Expand Down
Expand Up @@ -157,10 +157,7 @@ public class GridCacheContext<K, V> implements Externalizable {
private ThreadLocal<CacheFlag[]> forcedFlags = new ThreadLocal<>(); private ThreadLocal<CacheFlag[]> forcedFlags = new ThreadLocal<>();


/** Constant array to avoid recreation. */ /** Constant array to avoid recreation. */
private static final CacheFlag[] FLAG_LOCAL_READ = new CacheFlag[]{LOCAL, READ}; private static final CacheFlag[] FLAG_READ = new CacheFlag[]{READ};

/** Local flag array. */
private static final CacheFlag[] FLAG_LOCAL = new CacheFlag[]{LOCAL};


/** Cache name. */ /** Cache name. */
private String cacheName; private String cacheName;
Expand Down Expand Up @@ -1114,7 +1111,7 @@ public <E> boolean isAll(E e, @Nullable IgnitePredicate<? super E>[] p) throws I
return true; return true;


// We should allow only local read-only operations within filter checking. // We should allow only local read-only operations within filter checking.
CacheFlag[] oldFlags = forceFlags(FLAG_LOCAL_READ); CacheFlag[] oldFlags = forceFlags(FLAG_READ);


try { try {
boolean pass = F.isAll(e, p); boolean pass = F.isAll(e, p);
Expand Down Expand Up @@ -1189,22 +1186,13 @@ public boolean isAllLocked(GridCacheEntryEx e, CacheEntryPredicate[] p) throws I
return true; return true;
} }


/**
* Forces LOCAL flag.
*
* @return Previously forced flags.
*/
@Nullable public CacheFlag[] forceLocal() {
return forceFlags(FLAG_LOCAL);
}

/** /**
* Forces LOCAL and READ flags. * Forces LOCAL and READ flags.
* *
* @return Forced flags that were set prior to method call. * @return Forced flags that were set prior to method call.
*/ */
@Nullable public CacheFlag[] forceLocalRead() { @Nullable public CacheFlag[] forceLocalRead() {
return forceFlags(FLAG_LOCAL_READ); return forceFlags(FLAG_READ);
} }


/** /**
Expand Down Expand Up @@ -1381,7 +1369,7 @@ public void denyOnFlag(CacheFlag flag) {
* *
*/ */
public void denyOnLocalRead() { public void denyOnLocalRead() {
denyOnFlags(FLAG_LOCAL_READ); denyOnFlags(FLAG_READ);
} }


/** /**
Expand Down
Expand Up @@ -609,8 +609,6 @@ protected final void releaseSwap() throws IgniteCheckedException {
String taskName, String taskName,
@Nullable IgniteCacheExpiryPolicy expirePlc) @Nullable IgniteCacheExpiryPolicy expirePlc)
throws IgniteCheckedException, GridCacheEntryRemovedException { throws IgniteCheckedException, GridCacheEntryRemovedException {
cctx.denyOnFlag(LOCAL);

return innerGet0(tx, return innerGet0(tx,
readSwap, readSwap,
readThrough, readThrough,
Expand Down
Expand Up @@ -203,7 +203,7 @@ public IgniteInternalFuture<Boolean> removexAsync(K key, @Nullable GridCacheEntr
* if there is one. * if there is one.
* <h2 class="header">Cache Flags</h2> * <h2 class="header">Cache Flags</h2>
* This method is not available if any of the following flags are set on projection: * This method is not available if any of the following flags are set on projection:
* {@link CacheFlag#LOCAL}, {@link CacheFlag#READ}. * {@link CacheFlag#READ}.
* *
* @param key Key to store in cache. * @param key Key to store in cache.
* @param oldVal Old value to match. * @param oldVal Old value to match.
Expand All @@ -228,7 +228,7 @@ public IgniteInternalFuture<Boolean> removexAsync(K key, @Nullable GridCacheEntr
* if there is one. * if there is one.
* <h2 class="header">Cache Flags</h2> * <h2 class="header">Cache Flags</h2>
* This method is not available if any of the following flags are set on projection: * This method is not available if any of the following flags are set on projection:
* {@link CacheFlag#LOCAL}, {@link CacheFlag#READ}. * {@link CacheFlag#READ}.
* *
* @param key Key to store in cache. * @param key Key to store in cache.
* @param oldVal Old value to match. * @param oldVal Old value to match.
Expand All @@ -250,7 +250,7 @@ public IgniteInternalFuture<Boolean> removexAsync(K key, @Nullable GridCacheEntr
* if there is one. * if there is one.
* <h2 class="header">Cache Flags</h2> * <h2 class="header">Cache Flags</h2>
* This method is not available if any of the following flags are set on projection: * This method is not available if any of the following flags are set on projection:
* {@link CacheFlag#LOCAL}, {@link CacheFlag#READ}. * {@link CacheFlag#READ}.
* *
* @param key Key whose mapping is to be removed from cache. * @param key Key whose mapping is to be removed from cache.
* @param val Value to match against currently cached value. * @param val Value to match against currently cached value.
Expand All @@ -274,7 +274,7 @@ public IgniteInternalFuture<Boolean> removexAsync(K key, @Nullable GridCacheEntr
* if there is one. * if there is one.
* <h2 class="header">Cache Flags</h2> * <h2 class="header">Cache Flags</h2>
* This method is not available if any of the following flags are set on projection: * This method is not available if any of the following flags are set on projection:
* {@link CacheFlag#LOCAL}, {@link CacheFlag#READ}. * {@link CacheFlag#READ}.
* *
* @param key Key whose mapping is to be removed from cache. * @param key Key whose mapping is to be removed from cache.
* @param val Value to match against currently cached value. * @param val Value to match against currently cached value.
Expand Down
Expand Up @@ -178,7 +178,6 @@ public GridDistributedCacheEntry entryExx(
final boolean deserializePortable, final boolean deserializePortable,
final boolean skipVals final boolean skipVals
) { ) {
ctx.denyOnFlag(LOCAL);
ctx.checkSecurity(GridSecurityPermission.CACHE_READ); ctx.checkSecurity(GridSecurityPermission.CACHE_READ);


if (F.isEmpty(keys)) if (F.isEmpty(keys))
Expand Down
Expand Up @@ -364,7 +364,6 @@ public void processDhtAtomicUpdateRequest(
boolean deserializePortable, boolean deserializePortable,
boolean skipVals boolean skipVals
) { ) {
ctx.denyOnFlag(LOCAL);
ctx.checkSecurity(GridSecurityPermission.CACHE_READ); ctx.checkSecurity(GridSecurityPermission.CACHE_READ);


if (F.isEmpty(keys)) if (F.isEmpty(keys))
Expand Down
Expand Up @@ -104,7 +104,6 @@ public void dht(GridDhtCache<K, V> dht) {
final boolean deserializePortable, final boolean deserializePortable,
final boolean skipVals final boolean skipVals
) { ) {
ctx.denyOnFlag(LOCAL);
ctx.checkSecurity(GridSecurityPermission.CACHE_READ); ctx.checkSecurity(GridSecurityPermission.CACHE_READ);


if (F.isEmpty(keys)) if (F.isEmpty(keys))
Expand Down
Expand Up @@ -482,8 +482,6 @@ public GridLocalAtomicCache(GridCacheContext<K, V> ctx) {


@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Nullable public V get(K key, boolean deserializePortable) throws IgniteCheckedException { @Override @Nullable public V get(K key, boolean deserializePortable) throws IgniteCheckedException {
ctx.denyOnFlag(LOCAL);

String taskName = ctx.kernalContext().job().currentTaskName(); String taskName = ctx.kernalContext().job().currentTaskName();


Map<K, V> m = getAllInternal(Collections.singleton(key), Map<K, V> m = getAllInternal(Collections.singleton(key),
Expand All @@ -503,8 +501,6 @@ public GridLocalAtomicCache(GridCacheContext<K, V> ctx) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override public final Map<K, V> getAll(Collection<? extends K> keys, boolean deserializePortable) @Override public final Map<K, V> getAll(Collection<? extends K> keys, boolean deserializePortable)
throws IgniteCheckedException { throws IgniteCheckedException {
ctx.denyOnFlag(LOCAL);

A.notNull(keys, "keys"); A.notNull(keys, "keys");


String taskName = ctx.kernalContext().job().currentTaskName(); String taskName = ctx.kernalContext().job().currentTaskName();
Expand All @@ -531,8 +527,6 @@ public GridLocalAtomicCache(GridCacheContext<K, V> ctx) {
final boolean deserializePortable, final boolean deserializePortable,
final boolean skipVals final boolean skipVals
) { ) {
ctx.denyOnFlag(LOCAL);

A.notNull(keys, "keys"); A.notNull(keys, "keys");


final boolean swapOrOffheap = ctx.isSwapOrOffheapEnabled(); final boolean swapOrOffheap = ctx.isSwapOrOffheapEnabled();
Expand Down
Expand Up @@ -215,7 +215,7 @@ with Iterable[Cache.Entry[K, V]] with Ordered[IgniteCache[K, V]] {
* *
* ===Cache Flags=== * ===Cache Flags===
* This method is not available if any of the following flags are set on projection: * This method is not available if any of the following flags are set on projection:
* `CacheFlag#LOCAL`, `CacheFlag#READ`. * `CacheFlag#READ`.
* *
* @param kv Key-Value pair to store in cache. * @param kv Key-Value pair to store in cache.
* @return `True` if value was stored in cache, `false` otherwise. * @return `True` if value was stored in cache, `false` otherwise.
Expand All @@ -237,7 +237,7 @@ with Iterable[Cache.Entry[K, V]] with Ordered[IgniteCache[K, V]] {
* *
* ===Cache Flags=== * ===Cache Flags===
* This method is not available if any of the following flags are set on projection: * This method is not available if any of the following flags are set on projection:
* `CacheFlag#LOCAL`, `CacheFlag#READ`. * `CacheFlag#READ`.
* *
* @param kv Key-Value pair to store in cache. * @param kv Key-Value pair to store in cache.
* @return Previous value associated with specified key, or `null` * @return Previous value associated with specified key, or `null`
Expand All @@ -261,7 +261,7 @@ with Iterable[Cache.Entry[K, V]] with Ordered[IgniteCache[K, V]] {
* *
* ===Cache Flags=== * ===Cache Flags===
* This method is not available if any of the following flags are set on projection: * This method is not available if any of the following flags are set on projection:
* `CacheFlag#LOCAL`, `CacheFlag#READ`. * `CacheFlag#READ`.
* *
* @param kv Key-Value pair to store in cache. * @param kv Key-Value pair to store in cache.
* @return Previous value associated with specified key as an option. * @return Previous value associated with specified key as an option.
Expand Down Expand Up @@ -291,7 +291,7 @@ with Iterable[Cache.Entry[K, V]] with Ordered[IgniteCache[K, V]] {
* *
* ===Cache Flags=== * ===Cache Flags===
* This method is not available if any of the following flags are set on projection: * This method is not available if any of the following flags are set on projection:
* `CacheFlag#LOCAL`, `CacheFlag#READ`. * `CacheFlag#READ`.
* *
* @param kv1 Key-value pair to store in cache. * @param kv1 Key-value pair to store in cache.
* @param kv2 Key-value pair to store in cache. * @param kv2 Key-value pair to store in cache.
Expand Down Expand Up @@ -321,7 +321,7 @@ with Iterable[Cache.Entry[K, V]] with Ordered[IgniteCache[K, V]] {
* *
* ===Cache Flags=== * ===Cache Flags===
* This method is not available if any of the following flags are set on projection: * This method is not available if any of the following flags are set on projection:
* `CacheFlag#LOCAL`, `CacheFlag#READ`. * `CacheFlag#READ`.
* *
* @param kvs Key-value pairs to store in cache. If `null` this function is no-op. * @param kvs Key-value pairs to store in cache. If `null` this function is no-op.
* @see `IgniteCache#putAll(...)` * @see `IgniteCache#putAll(...)`
Expand All @@ -343,7 +343,7 @@ with Iterable[Cache.Entry[K, V]] with Ordered[IgniteCache[K, V]] {
* *
* ===Cache Flags=== * ===Cache Flags===
* This method is not available if any of the following flags are set on projection: * This method is not available if any of the following flags are set on projection:
* `CacheFlag#LOCAL`, `CacheFlag#READ`. * `CacheFlag#READ`.
* *
* @param ks Sequence of additional keys to remove. If `null` - this function is no-op. * @param ks Sequence of additional keys to remove. If `null` - this function is no-op.
* @see `IgniteCache#removeAll(...)` * @see `IgniteCache#removeAll(...)`
Expand Down Expand Up @@ -388,7 +388,7 @@ with Iterable[Cache.Entry[K, V]] with Ordered[IgniteCache[K, V]] {
* *
* ===Cache Flags=== * ===Cache Flags===
* This method is not available if any of the following flags are set on projection: * This method is not available if any of the following flags are set on projection:
* `CacheFlag#LOCAL`, `CacheFlag#READ`. * `CacheFlag#READ`.
* *
* @param k Key whose mapping is to be removed from cache. * @param k Key whose mapping is to be removed from cache.
* @return Previous value associated with specified key, or `null` * @return Previous value associated with specified key, or `null`
Expand Down Expand Up @@ -420,7 +420,7 @@ with Iterable[Cache.Entry[K, V]] with Ordered[IgniteCache[K, V]] {
* *
* ===Cache Flags=== * ===Cache Flags===
* This method is not available if any of the following flags are set on projection: * This method is not available if any of the following flags are set on projection:
* `CacheFlag#LOCAL`, `CacheFlag#READ`. * `CacheFlag#READ`.
* *
* @param k Key whose mapping is to be removed from cache. * @param k Key whose mapping is to be removed from cache.
* @return Previous value associated with specified key as an option. * @return Previous value associated with specified key as an option.
Expand Down Expand Up @@ -451,7 +451,7 @@ with Iterable[Cache.Entry[K, V]] with Ordered[IgniteCache[K, V]] {
* *
* ===Cache Flags=== * ===Cache Flags===
* This method is not available if any of the following flags are set on projection: * This method is not available if any of the following flags are set on projection:
* `CacheFlag#LOCAL`, `CacheFlag#READ`. * `CacheFlag#READ`.
* *
* @param k1 1st key to remove. * @param k1 1st key to remove.
* @param k2 2nd key to remove. * @param k2 2nd key to remove.
Expand Down

0 comments on commit 4bc5b22

Please sign in to comment.