You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by "gordon.reid@ninemilefinancial" <go...@ninemilefinancial.com> on 2017/02/12 23:04:17 UTC

Grid Events and oldValue versus newValue

When updating entities in my cache, the oldValue=newValue in the event,
unless I do a put with the original object instance. This is of course not
always possible.

Here is a simplified example.

IgnitePredicate<CacheEvent> locLsnr = evt -> {
    // do something
};
ignite.events().localListen(locLsnr,EventType.EVT_CACHE_OBJECT_PUT);
IgniteCache<TradeKey, Trade> cache = ignite.getOrCreateCache("MyCache");

Trade trade1 = new Trade();
trade1.setId(1);
trade1.setSize(10);
cache.put(new TradeKey(trade.getId()), trade1); 
// event is generated
//evt.oldValue is null, no problem
trade1.setSize(20);
cache.put(new TradeKey(trade.getId()), trade1); 
// event is generated
// evt.oldValue().getSize() is 10, evt.newValue().getSize() is 20, this is
GOOD

But, if I retrieve the trade from the cache again before updating (from
another part of the application for example), I am not able to see what the
old value was in the event. Old value will just show the new value.

IgnitePredicate<CacheEvent> locLsnr = evt -> {
    // do something
};
ignite.events().localListen(locLsnr,EventType.EVT_CACHE_OBJECT_PUT);
IgniteCache<TradeKey, Trade> cache = ignite.getOrCreateCache("MyCache");

Trade trade1 = new Trade();
trade1.setId(1);
trade1.setSize(10);
cache.put(new TradeKey(trade.getId()), trade1); 
// event is generated
//evt.oldValue is null, no problem
trade1 = cache.get(new TradeKey(1)); // or could be a query or any search on
the cache
trade1.setSize(20);
cache.put(new TradeKey(trade.getId()),trade1); 
// event is generated
// evt.oldValue().getSize() is 20, evt.newValue().getSize() is 20, this is
BAD

Any advice? Thanks.



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Grid-Events-and-oldValue-versus-newValue-tp10577.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Grid Events and oldValue versus newValue

Posted by Andrey Mashenkov <an...@gmail.com>.
Hi Grodon,

I've made a reproducer, but it work fine for me on ignite-1.7 and
ignite-1.8.
Please, check if I missed smth in repro attached.


On Tue, Feb 14, 2017 at 10:13 AM, gordon.reid@ninemilefinancial <
gordon.reid@ninemilefinancial.com> wrote:

> Sure, thanks Andrey. Please see attached. I have removed some sections
> which aren’t relevant such as the service configuration. I have also
> attached my main class.
>
>
>
> Thanks,
>
> Gordon.
>
>
>
>
>
>
>
> *From:* Andrey Mashenkov [via Apache Ignite Users] [mailto:ml-node+[hidden
> email] <http:///user/SendEmail.jtp?type=node&node=10625&i=0>]
> *Sent:* Tuesday, 14 February 2017 4:07 PM
> *To:* Gordon Reid (Nine Mile) <[hidden email]
> <http:///user/SendEmail.jtp?type=node&node=10625&i=1>>
> *Subject:* Re: Grid Events and oldValue versus newValue
>
>
>
> Hi Gorgon,
>
>
>
> I can't reproduce your issue with default cache configuration on different
> Ignite versions.
>
> Would you please provide grid and cache configuration?
>
>
>
> On Tue, Feb 14, 2017 at 1:27 AM, [hidden email]
> <http:///user/SendEmail.jtp?type=node&node=10625&i=2> <[hidden email]
> <http:///user/SendEmail.jtp?type=node&node=10620&i=0>> wrote:
>
> Thanks for your reply Andrew.
>
> Actually I did not set copyOnRead manually. Based on your suggestion, I
> have
> now tried setting it manually to true, and then also to false. This does
> not
> seem to change the behavior in my case. I still am not able to see the
> previous state of the record on the oldValue property of the event.
>
>
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/Grid-Events-and-oldValue-versus-
> newValue-tp10577p10611.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>
>
>
>
> ------------------------------
>
> *If you reply to this email, your message will be added to the discussion
> below:*
>
> http://apache-ignite-users.70518.x6.nabble.com/Grid-
> Events-and-oldValue-versus-newValue-tp10577p10620.html
>
> To unsubscribe from Grid Events and oldValue versus newValue, click here.
> NAML
> <http://apache-ignite-users.70518.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
> *cache_reduced.xml* (7K) Download Attachment
> <http://apache-ignite-users.70518.x6.nabble.com/attachment/10625/0/cache_reduced.xml>
> *ServiceGrid.java* (5K) Download Attachment
> <http://apache-ignite-users.70518.x6.nabble.com/attachment/10625/1/ServiceGrid.java>
>
> ------------------------------
> View this message in context: RE: Grid Events and oldValue versus newValue
> <http://apache-ignite-users.70518.x6.nabble.com/Grid-Events-and-oldValue-versus-newValue-tp10577p10625.html>
>
> Sent from the Apache Ignite Users mailing list archive
> <http://apache-ignite-users.70518.x6.nabble.com/> at Nabble.com.
>



-- 
Best regards,
Andrey V. Mashenkov

RE: Grid Events and oldValue versus newValue

Posted by "gordon.reid@ninemilefinancial" <go...@ninemilefinancial.com>.
Sure, thanks Andrey. Please see attached. I have removed some sections which aren't relevant such as the service configuration. I have also attached my main class.

Thanks,
Gordon.



From: Andrey Mashenkov [via Apache Ignite Users] [mailto:ml-node+s70518n10620h53@n6.nabble.com]
Sent: Tuesday, 14 February 2017 4:07 PM
To: Gordon Reid (Nine Mile) <go...@ninemilefinancial.com>
Subject: Re: Grid Events and oldValue versus newValue

Hi Gorgon,

I can't reproduce your issue with default cache configuration on different Ignite versions.
Would you please provide grid and cache configuration?

On Tue, Feb 14, 2017 at 1:27 AM, gordon.reid@ninemilefinancial<ma...@ninemilefinancial> <[hidden email]</user/SendEmail.jtp?type=node&node=10620&i=0>> wrote:
Thanks for your reply Andrew.

Actually I did not set copyOnRead manually. Based on your suggestion, I have
now tried setting it manually to true, and then also to false. This does not
seem to change the behavior in my case. I still am not able to see the
previous state of the record on the oldValue property of the event.





--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Grid-Events-and-oldValue-versus-newValue-tp10577p10611.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.


________________________________
If you reply to this email, your message will be added to the discussion below:
http://apache-ignite-users.70518.x6.nabble.com/Grid-Events-and-oldValue-versus-newValue-tp10577p10620.html
To unsubscribe from Grid Events and oldValue versus newValue, click here<http://apache-ignite-users.70518.x6.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=10577&code=Z29yZG9uLnJlaWRAbmluZW1pbGVmaW5hbmNpYWwuY29tfDEwNTc3fDExMjY5NjAyOTI=>.
NAML<http://apache-ignite-users.70518.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>


cache_reduced.xml (7K) <http://apache-ignite-users.70518.x6.nabble.com/attachment/10625/0/cache_reduced.xml>
ServiceGrid.java (5K) <http://apache-ignite-users.70518.x6.nabble.com/attachment/10625/1/ServiceGrid.java>




--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Grid-Events-and-oldValue-versus-newValue-tp10577p10625.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Grid Events and oldValue versus newValue

Posted by Andrey Mashenkov <am...@gridgain.com>.
Hi Gorgon,

I can't reproduce your issue with default cache configuration on different
Ignite versions.
Would you please provide grid and cache configuration?

On Tue, Feb 14, 2017 at 1:27 AM, gordon.reid@ninemilefinancial <
gordon.reid@ninemilefinancial.com> wrote:

> Thanks for your reply Andrew.
>
> Actually I did not set copyOnRead manually. Based on your suggestion, I
> have
> now tried setting it manually to true, and then also to false. This does
> not
> seem to change the behavior in my case. I still am not able to see the
> previous state of the record on the oldValue property of the event.
>
>
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/Grid-Events-and-oldValue-versus-
> newValue-tp10577p10611.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Re: Grid Events and oldValue versus newValue

Posted by "gordon.reid@ninemilefinancial" <go...@ninemilefinancial.com>.
Thanks for your reply Andrew.

Actually I did not set copyOnRead manually. Based on your suggestion, I have
now tried setting it manually to true, and then also to false. This does not
seem to change the behavior in my case. I still am not able to see the
previous state of the record on the oldValue property of the event.





--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Grid-Events-and-oldValue-versus-newValue-tp10577p10611.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Grid Events and oldValue versus newValue

Posted by Andrey Mashenkov <an...@gmail.com>.
Hi Gordon,

It looks like you turn off CacheConfguration.copyOnRead that is true by
default [1].
In this case you update cached value directly bypassing Ignite.

[1]
http://apacheignite.gridgain.org/docs/performance-tips#do-not-copy-value-on-read


On Mon, Feb 13, 2017 at 2:04 AM, gordon.reid@ninemilefinancial <
gordon.reid@ninemilefinancial.com> wrote:

> When updating entities in my cache, the oldValue=newValue in the event,
> unless I do a put with the original object instance. This is of course not
> always possible.
>
> Here is a simplified example.
>
> IgnitePredicate<CacheEvent> locLsnr = evt -> {
>     // do something
> };
> ignite.events().localListen(locLsnr,EventType.EVT_CACHE_OBJECT_PUT);
> IgniteCache<TradeKey, Trade> cache = ignite.getOrCreateCache("MyCache");
>
> Trade trade1 = new Trade();
> trade1.setId(1);
> trade1.setSize(10);
> cache.put(new TradeKey(trade.getId()), trade1);
> // event is generated
> //evt.oldValue is null, no problem
> trade1.setSize(20);
> cache.put(new TradeKey(trade.getId()), trade1);
> // event is generated
> // evt.oldValue().getSize() is 10, evt.newValue().getSize() is 20, this is
> GOOD
>
> But, if I retrieve the trade from the cache again before updating (from
> another part of the application for example), I am not able to see what the
> old value was in the event. Old value will just show the new value.
>
> IgnitePredicate<CacheEvent> locLsnr = evt -> {
>     // do something
> };
> ignite.events().localListen(locLsnr,EventType.EVT_CACHE_OBJECT_PUT);
> IgniteCache<TradeKey, Trade> cache = ignite.getOrCreateCache("MyCache");
>
> Trade trade1 = new Trade();
> trade1.setId(1);
> trade1.setSize(10);
> cache.put(new TradeKey(trade.getId()), trade1);
> // event is generated
> //evt.oldValue is null, no problem
> trade1 = cache.get(new TradeKey(1)); // or could be a query or any search
> on
> the cache
> trade1.setSize(20);
> cache.put(new TradeKey(trade.getId()),trade1);
> // event is generated
> // evt.oldValue().getSize() is 20, evt.newValue().getSize() is 20, this is
> BAD
>
> Any advice? Thanks.
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/Grid-Events-and-oldValue-versus-newValue-tp10577.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>



-- 
Best regards,
Andrey V. Mashenkov