<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 15, 2014 at 12:51 AM, Sanne Grinovero <span dir="ltr">&lt;<a href="mailto:sanne@infinispan.org" target="_blank">sanne@infinispan.org</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi all,<br>
I was toying with a custom CacheStore experiment, and am having some<br>
friction with some of the new SPIs.<br>
<br>
So interface org.infinispan.marshall.core.MarshalledEntryFactory&lt;K, V&gt;<br>
is an helper to use in the CacheStorei implementation, which exposes<br>
three methods:<br>
<br>
   MarshalledEntry&lt;K,V&gt; newMarshalledEntry(ByteBuffer key, ByteBuffer<br>
valueBytes, ByteBuffer metadataBytes);<br>
   MarshalledEntry&lt;K,V&gt; newMarshalledEntry(Object key, ByteBuffer<br>
valueBytes, ByteBuffer metadataBytes);<br>
   MarshalledEntry&lt;K,V&gt; newMarshalledEntry(Object key, Object value,<br>
InternalMetadata im);<br>
<br>
In my CacheStore - and I suspect most efficiency minded<br>
implementations - I don&#39;t care about the value Object but I express a<br>
specific physical layout for the metadata, so to run for example an<br>
efficient &quot;purge expired&quot; task.<br>
So, the key is given, the value Object needs to be serialized, but the<br>
InternalMetadata I can map to specific fields.<br>
<br>
Problem is at read time: I don&#39;t have a marshalled version of the<br>
Metadata but I need to unmarshall the value.. there is no helper to<br>
cover for this case.<br>
<br>
Wouldn&#39;t this interface be more practical if it had:<br>
<br>
Object unMarshallKey(ByteBuffer);<br>
Object unMarshallValue(ByteBuffer);<br>
InternalMetadata unMarshallMetadata(ByteBuffer);<br>
MarshalledEntry newMarshalledEntry(Object key, Object value,<br>
InternalMetadata im);<br></blockquote><div><br></div><div>I guess the idea was that MarshalledEntry unmarshalls the key, value, and metadata lazily. Even a purge listener may only be interested in the key, and in that case case we can avoid unmarshalling the value.</div>

<div><br></div><div>I think you can do what you want by stuffing the bytes for everything in the MarshalledEntry, and unmarshalling the data via MarshalledEntry.getMetadata().</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<br>
Also, I&#39;d get rid of generics. They are not helping at all, I can<br>
hardly couple my custom CacheStore implementation to the end user&#39;s<br>
domain model, right?<br></blockquote><div><br></div><div>I can see the user writing a custom JDBC store that stores the object&#39;s properties into separate columns and thus supporting a single type. But it&#39;s a pretty specialized case, and the user can very well do the casts himself.</div>

<div><br></div><div>Maybe Paul and Will have more stuff to add here, they been discussing about generics in the cache store SPIs around <a href="https://github.com/infinispan/infinispan/pull/2705">https://github.com/infinispan/infinispan/pull/2705</a></div>

<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
I was also quite surprised that other existing CacheStore<br>
implementations don&#39;t have this limitation; peeking in the<br>
JDBCCacheStore to see how this is supposed to work, it seems that<br>
essentially it duplicates the data by serializazing the<br>
InternalMetadata in the BLOB but also stored an Expiry column to query<br>
via SQL. I was interested to see how the Purge method could be<br>
implemented efficiently, and found a &quot;TODO notify listeners&quot; ;-)<br></blockquote><div><br></div><div>I believe the reason why we don&#39;t support purge listeners in the JDBC store is that we don&#39;t want to fetch the entries from the database at all. We can&#39;t ask CacheNotifier whether there are any listeners registered ATM, we need that to avoid the overhead when there are no listeners.</div>

<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
All other JDBC based stores serialize buckets in groups, REST store<br>
doesn&#39;t do purging, LevelDB also does duplication for the metadata,<br>
Cassandra is outdated and doesn&#39;t do events on expiry.<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>
</blockquote></div><br></div></div>