<div dir="ltr">What if we move the discussion to <a href="https://github.com/infinispan/infinispan-designs">https://github.com/infinispan/infinispan-designs</a> ?<div><br></div><div><br></div><div>Katia</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 6, 2017 at 11:04 AM, Radim Vansa <span dir="ltr">&lt;<a href="mailto:rvansa@redhat.com" target="_blank">rvansa@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 04/06/2017 12:15 AM, Katia Aresti wrote:<br>
&gt;<br>
&gt;<br>
&gt; On Wed, Apr 5, 2017 at 9:56 AM, Radim Vansa &lt;<a href="mailto:rvansa@redhat.com">rvansa@redhat.com</a><br>
</span><span class="">&gt; &lt;mailto:<a href="mailto:rvansa@redhat.com">rvansa@redhat.com</a>&gt;&gt; wrote:<br>
&gt;<br>
&gt;     On 04/04/2017 06:40 PM, William Burns wrote:<br>
&gt;     &gt;<br>
&gt;     &gt;<br>
&gt;     &gt; On Tue, Apr 4, 2017 at 11:45 AM Katia Aresti &lt;<a href="mailto:karesti@redhat.com">karesti@redhat.com</a><br>
&gt;     &lt;mailto:<a href="mailto:karesti@redhat.com">karesti@redhat.com</a>&gt;<br>
</span><div><div class="h5">&gt;     &gt; &lt;mailto:<a href="mailto:karesti@redhat.com">karesti@redhat.com</a> &lt;mailto:<a href="mailto:karesti@redhat.com">karesti@redhat.com</a>&gt;&gt;&gt; wrote:<br>
&gt;     &gt;<br>
&gt;     &gt;     Hi all,<br>
&gt;     &gt;<br>
&gt;     &gt;     As you probably know, Will and I are working on the vert-x<br>
&gt;     &gt;     infinispan integration [1], where the primary goal is to make<br>
&gt;     &gt;     infinispan the default cluster management of vert-x. (yeah!)<br>
&gt;     &gt;     Vert-x needs support for an Async Multimap. Today&#39;s<br>
&gt;     implementation<br>
&gt;     &gt;     is a wrapper on a normal Cache where only Cache Key&#39;s are<br>
&gt;     used to<br>
&gt;     &gt;     implement the multi map [2].<br>
&gt;     &gt;     This is not very efficient, so after trying some other<br>
&gt;     alternative<br>
&gt;     &gt;     implementations [3] that don&#39;t fully work (injection not<br>
&gt;     working),<br>
&gt;     &gt;     Will and I have come to the conclusion that it might be a good<br>
&gt;     &gt;     idea to start having our own native CacheMultimap. This first<br>
&gt;     &gt;     multimap won&#39;t support duplicate values on key&#39;s.<br>
&gt;     &gt;<br>
&gt;     &gt;     As a quick start, the smallest multimap we need should implement<br>
&gt;     &gt;     the following interface :<br>
&gt;     &gt;<br>
&gt;     &gt; I agree that having a very slim API to start should be better<br>
&gt;     since we<br>
&gt;     &gt; know how much trouble we get into implementing a very large API like<br>
&gt;     &gt; ConcurrentMap :)<br>
&gt;     &gt;<br>
&gt;     &gt;     public interface CacheMultimap&lt;K,V&gt; {<br>
&gt;     &gt;<br>
&gt;<br>
&gt;     I don&#39;t see anything async in this interface. If that&#39;s async, provide<br>
&gt;     CompletableFuture return values.<br>
&gt;     I am also considering if we want any fire &amp; forget variants for these<br>
&gt;     operations, but since we have to do retries to achieve consistency<br>
&gt;     (and<br>
&gt;     therefore we need some messages from owners to originator), I wouldn&#39;t<br>
&gt;     include them.<br>
&gt;<br>
&gt;<br>
&gt; Today&#39;s vert-x API calls the vertx.executeBlocking(future =&gt; cache...)<br>
&gt;<br>
&gt; I considered the option of CompletableFuture, but for simplicity I<br>
&gt; suggested the basic method.<br>
&gt; Today&#39;s CacheAPI makes a difference between &quot;put&quot; and &quot;putAsync&quot;.<br>
&gt; Would you call the interface CacheMultimapAsync or CacheMultimap with<br>
&gt; addAsyc method ?<br>
<br>
</div></div>&quot;In a perfect world, there will be no war or hunger, all APIs will be<br>
written asynchronously and bunny rabbits will skip hand-in-hand with<br>
baby lambs across sunny green meadows.&quot; (quoting Vert.x docs)<br>
<br>
While minimalistic API is a good way to start, it shouldn&#39;t contain<br>
anything we&#39;d want to get rid of in close future. And especially since<br>
the main drive for multimaps is Vert.x which consumes asynchronous APIs<br>
(and has support for legacy synchronous APIs, the executeBlocking<br>
method), we should have the design adapted to that from the beginning.<br>
<br>
CompletableFuture is not a rocket science, and you can use the already<br>
asynchronous Infinispan internals.<br>
<br>
I don&#39;t think we should have two interfaces, I believe that single<br>
interface with async methods only is absolutely sufficient. Though I<br>
wouldn&#39;t add the *Async suffix at all there. If someone wants to execute<br>
the methods synchronously he can call .get() or .join() - just 6/7<br>
characters more.<br>
<span class=""><br>
&gt;<br>
&gt;     &gt;         V put(K key,V value);<br>
&gt;     &gt;<br>
&gt;     &gt; This should probably return a boolean or Void. I am leaning towards<br>
&gt;     &gt; the first, but I am open either way.<br>
&gt;<br>
&gt;     I would rather call this &quot;add&quot;, as vert-x does. CompletableFuture as<br>
&gt;     return type here will allow to easily register the handler<br>
&gt;<br>
&gt;<br>
&gt; -1 I prefer keeping &quot;put&quot; name because it is still a Map and makes<br>
&gt; more sense to me considering the actual Cache API too. The return type<br>
&gt; V was a transcription mistake, it should be void for me, as Will<br>
&gt; pointed out.<br>
<br>
</span>To me &quot;put&quot; is linked with overwriting the previous value, while you add<br>
to the underlying collection or create a new single-element one. But<br>
whatever, I care more about the return values :)<br>
<br>
R.<br>
<div><div class="h5"><br>
&gt;<br>
&gt;<br>
&gt;     &gt;         Collection&lt;V&gt; get(K key);<br>
&gt;     &gt;<br>
&gt;     &gt;         boolean remove(K key,V value);<br>
&gt;     &gt;<br>
&gt;     &gt; We probably want a `boolean remove(K key)` method as well that<br>
&gt;     removes<br>
&gt;     &gt; all values mapped to the given key.<br>
&gt;<br>
&gt;     What about &quot;reset(key)&quot;?<br>
&gt;<br>
&gt;<br>
&gt;     &gt;     }<br>
&gt;     &gt;<br>
&gt;     &gt;     CacheMultimapImpl will be a wrapper on a normal Cache,<br>
&gt;     similar to [3].<br>
&gt;     &gt;<br>
&gt;     &gt;     We could add a new method in EmbeddedCacheManager.java<br>
&gt;     &gt;<br>
&gt;     &gt;     &lt;K, V&gt; CacheMultimap&lt;K, V&gt; getCacheMultimap(String cacheName,<br>
&gt;     &gt;     boolean createIfAbsent);<br>
&gt;     &gt;<br>
&gt;     &gt;<br>
&gt;     &gt; I was thinking maybe this would exist in a separate module<br>
&gt;     (outside of<br>
&gt;     &gt; core)? or class that wraps (similar to DistributedExecutor) instead.<br>
&gt;     &gt; My worry is about transactions, since the entry point to that is<br>
&gt;     &gt; through Cache interface. The other option is we could add a<br>
&gt;     `getCache`<br>
&gt;     &gt; method on the `CacheMultiMap`.<br>
&gt;<br>
&gt;     +1 Since the names of multimaps and maps will clash, we shouldn&#39;t hide<br>
&gt;     that the underlying implementation is a Cache, so I&#39;d suggest<br>
&gt;     something like<br>
&gt;<br>
&gt;     static &lt;K, V&gt; CacheMultimap&lt;K, V&gt; CacheMultimapFactory.get(<wbr>Cache&lt;K,<br>
&gt;     Object&gt; c) { ... }<br>
&gt;<br>
&gt;     &gt;<br>
&gt;     &gt;<br>
&gt;     &gt;     Implementation will create a cache as always and return a new<br>
&gt;     &gt;     CacheMultimapImpl(cache).<br>
&gt;     &gt;<br>
&gt;     &gt;     What do you think ? Please fell free to suggest any other<br>
&gt;     &gt;     alternative or idea.<br>
&gt;     &gt;<br>
&gt;     &gt;     Cheers<br>
&gt;     &gt;<br>
&gt;     &gt;     Katia<br>
&gt;     &gt;<br>
&gt;     &gt;     [1] <a href="https://github.com/vert-x3/vertx-infinispan" rel="noreferrer" target="_blank">https://github.com/vert-x3/<wbr>vertx-infinispan</a><br>
&gt;     &lt;<a href="https://github.com/vert-x3/vertx-infinispan" rel="noreferrer" target="_blank">https://github.com/vert-x3/<wbr>vertx-infinispan</a>&gt;<br>
&gt;     &gt;<br>
&gt;     &gt;     [2]<br>
&gt;     &gt;<br>
&gt;     <a href="https://github.com/vert-x3/vertx-infinispan/blob/master/src/main/java/io/vertx/ext/cluster/infinispan/impl/InfinispanAsyncMultiMap.java" rel="noreferrer" target="_blank">https://github.com/vert-x3/<wbr>vertx-infinispan/blob/master/<wbr>src/main/java/io/vertx/ext/<wbr>cluster/infinispan/impl/<wbr>InfinispanAsyncMultiMap.java</a><br>
&gt;     &lt;<a href="https://github.com/vert-x3/vertx-infinispan/blob/master/src/main/java/io/vertx/ext/cluster/infinispan/impl/InfinispanAsyncMultiMap.java" rel="noreferrer" target="_blank">https://github.com/vert-x3/<wbr>vertx-infinispan/blob/master/<wbr>src/main/java/io/vertx/ext/<wbr>cluster/infinispan/impl/<wbr>InfinispanAsyncMultiMap.java</a>&gt;<br>
&gt;     &gt;<br>
&gt;     &gt;     [3]<br>
&gt;     <a href="https://gist.github.com/karesti/194bb998856d4a2828d83754130ed79c" rel="noreferrer" target="_blank">https://gist.github.com/<wbr>karesti/<wbr>194bb998856d4a2828d83754130ed7<wbr>9c</a><br>
&gt;     &lt;<a href="https://gist.github.com/karesti/194bb998856d4a2828d83754130ed79c" rel="noreferrer" target="_blank">https://gist.github.com/<wbr>karesti/<wbr>194bb998856d4a2828d83754130ed7<wbr>9c</a>&gt;<br>
&gt;     &gt;     ______________________________<wbr>_________________<br>
&gt;     &gt;     infinispan-dev mailing list<br>
&gt;     &gt; <a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
&gt;     &lt;mailto:<a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.<wbr>jboss.org</a>&gt;<br>
</div></div>&gt;     &lt;mailto:<a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.<wbr>jboss.org</a><br>
<span class="">&gt;     &lt;mailto:<a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.<wbr>jboss.org</a>&gt;&gt;<br>
&gt;     &gt; <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/infinispan-<wbr>dev</a><br>
&gt;     &lt;<a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/infinispan-<wbr>dev</a>&gt;<br>
&gt;     &gt;<br>
&gt;     &gt;<br>
&gt;     &gt;<br>
&gt;     &gt; ______________________________<wbr>_________________<br>
&gt;     &gt; infinispan-dev mailing list<br>
&gt;     &gt; <a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
</span>&gt;     &lt;mailto:<a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.<wbr>jboss.org</a>&gt;<br>
&gt;     &gt; <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/infinispan-<wbr>dev</a><br>
&gt;     &lt;<a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/infinispan-<wbr>dev</a>&gt;<br>
&gt;<br>
&gt;<br>
&gt;     --<br>
&gt;     Radim Vansa &lt;<a href="mailto:rvansa@redhat.com">rvansa@redhat.com</a> &lt;mailto:<a href="mailto:rvansa@redhat.com">rvansa@redhat.com</a>&gt;&gt;<br>
<span class="">&gt;     JBoss Performance Team<br>
&gt;<br>
&gt;     ______________________________<wbr>_________________<br>
&gt;     infinispan-dev mailing list<br>
</span>&gt;     <a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.<wbr>jboss.org</a>&gt;<br>
&gt;     <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/infinispan-<wbr>dev</a><br>
<div class="HOEnZb"><div class="h5">&gt;     &lt;<a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/infinispan-<wbr>dev</a>&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; ______________________________<wbr>_________________<br>
&gt; infinispan-dev mailing list<br>
&gt; <a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/infinispan-<wbr>dev</a><br>
<br>
<br>
--<br>
Radim Vansa &lt;<a href="mailto:rvansa@redhat.com">rvansa@redhat.com</a>&gt;<br>
JBoss Performance Team<br>
<br>
______________________________<wbr>_________________<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" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/infinispan-<wbr>dev</a><br>
</div></div></blockquote></div><br></div>