blob: 0e74839967d029cd4e06419fdd092f7bd0ca9901 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_291) on Mon Jan 10 11:05:25 MSK 2022 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>AffinityFunction (Ignite 2.12.0)</title>
<meta name="date" content="2022-01-10">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
<link rel='shortcut icon' href='https://ignite.apache.org/favicon.ico'/>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="AffinityFunction (Ignite 2.12.0)";
}
}
catch(err) {
}
//-->
var methods = {"i0":6,"i1":6,"i2":6,"i3":6,"i4":6};
var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],4:["t3","Abstract Methods"]};
var altColor = "altColor";
var rowColor = "rowColor";
var tableTab = "tableTab";
var activeTableTab = "activeTableTab";
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar.top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.top.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/AffinityFunction.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../org/apache/ignite/cache/affinity/AffinityCentralizedFunction.html" title="annotation in org.apache.ignite.cache.affinity"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../../org/apache/ignite/cache/affinity/AffinityFunctionContext.html" title="interface in org.apache.ignite.cache.affinity"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/apache/ignite/cache/affinity/AffinityFunction.html" target="_top">Frames</a></li>
<li><a href="AffinityFunction.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a name="skip.navbar.top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">org.apache.ignite.cache.affinity</div>
<h2 title="Interface AffinityFunction" class="title">Interface AffinityFunction</h2>
</div>
<div class="contentContainer">
<div class="description">
<ul class="blockList">
<li class="blockList">
<dl>
<dt>All Superinterfaces:</dt>
<dd><a href="https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html?is-external=true" title="class or interface in java.io">Serializable</a></dd>
</dl>
<dl>
<dt>All Known Implementing Classes:</dt>
<dd><a href="../../../../../org/apache/ignite/ml/dataset/impl/cache/util/DatasetAffinityFunctionWrapper.html" title="class in org.apache.ignite.ml.dataset.impl.cache.util">DatasetAffinityFunctionWrapper</a>, <a href="../../../../../org/apache/ignite/platform/dotnet/PlatformDotNetAffinityFunction.html" title="class in org.apache.ignite.platform.dotnet">PlatformDotNetAffinityFunction</a>, <a href="../../../../../org/apache/ignite/cache/affinity/rendezvous/RendezvousAffinityFunction.html" title="class in org.apache.ignite.cache.affinity.rendezvous">RendezvousAffinityFunction</a></dd>
</dl>
<hr>
<br>
<pre>public interface <span class="typeNameLabel">AffinityFunction</span>
extends <a href="https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html?is-external=true" title="class or interface in java.io">Serializable</a></pre>
<div class="block">Cache key affinity which maps keys to nodes. This interface is utilized for
both, replicated and partitioned caches. Cache affinity can be configured
for individual caches via <a href="../../../../../org/apache/ignite/configuration/CacheConfiguration.html#getAffinity--"><code>CacheConfiguration.getAffinity()</code></a> method.
<p>
Whenever a key is given to cache, it is first passed to a pluggable
<a href="../../../../../org/apache/ignite/cache/affinity/AffinityKeyMapper.html" title="interface in org.apache.ignite.cache.affinity"><code>AffinityKeyMapper</code></a> which may potentially map this key to an alternate
key which should be used for affinity. The key returned from
<a href="../../../../../org/apache/ignite/cache/affinity/AffinityKeyMapper.html#affinityKey-java.lang.Object-"><code>AffinityKeyMapper.affinityKey(Object)</code></a> method is then passed to
<a href="../../../../../org/apache/ignite/cache/affinity/AffinityFunction.html#partition-java.lang.Object-"><code>partition(Object)</code></a> method to find out the partition for the key.
On each topology change, partition-to-node mapping is calculated using
<a href="../../../../../org/apache/ignite/cache/affinity/AffinityFunction.html#assignPartitions-org.apache.ignite.cache.affinity.AffinityFunctionContext-"><code>assignPartitions(AffinityFunctionContext)</code></a> method, which assigns a collection
of nodes to each partition.
This collection of nodes is used for node affinity. In <a href="../../../../../org/apache/ignite/cache/CacheMode.html#REPLICATED"><code>REPLICATED</code></a>
cache mode the key will be cached on all returned nodes; generally, all caching nodes
participate in caching every key in replicated mode. In <a href="../../../../../org/apache/ignite/cache/CacheMode.html#PARTITIONED"><code>PARTITIONED</code></a>
mode, only primary and backup nodes are returned with primary node always in the
first position. So if there is <code>1</code> backup node, then the returned collection will
have <code>2</code> nodes in it - <code>primary</code> node in first position, and <code>backup</code>
node in second.
<p>
For more information about cache affinity and examples refer to <a href="../../../../../org/apache/ignite/cache/affinity/AffinityKeyMapper.html" title="interface in org.apache.ignite.cache.affinity"><code>AffinityKeyMapper</code></a> and
<a href="../../../../../org/apache/ignite/cache/affinity/AffinityKeyMapped.html" title="annotation in org.apache.ignite.cache.affinity"><code>@AffinityKeyMapped</code></a> documentation.</div>
<dl>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../../../org/apache/ignite/cache/affinity/AffinityKeyMapped.html" title="annotation in org.apache.ignite.cache.affinity"><code>AffinityKeyMapped</code></a>,
<a href="../../../../../org/apache/ignite/cache/affinity/AffinityKeyMapper.html" title="interface in org.apache.ignite.cache.affinity"><code>AffinityKeyMapper</code></a>,
<a href="../../../../../org/apache/ignite/configuration/IgniteConfiguration.html#isLateAffinityAssignment--"><code>IgniteConfiguration.isLateAffinityAssignment()</code></a></dd>
</dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method.summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd">&nbsp;</span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t3" class="tableTab"><span><a href="javascript:show(4);">Abstract Methods</a></span><span class="tabEnd">&nbsp;</span></span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr id="i0" class="altColor">
<td class="colFirst"><code><a href="https://docs.oracle.com/javase/8/docs/api/java/util/List.html?is-external=true" title="class or interface in java.util">List</a><span class='angle_bracket'>&lt;</span><a href="https://docs.oracle.com/javase/8/docs/api/java/util/List.html?is-external=true" title="class or interface in java.util">List</a><span class='angle_bracket'>&lt;</span><a href="../../../../../org/apache/ignite/cluster/ClusterNode.html" title="interface in org.apache.ignite.cluster">ClusterNode</a><span class='angle_bracket'>&gt;</span><span class='angle_bracket'>&gt;</span></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/ignite/cache/affinity/AffinityFunction.html#assignPartitions-org.apache.ignite.cache.affinity.AffinityFunctionContext-">assignPartitions</a></span>(<a href="../../../../../org/apache/ignite/cache/affinity/AffinityFunctionContext.html" title="interface in org.apache.ignite.cache.affinity">AffinityFunctionContext</a>&nbsp;affCtx)</code>
<div class="block">Gets affinity nodes for a partition.</div>
</td>
</tr>
<tr id="i1" class="rowColor">
<td class="colFirst"><code>int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/ignite/cache/affinity/AffinityFunction.html#partition-java.lang.Object-">partition</a></span>(<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a>&nbsp;key)</code>
<div class="block">Gets partition number for a given key starting from <code>0</code>.</div>
</td>
</tr>
<tr id="i2" class="altColor">
<td class="colFirst"><code>int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/ignite/cache/affinity/AffinityFunction.html#partitions--">partitions</a></span>()</code>
<div class="block">Gets total number of partitions available.</div>
</td>
</tr>
<tr id="i3" class="rowColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/ignite/cache/affinity/AffinityFunction.html#removeNode-java.util.UUID-">removeNode</a></span>(<a href="https://docs.oracle.com/javase/8/docs/api/java/util/UUID.html?is-external=true" title="class or interface in java.util">UUID</a>&nbsp;nodeId)</code>
<div class="block">Removes node from affinity.</div>
</td>
</tr>
<tr id="i4" class="altColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/ignite/cache/affinity/AffinityFunction.html#reset--">reset</a></span>()</code>
<div class="block">Resets cache affinity to its initial state.</div>
</td>
</tr>
</table>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method.detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a name="reset--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>reset</h4>
<pre>void&nbsp;reset()</pre>
<div class="block">Resets cache affinity to its initial state. This method will be called by
the system any time the affinity has been sent to remote node where
it has to be reinitialized. If your implementation of affinity function
has no initialization logic, leave this method empty.</div>
</li>
</ul>
<a name="partitions--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>partitions</h4>
<pre>int&nbsp;partitions()</pre>
<div class="block">Gets total number of partitions available. All caches should always provide
correct partition count which should be the same on all participating nodes.
Note that partitions should always be numbered from <code>0</code> inclusively to
<code>N</code> exclusively without any gaps.</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>Total partition count.</dd>
</dl>
</li>
</ul>
<a name="partition-java.lang.Object-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>partition</h4>
<pre>int&nbsp;partition(<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a>&nbsp;key)</pre>
<div class="block">Gets partition number for a given key starting from <code>0</code>. Partitioned caches
should make sure that keys are about evenly distributed across all partitions
from <code>0</code> to <a href="../../../../../org/apache/ignite/cache/affinity/AffinityFunction.html#partitions--"><code>partition count</code></a> for best performance.
<p>
Note that for fully replicated caches it is possible to segment key sets among different
grid node groups. In that case each node group should return a unique partition
number. However, unlike partitioned cache, mappings of keys to nodes in
replicated caches are constant and a node cannot migrate from one partition
to another.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>key</code> - Key to get partition for.</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>Partition number for a given key.</dd>
</dl>
</li>
</ul>
<a name="assignPartitions-org.apache.ignite.cache.affinity.AffinityFunctionContext-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>assignPartitions</h4>
<pre><a href="https://docs.oracle.com/javase/8/docs/api/java/util/List.html?is-external=true" title="class or interface in java.util">List</a><span class='angle_bracket'>&lt;</span><a href="https://docs.oracle.com/javase/8/docs/api/java/util/List.html?is-external=true" title="class or interface in java.util">List</a><span class='angle_bracket'>&lt;</span><a href="../../../../../org/apache/ignite/cluster/ClusterNode.html" title="interface in org.apache.ignite.cluster">ClusterNode</a><span class='angle_bracket'>&gt;</span><span class='angle_bracket'>&gt;</span>&nbsp;assignPartitions(<a href="../../../../../org/apache/ignite/cache/affinity/AffinityFunctionContext.html" title="interface in org.apache.ignite.cache.affinity">AffinityFunctionContext</a>&nbsp;affCtx)</pre>
<div class="block">Gets affinity nodes for a partition. In case of replicated cache, all returned
nodes are updated in the same manner. In case of partitioned cache, the returned
list should contain only the primary and back up nodes with primary node being
always first.
<p>
Note that partitioned affinity must obey the following contract: given that node
<code>N</code> is primary for some key <code>K</code>, if any other node(s) leave
grid and no node joins grid, node <code>N</code> will remain primary for key <code>K</code>.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>affCtx</code> - Affinity function context. Will provide all required information to calculate
new partition assignments.</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>Unmodifiable list indexed by partition number. Each element of array is a collection in which
first node is a primary node and other nodes are backup nodes.</dd>
</dl>
</li>
</ul>
<a name="removeNode-java.util.UUID-">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>removeNode</h4>
<pre>void&nbsp;removeNode(<a href="https://docs.oracle.com/javase/8/docs/api/java/util/UUID.html?is-external=true" title="class or interface in java.util">UUID</a>&nbsp;nodeId)</pre>
<div class="block">Removes node from affinity. This method is called when it is safe to remove left node from
affinity mapping.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>nodeId</code> - ID of node to remove.</dd>
</dl>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.bottom.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/AffinityFunction.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../org/apache/ignite/cache/affinity/AffinityCentralizedFunction.html" title="annotation in org.apache.ignite.cache.affinity"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../../org/apache/ignite/cache/affinity/AffinityFunctionContext.html" title="interface in org.apache.ignite.cache.affinity"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/apache/ignite/cache/affinity/AffinityFunction.html" target="_top">Frames</a></li>
<li><a href="AffinityFunction.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a name="skip.navbar.bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<p class="legalCopy"><small><table width="100%" border="0" cellspacing=0 cellpadding=0 style="padding: 5px"> <tr> <td> <table style="padding-left: 0; margin: 0"> <tbody style="padding: 0; margin: 0"> <tr style="padding: 0; margin: 0"> <td> <a target=_blank href="https://ignite.apache.org"><nobr>2022 Copyright &#169; Apache Software Foundation</nobr></a> </td> </tr> </tbody> </table> </td> <td width="100%" align="right" valign="center"> <a href="https://twitter.com/ApacheIgnite" class="twitter-follow-button" data-show-count="false" data-size="large">Follow @ApacheIgnite</a> </td> </tr> <tr> <td colspan="2" valign="top" align="left"> <table style="padding-left: 0; margin: 0"> <tbody style="padding: 0; margin: 0"> <tr style="padding: 0; margin: 0"> <td> <b>Ignite Database and Caching Platform</b> </td> <td>:&nbsp;&nbsp; ver. <strong>2.12.0</strong> </td> </tr> <tr style="padding: 0; margin: 0"> <td> <b>Release Date</b> </td> <td>:&nbsp;&nbsp; January 10 2022 </td> </tr> </tbody> </table> </td> </tr> </table></small></p>
</body>
</html>