You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by mateusz <pa...@gmail.com> on 2016/07/20 07:01:28 UTC

Transactional adding to IgniteQueue and IgniteSet

Hello Ignite Users,

in
https://apacheignite.readme.io/docs/queue-and-set#collection-configuration
is stated, that the underlying cache for IgniteQueue can be transactional.
Since the underlying cache is an implementation detail, I expected the
IgniteQueue, configured with a transactional underlying cache, to be
transactional itself. Unfortunately, this is not the case. 

I've added a test also using a IgniteCache as comparison (where a
modification is rolled back) to the IgniteQueue (where a modification is not
rolled back).

@Test
public void transactionalAddToQueueCanBeRolledBack() throws Exception {
	// given
	Ignite ignite = Ignition.start();

	CacheConfiguration<Integer, String> cacheConfig = new
CacheConfiguration<>();
	cacheConfig.setName("cache" + System.currentTimeMillis());
	cacheConfig.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
	IgniteCache<Integer, String> cache = ignite.getOrCreateCache(cacheConfig);

	CollectionConfiguration queueConfig = new CollectionConfiguration();
	queueConfig.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
	IgniteQueue<String> queue = ignite.queue("queue" +
System.currentTimeMillis(), 0, queueConfig);

	// when
	Transaction txStart =
ignite.transactions().txStart(TransactionConcurrency.PESSIMISTIC,
			TransactionIsolation.SERIALIZABLE);
	cache.put(1, "foo");
	queue.add("foo");
	txStart.rollback();

	// then
	assertEquals(0, cache.size());
	assertEquals(0, queue.size()); // AssertionError: expected: <0> but was:
<1>
}

The same happens using IgniteSet.

Is the adding supposed to be transactional in this case?

Kind regards
Mateusz




--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Transactional-adding-to-IgniteQueue-and-IgniteSet-tp6410.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Transactional adding to IgniteQueue and IgniteSet

Posted by Denis Magda <dm...@gridgain.com>.
Mateusz,

There are two implementation IgniteQueue’s implementations are available for usage. The first one is for ATOMIC mode while the other is for TRANSACTIONAL mode. Both modes guarantee data consistency. However depending on a use case one of them can show better performance than the other.

—
Denis

> On Jul 20, 2016, at 2:15 PM, mateusz <pa...@gmail.com> wrote:
> 
> Thanks Denis,
> 
> a follow up question: What does the AtomicityMode in CollectionConfiguration
> actually provide? Assuming the queue does involve multiple write operations
> and ATOMIC does not imply isolation, would setting it to ATOMIC not impact
> correctness?
> 
> Just wondering ...
> 
> Mateusz
> 
> 
> 
> --
> View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Transactional-adding-to-IgniteQueue-and-IgniteSet-tp6410p6414.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.


Re: Transactional adding to IgniteQueue and IgniteSet

Posted by mateusz <pa...@gmail.com>.
Thanks Denis,

a follow up question: What does the AtomicityMode in CollectionConfiguration
actually provide? Assuming the queue does involve multiple write operations
and ATOMIC does not imply isolation, would setting it to ATOMIC not impact
correctness?

Just wondering ...

Mateusz



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Transactional-adding-to-IgniteQueue-and-IgniteSet-tp6410p6414.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Transactional adding to IgniteQueue and IgniteSet

Posted by Denis Magda <dm...@gridgain.com>.
Hi Mateusz,

It’s not supported since IgniteSet/IgniteQueue operations are always executed in their own internal transaction. To my knowledge there are no plans to change this architectural design.

—
Denis

> On Jul 20, 2016, at 10:01 AM, mateusz <pa...@gmail.com> wrote:
> 
> Hello Ignite Users,
> 
> in
> https://apacheignite.readme.io/docs/queue-and-set#collection-configuration
> is stated, that the underlying cache for IgniteQueue can be transactional.
> Since the underlying cache is an implementation detail, I expected the
> IgniteQueue, configured with a transactional underlying cache, to be
> transactional itself. Unfortunately, this is not the case. 
> 
> I've added a test also using a IgniteCache as comparison (where a
> modification is rolled back) to the IgniteQueue (where a modification is not
> rolled back).
> 
> @Test
> public void transactionalAddToQueueCanBeRolledBack() throws Exception {
> 	// given
> 	Ignite ignite = Ignition.start();
> 
> 	CacheConfiguration<Integer, String> cacheConfig = new
> CacheConfiguration<>();
> 	cacheConfig.setName("cache" + System.currentTimeMillis());
> 	cacheConfig.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
> 	IgniteCache<Integer, String> cache = ignite.getOrCreateCache(cacheConfig);
> 
> 	CollectionConfiguration queueConfig = new CollectionConfiguration();
> 	queueConfig.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
> 	IgniteQueue<String> queue = ignite.queue("queue" +
> System.currentTimeMillis(), 0, queueConfig);
> 
> 	// when
> 	Transaction txStart =
> ignite.transactions().txStart(TransactionConcurrency.PESSIMISTIC,
> 			TransactionIsolation.SERIALIZABLE);
> 	cache.put(1, "foo");
> 	queue.add("foo");
> 	txStart.rollback();
> 
> 	// then
> 	assertEquals(0, cache.size());
> 	assertEquals(0, queue.size()); // AssertionError: expected: <0> but was:
> <1>
> }
> 
> The same happens using IgniteSet.
> 
> Is the adding supposed to be transactional in this case?
> 
> Kind regards
> Mateusz
> 
> 
> 
> 
> --
> View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Transactional-adding-to-IgniteQueue-and-IgniteSet-tp6410.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.