A Question About Behavior

classic Classic list List threaded Threaded
7 messages Options
Kevin Daly Kevin Daly
Reply | Threaded
Open this post in threaded view
|

A Question About Behavior

Working with an ignite cache and I leave the H2 Debug window open while I'm working.. So what I have noticed happening is that when I change values in an object, this is IMMEDIATELY changed in the H2 Database window, even if I start a transaction.. Should this happen only when I get and put a value into the cache.. Should the objects not be "detached"? So the question is how does this work? How would i control concurrency if multiple threads are accessing the Cache?
Kevin Daly Kevin Daly
Reply | Threaded
Open this post in threaded view
|

Re: A Question About Behavior

To expand on this is seems that if I use a QueryCursor to return the values and I manipulate them, the H2 Database's value and indexes are changed.. But If I pull the value out of the cache..

So changing values returned by a QueryCursor will cause the H2 index to be changed?
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: A Question About Behavior

In reply to this post by Kevin Daly
Hi Kevin,

It's strongly recommended that you don't mutate the instance that is already in cache. It can cause all different types of concurrency issues (for example, if it's concurrently serialized).

Actually, by default cache should create a copy each time you read the value. Did you set CacheConfiguration.copyOnRead property to false? If no, this can be a bug, please provide details on how you read from cache (code sample would be very useful as well).

In any case, you can always manually create a copy before doing modifications. This should fix the behavior.

-Val
Kevin Daly Kevin Daly
Reply | Threaded
Open this post in threaded view
|

Re: A Question About Behavior

I think this is a bug..

I have meetings most of today.. I will definitely get you a code Sample..

copyOnRead is set to true.

Will work around it and try to get you code examples later today..

Basically this is easy to re-produce though, all you have to do is do a query and pull an object out of the QueryCursor and change it while watching the H2Debug window.. You'll see the values in H2 change immediately.

Will update later with code/
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: A Question About Behavior

Kevin,

Got it. I will try to reproduce it myself as well.

-Val
Kevin Daly Kevin Daly
Reply | Threaded
Open this post in threaded view
|

Re: A Question About Behavior

We were directly Manipulating the Cache.Entry<KEY,VALUE> and it was reflecting directly in the H2 Indexes.. Not sure if it's desired behavior or not.. But a definite Gotcha....

To fix this we just call VALUE = ingintecache.get(KEY) to retrieve the value rather than getting it directly from the entry (VALUE = entry.getValue();

I still owe you some code :)

Just been pegged I will revisit this this week..
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: A Question About Behavior

Hi Kevin,

I reproduced the issue and create a ticket [1]. It will be fixed soon.

[1] https://issues.apache.org/jira/browse/IGNITE-2795

-Val