You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ignite.apache.org by ALEKSEY KUZNETSOV <al...@gmail.com> on 2017/03/29 16:36:10 UTC
putting entity into cache while commiting.Why!?
Hello, Igniters! I have one more question to you. Will appreciate any help.
Consider cache with near , dht configured not null.
When we start commit transaction , in method
*org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal#enlistWriteEntry*
we put newly created entry into cache by executing entryEx().
I wonder if this entry will became visible for other transactions!?
--
*Best Regards,*
*Kuznetsov Aleksey*
Re: putting entity into cache while commiting.Why!?
Posted by Alexander Fedotov <al...@gmail.com>.
Actually, there is no dirty value. The value is visible only in scope of
the transaction.
You call doInTransaction for ignite(1) thus initiating a pessimistic
transaction.
Inside doInTransaction cache.put is called, but cache belongs to the
ignite(0) and therefore
the put happens in an implicit transaction and succeeds immediately.
So, the value received by cache.get is not a dirty value.
On Thu, Mar 30, 2017 at 5:57 PM, ALEKSEY KUZNETSOV <alkuznetsov.sb@gmail.com
> wrote:
> I don't see point of commiting key1 only to zero node and thus creating
> drity value on zero node.
>
> чт, 30 мар. 2017 г. в 17:36, Alexey Goncharuk <alexey.goncharuk@gmail.com
> >:
>
> > Note that you call doInTransaction() for ignite(1), but you have acquired
> > the cache reference for ignite(0), thus your cache.put() commits
> > immediately from another node, because transactional scope is node-local.
> >
> > If you change the test either to use ignite(0) for doInTransaction, or to
> > get the cache in the callable like ignite(1).cache("testCache"), the test
> > will not throw an exception. Note that it will hang because
> doInTrasaction
> > starts a pessimistic transaction which acquires a lock on key1, and then
> > you put it to infinite sleep. The lock prevents the transaction from
> > the main thread to commit.
> >
> > 2017-03-30 15:44 GMT+03:00 ALEKSEY KUZNETSOV <al...@gmail.com>:
> >
> > > I've edited code and now DIRTY READ occures!
> > >
> > > Ignite ignite0 = ignite(0);
> > > IgniteTransactions transactions = ignite0.transactions();
> > > IgniteCache<String, String> cache =
> > ignite0.getOrCreateCache("testCache");
> > > Object monitor = new Object();
> > >
> > > GridTestUtils.runAsync(new Callable<Object>() {
> > > @Override
> > > public Object call() throws Exception {
> > > doInTransaction(ignite(1), new Callable<Object>() {
> > > @Override
> > > public Object call() throws Exception {
> > > synchronized (monitor) {
> > > cache.put("key1", "val1!");
> > > monitor.wait();
> > > fail();
> > > return null;
> > > }
> > > }
> > > });
> > > return null;
> > > }
> > > });
> > > Thread.currentThread().sleep(1000);<------ dirty read occures only if
> > > we sleep some time !
> > > Transaction tx =
> > > transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> > > TransactionIsolation.READ_COMMITTED);
> > > String key1Value = cache.get("key1");
> > > if(key1Value.equals("val1!"))
> > > throw new RuntimeException("dirty read!");<------ exception does
> > > happen!
> > > cache.put("key1", "val1");
> > > cache.put("key2", "val2");
> > > cache.put("key3", "val3");
> > > tx.commit();
> > >
> > >
> > > чт, 30 мар. 2017 г. в 14:04, Alexey Goncharuk <
> > alexey.goncharuk@gmail.com
> > > >:
> > >
> > > > Agree, the cache is transactional, however, the second transaction
> does
> > > not
> > > > see the dirty value:
> > > >
> > > > Ignite ignite0 = ignite(0);
> > > > IgniteTransactions transactions = ignite0.transactions();
> > > > final IgniteCache<String, String> cache =
> > > > ignite0.getOrCreateCache("testCache");
> > > >
> > > > final Object monitor = new Object();
> > > >
> > > > GridTestUtils.runAsync(new Callable<Object>() {
> > > > @Override
> > > > public Object call() throws Exception {
> > > > synchronized (monitor){
> > > > doInTransaction(ignite(1), new Callable<Object>() {
> > > > @Override
> > > > public Object call() throws Exception {
> > > > cache.put("key1", "val1");
> > > > monitor.wait();
> > > > System.out.println("continue first transaction");
> > > > return null;
> > > > }
> > > > });
> > > > }
> > > > return null;
> > > > }
> > > > });
> > > >
> > > > Transaction tx =
> > > > transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> > > > TransactionIsolation.READ_COMMITTED);
> > > > assertNull(cache.get("key1")); // <- This check passes
> > > > tx.commit();
> > > >
> > > >
> > > > 2017-03-30 13:30 GMT+03:00 ALEKSEY KUZNETSOV <
> alkuznetsov.sb@gmail.com
> > >:
> > > >
> > > > > Well, i changed code , added :
> > > > >
> > > > > CacheConfiguration config = cache.getConfiguration(
> > > > > CacheConfiguration.class);
> > > > > System.out.println(config.getAtomicityMode());//TRANSACTIONAL
> > > > >
> > > > > So, atomicity is transactional
> > > > >
> > > > > чт, 30 мар. 2017 г. в 12:43, Alexey Goncharuk <
> > > > alexey.goncharuk@gmail.com
> > > > > >:
> > > > >
> > > > > > Aleksey,
> > > > > >
> > > > > > It looks like in your test the result of method atomicityMode()
> is
> > > not
> > > > > used
> > > > > > because you do getOrCreateCache() without the configuration
> > argument,
> > > > > which
> > > > > > will create a cache with a default configuration, which is
> ATOMIC.
> > > > > >
> > > > > > 2017-03-30 12:06 GMT+03:00 ALEKSEY KUZNETSOV <
> > > alkuznetsov.sb@gmail.com
> > > > >:
> > > > > >
> > > > > > > public class FooTest extends GridCacheAbstractSelfTest {
> > > > > > >
> > > > > > > @Override
> > > > > > > protected void afterTestsStopped() throws Exception {
> > > > > > > super.afterTestsStopped();
> > > > > > > stopAllGrids();
> > > > > > > }
> > > > > > >
> > > > > > > @Override
> > > > > > > protected int gridCount() {
> > > > > > > return 3;
> > > > > > > }
> > > > > > >
> > > > > > > @Override
> > > > > > > protected CacheMode cacheMode() {
> > > > > > > return CacheMode.PARTITIONED;
> > > > > > > }
> > > > > > >
> > > > > > > @Override
> > > > > > > protected CacheAtomicityMode atomicityMode() {
> > > > > > > return CacheAtomicityMode.TRANSACTIONAL;
> > > > > > > }
> > > > > > >
> > > > > > > public void testLoggingTransactions() throws
> > > > InterruptedException {
> > > > > > > Ignite ignite0 = ignite(0);
> > > > > > > IgniteTransactions transactions =
> ignite0.transactions();
> > > > > > > IgniteCache<String, String> cache =
> > > > > > > ignite0.getOrCreateCache("testCache");
> > > > > > > Object monitor = new Object();
> > > > > > >
> > > > > > > GridTestUtils.runAsync(new Callable<Object>() {
> > > > > > > @Override
> > > > > > > public Object call() throws Exception {
> > > > > > > synchronized (monitor){
> > > > > > > doInTransaction(ignite(1), new
> > > > Callable<Object>() {
> > > > > > > @Override
> > > > > > > public Object call() throws Exception {
> > > > > > > cache.put("key1", "val1");
> > > > > > > monitor.wait();
> > > > > > > System.out.println("continue first
> > > > > > > transaction");
> > > > > > > return null;
> > > > > > > }
> > > > > > > });
> > > > > > > }
> > > > > > > return null;
> > > > > > > }
> > > > > > > });
> > > > > > >
> > > > > > > Transaction tx =
> > > > > > > transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> > > > > > > TransactionIsolation.READ_COMMITTED);
> > > > > > > cache.put("key1", "val1");
> > > > > > > cache.put("key2", "val2");
> > > > > > > cache.put("key3", "val3");
> > > > > > > tx.commit();
> > > > > > >
> > > > > > > }
> > > > > > > }
> > > > > > >
> > > > > > >
> > > > > > > чт, 30 мар. 2017 г. в 11:55, Alexey Goncharuk <
> > > > > > alexey.goncharuk@gmail.com
> > > > > > > >:
> > > > > > >
> > > > > > > > Can you please paste the full example?
> > > > > > > >
> > > > > > > > 2017-03-30 11:50 GMT+03:00 ALEKSEY KUZNETSOV <
> > > > > alkuznetsov.sb@gmail.com
> > > > > > >:
> > > > > > > >
> > > > > > > > > But i managed to read dirty. That is my example :
> > > > > > > > >
> > > > > > > > > Ignite ignite0 = ignite(0);
> > > > > > > > > IgniteTransactions transactions = ignite0.transactions();
> > > > > > > > > IgniteCache<String, String> cache =
> > > > > > > > ignite0.getOrCreateCache("testCache");
> > > > > > > > > Object monitor = new Object();
> > > > > > > > >
> > > > > > > > > GridTestUtils.runAsync(new Callable<Object>() {
> > > > > > > > > @Override
> > > > > > > > > public Object call() throws Exception {
> > > > > > > > > synchronized (monitor){
> > > > > > > > > doInTransaction(ignite(1), new
> > Callable<Object>() {
> > > > > > > > > @Override
> > > > > > > > > public Object call() throws Exception {
> > > > > > > > > cache.put("key1", "val1");
> > > > > > > > > monitor.wait();
> > > > > > > > > return null;
> > > > > > > > > }
> > > > > > > > > });
> > > > > > > > > }
> > > > > > > > > return null;
> > > > > > > > > }
> > > > > > > > > });
> > > > > > > > >
> > > > > > > > > Transaction tx =
> > > > > > > > > transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> > > > > > > > > TransactionIsolation.READ_COMMITTED);
> > > > > > > > > cache.put("key1", "val1");
> > > > > > > > >
> > > > > > > > > And through debugging cache.put() method i can see in
> method
> > > > > > > > > *org.apache.ignite.internal.processors.cache.distributed.
> > > > > > > > > near.GridNearTxLocal#enlistWriteEntry*
> > > > > > > > > that "key1" already *EXISTS *in internal cache :
> > > > > > > > cacheCtx.cache().entryEx()
> > > > > > > > > returns not null.
> > > > > > > > >
> > > > > > > > > ср, 29 мар. 2017 г. в 20:11, Alexander Fedotov <
> > > > > > > > > alexander.fedotoff@gmail.com
> > > > > > > > > >:
> > > > > > > > >
> > > > > > > > > Hello Aleksey,
> > > > > > > > >
> > > > > > > > > No, the enlisted entry won't be visible for other
> > transactions.
> > > > > Dirty
> > > > > > > > reads
> > > > > > > > > are not allowed in Ignite.
> > > > > > > > >
> > > > > > > > > Kind regards,
> > > > > > > > > Alex
> > > > > > > > >
> > > > > > > > > 29 марта 2017 г. 7:36 PM пользователь "ALEKSEY KUZNETSOV" <
> > > > > > > > > alkuznetsov.sb@gmail.com> написал:
> > > > > > > > >
> > > > > > > > > Hello, Igniters! I have one more question to you. Will
> > > appreciate
> > > > > any
> > > > > > > > help.
> > > > > > > > > Consider cache with near , dht configured not null.
> > > > > > > > > When we start commit transaction , in method
> > > > > > > > > *org.apache.ignite.internal.processors.cache.distributed.
> > > > > > > > > near.GridNearTxLocal#enlistWriteEntry*
> > > > > > > > > we put newly created entry into cache by executing
> entryEx().
> > > > > > > > > I wonder if this entry will became visible for other
> > > > transactions!?
> > > > > > > > > --
> > > > > > > > >
> > > > > > > > > *Best Regards,*
> > > > > > > > >
> > > > > > > > > *Kuznetsov Aleksey*
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > >
> > > > > > > > > *Best Regards,*
> > > > > > > > >
> > > > > > > > > *Kuznetsov Aleksey*
> > > > > > > > >
> > > > > > > >
> > > > > > > --
> > > > > > >
> > > > > > > *Best Regards,*
> > > > > > >
> > > > > > > *Kuznetsov Aleksey*
> > > > > > >
> > > > > >
> > > > > --
> > > > >
> > > > > *Best Regards,*
> > > > >
> > > > > *Kuznetsov Aleksey*
> > > > >
> > > >
> > > --
> > >
> > > *Best Regards,*
> > >
> > > *Kuznetsov Aleksey*
> > >
> >
> --
>
> *Best Regards,*
>
> *Kuznetsov Aleksey*
>
--
Kind regards,
Alex.
Re: putting entity into cache while commiting.Why!?
Posted by ALEKSEY KUZNETSOV <al...@gmail.com>.
I don't see point of commiting key1 only to zero node and thus creating
drity value on zero node.
чт, 30 мар. 2017 г. в 17:36, Alexey Goncharuk <al...@gmail.com>:
> Note that you call doInTransaction() for ignite(1), but you have acquired
> the cache reference for ignite(0), thus your cache.put() commits
> immediately from another node, because transactional scope is node-local.
>
> If you change the test either to use ignite(0) for doInTransaction, or to
> get the cache in the callable like ignite(1).cache("testCache"), the test
> will not throw an exception. Note that it will hang because doInTrasaction
> starts a pessimistic transaction which acquires a lock on key1, and then
> you put it to infinite sleep. The lock prevents the transaction from
> the main thread to commit.
>
> 2017-03-30 15:44 GMT+03:00 ALEKSEY KUZNETSOV <al...@gmail.com>:
>
> > I've edited code and now DIRTY READ occures!
> >
> > Ignite ignite0 = ignite(0);
> > IgniteTransactions transactions = ignite0.transactions();
> > IgniteCache<String, String> cache =
> ignite0.getOrCreateCache("testCache");
> > Object monitor = new Object();
> >
> > GridTestUtils.runAsync(new Callable<Object>() {
> > @Override
> > public Object call() throws Exception {
> > doInTransaction(ignite(1), new Callable<Object>() {
> > @Override
> > public Object call() throws Exception {
> > synchronized (monitor) {
> > cache.put("key1", "val1!");
> > monitor.wait();
> > fail();
> > return null;
> > }
> > }
> > });
> > return null;
> > }
> > });
> > Thread.currentThread().sleep(1000);<------ dirty read occures only if
> > we sleep some time !
> > Transaction tx =
> > transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> > TransactionIsolation.READ_COMMITTED);
> > String key1Value = cache.get("key1");
> > if(key1Value.equals("val1!"))
> > throw new RuntimeException("dirty read!");<------ exception does
> > happen!
> > cache.put("key1", "val1");
> > cache.put("key2", "val2");
> > cache.put("key3", "val3");
> > tx.commit();
> >
> >
> > чт, 30 мар. 2017 г. в 14:04, Alexey Goncharuk <
> alexey.goncharuk@gmail.com
> > >:
> >
> > > Agree, the cache is transactional, however, the second transaction does
> > not
> > > see the dirty value:
> > >
> > > Ignite ignite0 = ignite(0);
> > > IgniteTransactions transactions = ignite0.transactions();
> > > final IgniteCache<String, String> cache =
> > > ignite0.getOrCreateCache("testCache");
> > >
> > > final Object monitor = new Object();
> > >
> > > GridTestUtils.runAsync(new Callable<Object>() {
> > > @Override
> > > public Object call() throws Exception {
> > > synchronized (monitor){
> > > doInTransaction(ignite(1), new Callable<Object>() {
> > > @Override
> > > public Object call() throws Exception {
> > > cache.put("key1", "val1");
> > > monitor.wait();
> > > System.out.println("continue first transaction");
> > > return null;
> > > }
> > > });
> > > }
> > > return null;
> > > }
> > > });
> > >
> > > Transaction tx =
> > > transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> > > TransactionIsolation.READ_COMMITTED);
> > > assertNull(cache.get("key1")); // <- This check passes
> > > tx.commit();
> > >
> > >
> > > 2017-03-30 13:30 GMT+03:00 ALEKSEY KUZNETSOV <alkuznetsov.sb@gmail.com
> >:
> > >
> > > > Well, i changed code , added :
> > > >
> > > > CacheConfiguration config = cache.getConfiguration(
> > > > CacheConfiguration.class);
> > > > System.out.println(config.getAtomicityMode());//TRANSACTIONAL
> > > >
> > > > So, atomicity is transactional
> > > >
> > > > чт, 30 мар. 2017 г. в 12:43, Alexey Goncharuk <
> > > alexey.goncharuk@gmail.com
> > > > >:
> > > >
> > > > > Aleksey,
> > > > >
> > > > > It looks like in your test the result of method atomicityMode() is
> > not
> > > > used
> > > > > because you do getOrCreateCache() without the configuration
> argument,
> > > > which
> > > > > will create a cache with a default configuration, which is ATOMIC.
> > > > >
> > > > > 2017-03-30 12:06 GMT+03:00 ALEKSEY KUZNETSOV <
> > alkuznetsov.sb@gmail.com
> > > >:
> > > > >
> > > > > > public class FooTest extends GridCacheAbstractSelfTest {
> > > > > >
> > > > > > @Override
> > > > > > protected void afterTestsStopped() throws Exception {
> > > > > > super.afterTestsStopped();
> > > > > > stopAllGrids();
> > > > > > }
> > > > > >
> > > > > > @Override
> > > > > > protected int gridCount() {
> > > > > > return 3;
> > > > > > }
> > > > > >
> > > > > > @Override
> > > > > > protected CacheMode cacheMode() {
> > > > > > return CacheMode.PARTITIONED;
> > > > > > }
> > > > > >
> > > > > > @Override
> > > > > > protected CacheAtomicityMode atomicityMode() {
> > > > > > return CacheAtomicityMode.TRANSACTIONAL;
> > > > > > }
> > > > > >
> > > > > > public void testLoggingTransactions() throws
> > > InterruptedException {
> > > > > > Ignite ignite0 = ignite(0);
> > > > > > IgniteTransactions transactions = ignite0.transactions();
> > > > > > IgniteCache<String, String> cache =
> > > > > > ignite0.getOrCreateCache("testCache");
> > > > > > Object monitor = new Object();
> > > > > >
> > > > > > GridTestUtils.runAsync(new Callable<Object>() {
> > > > > > @Override
> > > > > > public Object call() throws Exception {
> > > > > > synchronized (monitor){
> > > > > > doInTransaction(ignite(1), new
> > > Callable<Object>() {
> > > > > > @Override
> > > > > > public Object call() throws Exception {
> > > > > > cache.put("key1", "val1");
> > > > > > monitor.wait();
> > > > > > System.out.println("continue first
> > > > > > transaction");
> > > > > > return null;
> > > > > > }
> > > > > > });
> > > > > > }
> > > > > > return null;
> > > > > > }
> > > > > > });
> > > > > >
> > > > > > Transaction tx =
> > > > > > transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> > > > > > TransactionIsolation.READ_COMMITTED);
> > > > > > cache.put("key1", "val1");
> > > > > > cache.put("key2", "val2");
> > > > > > cache.put("key3", "val3");
> > > > > > tx.commit();
> > > > > >
> > > > > > }
> > > > > > }
> > > > > >
> > > > > >
> > > > > > чт, 30 мар. 2017 г. в 11:55, Alexey Goncharuk <
> > > > > alexey.goncharuk@gmail.com
> > > > > > >:
> > > > > >
> > > > > > > Can you please paste the full example?
> > > > > > >
> > > > > > > 2017-03-30 11:50 GMT+03:00 ALEKSEY KUZNETSOV <
> > > > alkuznetsov.sb@gmail.com
> > > > > >:
> > > > > > >
> > > > > > > > But i managed to read dirty. That is my example :
> > > > > > > >
> > > > > > > > Ignite ignite0 = ignite(0);
> > > > > > > > IgniteTransactions transactions = ignite0.transactions();
> > > > > > > > IgniteCache<String, String> cache =
> > > > > > > ignite0.getOrCreateCache("testCache");
> > > > > > > > Object monitor = new Object();
> > > > > > > >
> > > > > > > > GridTestUtils.runAsync(new Callable<Object>() {
> > > > > > > > @Override
> > > > > > > > public Object call() throws Exception {
> > > > > > > > synchronized (monitor){
> > > > > > > > doInTransaction(ignite(1), new
> Callable<Object>() {
> > > > > > > > @Override
> > > > > > > > public Object call() throws Exception {
> > > > > > > > cache.put("key1", "val1");
> > > > > > > > monitor.wait();
> > > > > > > > return null;
> > > > > > > > }
> > > > > > > > });
> > > > > > > > }
> > > > > > > > return null;
> > > > > > > > }
> > > > > > > > });
> > > > > > > >
> > > > > > > > Transaction tx =
> > > > > > > > transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> > > > > > > > TransactionIsolation.READ_COMMITTED);
> > > > > > > > cache.put("key1", "val1");
> > > > > > > >
> > > > > > > > And through debugging cache.put() method i can see in method
> > > > > > > > *org.apache.ignite.internal.processors.cache.distributed.
> > > > > > > > near.GridNearTxLocal#enlistWriteEntry*
> > > > > > > > that "key1" already *EXISTS *in internal cache :
> > > > > > > cacheCtx.cache().entryEx()
> > > > > > > > returns not null.
> > > > > > > >
> > > > > > > > ср, 29 мар. 2017 г. в 20:11, Alexander Fedotov <
> > > > > > > > alexander.fedotoff@gmail.com
> > > > > > > > >:
> > > > > > > >
> > > > > > > > Hello Aleksey,
> > > > > > > >
> > > > > > > > No, the enlisted entry won't be visible for other
> transactions.
> > > > Dirty
> > > > > > > reads
> > > > > > > > are not allowed in Ignite.
> > > > > > > >
> > > > > > > > Kind regards,
> > > > > > > > Alex
> > > > > > > >
> > > > > > > > 29 марта 2017 г. 7:36 PM пользователь "ALEKSEY KUZNETSOV" <
> > > > > > > > alkuznetsov.sb@gmail.com> написал:
> > > > > > > >
> > > > > > > > Hello, Igniters! I have one more question to you. Will
> > appreciate
> > > > any
> > > > > > > help.
> > > > > > > > Consider cache with near , dht configured not null.
> > > > > > > > When we start commit transaction , in method
> > > > > > > > *org.apache.ignite.internal.processors.cache.distributed.
> > > > > > > > near.GridNearTxLocal#enlistWriteEntry*
> > > > > > > > we put newly created entry into cache by executing entryEx().
> > > > > > > > I wonder if this entry will became visible for other
> > > transactions!?
> > > > > > > > --
> > > > > > > >
> > > > > > > > *Best Regards,*
> > > > > > > >
> > > > > > > > *Kuznetsov Aleksey*
> > > > > > > >
> > > > > > > > --
> > > > > > > >
> > > > > > > > *Best Regards,*
> > > > > > > >
> > > > > > > > *Kuznetsov Aleksey*
> > > > > > > >
> > > > > > >
> > > > > > --
> > > > > >
> > > > > > *Best Regards,*
> > > > > >
> > > > > > *Kuznetsov Aleksey*
> > > > > >
> > > > >
> > > > --
> > > >
> > > > *Best Regards,*
> > > >
> > > > *Kuznetsov Aleksey*
> > > >
> > >
> > --
> >
> > *Best Regards,*
> >
> > *Kuznetsov Aleksey*
> >
>
--
*Best Regards,*
*Kuznetsov Aleksey*
Re: putting entity into cache while commiting.Why!?
Posted by Alexey Goncharuk <al...@gmail.com>.
Note that you call doInTransaction() for ignite(1), but you have acquired
the cache reference for ignite(0), thus your cache.put() commits
immediately from another node, because transactional scope is node-local.
If you change the test either to use ignite(0) for doInTransaction, or to
get the cache in the callable like ignite(1).cache("testCache"), the test
will not throw an exception. Note that it will hang because doInTrasaction
starts a pessimistic transaction which acquires a lock on key1, and then
you put it to infinite sleep. The lock prevents the transaction from
the main thread to commit.
2017-03-30 15:44 GMT+03:00 ALEKSEY KUZNETSOV <al...@gmail.com>:
> I've edited code and now DIRTY READ occures!
>
> Ignite ignite0 = ignite(0);
> IgniteTransactions transactions = ignite0.transactions();
> IgniteCache<String, String> cache = ignite0.getOrCreateCache("testCache");
> Object monitor = new Object();
>
> GridTestUtils.runAsync(new Callable<Object>() {
> @Override
> public Object call() throws Exception {
> doInTransaction(ignite(1), new Callable<Object>() {
> @Override
> public Object call() throws Exception {
> synchronized (monitor) {
> cache.put("key1", "val1!");
> monitor.wait();
> fail();
> return null;
> }
> }
> });
> return null;
> }
> });
> Thread.currentThread().sleep(1000);<------ dirty read occures only if
> we sleep some time !
> Transaction tx =
> transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> TransactionIsolation.READ_COMMITTED);
> String key1Value = cache.get("key1");
> if(key1Value.equals("val1!"))
> throw new RuntimeException("dirty read!");<------ exception does
> happen!
> cache.put("key1", "val1");
> cache.put("key2", "val2");
> cache.put("key3", "val3");
> tx.commit();
>
>
> чт, 30 мар. 2017 г. в 14:04, Alexey Goncharuk <alexey.goncharuk@gmail.com
> >:
>
> > Agree, the cache is transactional, however, the second transaction does
> not
> > see the dirty value:
> >
> > Ignite ignite0 = ignite(0);
> > IgniteTransactions transactions = ignite0.transactions();
> > final IgniteCache<String, String> cache =
> > ignite0.getOrCreateCache("testCache");
> >
> > final Object monitor = new Object();
> >
> > GridTestUtils.runAsync(new Callable<Object>() {
> > @Override
> > public Object call() throws Exception {
> > synchronized (monitor){
> > doInTransaction(ignite(1), new Callable<Object>() {
> > @Override
> > public Object call() throws Exception {
> > cache.put("key1", "val1");
> > monitor.wait();
> > System.out.println("continue first transaction");
> > return null;
> > }
> > });
> > }
> > return null;
> > }
> > });
> >
> > Transaction tx =
> > transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> > TransactionIsolation.READ_COMMITTED);
> > assertNull(cache.get("key1")); // <- This check passes
> > tx.commit();
> >
> >
> > 2017-03-30 13:30 GMT+03:00 ALEKSEY KUZNETSOV <al...@gmail.com>:
> >
> > > Well, i changed code , added :
> > >
> > > CacheConfiguration config = cache.getConfiguration(
> > > CacheConfiguration.class);
> > > System.out.println(config.getAtomicityMode());//TRANSACTIONAL
> > >
> > > So, atomicity is transactional
> > >
> > > чт, 30 мар. 2017 г. в 12:43, Alexey Goncharuk <
> > alexey.goncharuk@gmail.com
> > > >:
> > >
> > > > Aleksey,
> > > >
> > > > It looks like in your test the result of method atomicityMode() is
> not
> > > used
> > > > because you do getOrCreateCache() without the configuration argument,
> > > which
> > > > will create a cache with a default configuration, which is ATOMIC.
> > > >
> > > > 2017-03-30 12:06 GMT+03:00 ALEKSEY KUZNETSOV <
> alkuznetsov.sb@gmail.com
> > >:
> > > >
> > > > > public class FooTest extends GridCacheAbstractSelfTest {
> > > > >
> > > > > @Override
> > > > > protected void afterTestsStopped() throws Exception {
> > > > > super.afterTestsStopped();
> > > > > stopAllGrids();
> > > > > }
> > > > >
> > > > > @Override
> > > > > protected int gridCount() {
> > > > > return 3;
> > > > > }
> > > > >
> > > > > @Override
> > > > > protected CacheMode cacheMode() {
> > > > > return CacheMode.PARTITIONED;
> > > > > }
> > > > >
> > > > > @Override
> > > > > protected CacheAtomicityMode atomicityMode() {
> > > > > return CacheAtomicityMode.TRANSACTIONAL;
> > > > > }
> > > > >
> > > > > public void testLoggingTransactions() throws
> > InterruptedException {
> > > > > Ignite ignite0 = ignite(0);
> > > > > IgniteTransactions transactions = ignite0.transactions();
> > > > > IgniteCache<String, String> cache =
> > > > > ignite0.getOrCreateCache("testCache");
> > > > > Object monitor = new Object();
> > > > >
> > > > > GridTestUtils.runAsync(new Callable<Object>() {
> > > > > @Override
> > > > > public Object call() throws Exception {
> > > > > synchronized (monitor){
> > > > > doInTransaction(ignite(1), new
> > Callable<Object>() {
> > > > > @Override
> > > > > public Object call() throws Exception {
> > > > > cache.put("key1", "val1");
> > > > > monitor.wait();
> > > > > System.out.println("continue first
> > > > > transaction");
> > > > > return null;
> > > > > }
> > > > > });
> > > > > }
> > > > > return null;
> > > > > }
> > > > > });
> > > > >
> > > > > Transaction tx =
> > > > > transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> > > > > TransactionIsolation.READ_COMMITTED);
> > > > > cache.put("key1", "val1");
> > > > > cache.put("key2", "val2");
> > > > > cache.put("key3", "val3");
> > > > > tx.commit();
> > > > >
> > > > > }
> > > > > }
> > > > >
> > > > >
> > > > > чт, 30 мар. 2017 г. в 11:55, Alexey Goncharuk <
> > > > alexey.goncharuk@gmail.com
> > > > > >:
> > > > >
> > > > > > Can you please paste the full example?
> > > > > >
> > > > > > 2017-03-30 11:50 GMT+03:00 ALEKSEY KUZNETSOV <
> > > alkuznetsov.sb@gmail.com
> > > > >:
> > > > > >
> > > > > > > But i managed to read dirty. That is my example :
> > > > > > >
> > > > > > > Ignite ignite0 = ignite(0);
> > > > > > > IgniteTransactions transactions = ignite0.transactions();
> > > > > > > IgniteCache<String, String> cache =
> > > > > > ignite0.getOrCreateCache("testCache");
> > > > > > > Object monitor = new Object();
> > > > > > >
> > > > > > > GridTestUtils.runAsync(new Callable<Object>() {
> > > > > > > @Override
> > > > > > > public Object call() throws Exception {
> > > > > > > synchronized (monitor){
> > > > > > > doInTransaction(ignite(1), new Callable<Object>() {
> > > > > > > @Override
> > > > > > > public Object call() throws Exception {
> > > > > > > cache.put("key1", "val1");
> > > > > > > monitor.wait();
> > > > > > > return null;
> > > > > > > }
> > > > > > > });
> > > > > > > }
> > > > > > > return null;
> > > > > > > }
> > > > > > > });
> > > > > > >
> > > > > > > Transaction tx =
> > > > > > > transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> > > > > > > TransactionIsolation.READ_COMMITTED);
> > > > > > > cache.put("key1", "val1");
> > > > > > >
> > > > > > > And through debugging cache.put() method i can see in method
> > > > > > > *org.apache.ignite.internal.processors.cache.distributed.
> > > > > > > near.GridNearTxLocal#enlistWriteEntry*
> > > > > > > that "key1" already *EXISTS *in internal cache :
> > > > > > cacheCtx.cache().entryEx()
> > > > > > > returns not null.
> > > > > > >
> > > > > > > ср, 29 мар. 2017 г. в 20:11, Alexander Fedotov <
> > > > > > > alexander.fedotoff@gmail.com
> > > > > > > >:
> > > > > > >
> > > > > > > Hello Aleksey,
> > > > > > >
> > > > > > > No, the enlisted entry won't be visible for other transactions.
> > > Dirty
> > > > > > reads
> > > > > > > are not allowed in Ignite.
> > > > > > >
> > > > > > > Kind regards,
> > > > > > > Alex
> > > > > > >
> > > > > > > 29 марта 2017 г. 7:36 PM пользователь "ALEKSEY KUZNETSOV" <
> > > > > > > alkuznetsov.sb@gmail.com> написал:
> > > > > > >
> > > > > > > Hello, Igniters! I have one more question to you. Will
> appreciate
> > > any
> > > > > > help.
> > > > > > > Consider cache with near , dht configured not null.
> > > > > > > When we start commit transaction , in method
> > > > > > > *org.apache.ignite.internal.processors.cache.distributed.
> > > > > > > near.GridNearTxLocal#enlistWriteEntry*
> > > > > > > we put newly created entry into cache by executing entryEx().
> > > > > > > I wonder if this entry will became visible for other
> > transactions!?
> > > > > > > --
> > > > > > >
> > > > > > > *Best Regards,*
> > > > > > >
> > > > > > > *Kuznetsov Aleksey*
> > > > > > >
> > > > > > > --
> > > > > > >
> > > > > > > *Best Regards,*
> > > > > > >
> > > > > > > *Kuznetsov Aleksey*
> > > > > > >
> > > > > >
> > > > > --
> > > > >
> > > > > *Best Regards,*
> > > > >
> > > > > *Kuznetsov Aleksey*
> > > > >
> > > >
> > > --
> > >
> > > *Best Regards,*
> > >
> > > *Kuznetsov Aleksey*
> > >
> >
> --
>
> *Best Regards,*
>
> *Kuznetsov Aleksey*
>
Re: putting entity into cache while commiting.Why!?
Posted by ALEKSEY KUZNETSOV <al...@gmail.com>.
I've edited code and now DIRTY READ occures!
Ignite ignite0 = ignite(0);
IgniteTransactions transactions = ignite0.transactions();
IgniteCache<String, String> cache = ignite0.getOrCreateCache("testCache");
Object monitor = new Object();
GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
doInTransaction(ignite(1), new Callable<Object>() {
@Override
public Object call() throws Exception {
synchronized (monitor) {
cache.put("key1", "val1!");
monitor.wait();
fail();
return null;
}
}
});
return null;
}
});
Thread.currentThread().sleep(1000);<------ dirty read occures only if
we sleep some time !
Transaction tx =
transactions.txStart(TransactionConcurrency.OPTIMISTIC,
TransactionIsolation.READ_COMMITTED);
String key1Value = cache.get("key1");
if(key1Value.equals("val1!"))
throw new RuntimeException("dirty read!");<------ exception does happen!
cache.put("key1", "val1");
cache.put("key2", "val2");
cache.put("key3", "val3");
tx.commit();
чт, 30 мар. 2017 г. в 14:04, Alexey Goncharuk <al...@gmail.com>:
> Agree, the cache is transactional, however, the second transaction does not
> see the dirty value:
>
> Ignite ignite0 = ignite(0);
> IgniteTransactions transactions = ignite0.transactions();
> final IgniteCache<String, String> cache =
> ignite0.getOrCreateCache("testCache");
>
> final Object monitor = new Object();
>
> GridTestUtils.runAsync(new Callable<Object>() {
> @Override
> public Object call() throws Exception {
> synchronized (monitor){
> doInTransaction(ignite(1), new Callable<Object>() {
> @Override
> public Object call() throws Exception {
> cache.put("key1", "val1");
> monitor.wait();
> System.out.println("continue first transaction");
> return null;
> }
> });
> }
> return null;
> }
> });
>
> Transaction tx =
> transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> TransactionIsolation.READ_COMMITTED);
> assertNull(cache.get("key1")); // <- This check passes
> tx.commit();
>
>
> 2017-03-30 13:30 GMT+03:00 ALEKSEY KUZNETSOV <al...@gmail.com>:
>
> > Well, i changed code , added :
> >
> > CacheConfiguration config = cache.getConfiguration(
> > CacheConfiguration.class);
> > System.out.println(config.getAtomicityMode());//TRANSACTIONAL
> >
> > So, atomicity is transactional
> >
> > чт, 30 мар. 2017 г. в 12:43, Alexey Goncharuk <
> alexey.goncharuk@gmail.com
> > >:
> >
> > > Aleksey,
> > >
> > > It looks like in your test the result of method atomicityMode() is not
> > used
> > > because you do getOrCreateCache() without the configuration argument,
> > which
> > > will create a cache with a default configuration, which is ATOMIC.
> > >
> > > 2017-03-30 12:06 GMT+03:00 ALEKSEY KUZNETSOV <alkuznetsov.sb@gmail.com
> >:
> > >
> > > > public class FooTest extends GridCacheAbstractSelfTest {
> > > >
> > > > @Override
> > > > protected void afterTestsStopped() throws Exception {
> > > > super.afterTestsStopped();
> > > > stopAllGrids();
> > > > }
> > > >
> > > > @Override
> > > > protected int gridCount() {
> > > > return 3;
> > > > }
> > > >
> > > > @Override
> > > > protected CacheMode cacheMode() {
> > > > return CacheMode.PARTITIONED;
> > > > }
> > > >
> > > > @Override
> > > > protected CacheAtomicityMode atomicityMode() {
> > > > return CacheAtomicityMode.TRANSACTIONAL;
> > > > }
> > > >
> > > > public void testLoggingTransactions() throws
> InterruptedException {
> > > > Ignite ignite0 = ignite(0);
> > > > IgniteTransactions transactions = ignite0.transactions();
> > > > IgniteCache<String, String> cache =
> > > > ignite0.getOrCreateCache("testCache");
> > > > Object monitor = new Object();
> > > >
> > > > GridTestUtils.runAsync(new Callable<Object>() {
> > > > @Override
> > > > public Object call() throws Exception {
> > > > synchronized (monitor){
> > > > doInTransaction(ignite(1), new
> Callable<Object>() {
> > > > @Override
> > > > public Object call() throws Exception {
> > > > cache.put("key1", "val1");
> > > > monitor.wait();
> > > > System.out.println("continue first
> > > > transaction");
> > > > return null;
> > > > }
> > > > });
> > > > }
> > > > return null;
> > > > }
> > > > });
> > > >
> > > > Transaction tx =
> > > > transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> > > > TransactionIsolation.READ_COMMITTED);
> > > > cache.put("key1", "val1");
> > > > cache.put("key2", "val2");
> > > > cache.put("key3", "val3");
> > > > tx.commit();
> > > >
> > > > }
> > > > }
> > > >
> > > >
> > > > чт, 30 мар. 2017 г. в 11:55, Alexey Goncharuk <
> > > alexey.goncharuk@gmail.com
> > > > >:
> > > >
> > > > > Can you please paste the full example?
> > > > >
> > > > > 2017-03-30 11:50 GMT+03:00 ALEKSEY KUZNETSOV <
> > alkuznetsov.sb@gmail.com
> > > >:
> > > > >
> > > > > > But i managed to read dirty. That is my example :
> > > > > >
> > > > > > Ignite ignite0 = ignite(0);
> > > > > > IgniteTransactions transactions = ignite0.transactions();
> > > > > > IgniteCache<String, String> cache =
> > > > > ignite0.getOrCreateCache("testCache");
> > > > > > Object monitor = new Object();
> > > > > >
> > > > > > GridTestUtils.runAsync(new Callable<Object>() {
> > > > > > @Override
> > > > > > public Object call() throws Exception {
> > > > > > synchronized (monitor){
> > > > > > doInTransaction(ignite(1), new Callable<Object>() {
> > > > > > @Override
> > > > > > public Object call() throws Exception {
> > > > > > cache.put("key1", "val1");
> > > > > > monitor.wait();
> > > > > > return null;
> > > > > > }
> > > > > > });
> > > > > > }
> > > > > > return null;
> > > > > > }
> > > > > > });
> > > > > >
> > > > > > Transaction tx =
> > > > > > transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> > > > > > TransactionIsolation.READ_COMMITTED);
> > > > > > cache.put("key1", "val1");
> > > > > >
> > > > > > And through debugging cache.put() method i can see in method
> > > > > > *org.apache.ignite.internal.processors.cache.distributed.
> > > > > > near.GridNearTxLocal#enlistWriteEntry*
> > > > > > that "key1" already *EXISTS *in internal cache :
> > > > > cacheCtx.cache().entryEx()
> > > > > > returns not null.
> > > > > >
> > > > > > ср, 29 мар. 2017 г. в 20:11, Alexander Fedotov <
> > > > > > alexander.fedotoff@gmail.com
> > > > > > >:
> > > > > >
> > > > > > Hello Aleksey,
> > > > > >
> > > > > > No, the enlisted entry won't be visible for other transactions.
> > Dirty
> > > > > reads
> > > > > > are not allowed in Ignite.
> > > > > >
> > > > > > Kind regards,
> > > > > > Alex
> > > > > >
> > > > > > 29 марта 2017 г. 7:36 PM пользователь "ALEKSEY KUZNETSOV" <
> > > > > > alkuznetsov.sb@gmail.com> написал:
> > > > > >
> > > > > > Hello, Igniters! I have one more question to you. Will appreciate
> > any
> > > > > help.
> > > > > > Consider cache with near , dht configured not null.
> > > > > > When we start commit transaction , in method
> > > > > > *org.apache.ignite.internal.processors.cache.distributed.
> > > > > > near.GridNearTxLocal#enlistWriteEntry*
> > > > > > we put newly created entry into cache by executing entryEx().
> > > > > > I wonder if this entry will became visible for other
> transactions!?
> > > > > > --
> > > > > >
> > > > > > *Best Regards,*
> > > > > >
> > > > > > *Kuznetsov Aleksey*
> > > > > >
> > > > > > --
> > > > > >
> > > > > > *Best Regards,*
> > > > > >
> > > > > > *Kuznetsov Aleksey*
> > > > > >
> > > > >
> > > > --
> > > >
> > > > *Best Regards,*
> > > >
> > > > *Kuznetsov Aleksey*
> > > >
> > >
> > --
> >
> > *Best Regards,*
> >
> > *Kuznetsov Aleksey*
> >
>
--
*Best Regards,*
*Kuznetsov Aleksey*
Re: putting entity into cache while commiting.Why!?
Posted by Alexey Goncharuk <al...@gmail.com>.
Agree, the cache is transactional, however, the second transaction does not
see the dirty value:
Ignite ignite0 = ignite(0);
IgniteTransactions transactions = ignite0.transactions();
final IgniteCache<String, String> cache =
ignite0.getOrCreateCache("testCache");
final Object monitor = new Object();
GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
synchronized (monitor){
doInTransaction(ignite(1), new Callable<Object>() {
@Override
public Object call() throws Exception {
cache.put("key1", "val1");
monitor.wait();
System.out.println("continue first transaction");
return null;
}
});
}
return null;
}
});
Transaction tx =
transactions.txStart(TransactionConcurrency.OPTIMISTIC,
TransactionIsolation.READ_COMMITTED);
assertNull(cache.get("key1")); // <- This check passes
tx.commit();
2017-03-30 13:30 GMT+03:00 ALEKSEY KUZNETSOV <al...@gmail.com>:
> Well, i changed code , added :
>
> CacheConfiguration config = cache.getConfiguration(
> CacheConfiguration.class);
> System.out.println(config.getAtomicityMode());//TRANSACTIONAL
>
> So, atomicity is transactional
>
> чт, 30 мар. 2017 г. в 12:43, Alexey Goncharuk <alexey.goncharuk@gmail.com
> >:
>
> > Aleksey,
> >
> > It looks like in your test the result of method atomicityMode() is not
> used
> > because you do getOrCreateCache() without the configuration argument,
> which
> > will create a cache with a default configuration, which is ATOMIC.
> >
> > 2017-03-30 12:06 GMT+03:00 ALEKSEY KUZNETSOV <al...@gmail.com>:
> >
> > > public class FooTest extends GridCacheAbstractSelfTest {
> > >
> > > @Override
> > > protected void afterTestsStopped() throws Exception {
> > > super.afterTestsStopped();
> > > stopAllGrids();
> > > }
> > >
> > > @Override
> > > protected int gridCount() {
> > > return 3;
> > > }
> > >
> > > @Override
> > > protected CacheMode cacheMode() {
> > > return CacheMode.PARTITIONED;
> > > }
> > >
> > > @Override
> > > protected CacheAtomicityMode atomicityMode() {
> > > return CacheAtomicityMode.TRANSACTIONAL;
> > > }
> > >
> > > public void testLoggingTransactions() throws InterruptedException {
> > > Ignite ignite0 = ignite(0);
> > > IgniteTransactions transactions = ignite0.transactions();
> > > IgniteCache<String, String> cache =
> > > ignite0.getOrCreateCache("testCache");
> > > Object monitor = new Object();
> > >
> > > GridTestUtils.runAsync(new Callable<Object>() {
> > > @Override
> > > public Object call() throws Exception {
> > > synchronized (monitor){
> > > doInTransaction(ignite(1), new Callable<Object>() {
> > > @Override
> > > public Object call() throws Exception {
> > > cache.put("key1", "val1");
> > > monitor.wait();
> > > System.out.println("continue first
> > > transaction");
> > > return null;
> > > }
> > > });
> > > }
> > > return null;
> > > }
> > > });
> > >
> > > Transaction tx =
> > > transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> > > TransactionIsolation.READ_COMMITTED);
> > > cache.put("key1", "val1");
> > > cache.put("key2", "val2");
> > > cache.put("key3", "val3");
> > > tx.commit();
> > >
> > > }
> > > }
> > >
> > >
> > > чт, 30 мар. 2017 г. в 11:55, Alexey Goncharuk <
> > alexey.goncharuk@gmail.com
> > > >:
> > >
> > > > Can you please paste the full example?
> > > >
> > > > 2017-03-30 11:50 GMT+03:00 ALEKSEY KUZNETSOV <
> alkuznetsov.sb@gmail.com
> > >:
> > > >
> > > > > But i managed to read dirty. That is my example :
> > > > >
> > > > > Ignite ignite0 = ignite(0);
> > > > > IgniteTransactions transactions = ignite0.transactions();
> > > > > IgniteCache<String, String> cache =
> > > > ignite0.getOrCreateCache("testCache");
> > > > > Object monitor = new Object();
> > > > >
> > > > > GridTestUtils.runAsync(new Callable<Object>() {
> > > > > @Override
> > > > > public Object call() throws Exception {
> > > > > synchronized (monitor){
> > > > > doInTransaction(ignite(1), new Callable<Object>() {
> > > > > @Override
> > > > > public Object call() throws Exception {
> > > > > cache.put("key1", "val1");
> > > > > monitor.wait();
> > > > > return null;
> > > > > }
> > > > > });
> > > > > }
> > > > > return null;
> > > > > }
> > > > > });
> > > > >
> > > > > Transaction tx =
> > > > > transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> > > > > TransactionIsolation.READ_COMMITTED);
> > > > > cache.put("key1", "val1");
> > > > >
> > > > > And through debugging cache.put() method i can see in method
> > > > > *org.apache.ignite.internal.processors.cache.distributed.
> > > > > near.GridNearTxLocal#enlistWriteEntry*
> > > > > that "key1" already *EXISTS *in internal cache :
> > > > cacheCtx.cache().entryEx()
> > > > > returns not null.
> > > > >
> > > > > ср, 29 мар. 2017 г. в 20:11, Alexander Fedotov <
> > > > > alexander.fedotoff@gmail.com
> > > > > >:
> > > > >
> > > > > Hello Aleksey,
> > > > >
> > > > > No, the enlisted entry won't be visible for other transactions.
> Dirty
> > > > reads
> > > > > are not allowed in Ignite.
> > > > >
> > > > > Kind regards,
> > > > > Alex
> > > > >
> > > > > 29 марта 2017 г. 7:36 PM пользователь "ALEKSEY KUZNETSOV" <
> > > > > alkuznetsov.sb@gmail.com> написал:
> > > > >
> > > > > Hello, Igniters! I have one more question to you. Will appreciate
> any
> > > > help.
> > > > > Consider cache with near , dht configured not null.
> > > > > When we start commit transaction , in method
> > > > > *org.apache.ignite.internal.processors.cache.distributed.
> > > > > near.GridNearTxLocal#enlistWriteEntry*
> > > > > we put newly created entry into cache by executing entryEx().
> > > > > I wonder if this entry will became visible for other transactions!?
> > > > > --
> > > > >
> > > > > *Best Regards,*
> > > > >
> > > > > *Kuznetsov Aleksey*
> > > > >
> > > > > --
> > > > >
> > > > > *Best Regards,*
> > > > >
> > > > > *Kuznetsov Aleksey*
> > > > >
> > > >
> > > --
> > >
> > > *Best Regards,*
> > >
> > > *Kuznetsov Aleksey*
> > >
> >
> --
>
> *Best Regards,*
>
> *Kuznetsov Aleksey*
>
Re: putting entity into cache while commiting.Why!?
Posted by ALEKSEY KUZNETSOV <al...@gmail.com>.
Well, i changed code , added :
CacheConfiguration config = cache.getConfiguration(CacheConfiguration.class);
System.out.println(config.getAtomicityMode());//TRANSACTIONAL
So, atomicity is transactional
чт, 30 мар. 2017 г. в 12:43, Alexey Goncharuk <al...@gmail.com>:
> Aleksey,
>
> It looks like in your test the result of method atomicityMode() is not used
> because you do getOrCreateCache() without the configuration argument, which
> will create a cache with a default configuration, which is ATOMIC.
>
> 2017-03-30 12:06 GMT+03:00 ALEKSEY KUZNETSOV <al...@gmail.com>:
>
> > public class FooTest extends GridCacheAbstractSelfTest {
> >
> > @Override
> > protected void afterTestsStopped() throws Exception {
> > super.afterTestsStopped();
> > stopAllGrids();
> > }
> >
> > @Override
> > protected int gridCount() {
> > return 3;
> > }
> >
> > @Override
> > protected CacheMode cacheMode() {
> > return CacheMode.PARTITIONED;
> > }
> >
> > @Override
> > protected CacheAtomicityMode atomicityMode() {
> > return CacheAtomicityMode.TRANSACTIONAL;
> > }
> >
> > public void testLoggingTransactions() throws InterruptedException {
> > Ignite ignite0 = ignite(0);
> > IgniteTransactions transactions = ignite0.transactions();
> > IgniteCache<String, String> cache =
> > ignite0.getOrCreateCache("testCache");
> > Object monitor = new Object();
> >
> > GridTestUtils.runAsync(new Callable<Object>() {
> > @Override
> > public Object call() throws Exception {
> > synchronized (monitor){
> > doInTransaction(ignite(1), new Callable<Object>() {
> > @Override
> > public Object call() throws Exception {
> > cache.put("key1", "val1");
> > monitor.wait();
> > System.out.println("continue first
> > transaction");
> > return null;
> > }
> > });
> > }
> > return null;
> > }
> > });
> >
> > Transaction tx =
> > transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> > TransactionIsolation.READ_COMMITTED);
> > cache.put("key1", "val1");
> > cache.put("key2", "val2");
> > cache.put("key3", "val3");
> > tx.commit();
> >
> > }
> > }
> >
> >
> > чт, 30 мар. 2017 г. в 11:55, Alexey Goncharuk <
> alexey.goncharuk@gmail.com
> > >:
> >
> > > Can you please paste the full example?
> > >
> > > 2017-03-30 11:50 GMT+03:00 ALEKSEY KUZNETSOV <alkuznetsov.sb@gmail.com
> >:
> > >
> > > > But i managed to read dirty. That is my example :
> > > >
> > > > Ignite ignite0 = ignite(0);
> > > > IgniteTransactions transactions = ignite0.transactions();
> > > > IgniteCache<String, String> cache =
> > > ignite0.getOrCreateCache("testCache");
> > > > Object monitor = new Object();
> > > >
> > > > GridTestUtils.runAsync(new Callable<Object>() {
> > > > @Override
> > > > public Object call() throws Exception {
> > > > synchronized (monitor){
> > > > doInTransaction(ignite(1), new Callable<Object>() {
> > > > @Override
> > > > public Object call() throws Exception {
> > > > cache.put("key1", "val1");
> > > > monitor.wait();
> > > > return null;
> > > > }
> > > > });
> > > > }
> > > > return null;
> > > > }
> > > > });
> > > >
> > > > Transaction tx =
> > > > transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> > > > TransactionIsolation.READ_COMMITTED);
> > > > cache.put("key1", "val1");
> > > >
> > > > And through debugging cache.put() method i can see in method
> > > > *org.apache.ignite.internal.processors.cache.distributed.
> > > > near.GridNearTxLocal#enlistWriteEntry*
> > > > that "key1" already *EXISTS *in internal cache :
> > > cacheCtx.cache().entryEx()
> > > > returns not null.
> > > >
> > > > ср, 29 мар. 2017 г. в 20:11, Alexander Fedotov <
> > > > alexander.fedotoff@gmail.com
> > > > >:
> > > >
> > > > Hello Aleksey,
> > > >
> > > > No, the enlisted entry won't be visible for other transactions. Dirty
> > > reads
> > > > are not allowed in Ignite.
> > > >
> > > > Kind regards,
> > > > Alex
> > > >
> > > > 29 марта 2017 г. 7:36 PM пользователь "ALEKSEY KUZNETSOV" <
> > > > alkuznetsov.sb@gmail.com> написал:
> > > >
> > > > Hello, Igniters! I have one more question to you. Will appreciate any
> > > help.
> > > > Consider cache with near , dht configured not null.
> > > > When we start commit transaction , in method
> > > > *org.apache.ignite.internal.processors.cache.distributed.
> > > > near.GridNearTxLocal#enlistWriteEntry*
> > > > we put newly created entry into cache by executing entryEx().
> > > > I wonder if this entry will became visible for other transactions!?
> > > > --
> > > >
> > > > *Best Regards,*
> > > >
> > > > *Kuznetsov Aleksey*
> > > >
> > > > --
> > > >
> > > > *Best Regards,*
> > > >
> > > > *Kuznetsov Aleksey*
> > > >
> > >
> > --
> >
> > *Best Regards,*
> >
> > *Kuznetsov Aleksey*
> >
>
--
*Best Regards,*
*Kuznetsov Aleksey*
Re: putting entity into cache while commiting.Why!?
Posted by Alexey Goncharuk <al...@gmail.com>.
Aleksey,
It looks like in your test the result of method atomicityMode() is not used
because you do getOrCreateCache() without the configuration argument, which
will create a cache with a default configuration, which is ATOMIC.
2017-03-30 12:06 GMT+03:00 ALEKSEY KUZNETSOV <al...@gmail.com>:
> public class FooTest extends GridCacheAbstractSelfTest {
>
> @Override
> protected void afterTestsStopped() throws Exception {
> super.afterTestsStopped();
> stopAllGrids();
> }
>
> @Override
> protected int gridCount() {
> return 3;
> }
>
> @Override
> protected CacheMode cacheMode() {
> return CacheMode.PARTITIONED;
> }
>
> @Override
> protected CacheAtomicityMode atomicityMode() {
> return CacheAtomicityMode.TRANSACTIONAL;
> }
>
> public void testLoggingTransactions() throws InterruptedException {
> Ignite ignite0 = ignite(0);
> IgniteTransactions transactions = ignite0.transactions();
> IgniteCache<String, String> cache =
> ignite0.getOrCreateCache("testCache");
> Object monitor = new Object();
>
> GridTestUtils.runAsync(new Callable<Object>() {
> @Override
> public Object call() throws Exception {
> synchronized (monitor){
> doInTransaction(ignite(1), new Callable<Object>() {
> @Override
> public Object call() throws Exception {
> cache.put("key1", "val1");
> monitor.wait();
> System.out.println("continue first
> transaction");
> return null;
> }
> });
> }
> return null;
> }
> });
>
> Transaction tx =
> transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> TransactionIsolation.READ_COMMITTED);
> cache.put("key1", "val1");
> cache.put("key2", "val2");
> cache.put("key3", "val3");
> tx.commit();
>
> }
> }
>
>
> чт, 30 мар. 2017 г. в 11:55, Alexey Goncharuk <alexey.goncharuk@gmail.com
> >:
>
> > Can you please paste the full example?
> >
> > 2017-03-30 11:50 GMT+03:00 ALEKSEY KUZNETSOV <al...@gmail.com>:
> >
> > > But i managed to read dirty. That is my example :
> > >
> > > Ignite ignite0 = ignite(0);
> > > IgniteTransactions transactions = ignite0.transactions();
> > > IgniteCache<String, String> cache =
> > ignite0.getOrCreateCache("testCache");
> > > Object monitor = new Object();
> > >
> > > GridTestUtils.runAsync(new Callable<Object>() {
> > > @Override
> > > public Object call() throws Exception {
> > > synchronized (monitor){
> > > doInTransaction(ignite(1), new Callable<Object>() {
> > > @Override
> > > public Object call() throws Exception {
> > > cache.put("key1", "val1");
> > > monitor.wait();
> > > return null;
> > > }
> > > });
> > > }
> > > return null;
> > > }
> > > });
> > >
> > > Transaction tx =
> > > transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> > > TransactionIsolation.READ_COMMITTED);
> > > cache.put("key1", "val1");
> > >
> > > And through debugging cache.put() method i can see in method
> > > *org.apache.ignite.internal.processors.cache.distributed.
> > > near.GridNearTxLocal#enlistWriteEntry*
> > > that "key1" already *EXISTS *in internal cache :
> > cacheCtx.cache().entryEx()
> > > returns not null.
> > >
> > > ср, 29 мар. 2017 г. в 20:11, Alexander Fedotov <
> > > alexander.fedotoff@gmail.com
> > > >:
> > >
> > > Hello Aleksey,
> > >
> > > No, the enlisted entry won't be visible for other transactions. Dirty
> > reads
> > > are not allowed in Ignite.
> > >
> > > Kind regards,
> > > Alex
> > >
> > > 29 марта 2017 г. 7:36 PM пользователь "ALEKSEY KUZNETSOV" <
> > > alkuznetsov.sb@gmail.com> написал:
> > >
> > > Hello, Igniters! I have one more question to you. Will appreciate any
> > help.
> > > Consider cache with near , dht configured not null.
> > > When we start commit transaction , in method
> > > *org.apache.ignite.internal.processors.cache.distributed.
> > > near.GridNearTxLocal#enlistWriteEntry*
> > > we put newly created entry into cache by executing entryEx().
> > > I wonder if this entry will became visible for other transactions!?
> > > --
> > >
> > > *Best Regards,*
> > >
> > > *Kuznetsov Aleksey*
> > >
> > > --
> > >
> > > *Best Regards,*
> > >
> > > *Kuznetsov Aleksey*
> > >
> >
> --
>
> *Best Regards,*
>
> *Kuznetsov Aleksey*
>
Re: putting entity into cache while commiting.Why!?
Posted by ALEKSEY KUZNETSOV <al...@gmail.com>.
public class FooTest extends GridCacheAbstractSelfTest {
@Override
protected void afterTestsStopped() throws Exception {
super.afterTestsStopped();
stopAllGrids();
}
@Override
protected int gridCount() {
return 3;
}
@Override
protected CacheMode cacheMode() {
return CacheMode.PARTITIONED;
}
@Override
protected CacheAtomicityMode atomicityMode() {
return CacheAtomicityMode.TRANSACTIONAL;
}
public void testLoggingTransactions() throws InterruptedException {
Ignite ignite0 = ignite(0);
IgniteTransactions transactions = ignite0.transactions();
IgniteCache<String, String> cache =
ignite0.getOrCreateCache("testCache");
Object monitor = new Object();
GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
synchronized (monitor){
doInTransaction(ignite(1), new Callable<Object>() {
@Override
public Object call() throws Exception {
cache.put("key1", "val1");
monitor.wait();
System.out.println("continue first transaction");
return null;
}
});
}
return null;
}
});
Transaction tx =
transactions.txStart(TransactionConcurrency.OPTIMISTIC,
TransactionIsolation.READ_COMMITTED);
cache.put("key1", "val1");
cache.put("key2", "val2");
cache.put("key3", "val3");
tx.commit();
}
}
чт, 30 мар. 2017 г. в 11:55, Alexey Goncharuk <al...@gmail.com>:
> Can you please paste the full example?
>
> 2017-03-30 11:50 GMT+03:00 ALEKSEY KUZNETSOV <al...@gmail.com>:
>
> > But i managed to read dirty. That is my example :
> >
> > Ignite ignite0 = ignite(0);
> > IgniteTransactions transactions = ignite0.transactions();
> > IgniteCache<String, String> cache =
> ignite0.getOrCreateCache("testCache");
> > Object monitor = new Object();
> >
> > GridTestUtils.runAsync(new Callable<Object>() {
> > @Override
> > public Object call() throws Exception {
> > synchronized (monitor){
> > doInTransaction(ignite(1), new Callable<Object>() {
> > @Override
> > public Object call() throws Exception {
> > cache.put("key1", "val1");
> > monitor.wait();
> > return null;
> > }
> > });
> > }
> > return null;
> > }
> > });
> >
> > Transaction tx =
> > transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> > TransactionIsolation.READ_COMMITTED);
> > cache.put("key1", "val1");
> >
> > And through debugging cache.put() method i can see in method
> > *org.apache.ignite.internal.processors.cache.distributed.
> > near.GridNearTxLocal#enlistWriteEntry*
> > that "key1" already *EXISTS *in internal cache :
> cacheCtx.cache().entryEx()
> > returns not null.
> >
> > ср, 29 мар. 2017 г. в 20:11, Alexander Fedotov <
> > alexander.fedotoff@gmail.com
> > >:
> >
> > Hello Aleksey,
> >
> > No, the enlisted entry won't be visible for other transactions. Dirty
> reads
> > are not allowed in Ignite.
> >
> > Kind regards,
> > Alex
> >
> > 29 марта 2017 г. 7:36 PM пользователь "ALEKSEY KUZNETSOV" <
> > alkuznetsov.sb@gmail.com> написал:
> >
> > Hello, Igniters! I have one more question to you. Will appreciate any
> help.
> > Consider cache with near , dht configured not null.
> > When we start commit transaction , in method
> > *org.apache.ignite.internal.processors.cache.distributed.
> > near.GridNearTxLocal#enlistWriteEntry*
> > we put newly created entry into cache by executing entryEx().
> > I wonder if this entry will became visible for other transactions!?
> > --
> >
> > *Best Regards,*
> >
> > *Kuznetsov Aleksey*
> >
> > --
> >
> > *Best Regards,*
> >
> > *Kuznetsov Aleksey*
> >
>
--
*Best Regards,*
*Kuznetsov Aleksey*
Re: putting entity into cache while commiting.Why!?
Posted by Alexey Goncharuk <al...@gmail.com>.
Can you please paste the full example?
2017-03-30 11:50 GMT+03:00 ALEKSEY KUZNETSOV <al...@gmail.com>:
> But i managed to read dirty. That is my example :
>
> Ignite ignite0 = ignite(0);
> IgniteTransactions transactions = ignite0.transactions();
> IgniteCache<String, String> cache = ignite0.getOrCreateCache("testCache");
> Object monitor = new Object();
>
> GridTestUtils.runAsync(new Callable<Object>() {
> @Override
> public Object call() throws Exception {
> synchronized (monitor){
> doInTransaction(ignite(1), new Callable<Object>() {
> @Override
> public Object call() throws Exception {
> cache.put("key1", "val1");
> monitor.wait();
> return null;
> }
> });
> }
> return null;
> }
> });
>
> Transaction tx =
> transactions.txStart(TransactionConcurrency.OPTIMISTIC,
> TransactionIsolation.READ_COMMITTED);
> cache.put("key1", "val1");
>
> And through debugging cache.put() method i can see in method
> *org.apache.ignite.internal.processors.cache.distributed.
> near.GridNearTxLocal#enlistWriteEntry*
> that "key1" already *EXISTS *in internal cache : cacheCtx.cache().entryEx()
> returns not null.
>
> ср, 29 мар. 2017 г. в 20:11, Alexander Fedotov <
> alexander.fedotoff@gmail.com
> >:
>
> Hello Aleksey,
>
> No, the enlisted entry won't be visible for other transactions. Dirty reads
> are not allowed in Ignite.
>
> Kind regards,
> Alex
>
> 29 марта 2017 г. 7:36 PM пользователь "ALEKSEY KUZNETSOV" <
> alkuznetsov.sb@gmail.com> написал:
>
> Hello, Igniters! I have one more question to you. Will appreciate any help.
> Consider cache with near , dht configured not null.
> When we start commit transaction , in method
> *org.apache.ignite.internal.processors.cache.distributed.
> near.GridNearTxLocal#enlistWriteEntry*
> we put newly created entry into cache by executing entryEx().
> I wonder if this entry will became visible for other transactions!?
> --
>
> *Best Regards,*
>
> *Kuznetsov Aleksey*
>
> --
>
> *Best Regards,*
>
> *Kuznetsov Aleksey*
>
Re: putting entity into cache while commiting.Why!?
Posted by ALEKSEY KUZNETSOV <al...@gmail.com>.
But i managed to read dirty. That is my example :
Ignite ignite0 = ignite(0);
IgniteTransactions transactions = ignite0.transactions();
IgniteCache<String, String> cache = ignite0.getOrCreateCache("testCache");
Object monitor = new Object();
GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
synchronized (monitor){
doInTransaction(ignite(1), new Callable<Object>() {
@Override
public Object call() throws Exception {
cache.put("key1", "val1");
monitor.wait();
return null;
}
});
}
return null;
}
});
Transaction tx =
transactions.txStart(TransactionConcurrency.OPTIMISTIC,
TransactionIsolation.READ_COMMITTED);
cache.put("key1", "val1");
And through debugging cache.put() method i can see in method
*org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal#enlistWriteEntry*
that "key1" already *EXISTS *in internal cache : cacheCtx.cache().entryEx()
returns not null.
ср, 29 мар. 2017 г. в 20:11, Alexander Fedotov <alexander.fedotoff@gmail.com
>:
Hello Aleksey,
No, the enlisted entry won't be visible for other transactions. Dirty reads
are not allowed in Ignite.
Kind regards,
Alex
29 марта 2017 г. 7:36 PM пользователь "ALEKSEY KUZNETSOV" <
alkuznetsov.sb@gmail.com> написал:
Hello, Igniters! I have one more question to you. Will appreciate any help.
Consider cache with near , dht configured not null.
When we start commit transaction , in method
*org.apache.ignite.internal.processors.cache.distributed.
near.GridNearTxLocal#enlistWriteEntry*
we put newly created entry into cache by executing entryEx().
I wonder if this entry will became visible for other transactions!?
--
*Best Regards,*
*Kuznetsov Aleksey*
--
*Best Regards,*
*Kuznetsov Aleksey*
Re: putting entity into cache while commiting.Why!?
Posted by Alexander Fedotov <al...@gmail.com>.
Hello Aleksey,
No, the enlisted entry won't be visible for other transactions. Dirty reads
are not allowed in Ignite.
Kind regards,
Alex
29 марта 2017 г. 7:36 PM пользователь "ALEKSEY KUZNETSOV" <
alkuznetsov.sb@gmail.com> написал:
Hello, Igniters! I have one more question to you. Will appreciate any help.
Consider cache with near , dht configured not null.
When we start commit transaction , in method
*org.apache.ignite.internal.processors.cache.distributed.
near.GridNearTxLocal#enlistWriteEntry*
we put newly created entry into cache by executing entryEx().
I wonder if this entry will became visible for other transactions!?
--
*Best Regards,*
*Kuznetsov Aleksey*