<div dir="ltr"><br><div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 28, 2013 at 1:56 PM, Manik Surtani <span dir="ltr"><<a href="mailto:msurtani@redhat.com" target="_blank">msurtani@redhat.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Let me clarify a few things on this thread. THere seems to be a bit of confusion here. :)<br>
<br>
storeAsBinary in Infinispan was designed with the following purposes in mind, in order of importance:<br>
<br>
1) Performance. Prevent serialising/deserializing an entry multiple times (e.g., to write through to disk, to replicate over the network, concurrent threads needing to read the object representation).<br>
<br></blockquote><div><br>TBH I don't think storeAsBinary as it works now is that good for
performance, because MarshalledValueInterceptor compacts keys/values
after every operation (see MarshalledValueInterceptor.java:320 and its
callers). Once a key/value is deserialized, its serialized form is
deleted, and it has to be serialized again if a remote node asks for it. <br><br>So it would save at most one serialization compared to storing the entries as references (and only if the entry also needs to be written to a cache store). Instead it adds a bit of overhead on each operation to keep track of the marshalled value status.<br>
<div class="gmail_extra"><br></div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
2) Classloader isolation (as Galder mentioned). This became a secondary purpose of this feature (originally observed as a side-effect). Enhanced by allowing storeKeyAsBinary and storeValueAsBinary options for more fine-grained control of this behaviour.<br>
<br></blockquote><div><br></div><div>I'd say this has become the reason most people use this feature now, even though a regular cache should work fine in AS7 there are still other environments where it is needed.<br>
<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Now lets consider what JSR 107 needs. Similarly named, the feature in JSR 107 serves a completely different purpose, and this is referential integrity. Think database-style isolation (repeatable read, etc) where concurrent threads holding object references to the same value, and mutating the same value, are not visible until a commit.<br>
<br>
I originally thought that Infinispan's storeAsBinary can be used for this, but apparently not without some additional changes/tweaks. Maybe we need:<br>
<br>
1) A new config option for this behaviour. <storeAsBinary defensive="true" /> ?<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
2) If enabled, maybe use a subclass of MarshalledValue (DefensiveMarshalledValue?) that *always* stores a byte[] and never caches the object representation?<br>
<br></blockquote><div><br></div><div>I think we'd still need to cache the object instance while the command is executing, otherwise we'll have too many deserializations. But perhaps the new setting could control whether MarshalledValueInterceptor calls MarshalledValue.compact with preferSerializedRepresentation == true instead of false, as it does now.<br>
<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
What do you think?<br>
<br>
Cheers<br>
<span class=""><font color="#888888">Manik<br>
</font></span><div class=""><div class="h5"><br>
On 28 Jan 2013, at 10:00, Sanne Grinovero <<a href="mailto:sanne@infinispan.org">sanne@infinispan.org</a>> wrote:<br>
<br>
> I remember Manik and me pair-programming on that class to simplify it<br>
> a bit - especially as there are some performance complexities - but we<br>
> ended up not touching it as any change would have violated some<br>
> expectations of one feature or another.<br>
><br>
> Let's put this on the list of cleanups to be performed for 6.0?<br>
><br>
> On 28 January 2013 09:14, Galder Zamarreño <<a href="mailto:galder@redhat.com">galder@redhat.com</a>> wrote:<br>
>><br>
>> On Jan 25, 2013, at 11:37 AM, Sanne Grinovero <<a href="mailto:sanne@infinispan.org">sanne@infinispan.org</a>> wrote:<br>
>><br>
>>> On 25 January 2013 11:11, Galder Zamarreño <<a href="mailto:galder@redhat.com">galder@redhat.com</a>> wrote:<br>
>>>><br>
>>>> On Jan 24, 2013, at 4:26 PM, Sanne Grinovero <<a href="mailto:sanne@infinispan.org">sanne@infinispan.org</a>> wrote:<br>
>>>><br>
>>>>> It's important to note that Infinispan's implementation of storing as<br>
>>>>> binary isn't guaranteeing different instances of objects are returned<br>
>>>>> to different get() invocations (especially when they happen in<br>
>>>>> parallel).<br>
>>>><br>
>>>> ^ Do you have a test for this?<br>
>>><br>
>>> No, it's self-evident by reading the code. I'd venture saying it's a<br>
>>> design choice: the option was not designed to provide isolation,<br>
>>> people should not abuse of it for a different purpose.<br>
>>><br>
>>>> Could this be related to the fact that a get(), unless it had received that entry from another node, will held as reference?<br>
>>>><br>
>>>> It'd be interesting if that test works if after a put() you call compact()...<br>
>>>><br>
>>>>> This is the reason for example that Hibernate OGM can't use this flag<br>
>>>>> to have safe and independent instances, but needs to make defensive<br>
>>>>> copies if returned values. As I read in your first post, you want to<br>
>>>>> use this for defensive copies: that doesn't work, especially if the<br>
>>>>> TCK is performing concurrent requests.<br>
>>>><br>
>>>> ^ As I said, the storeAsBinary feature is heavily optimised for performance, hence why it initially keeps instances as references, so that if another thread requests the entry soon later, a reference is sent back (no need to serialize/deserialize the entry just put)<br>
>>><br>
>>> As you say "the reference is sent back", even if it's the same<br>
>>> instance as a previous request. I have no doubt that's for performance<br>
>>> reasons: I patched that code myself and have carefully kept that<br>
>>> "feature" of instance reuse available.<br>
>>> I'm not sure it can provide much of a benefit generally speaking, but<br>
>>> this has always been like that and I guess there could be specific<br>
>>> access patterns in which this is very useful.<br>
>><br>
>> The reason we have storeAsBinary is due to lazyDeserialization. The latter was a solution we designed to get around deserialization issues on app server environments where JGroups would attempt to deserialize data with the wrong classloader.<br>
>><br>
>> The idea at the time was that deserialization would be delayed until a thread with the correct classloader in context would come and deserialize data, hence the name: lazy deserialization. This was needed in AS4/5/6.<br>
>><br>
>> The design has always been the same, make sure data is kept in binary format in the receiver and only deserialize when needed.<br>
>><br>
>> This lazy deserialization is no longer needed in AS7 cos a particular plugin is set in JBoss Marshaller which adds modular classloader info to serialized data. So, when data arrives in the receiver, it can be deserialized directly cos the classloader info allows for the correct classloader to be found.<br>
>><br>
>> The naming change of lazyDeserialization to storeAsBinary was on purpouse and precisely with the aim of it becoming a way to provide store-as-value capabilities. The problem is that as you and Vladimir have spotted, this doesn't really work like that.<br>
>><br>
>>><br>
>>> Cheers,<br>
>>> Sanne<br>
>>><br>
>>>><br>
>>>>><br>
>>>>><br>
>>>>><br>
>>>>> On 24 January 2013 16:09, Manik Surtani <<a href="mailto:manik@jboss.org">manik@jboss.org</a>> wrote:<br>
>>>>>><br>
>>>>>> On 24 Jan 2013, at 15:39, Vladimir Blagojevic <<a href="mailto:vblagoje@redhat.com">vblagoje@redhat.com</a>> wrote:<br>
>>>>>><br>
>>>>>>> No valid reason Manik. In summary I thought I would have gotten our keys/values serialized even in local VM if I turn on storeAsBinary but that does not seem to be the case.<br>
>>>>>><br>
>>>>>> Is it not? Perhaps it is only serialised the first time a serial form is necessary. You can get around this by calling compact()<br>
>>>>>><br>
>>>>>> <a href="http://docs.jboss.org/infinispan/5.1/apidocs/org/infinispan/Cache.html#compact()" target="_blank">http://docs.jboss.org/infinispan/5.1/apidocs/org/infinispan/Cache.html#compact()</a><br>
>>>>>><br>
>>>>>> But this definitely isn't the most optimal way of doing things. Perhaps a new config option for eager serialisation might be necessary, but for now calling compact() should work.<br>
>>>>>><br>
>>>>>>> I need to use storeAsBinary to complete a feature of JSR 107 that allows storing of key/value pairs as serialized values rather than simple references.<br>
>>>>>><br>
>>>>>> Yup, I realise.<br>
>>>>>><br>
>>>>>>><br>
>>>>>>> TBH, I am not sure how can we do this given mechanisms we have in place. I would have to implement serialization/deserialization in our jsr 107 project but that would be a wrong path if we can somehow turn on our own existing storeAsBinary for in VM stored objects (see Galder's email on what is currently done)<br>
>>>>>>><br>
>>>>>>><br>
>>>>>>> Regards,<br>
>>>>>>> Vladimir<br>
>>>>>>> On 13-01-24 7:09 AM, Manik Surtani wrote:<br>
>>>>>>>> JSR 107's storeAsBinary and our storeAsBinary are conceptually the same. You get a defensive copy and this should work.<br>
>>>>>>>><br>
>>>>>>>> But see my comment below:<br>
>>>>>>>><br>
>>>>>>>> Also adding Mircea in cc. Any reason why you're not using infinispan-dev for this?<br>
>>>>>>>><br>
>>>>>>>> On 24 Jan 2013, at 12:00, Galder Zamarreño <<a href="mailto:galder@redhat.com">galder@redhat.com</a>> wrote:<br>
>>>>>>>><br>
>>>>>>>>> Hey Vladimir,<br>
>>>>>>>>><br>
>>>>>>>>> IIRC, for performance reasons, even with storeAsBinary, Infinispan keeps the data as normal instance locally. When data is serialized and sent to other nodes, again for performance reasons, it keeps it as raw or byte[] format.<br>
>>>>>>>>><br>
>>>>>>>>> So, storing objects by value only happens in counted occassions when storeAsBinary is enabled.<br>
>>>>>>>>><br>
>>>>>>>>> You can track it by using a debugger and see how the the MarshalledValue instances are created.<br>
>>>>>>>>><br>
>>>>>>>>> Not sure how to fix this without some extra configuration option.<br>
>>>>>>>>><br>
>>>>>>>>> Cheers,<br>
>>>>>>>>><br>
>>>>>>>>> On Jan 23, 2013, at 5:38 PM, Vladimir Blagojevic <<a href="mailto:vblagoje@redhat.com">vblagoje@redhat.com</a>> wrote:<br>
>>>>>>>>><br>
>>>>>>>>>> Galder,<br>
>>>>>>>>>><br>
>>>>>>>>>> A quick search of help from you beacuse you are more familiar with this area (storeAsBinary) than I am. There is a tck test that checks storing of objects by value not by reference in the cache [1]. I thought that if we set our underlying cache to be storeAsBinary we would handle this tck requirement (store by value if neeed rather than by reference). However, StoreByValueTest fails although I set our underlying Infinispan cache to be storeAsBinary. I am using local cache athough I tried with transport and dist_async setup as well - same result. Any ideas what is going on?<br>
>>>>>>>>>><br>
>>>>>>>>>> Have a look at the test [1] , result I get are below:<br>
>>>>>>>>>><br>
>>>>>>>>>><br>
>>>>>>>>>> -------------------------------------------------------<br>
>>>>>>>>>> Running org.jsr107.tck.StoreByValueTest<br>
>>>>>>>>>> Jan 23, 2013 12:35:29 PM org.jsr107.tck.util.ExcludeList <init><br>
>>>>>>>>>> INFO: ===== ExcludeList url=file:/Users/vladimir/workspace/jsr107/jsr107tck/implementation-tester/target/test-classes/ExcludeList<br>
>>>>>>>>>> Defined org.jsr107.tck.StoreByValueTest config StoreAsBinaryConfiguration{enabled=true, storeKeysAsBinary=true, storeValuesAsBinary=true}<br>
>>>>>>>>>> Tests run: 6, Failures: 6, Errors: 0, Skipped: 0, Time elapsed: 21.852 sec <<< FAILURE!<br>
>>>>>>>>>><br>
>>>>>>>>>> Results :<br>
>>>>>>>>>><br>
>>>>>>>>>> Failed tests: get_Existing_MutateValue(org.jsr107.tck.StoreByValueTest): expected: java.util.Date<Wed Jan 23 12:35:34 EST 2013> but was: java.util.Date<Wed Jan 23 12:35:34 EST 2013><br>
>>>>>>>> ?? These seem the same to me? How is the TCK testing for these two values? By reference? Or using .equals()?<br>
>>>>>>>><br>
>>>>>>>>>> get_Existing_MutateKey(org.jsr107.tck.StoreByValueTest): expected:<Wed Jan 23 12:35:38 EST 2013> but was:<null><br>
>>>>>>>> This seems a bigger issue. You might want to look at Infinispan logs here?<br>
>>>>>>>><br>
>>>>>>>>>> getAndPut_NotThere(org.jsr107.tck.StoreByValueTest): expected: java.util.Date<Wed Jan 23 12:35:41 EST 2013> but was: java.util.Date<Wed Jan 23 12:35:41 EST 2013><br>
>>>>>>>> Again, see my first comment.<br>
>>>>>>>><br>
>>>>>>>>>> getAndPut_Existing_MutateValue(org.jsr107.tck.StoreByValueTest): expected: java.util.Date<Wed Jan 23 12:35:45 EST 2013> but was: java.util.Date<Wed Jan 23 12:35:45 EST 2013><br>
>>>>>>>> Again, see my first comment.<br>
>>>>>>>><br>
>>>>>>>>>> getAndPut_Existing_NonSameKey_MutateValue(org.jsr107.tck.StoreByValueTest): expected: java.util.Date<Wed Jan 23 12:35:48 EST 2013> but was: java.util.Date<Wed Jan 23 12:35:48 EST 2013><br>
>>>>>>>> Again, see my first comment.<br>
>>>>>>>><br>
>>>>>>>>>> getAndPut_Existing_NonSameKey_MutateKey(org.jsr107.tck.StoreByValueTest): expected:<Wed Jan 23 12:35:51 EST 2013> but was:<null><br>
>>>>>>>>>><br>
>>>>>>>>>> Tests run: 6, Failures: 6, Errors: 0, Skipped: 0<br>
>>>>>>>>>><br>
>>>>>>>>>> [1] <a href="https://github.com/jsr107/jsr107tck/blob/master/cache-tests/src/test/java/org/jsr107/tck/StoreByValueTest.java" target="_blank">https://github.com/jsr107/jsr107tck/blob/master/cache-tests/src/test/java/org/jsr107/tck/StoreByValueTest.java</a><br>
>>>>>>>>><br>
>>>>>>>>> --<br>
>>>>>>>>> Galder Zamarreño<br>
>>>>>>>>> <a href="mailto:galder@redhat.com">galder@redhat.com</a><br>
>>>>>>>>> <a href="http://twitter.com/galderz" target="_blank">twitter.com/galderz</a><br>
>>>>>>>>><br>
>>>>>>>>> Project Lead, Escalante<br>
>>>>>>>>> <a href="http://escalante.io" target="_blank">http://escalante.io</a><br>
>>>>>>>>><br>
>>>>>>>>> Engineer, Infinispan<br>
>>>>>>>>> <a href="http://infinispan.org" target="_blank">http://infinispan.org</a><br>
>>>>>>>>><br>
>>>>>>>> --<br>
>>>>>>>> Manik Surtani<br>
>>>>>>>> <a href="mailto:manik@jboss.org">manik@jboss.org</a><br>
>>>>>>>> <a href="http://twitter.com/maniksurtani" target="_blank">twitter.com/maniksurtani</a><br>
>>>>>>>><br>
>>>>>>>> Platform Architect, JBoss Data Grid<br>
>>>>>>>> <a href="http://red.ht/data-grid" target="_blank">http://red.ht/data-grid</a><br>
>>>>>>>><br>
>>>>>>><br>
>>>>>><br>
>>>>>> --<br>
>>>>>> Manik Surtani<br>
>>>>>> <a href="mailto:manik@jboss.org">manik@jboss.org</a><br>
>>>>>> <a href="http://twitter.com/maniksurtani" target="_blank">twitter.com/maniksurtani</a><br>
>>>>>><br>
>>>>>> Platform Architect, JBoss Data Grid<br>
>>>>>> <a href="http://red.ht/data-grid" target="_blank">http://red.ht/data-grid</a><br>
>>>>>><br>
>>>>>><br>
>>>>>> _______________________________________________<br>
>>>>>> infinispan-dev mailing list<br>
>>>>>> <a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
>>>>>> <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
>>>>><br>
>>>>> _______________________________________________<br>
>>>>> infinispan-dev mailing list<br>
>>>>> <a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
>>>>> <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
>>>><br>
>>>><br>
>>>> --<br>
>>>> Galder Zamarreño<br>
>>>> <a href="mailto:galder@redhat.com">galder@redhat.com</a><br>
>>>> <a href="http://twitter.com/galderz" target="_blank">twitter.com/galderz</a><br>
>>>><br>
>>>> Project Lead, Escalante<br>
>>>> <a href="http://escalante.io" target="_blank">http://escalante.io</a><br>
>>>><br>
>>>> Engineer, Infinispan<br>
>>>> <a href="http://infinispan.org" target="_blank">http://infinispan.org</a><br>
>>>><br>
>>>><br>
>>>> _______________________________________________<br>
>>>> infinispan-dev mailing list<br>
>>>> <a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
>>>> <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
>>><br>
>>> _______________________________________________<br>
>>> infinispan-dev mailing list<br>
>>> <a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
>>> <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
>><br>
>><br>
>> --<br>
>> Galder Zamarreño<br>
>> <a href="mailto:galder@redhat.com">galder@redhat.com</a><br>
>> <a href="http://twitter.com/galderz" target="_blank">twitter.com/galderz</a><br>
>><br>
>> Project Lead, Escalante<br>
>> <a href="http://escalante.io" target="_blank">http://escalante.io</a><br>
>><br>
>> Engineer, Infinispan<br>
>> <a href="http://infinispan.org" target="_blank">http://infinispan.org</a><br>
>><br>
>><br>
>> _______________________________________________<br>
>> infinispan-dev mailing list<br>
>> <a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
>> <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
><br>
> _______________________________________________<br>
> infinispan-dev mailing list<br>
> <a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
<br>
--<br>
Manik Surtani<br>
<a href="mailto:manik@jboss.org">manik@jboss.org</a><br>
<a href="http://twitter.com/maniksurtani" target="_blank">twitter.com/maniksurtani</a><br>
<br>
Platform Architect, JBoss Data Grid<br>
<a href="http://red.ht/data-grid" target="_blank">http://red.ht/data-grid</a><br>
<br>
<br>
_______________________________________________<br>
infinispan-dev mailing list<br>
<a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
</div></div></blockquote></div><br></div></div></div>