<div dir="ltr">Adrian, I don&#39;t think that will work. The Hash doesn&#39;t know the number of segments so it can&#39;t tell where a particular key will land - even assuming knowledge about how the ConsistentHash will map hash codes to segments.<div><br></div><div>However, I&#39;m all for replacing the current Hash interface with another interface that maps keys directly to segments.</div><div><br></div><div>Cheers</div><div>Dan</div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 20, 2015 at 4:08 AM, Adrian Nistor <span dir="ltr">&lt;<a href="mailto:anistor@redhat.com" target="_blank">anistor@redhat.com</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 Sanne,<br>
<br>
An alternative approach would be to implement an<br>
org.infinispan.commons.hash.Hash which delegates to the stock<br>
implementation for all keys except those that need to be assigned to a<br>
specific segment. It should return the desired segment for those.<br>
<span class=""><font color="#888888"><br>
Adrian<br>
</font></span><div class=""><div class="h5"><br>
<br>
On 01/20/2015 02:48 AM, Sanne Grinovero wrote:<br>
&gt; Hi all,<br>
&gt;<br>
&gt; I&#39;m playing with an idea for some internal components to be able to<br>
&gt; &quot;tag&quot; the key for an entry to be stored into Infinispan in a very<br>
&gt; specific segment of the CH.<br>
&gt;<br>
&gt; Conceptually the plan is easy to understand by looking at this patch:<br>
&gt;<br>
&gt; <a href="https://github.com/Sanne/infinispan/commit/45a3d9e62318d5f5f950a60b5bb174d23037335f" target="_blank">https://github.com/Sanne/infinispan/commit/45a3d9e62318d5f5f950a60b5bb174d23037335f</a><br>
&gt;<br>
&gt; Hacking the change into ReplicatedConsistentHash is quite barbaric,<br>
&gt; please bear with me as I couldn&#39;t figure a better way to be able to<br>
&gt; experiment with this. I&#39;ll probably want to extend this class, but<br>
&gt; then I&#39;m not sure how to plug it in?<br></div></div></blockquote><div><br></div><div>You would need to create your own ConsistentHashFactory, possibly extending ReplicatedConsistentHashFactory. You can then plug the factory in with </div><div><br></div><div>configurationBuilder.clustering().hash().consistentHashFactory(yourFactory)</div><div><br></div><div>However, this isn&#39;t a really good idea, because then you need a different implementation for distributed mode, and then another implementation for topology-aware clusters (with rack/machine/site ids). And your users would also need to select the proper factory for each cache.</div><div> </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"><div class=""><div class="h5">
&gt;<br>
&gt; What would you all think of such a &quot;tagging&quot; mechanism?<br>
&gt;<br>
&gt; # Why I didn&#39;t use the KeyAffinityService<br>
&gt; - I need to use my own keys, not the meaningless stuff produced by the service<br>
&gt; - the extensive usage of Random in there doesn&#39;t seem suited for a<br>
&gt; performance critical path</div></div></blockquote><div><br></div><div>You can plug in your own KeyGenerator to generate keys, and maybe replace the Random with a static/thread-local counter.</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"><div class=""><div class="h5"><span style="color:rgb(34,34,34)"> </span></div></div></blockquote><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"><div class=""><div class="h5">
&gt;<br>
&gt; # Why I didn&#39;t use the Grouping API<br>
&gt; - I need to pick the specific storage segment, not just co-locate with<br>
&gt; a different key<br>
&gt;<br></div></div></blockquote><div><br></div><div>This is actually a drawback of the KeyAffinityService more than Grouping. With grouping, you can actually follow the KeyAffinityService strategy and generate random strings until you get one in the proper segment, and then tag all your keys with that exact string.</div><div> </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"><div class=""><div class="h5">
&gt;<br>
&gt; The general goal is to make it possible to &quot;tag&quot; all entries of an<br>
&gt; index, and have an independent index for each segment of the CH. So<br>
&gt; the resulting effect would be, that when a primary owner for any key K<br>
&gt; is making an update, and this triggers an index update, that update is<br>
&gt;   A) going to happen on the same node -&gt; no need to forwarding to a<br>
&gt; &quot;master indexing node&quot;<br>
&gt;   B) each such writes on the index happen on the same node which is<br>
&gt; primary owner for all the written entries of the index.<br>
&gt;<br>
&gt; There are two additional nice consequences:<br>
&gt;   - there would be no need to perform a reliable &quot;master election&quot;:<br>
&gt; ownership singleton is already guaranteed by Infinispan&#39;s essential<br>
&gt; logic, so it would reuse that<br>
&gt;   - the propagation of writes on the index from the primary owner<br>
&gt; (which is the local node by definition) to backup owners could use<br>
&gt; REPL_ASYNC for most practical use cases.<br>
&gt;<br>
&gt; So net result is that the overhead for indexing is reduced to 0 (ZERO)<br>
&gt; blocking RPCs if the async repl is acceptable, or to only one blocking<br>
&gt; roundtrip if very strict consistency is required.<br></div></div></blockquote><div><br></div><div>Sounds very interesting, but I think there may be a problem with your strategy: Infinispan doesn&#39;t guarantee you that one of the nodes executing the CommitCommand is the primary owner at the time the CommitCommand is executed. You could have something like this:</div><div><br></div><div>Cluster [A, B, C, D], key k, owners(k) = [A, B] (A is primary)</div><div>C initiates a tx that executes put(k, v)</div><div>Tx prepare succeeds on A and B</div><div>A crashes, but the other nodes don&#39;t detect the crash yet</div><div>Tx commit succeeds on B, who still thinks is a backup owner</div><div>B detects the crash, installs a new cluster view consistent hash with owners(k) = [B]</div><div><br></div><div> </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"><div class=""><div class="h5">
&gt;<br>
&gt; Thanks,<br>
&gt; Sanne<br>
&gt; _______________________________________________<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" 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>
</div></div></blockquote></div><br></div></div>