Quantcast

Grid Events and oldValue versus newValue

classic Classic list List threaded Threaded
6 messages Options
gordon.reid@ninemilefinancial gordon.reid@ninemilefinancial
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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.
Andrew Mashenkov Andrew Mashenkov
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grid Events and oldValue versus newValue

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.



On Mon, Feb 13, 2017 at 2:04 AM, gordon.reid@ninemilefinancial <[hidden email]> 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
Regards, Andrew.
gordon.reid@ninemilefinancial gordon.reid@ninemilefinancial
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grid Events and oldValue versus newValue

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.

Andrey Mashenkov Andrey Mashenkov
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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 <[hidden email]> 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.

gordon.reid@ninemilefinancial gordon.reid@ninemilefinancial
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Grid Events and oldValue versus newValue

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]]
Sent: Tuesday, 14 February 2017 4:07 PM
To: Gordon Reid (Nine Mile) <[hidden email]>
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] <[hidden email]> 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


cache_reduced.xml (7K) Download Attachment
ServiceGrid.java (5K) Download Attachment
Andrew Mashenkov Andrew Mashenkov
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grid Events and oldValue versus newValue

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 <[hidden email]> 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:[hidden email][hidden email]]
Sent: Tuesday, 14 February 2017 4:07 PM
To: Gordon Reid (Nine Mile) <[hidden email]>
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] <[hidden email]> 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


cache_reduced.xml (7K) Download Attachment
ServiceGrid.java (5K) Download Attachment


View this message in context: RE: Grid Events and oldValue versus newValue

Sent from the Apache Ignite Users mailing list archive at Nabble.com.



--
Best regards,
Andrey V. Mashenkov

PutEventsTest.java (6K) Download Attachment
Regards, Andrew.
Loading...