Repository: incubator-ignite Updated Branches: refs/heads/ignite-42 05ef302cf -> f4b3995e4
# ignite-42 Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/f4b3995e Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/f4b3995e Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/f4b3995e Branch: refs/heads/ignite-42 Commit: f4b3995e404fac455b503dd5a21e6e921fc2e803 Parents: 05ef302 Author: sboikov <sboi...@gridgain.com> Authored: Tue Jan 20 10:48:05 2015 +0300 Committer: sboikov <sboi...@gridgain.com> Committed: Tue Jan 20 10:48:05 2015 +0300 ---------------------------------------------------------------------- .../ignite/cache/store/CacheStoreSession.java | 9 ++++- .../processors/cache/GridCacheStoreManager.java | 41 +++++++++++++++++--- .../GridCacheGroupLockAbstractSelfTest.java | 41 ++++++++++++++++---- .../junits/cache/TestCacheSession.java | 5 +++ .../cache/TestThreadLocalCacheSession.java | 7 ++++ .../GridCacheGroupLockSelfTestSuite.java | 2 +- 6 files changed, 89 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f4b3995e/modules/core/src/main/java/org/apache/ignite/cache/store/CacheStoreSession.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/CacheStoreSession.java b/modules/core/src/main/java/org/apache/ignite/cache/store/CacheStoreSession.java index 0fb5c47..e99df2c 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/store/CacheStoreSession.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/store/CacheStoreSession.java @@ -27,12 +27,17 @@ import java.util.*; */ public interface CacheStoreSession { /** - * @return Current cache transaction. + * @return Transaction belonging to current session. */ @Nullable public IgniteTx transaction(); /** - * @return Session properties. + * @return Current session properties. */ public <K, V> Map<K, V> properties(); + + /** + * @return Cache name. + */ + @Nullable public String cacheName(); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f4b3995e/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheStoreManager.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheStoreManager.java b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheStoreManager.java index c9ca7e4..41a8e64 100644 --- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheStoreManager.java +++ b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheStoreManager.java @@ -89,7 +89,7 @@ public class GridCacheStoreManager<K, V> extends GridCacheManagerAdapter<K, V> { sesField.setAccessible(true); - sesField.set(cfgStore, new ThreadLocalSession()); + sesField.set(cfgStore, new ThreadLocalSession(sesHolder)); sesEnabled = true; } @@ -499,7 +499,7 @@ public class GridCacheStoreManager<K, V> extends GridCacheManagerAdapter<K, V> { log.debug("Storing values in cache store [map=" + map0 + ']'); // TODO IGNITE-42. - Collection<Cache.Entry<? extends K, ? extends Object>> entries = new ArrayList<>(map.size()); + Collection<Cache.Entry<? extends K, ?>> entries = new ArrayList<>(map.size()); for (Map.Entry<K, IgniteBiTuple<V, GridCacheVersion>> e : map.entrySet()) entries.add(new CacheEntryImpl<>(e.getKey(), locStore ? e.getValue() : e.getValue().get1())); @@ -701,13 +701,13 @@ public class GridCacheStoreManager<K, V> extends GridCacheManagerAdapter<K, V> { ses = ((GridMetadataAware)tx).meta(SES_ATTR); if (ses == null) { - ses = new SessionData(tx); + ses = new SessionData(tx, cctx.name()); ((GridMetadataAware)tx).addMeta(SES_ATTR, ses); } } else - ses = new SessionData(null); + ses = new SessionData(null, cctx.name()); sesHolder.set(ses); @@ -722,13 +722,18 @@ public class GridCacheStoreManager<K, V> extends GridCacheManagerAdapter<K, V> { private final IgniteTx tx; /** */ + private final String cacheName; + + /** */ private Map<Object, Object> props; /** * @param tx Current transaction. + * @param cacheName Cache name. */ - private SessionData(@Nullable IgniteTx tx) { + private SessionData(@Nullable IgniteTx tx, @Nullable String cacheName) { this.tx = tx; + this.cacheName = cacheName; } /** @@ -747,12 +752,29 @@ public class GridCacheStoreManager<K, V> extends GridCacheManagerAdapter<K, V> { return props; } + + /** + * @return Cache name. + */ + private String cacheName() { + return cacheName; + } } /** * */ - private class ThreadLocalSession implements CacheStoreSession { + private static class ThreadLocalSession implements CacheStoreSession { + /** */ + private final ThreadLocal<SessionData> sesHolder; + + /** + * @param sesHolder Session holder. + */ + private ThreadLocalSession(ThreadLocal<SessionData> sesHolder) { + this.sesHolder = sesHolder; + } + /** {@inheritDoc} */ @Nullable @Override public IgniteTx transaction() { SessionData ses0 = sesHolder.get(); @@ -767,5 +789,12 @@ public class GridCacheStoreManager<K, V> extends GridCacheManagerAdapter<K, V> { return ses0 != null ? (Map<K1, V1>)ses0.properties() : null; } + + /** {@inheritDoc} */ + @Nullable @Override public String cacheName() { + SessionData ses0 = sesHolder.get(); + + return ses0 != null ? ses0.cacheName() : null; + } } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f4b3995e/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheGroupLockAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheGroupLockAbstractSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheGroupLockAbstractSelfTest.java index 7880b80..0a988db 100644 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheGroupLockAbstractSelfTest.java +++ b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheGroupLockAbstractSelfTest.java @@ -85,7 +85,11 @@ public abstract class GridCacheGroupLockAbstractSelfTest extends GridCommonAbstr cacheCfg.setWriteSynchronizationMode(GridCacheWriteSynchronizationMode.FULL_SYNC); cacheCfg.setAtomicityMode(TRANSACTIONAL); - cacheCfg.setCacheStoreFactory(new FactoryBuilder.SingletonFactory(store)); + cacheCfg.setCacheStoreFactory(new Factory<CacheStore<? super Object, ? super Object>>() { + @Override public CacheStore<? super Object, ? super Object> create() { + return store; + } + }); cacheCfg.setReadThrough(true); cacheCfg.setWriteThrough(true); @@ -141,6 +145,7 @@ public abstract class GridCacheGroupLockAbstractSelfTest extends GridCommonAbstr } /** + * @param concurrency Transaction concurrency mode. * @throws Exception If failed. */ private void checkGroupLockPutOneKey(IgniteTxConcurrency concurrency) throws Exception { @@ -208,6 +213,7 @@ public abstract class GridCacheGroupLockAbstractSelfTest extends GridCommonAbstr } /** + * @param concurrency Transaction concurrency mode. * @throws Exception If failed. */ private void checkGroupLockRemoveOneKey(IgniteTxConcurrency concurrency) throws Exception { @@ -288,6 +294,7 @@ public abstract class GridCacheGroupLockAbstractSelfTest extends GridCommonAbstr } /** + * @param concurrency Transaction concurrency mode. * @throws Exception If failed. */ private void checkGroupLockGetOneKey(IgniteTxConcurrency concurrency) throws Exception { @@ -342,17 +349,24 @@ public abstract class GridCacheGroupLockAbstractSelfTest extends GridCommonAbstr assertTrue("Failed to wait for unlock events: " + affinityKey, unlocks.awaitKeys(WAIT_TIMEOUT, affinityKey)); } - /** @throws IgniteCheckedException */ + /** + * @throws Exception If failed. + */ public void testGroupLockWithExternalLockOptimistic() throws Exception { checkGroupLockWithExternalLock(OPTIMISTIC); } - /** @throws IgniteCheckedException */ + /** + * @throws Exception If failed. + */ public void testGroupLockWithExternalLockPessimistic() throws Exception { checkGroupLockWithExternalLock(PESSIMISTIC); } - /** @throws IgniteCheckedException */ + /** + * @param concurrency Transaction concurrency mode. + * @throws Exception If failed. + */ private void checkGroupLockWithExternalLock(final IgniteTxConcurrency concurrency) throws Exception { assert sanityCheckEnabled(); @@ -437,6 +451,7 @@ public abstract class GridCacheGroupLockAbstractSelfTest extends GridCommonAbstr } /** + * @param concurrency Transaction concurrency mode. * @throws Exception If failed. */ private void checkSanityCheckDisabled(final IgniteTxConcurrency concurrency) throws Exception { @@ -500,6 +515,7 @@ public abstract class GridCacheGroupLockAbstractSelfTest extends GridCommonAbstr } /** + * @param concurrency Transaction concurrency mode. * @throws Exception If failed. */ private void checkGroupPartitionLock(IgniteTxConcurrency concurrency) throws Exception { @@ -624,6 +640,8 @@ public abstract class GridCacheGroupLockAbstractSelfTest extends GridCommonAbstr } /** + * @param concurrency Transaction concurrency mode. + * @param isolation Transaction isolation mode. * @throws Exception If failed. */ private void checkGetPut(IgniteTxConcurrency concurrency, IgniteTxIsolation isolation) throws Exception { @@ -683,6 +701,8 @@ public abstract class GridCacheGroupLockAbstractSelfTest extends GridCommonAbstr } /** + * @param concurrency Transaction concurrency mode. + * @param isolation Transaction isolation mode. * @throws Exception If failed. */ private void checkGetPutEmptyCache(IgniteTxConcurrency concurrency, IgniteTxIsolation isolation) throws Exception { @@ -764,6 +784,8 @@ public abstract class GridCacheGroupLockAbstractSelfTest extends GridCommonAbstr } /** + * @param concurrency Transaction concurrency mode. + * @param isolation Transaction isolation mode. * @throws Exception If failed. */ private void checkGetRemove(IgniteTxConcurrency concurrency, IgniteTxIsolation isolation) throws Exception { @@ -844,6 +866,7 @@ public abstract class GridCacheGroupLockAbstractSelfTest extends GridCommonAbstr } /** + * @param concurrency Transaction concurrency mode. * @throws Exception If failed. */ private void checkGetAfterPut(IgniteTxConcurrency concurrency) throws Exception { @@ -925,6 +948,7 @@ public abstract class GridCacheGroupLockAbstractSelfTest extends GridCommonAbstr } /** + * @param concurrency Transaction concurrency mode. * @throws Exception If failed. */ private void checkGetRepeatableRead(IgniteTxConcurrency concurrency) throws Exception { @@ -953,6 +977,7 @@ public abstract class GridCacheGroupLockAbstractSelfTest extends GridCommonAbstr } /** + * @param concurrency Transaction concurrency mode. * @throws Exception If failed. */ private void checkGroupLockPutWrongKey(IgniteTxConcurrency concurrency) throws Exception { @@ -988,6 +1013,7 @@ public abstract class GridCacheGroupLockAbstractSelfTest extends GridCommonAbstr } /** + * @param concurrency Transaction concurrency mode. * @throws Exception If failed. */ private void checkGroupLockRemoveWrongKey(IgniteTxConcurrency concurrency) throws Exception { @@ -1094,6 +1120,7 @@ public abstract class GridCacheGroupLockAbstractSelfTest extends GridCommonAbstr } /** + * @param concurrency Transaction concurrency mode. * @throws Exception If failed. */ private void checkGroupLockWriteThrough(IgniteTxConcurrency concurrency) throws Exception { @@ -1268,15 +1295,15 @@ public abstract class GridCacheGroupLockAbstractSelfTest extends GridCommonAbstr } /** {@inheritDoc} */ - @Override public void writeAll(Collection<Cache.Entry<? extends Object, ? extends Object>> entries) { - for (Cache.Entry<? extends Object, ? extends Object> e : entries) + @Override public void writeAll(Collection<Cache.Entry<?, ?>> entries) { + for (Cache.Entry<?, ?> e : entries) storeMap.put(e.getKey(), e.getValue()); putCnt.incrementAndGet(); } /** {@inheritDoc} */ - @Override public void write(Cache.Entry<? extends Object, ? extends Object> e) { + @Override public void write(Cache.Entry<?, ?> e) { storeMap.put(e.getKey(), e.getValue()); putCnt.incrementAndGet(); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f4b3995e/modules/core/src/test/java/org/gridgain/testframework/junits/cache/TestCacheSession.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/testframework/junits/cache/TestCacheSession.java b/modules/core/src/test/java/org/gridgain/testframework/junits/cache/TestCacheSession.java index 549ce35..35d0afb 100644 --- a/modules/core/src/test/java/org/gridgain/testframework/junits/cache/TestCacheSession.java +++ b/modules/core/src/test/java/org/gridgain/testframework/junits/cache/TestCacheSession.java @@ -57,4 +57,9 @@ public class TestCacheSession implements CacheStoreSession { return (Map<K, V>)props; } + + /** {@inheritDoc} */ + @Nullable @Override public String cacheName() { + return null; + } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f4b3995e/modules/core/src/test/java/org/gridgain/testframework/junits/cache/TestThreadLocalCacheSession.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/testframework/junits/cache/TestThreadLocalCacheSession.java b/modules/core/src/test/java/org/gridgain/testframework/junits/cache/TestThreadLocalCacheSession.java index 34a3b20..0a50be4 100644 --- a/modules/core/src/test/java/org/gridgain/testframework/junits/cache/TestThreadLocalCacheSession.java +++ b/modules/core/src/test/java/org/gridgain/testframework/junits/cache/TestThreadLocalCacheSession.java @@ -55,4 +55,11 @@ public class TestThreadLocalCacheSession implements CacheStoreSession { return ses != null ? (Map<K, V>)ses.properties() : null; } + + /** {@inheritDoc} */ + @Nullable @Override public String cacheName() { + TestCacheSession ses = sesHolder.get(); + + return ses != null ? ses.cacheName() : null; + } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f4b3995e/modules/core/src/test/java/org/gridgain/testsuites/GridCacheGroupLockSelfTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/testsuites/GridCacheGroupLockSelfTestSuite.java b/modules/core/src/test/java/org/gridgain/testsuites/GridCacheGroupLockSelfTestSuite.java index 262de5c..7a24378 100644 --- a/modules/core/src/test/java/org/gridgain/testsuites/GridCacheGroupLockSelfTestSuite.java +++ b/modules/core/src/test/java/org/gridgain/testsuites/GridCacheGroupLockSelfTestSuite.java @@ -31,7 +31,7 @@ public class GridCacheGroupLockSelfTestSuite extends TestSuite { * @throws Exception If failed. */ public static TestSuite suite() throws Exception { - TestSuite suite = new TestSuite("Gridgain Cache Group Lock Test Suite"); + TestSuite suite = new TestSuite("Ignite Cache Group Lock Test Suite"); // One node. suite.addTest(new TestSuite(GridCacheGroupLockNearSelfTest.class));