<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"><<a href="mailto:sanne@infinispan.org" target="_blank">sanne@infinispan.org</a>></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<K, V><br>
is an helper to use in the CacheStorei implementation, which exposes<br>
three methods:<br>
<br>
MarshalledEntry<K,V> newMarshalledEntry(ByteBuffer key, ByteBuffer<br>
valueBytes, ByteBuffer metadataBytes);<br>
MarshalledEntry<K,V> newMarshalledEntry(Object key, ByteBuffer<br>
valueBytes, ByteBuffer metadataBytes);<br>
MarshalledEntry<K,V> newMarshalledEntry(Object key, Object value,<br>
InternalMetadata im);<br>
<br>
In my CacheStore - and I suspect most efficiency minded<br>
implementations - I don'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 "purge expired" 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'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'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'd get rid of generics. They are not helping at all, I can<br>
hardly couple my custom CacheStore implementation to the end user'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's properties into separate columns and thus supporting a single type. But it'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'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 "TODO notify listeners" ;-)<br></blockquote><div><br></div><div>I believe the reason why we don't support purge listeners in the JDBC store is that we don't want to fetch the entries from the database at all. We can'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't do purging, LevelDB also does duplication for the metadata,<br>
Cassandra is outdated and doesn'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>