You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/01/16 16:43:15 UTC
[12/12] incubator-ignite git commit: #IGNITE-99: Refactoring. Move
GridCache.affinity() to Ignite.affinity(String cacheName).
#IGNITE-99: Refactoring. Move GridCache.affinity() to Ignite.affinity(String cacheName).
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/25609651
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/25609651
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/25609651
Branch: refs/heads/ignite-99
Commit: 25609651b3a7e5447d636167f5bb5255af23a2bc
Parents: ae4cbca
Author: ivasilinets <iv...@gridgain.com>
Authored: Fri Jan 16 18:27:15 2015 +0400
Committer: ivasilinets <iv...@gridgain.com>
Committed: Fri Jan 16 18:27:15 2015 +0400
----------------------------------------------------------------------
.../examples/datagrid/CacheEventsExample.java | 2 +-
.../examples/datagrid/CacheQueryExample.java | 47 +-
.../store/dummy/CacheDummyPersonStore.java | 2 +-
.../examples/ScalarCacheAffinityExample1.scala | 4 +-
.../examples/ScalarCacheQueryExample.scala | 10 +-
...GridClientAbstractMultiThreadedSelfTest.java | 9 +-
.../GridClientTestPortableAffinityKeyTask.java | 4 +-
.../GridClientPartitionAffinitySelfTest.java | 14 +-
.../GridClientAbstractMultiNodeSelfTest.java | 4 +-
.../integration/GridClientAbstractSelfTest.java | 6 +-
.../jdbc/GridJdbcComplexQuerySelfTest.java | 10 +-
.../gridgain/jdbc/GridJdbcMetadataSelfTest.java | 10 +-
.../src/test/resources/spring-server-node.xml | 2 +-
.../test/resources/spring-server-ssl-node.xml | 2 +-
.../src/main/java/org/apache/ignite/Ignite.java | 10 +-
.../java/org/apache/ignite/IgniteCache.java | 2 +-
.../org/apache/ignite/IgniteCacheAffinity.java | 262 ++++++
.../java/org/apache/ignite/IgniteCluster.java | 6 +-
.../cache/affinity/CacheAffinityFunction.java | 111 +++
.../affinity/CacheAffinityFunctionContext.java | 71 ++
.../ignite/cache/affinity/CacheAffinityKey.java | 188 +++++
.../cache/affinity/CacheAffinityKeyMapped.java | 158 ++++
.../cache/affinity/CacheAffinityKeyMapper.java | 64 ++
.../CacheAffinityNodeAddressHashResolver.java | 39 +
.../affinity/CacheAffinityNodeHashResolver.java | 43 +
.../CacheAffinityNodeIdHashResolver.java | 40 +
.../CacheCentralizedAffinityFunction.java | 31 +
.../CacheConsistentHashAffinityFunction.java | 703 ++++++++++++++++
.../cache/affinity/consistenthash/package.html | 24 +
.../fair/CachePartitionFairAffinity.java | 805 +++++++++++++++++++
.../ignite/cache/affinity/fair/package.html | 24 +
.../apache/ignite/cache/affinity/package.html | 24 +
.../CacheRendezvousAffinityFunction.java | 502 ++++++++++++
.../cache/affinity/rendezvous/package.html | 23 +
.../fs/IgniteFsGroupDataBlocksKeyMapper.java | 2 +-
.../StreamerCacheAffinityEventRouter.java | 2 +-
.../java/org/gridgain/grid/cache/GridCache.java | 16 +-
.../grid/cache/GridCacheConfiguration.java | 21 +-
.../org/gridgain/grid/cache/GridCacheMode.java | 5 +-
.../org/gridgain/grid/cache/GridCacheName.java | 8 +-
.../grid/cache/GridCachePreloadMode.java | 3 +-
.../grid/cache/GridCacheProjection.java | 5 +-
.../grid/cache/affinity/GridCacheAffinity.java | 262 ------
.../affinity/GridCacheAffinityFunction.java | 111 ---
.../GridCacheAffinityFunctionContext.java | 71 --
.../cache/affinity/GridCacheAffinityKey.java | 189 -----
.../affinity/GridCacheAffinityKeyMapped.java | 158 ----
.../affinity/GridCacheAffinityKeyMapper.java | 64 --
...ridCacheAffinityNodeAddressHashResolver.java | 39 -
.../GridCacheAffinityNodeHashResolver.java | 43 -
.../GridCacheAffinityNodeIdHashResolver.java | 40 -
.../GridCacheCentralizedAffinityFunction.java | 31 -
...GridCacheConsistentHashAffinityFunction.java | 703 ----------------
.../cache/affinity/consistenthash/package.html | 24 -
.../fair/GridCachePartitionFairAffinity.java | 805 -------------------
.../grid/cache/affinity/fair/package.html | 24 -
.../gridgain/grid/cache/affinity/package.html | 24 -
.../GridCacheRendezvousAffinityFunction.java | 503 ------------
.../grid/cache/affinity/rendezvous/package.html | 23 -
.../grid/cache/query/GridCacheQuery.java | 3 +-
.../org/gridgain/grid/kernal/GridGainEx.java | 4 +-
.../grid/kernal/GridJobContextImpl.java | 5 +-
.../org/gridgain/grid/kernal/GridKernal.java | 7 +
.../kernal/managers/GridManagerAdapter.java | 2 +-
.../loadbalancer/GridLoadBalancerManager.java | 4 +-
.../CacheAffinityFunctionContextImpl.java | 83 ++
.../affinity/GridAffinityAssignmentCache.java | 12 +-
.../affinity/GridAffinityProcessor.java | 14 +-
.../processors/affinity/GridAffinityUtils.java | 7 +-
.../GridCacheAffinityFunctionContextImpl.java | 83 --
.../cache/CacheDefaultAffinityKeyMapper.java | 136 ++++
.../processors/cache/GridCacheAdapter.java | 8 +-
.../processors/cache/GridCacheAttributes.java | 10 +-
.../GridCacheDefaultAffinityKeyMapper.java | 137 ----
.../processors/cache/GridCacheEntryImpl.java | 2 +-
.../cache/GridCachePreloaderAdapter.java | 5 +-
.../processors/cache/GridCacheProcessor.java | 44 +-
.../processors/cache/GridCacheProxyImpl.java | 14 +-
.../cache/affinity/CacheAffinityImpl.java | 221 +++++
.../cache/affinity/CacheAffinityProxy.java | 262 ++++++
.../cache/affinity/GridCacheAffinityImpl.java | 222 -----
.../cache/affinity/GridCacheAffinityProxy.java | 262 ------
.../GridCacheInternalKeyImpl.java | 4 +-
.../datastructures/GridCacheQueueAdapter.java | 4 +-
.../cache/datastructures/GridCacheSetImpl.java | 4 +-
.../GridDhtPartitionsExchangeFuture.java | 6 +-
.../distributed/near/GridNearGetFuture.java | 2 +-
.../closure/GridClosureProcessor.java | 10 +-
.../dataload/GridDataLoadCacheUpdaters.java | 3 +-
.../processors/ggfs/GridGgfsDataManager.java | 30 +-
.../processors/ggfs/GridGgfsProcessor.java | 5 +-
.../handlers/cache/GridCacheCommandHandler.java | 3 +-
.../top/GridTopologyCommandHandler.java | 6 +-
.../service/GridServiceProcessor.java | 2 +-
.../grid/kernal/visor/cache/VisorCache.java | 10 +-
.../cache/VisorCacheAffinityConfiguration.java | 10 +-
.../java/org/gridgain/jdbc/GridJdbcDriver.java | 4 +-
.../config/load/dsi-49-server-production.xml | 2 +-
...CachePartitionFairAffinityNodesSelfTest.java | 246 ++++++
.../CachePartitionFairAffinitySelfTest.java | 261 ++++++
.../cache/IgniteCacheInvokeAbstractTest.java | 2 +-
.../IgniteCacheExpiryPolicyAbstractTest.java | 10 +-
.../grid/GridCacheAffinityBackupsSelfTest.java | 111 ---
.../IgniteCacheAffinityBackupsSelfTest.java | 111 +++
...CachePartitionFairAffinityNodesSelfTest.java | 242 ------
.../GridCachePartitionFairAffinitySelfTest.java | 261 ------
.../grid/kernal/GridAffinityMappedTest.java | 13 +-
.../grid/kernal/GridAffinityP2PSelfTest.java | 8 +-
.../kernal/GridJobMasterLeaveAwareSelfTest.java | 11 +-
.../grid/kernal/GridMultipleJobsSelfTest.java | 5 +-
.../GridAffinityProcessorAbstractSelfTest.java | 9 +-
...AffinityProcessorConsistentHashSelfTest.java | 8 +-
...GridAffinityProcessorRendezvousSelfTest.java | 8 +-
.../cache/GridCacheAbstractFullApiSelfTest.java | 14 +-
.../cache/GridCacheAbstractMetricsSelfTest.java | 6 +-
.../GridCacheAbstractRemoveFailureTest.java | 4 +-
.../cache/GridCacheAbstractSelfTest.java | 12 +-
.../cache/GridCacheAffinityApiSelfTest.java | 361 ---------
.../cache/GridCacheAffinityMapperSelfTest.java | 132 ---
.../cache/GridCacheAffinityRoutingSelfTest.java | 690 ----------------
.../GridCacheAtomicMessageCountSelfTest.java | 4 +-
.../GridCacheConcurrentTxMultiNodeTest.java | 28 +-
...idCacheConfigurationConsistencySelfTest.java | 48 +-
...ridCacheConfigurationValidationSelfTest.java | 10 +-
.../cache/GridCacheDeploymentSelfTest.java | 12 +-
.../cache/GridCacheEntryVersionSelfTest.java | 8 +-
.../GridCacheExAbstractFullApiSelfTest.java | 4 +-
.../GridCacheGroupLockAbstractSelfTest.java | 143 ++--
.../cache/GridCacheGroupLockPutTask.java | 4 +-
.../GridCacheInterceptorAbstractSelfTest.java | 7 +-
.../processors/cache/GridCacheLeakTest.java | 4 +-
.../cache/GridCacheLifecycleAwareSelfTest.java | 8 +-
...HeapMultiThreadedUpdateAbstractSelfTest.java | 2 +-
.../cache/GridCacheOffheapUpdateSelfTest.java | 6 +-
.../cache/GridCacheP2PUndeploySelfTest.java | 5 +-
.../GridCachePartitionedAffinitySpreadTest.java | 8 +-
.../GridCachePreloadingEvictionsSelfTest.java | 4 +-
.../GridCacheQueryInternalKeysSelfTest.java | 2 +-
...idCacheValueConsistencyAbstractSelfTest.java | 4 +-
.../cache/IgniteCacheAffinityApiSelfTest.java | 361 +++++++++
.../IgniteCacheAffinityMapperSelfTest.java | 132 +++
.../IgniteCacheAffinityRoutingSelfTest.java | 689 ++++++++++++++++
.../processors/cache/IgniteTxAbstractTest.java | 10 +-
.../IgniteTxExceptionAbstractSelfTest.java | 9 +-
.../cache/IgniteTxMultiNodeAbstractTest.java | 3 +-
.../IgniteTxStoreExceptionAbstractSelfTest.java | 6 +-
...actQueueFailoverDataConsistencySelfTest.java | 4 +-
.../GridCacheQueueCleanupSelfTest.java | 2 +-
...GridCacheQueueMultiNodeAbstractSelfTest.java | 4 +-
...PartitionedQueueCreateMultiNodeSelfTest.java | 2 +-
...dCachePartitionedQueueEntryMoveSelfTest.java | 15 +-
.../CacheModuloAffinityFunction.java | 200 +++++
.../GridCacheAtomicTimeoutSelfTest.java | 4 +-
.../GridCacheClientModesAbstractSelfTest.java | 10 +-
.../GridCacheModuloAffinityFunction.java | 200 -----
.../GridCacheNodeFailureAbstractTest.java | 2 +-
...dCachePartitionedAffinityFilterSelfTest.java | 12 +-
...GridCachePreloadRestartAbstractSelfTest.java | 29 +-
.../GridCacheTransformEventSelfTest.java | 7 +-
...iteTxConsistencyRestartAbstractSelfTest.java | 4 +-
...xOriginatingNodeFailureAbstractSelfTest.java | 2 +-
...cOriginatingNodeFailureAbstractSelfTest.java | 4 +-
...heAbstractTransformWriteThroughSelfTest.java | 6 +-
.../dht/GridCacheAtomicNearCacheSelfTest.java | 17 +-
.../dht/GridCacheColocatedDebugTest.java | 6 +-
.../GridCacheDhtAtomicRemoveFailureTest.java | 1 -
.../dht/GridCacheDhtEntrySelfTest.java | 7 +-
.../dht/GridCacheDhtEntrySetSelfTest.java | 1 -
...GridCacheDhtEvictionNearReadersSelfTest.java | 13 +-
.../dht/GridCacheDhtEvictionSelfTest.java | 13 +-
.../GridCacheDhtEvictionsDisabledSelfTest.java | 2 +-
.../dht/GridCacheDhtInternalEntrySelfTest.java | 8 +-
.../dht/GridCacheDhtPreloadBigDataSelfTest.java | 5 +-
.../dht/GridCacheDhtPreloadDelayedSelfTest.java | 11 +-
.../GridCacheDhtPreloadDisabledSelfTest.java | 7 +-
.../GridCacheDhtPreloadMessageCountTest.java | 6 +-
...ridCacheDhtPreloadMultiThreadedSelfTest.java | 4 +-
.../dht/GridCacheDhtPreloadSelfTest.java | 32 +-
.../GridCacheDhtPreloadStartStopSelfTest.java | 14 +-
.../dht/GridCacheDhtPreloadUnloadSelfTest.java | 5 +-
.../distributed/dht/GridCacheDhtTestUtils.java | 17 +-
...cheGroupLockPartitionedAbstractSelfTest.java | 16 +-
...ockPartitionedMultiNodeAbstractSelfTest.java | 14 +-
...idCachePartitionedPreloadEventsSelfTest.java | 8 +-
...dCachePartitionedTopologyChangeSelfTest.java | 9 +-
...itionedTxOriginatingNodeFailureSelfTest.java | 13 +-
...ridCachePartitionedUnloadEventsSelfTest.java | 6 +-
.../dht/IgniteTxReentryColocatedSelfTest.java | 2 +-
...eAtomicInvalidPartitionHandlingSelfTest.java | 6 +-
.../atomic/GridCacheAtomicPreloadSelfTest.java | 12 +-
...ffinityFunctionExcludeNeighborsSelfTest.java | 32 +
...unctionExcludeNeighborsAbstractSelfTest.java | 184 -----
...ffinityFunctionExcludeNeighborsSelfTest.java | 32 -
.../near/GridCacheNearMetricsSelfTest.java | 50 +-
.../near/GridCacheNearMultiGetSelfTest.java | 4 +-
.../near/GridCacheNearMultiNodeSelfTest.java | 14 +-
.../near/GridCacheNearOnlyTopologySelfTest.java | 2 +-
.../GridCacheNearPartitionedClearSelfTest.java | 2 +-
.../GridCacheNearReaderPreloadSelfTest.java | 17 +-
.../near/GridCacheNearReadersSelfTest.java | 16 +-
.../near/GridCacheNearRemoveFailureTest.java | 1 -
.../near/GridCacheNearTxMultiNodeSelfTest.java | 6 +-
...AffinityExcludeNeighborsPerformanceTest.java | 16 +-
...rtitionedAffinityHashIdResolverSelfTest.java | 10 +-
.../GridCachePartitionedAffinitySelfTest.java | 23 +-
...ePartitionedBasicStoreMultiNodeSelfTest.java | 12 +-
...ionedClientOnlyNoPrimaryFullApiSelfTest.java | 4 +-
.../near/GridCachePartitionedEventSelfTest.java | 1 -
.../GridCachePartitionedEvictionSelfTest.java | 3 +-
.../GridCachePartitionedFullApiSelfTest.java | 16 +-
.../GridCachePartitionedLoadCacheSelfTest.java | 3 +-
...achePartitionedMultiNodeCounterSelfTest.java | 10 +-
...achePartitionedMultiNodeFullApiSelfTest.java | 38 +-
.../GridCachePartitionedNodeRestartTest.java | 4 +-
...ePartitionedOptimisticTxNodeRestartTest.java | 4 +-
.../GridCachePartitionedProjectionSelfTest.java | 4 +-
.../GridCachePartitionedStorePutSelfTest.java | 4 +-
.../GridCachePartitionedTxSalvageSelfTest.java | 4 +-
.../near/GridCachePutArrayValueSelfTest.java | 2 +-
...idCacheRendezvousAffinityClientSelfTest.java | 8 +-
...ffinityFunctionExcludeNeighborsSelfTest.java | 10 +-
...unctionExcludeNeighborsAbstractSelfTest.java | 184 +++++
.../near/IgniteTxReentryNearSelfTest.java | 2 +-
...dezvousAffinityMultiNodeFullApiSelfTest.java | 6 +-
...idCacheReplicatedUnswapAdvancedSelfTest.java | 2 +-
.../GridCacheReplicatedPreloadSelfTest.java | 6 +-
.../GridCacheDistributedEvictionsSelfTest.java | 4 +-
.../GridCacheEvictionTouchSelfTest.java | 16 +-
...cheSynchronousEvictionsFailoverSelfTest.java | 13 +-
.../local/GridCacheLocalFullApiSelfTest.java | 4 +-
...dCacheAbstractReduceFieldsQuerySelfTest.java | 18 +-
.../ggfs/GridGgfsAbstractSelfTest.java | 6 +-
.../ggfs/GridGgfsDataManagerSelfTest.java | 4 +-
.../GridGgfsProcessorValidationSelfTest.java | 2 +-
.../processors/ggfs/GridGgfsSizeSelfTest.java | 4 +-
.../GridServiceProcessorAbstractSelfTest.java | 2 +-
.../marshaller/GridMarshallerAbstractTest.java | 8 +-
...idOffHeapPartitionedMapAbstractSelfTest.java | 6 +-
...apPartitionedMapPerformanceAbstractTest.java | 6 +-
...GridUnsafePartitionedMapPerformanceTest.java | 4 +-
...ridCacheAffinityTransactionsOffHeapTest.java | 6 +-
.../cache/GridCacheGroupLockComparisonTest.java | 12 +-
.../capacity/spring-capacity-cache.xml | 2 +-
.../colocation/GridTestCacheStore.java | 2 +-
.../loadtests/colocation/GridTestKey.java | 4 +-
.../loadtests/colocation/spring-colocation.xml | 2 +-
.../GridCachePartitionedAtomicLongLoadTest.java | 4 +-
.../gridgain/loadtests/dsi/GridDsiPerfJob.java | 4 +-
.../gridgain/loadtests/dsi/GridDsiRequest.java | 4 +-
.../gridgain/loadtests/dsi/GridDsiResponse.java | 4 +-
.../gridgain/loadtests/dsi/GridDsiSession.java | 4 +-
...apPartitionedMapPerformanceAbstractTest.java | 6 +-
...GridUnsafePartitionedMapPerformanceTest.java | 4 +-
.../gridgain/testframework/GridTestUtils.java | 6 +-
.../junits/common/GridCommonAbstractTest.java | 32 +-
.../bamboo/GridDataGridTestSuite.java | 14 +-
.../tests/p2p/ExternalAffinityFunction.java | 161 ++++
.../tests/p2p/ExternalAffinityKeyMapper.java | 38 +
.../tests/p2p/GridExternalAffinityFunction.java | 161 ----
.../p2p/GridExternalAffinityKeyMapper.java | 38 -
...idHadoopDefaultMapReducePlannerSelfTest.java | 5 +
.../hibernate/GridHibernateL2CacheSelfTest.java | 6 +-
.../GridCacheAbstractFieldsQuerySelfTest.java | 36 +-
.../cache/GridCacheAbstractQuerySelfTest.java | 2 +-
.../cache/GridCacheOffHeapAndSwapSelfTest.java | 2 +-
.../GridCacheQueryMultiThreadedSelfTest.java | 4 +-
...GridCachePartitionedFieldsQuerySelfTest.java | 8 +-
.../near/GridCachePartitionedQuerySelfTest.java | 2 +-
.../java/org/gridgain/grid/GridSpringBean.java | 5 +
pom.xml | 4 +-
270 files changed, 7157 insertions(+), 7150 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/examples/src/main/java/org/gridgain/examples/datagrid/CacheEventsExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/gridgain/examples/datagrid/CacheEventsExample.java b/examples/src/main/java/org/gridgain/examples/datagrid/CacheEventsExample.java
index 5fc6ced..4544211 100644
--- a/examples/src/main/java/org/gridgain/examples/datagrid/CacheEventsExample.java
+++ b/examples/src/main/java/org/gridgain/examples/datagrid/CacheEventsExample.java
@@ -76,7 +76,7 @@ public class CacheEventsExample {
int key = evt.key();
- return key >= 10 && cache.affinity().isPrimary(g.cluster().localNode(), key);
+ return key >= 10 && g.affinity(CACHE_NAME).isPrimary(g.cluster().localNode(), key);
}
};
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/examples/src/main/java/org/gridgain/examples/datagrid/CacheQueryExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/gridgain/examples/datagrid/CacheQueryExample.java b/examples/src/main/java/org/gridgain/examples/datagrid/CacheQueryExample.java
index 03f9c5f..3a3400e 100644
--- a/examples/src/main/java/org/gridgain/examples/datagrid/CacheQueryExample.java
+++ b/examples/src/main/java/org/gridgain/examples/datagrid/CacheQueryExample.java
@@ -19,9 +19,8 @@ package org.gridgain.examples.datagrid;
import org.apache.ignite.*;
import org.apache.ignite.lang.*;
-import org.gridgain.grid.*;
import org.gridgain.grid.cache.*;
-import org.gridgain.grid.cache.affinity.*;
+import org.apache.ignite.cache.affinity.*;
import org.gridgain.grid.cache.query.*;
import java.io.*;
@@ -48,7 +47,7 @@ import java.util.*;
* </li>
* <li>
* Joins will work correctly only if joined objects are stored in
- * collocated mode. Refer to {@link GridCacheAffinityKey} javadoc for more details.
+ * collocated mode. Refer to {@link org.apache.ignite.cache.affinity.CacheAffinityKey} javadoc for more details.
* </li>
* <li>
* Note that if you created query on to replicated cache, all data will
@@ -120,10 +119,10 @@ public class CacheQueryExample {
* @throws IgniteCheckedException In case of error.
*/
private static void sqlQuery() throws IgniteCheckedException {
- GridCache<GridCacheAffinityKey<UUID>, Person> cache = Ignition.ignite().cache(CACHE_NAME);
+ GridCache<CacheAffinityKey<UUID>, Person> cache = Ignition.ignite().cache(CACHE_NAME);
// Create query which selects salaries based on range.
- GridCacheQuery<Map.Entry<GridCacheAffinityKey<UUID>, Person>> qry =
+ GridCacheQuery<Map.Entry<CacheAffinityKey<UUID>, Person>> qry =
cache.queries().createSqlQuery(Person.class, "salary > ? and salary <= ?");
// Execute queries for salary ranges.
@@ -140,10 +139,10 @@ public class CacheQueryExample {
* @throws IgniteCheckedException In case of error.
*/
private static void sqlQueryWithJoin() throws IgniteCheckedException {
- GridCache<GridCacheAffinityKey<UUID>, Person> cache = Ignition.ignite().cache(CACHE_NAME);
+ GridCache<CacheAffinityKey<UUID>, Person> cache = Ignition.ignite().cache(CACHE_NAME);
// Create query which joins on 2 types to select people for a specific organization.
- GridCacheQuery<Map.Entry<GridCacheAffinityKey<UUID>, Person>> qry =
+ GridCacheQuery<Map.Entry<CacheAffinityKey<UUID>, Person>> qry =
cache.queries().createSqlQuery(Person.class, "from Person, Organization " +
"where Person.orgId = Organization.id " +
"and lower(Organization.name) = lower(?)");
@@ -159,14 +158,14 @@ public class CacheQueryExample {
* @throws IgniteCheckedException In case of error.
*/
private static void textQuery() throws IgniteCheckedException {
- GridCache<GridCacheAffinityKey<UUID>, Person> cache = Ignition.ignite().cache(CACHE_NAME);
+ GridCache<CacheAffinityKey<UUID>, Person> cache = Ignition.ignite().cache(CACHE_NAME);
// Query for all people with "Master Degree" in their resumes.
- GridCacheQuery<Map.Entry<GridCacheAffinityKey<UUID>, Person>> masters =
+ GridCacheQuery<Map.Entry<CacheAffinityKey<UUID>, Person>> masters =
cache.queries().createFullTextQuery(Person.class, "Master");
// Query for all people with "Bachelor Degree"in their resumes.
- GridCacheQuery<Map.Entry<GridCacheAffinityKey<UUID>, Person>> bachelors =
+ GridCacheQuery<Map.Entry<CacheAffinityKey<UUID>, Person>> bachelors =
cache.queries().createFullTextQuery(Person.class, "Bachelor");
print("Following people have 'Master Degree' in their resumes: ", masters.execute().get());
@@ -180,21 +179,21 @@ public class CacheQueryExample {
* @throws IgniteCheckedException In case of error.
*/
private static void sqlQueryWithReducers() throws IgniteCheckedException {
- GridCacheProjection<GridCacheAffinityKey<UUID>, Person> cache = Ignition.ignite().cache(CACHE_NAME);
+ GridCacheProjection<CacheAffinityKey<UUID>, Person> cache = Ignition.ignite().cache(CACHE_NAME);
// Calculate average of salary of all persons in GridGain.
- GridCacheQuery<Map.Entry<GridCacheAffinityKey<UUID>, Person>> qry = cache.queries().createSqlQuery(
+ GridCacheQuery<Map.Entry<CacheAffinityKey<UUID>, Person>> qry = cache.queries().createSqlQuery(
Person.class,
"from Person, Organization where Person.orgId = Organization.id and " +
"lower(Organization.name) = lower(?)");
Collection<IgniteBiTuple<Double, Integer>> res = qry.execute(
- new IgniteReducer<Map.Entry<GridCacheAffinityKey<UUID>, Person>, IgniteBiTuple<Double, Integer>>() {
+ new IgniteReducer<Map.Entry<CacheAffinityKey<UUID>, Person>, IgniteBiTuple<Double, Integer>>() {
private double sum;
private int cnt;
- @Override public boolean collect(Map.Entry<GridCacheAffinityKey<UUID>, Person> e) {
+ @Override public boolean collect(Map.Entry<CacheAffinityKey<UUID>, Person> e) {
sum += e.getValue().salary;
cnt++;
@@ -229,10 +228,10 @@ public class CacheQueryExample {
* @throws IgniteCheckedException In case of error.
*/
private static void sqlQueryWithTransformer() throws IgniteCheckedException {
- GridCache<GridCacheAffinityKey<UUID>, Person> cache = Ignition.ignite().cache(CACHE_NAME);
+ GridCache<CacheAffinityKey<UUID>, Person> cache = Ignition.ignite().cache(CACHE_NAME);
// Create query to get names of all employees working for some company.
- GridCacheQuery<Map.Entry<GridCacheAffinityKey<UUID>, Person>> qry =
+ GridCacheQuery<Map.Entry<CacheAffinityKey<UUID>, Person>> qry =
cache.queries().createSqlQuery(Person.class,
"from Person, Organization " +
"where Person.orgId = Organization.id and lower(Organization.name) = lower(?)");
@@ -240,9 +239,9 @@ public class CacheQueryExample {
// Transformer to convert Person objects to String.
// Since caller only needs employee names, we only
// send names back.
- IgniteClosure<Map.Entry<GridCacheAffinityKey<UUID>, Person>, String> trans =
- new IgniteClosure<Map.Entry<GridCacheAffinityKey<UUID>, Person>, String>() {
- @Override public String apply(Map.Entry<GridCacheAffinityKey<UUID>, Person> e) {
+ IgniteClosure<Map.Entry<CacheAffinityKey<UUID>, Person>, String> trans =
+ new IgniteClosure<Map.Entry<CacheAffinityKey<UUID>, Person>, String>() {
+ @Override public String apply(Map.Entry<CacheAffinityKey<UUID>, Person> e) {
return e.getValue().lastName;
}
};
@@ -307,8 +306,8 @@ public class CacheQueryExample {
GridCacheProjection<UUID, Organization> orgCache = cache.projection(UUID.class, Organization.class);
// Person projection.
- GridCacheProjection<GridCacheAffinityKey<UUID>, Person> personCache =
- cache.projection(GridCacheAffinityKey.class, Person.class);
+ GridCacheProjection<CacheAffinityKey<UUID>, Person> personCache =
+ cache.projection(CacheAffinityKey.class, Person.class);
// Organizations.
Organization org1 = new Organization("GridGain");
@@ -399,7 +398,7 @@ public class CacheQueryExample {
private double salary;
/** Custom cache key to guarantee that person is always collocated with its organization. */
- private transient GridCacheAffinityKey<UUID> key;
+ private transient CacheAffinityKey<UUID> key;
/**
* Constructs person record.
@@ -428,9 +427,9 @@ public class CacheQueryExample {
*
* @return Custom affinity key to guarantee that person is always collocated with organization.
*/
- public GridCacheAffinityKey<UUID> key() {
+ public CacheAffinityKey<UUID> key() {
if (key == null)
- key = new GridCacheAffinityKey<>(id, orgId);
+ key = new CacheAffinityKey<>(id, orgId);
return key;
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/examples/src/main/java/org/gridgain/examples/datagrid/store/dummy/CacheDummyPersonStore.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/gridgain/examples/datagrid/store/dummy/CacheDummyPersonStore.java b/examples/src/main/java/org/gridgain/examples/datagrid/store/dummy/CacheDummyPersonStore.java
index 48390ac..939bc84 100644
--- a/examples/src/main/java/org/gridgain/examples/datagrid/store/dummy/CacheDummyPersonStore.java
+++ b/examples/src/main/java/org/gridgain/examples/datagrid/store/dummy/CacheDummyPersonStore.java
@@ -81,7 +81,7 @@ public class CacheDummyPersonStore extends GridCacheStoreAdapter<Long, Person> {
// but we check if local node is primary or backup anyway just to demonstrate that we can.
// Ideally, partition ID of a key would be stored in the database and only keys
// for partitions that belong on this node would be loaded from database.
- if (cache.affinity().isPrimaryOrBackup(ignite.cluster().localNode(), p.getId())) {
+ if (ignite.affinity(cacheName).isPrimaryOrBackup(ignite.cluster().localNode(), p.getId())) {
// Update dummy database.
// In real life data would be loaded from database.
dummyDB.put(p.getId(), p);
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/examples/src/main/scala/org/gridgain/scalar/examples/ScalarCacheAffinityExample1.scala
----------------------------------------------------------------------
diff --git a/examples/src/main/scala/org/gridgain/scalar/examples/ScalarCacheAffinityExample1.scala b/examples/src/main/scala/org/gridgain/scalar/examples/ScalarCacheAffinityExample1.scala
index 0946de7..600fd6d 100644
--- a/examples/src/main/scala/org/gridgain/scalar/examples/ScalarCacheAffinityExample1.scala
+++ b/examples/src/main/scala/org/gridgain/scalar/examples/ScalarCacheAffinityExample1.scala
@@ -22,7 +22,7 @@ import scalar._
import org.apache.ignite._
import org.jetbrains.annotations.Nullable
import java.util.concurrent.Callable
-import org.gridgain.grid.cache.affinity.GridCacheAffinityKeyMapped
+import org.apache.ignite.cache.affinity.CacheAffinityKeyMapped
import org.gridgain.grid.cache.GridCacheName
/**
@@ -65,7 +65,7 @@ object ScalarCacheAffinityExample1 {
keys.foreach(key => {
val res = grid$.call$(
new Callable[String] {
- @GridCacheAffinityKeyMapped
+ @CacheAffinityKeyMapped
def affinityKey(): String = key
@GridCacheName
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/examples/src/main/scala/org/gridgain/scalar/examples/ScalarCacheQueryExample.scala
----------------------------------------------------------------------
diff --git a/examples/src/main/scala/org/gridgain/scalar/examples/ScalarCacheQueryExample.scala b/examples/src/main/scala/org/gridgain/scalar/examples/ScalarCacheQueryExample.scala
index c1ee100..b455b2b 100644
--- a/examples/src/main/scala/org/gridgain/scalar/examples/ScalarCacheQueryExample.scala
+++ b/examples/src/main/scala/org/gridgain/scalar/examples/ScalarCacheQueryExample.scala
@@ -22,7 +22,7 @@ import scalar._
import org.apache.ignite._
import org.gridgain.grid.cache._
import GridCacheMode._
-import affinity._
+import org.apache.ignite.cache.affinity._
import java.util._
/**
@@ -57,7 +57,7 @@ object ScalarCacheQueryExample {
initialize()
// Cache instance shortcut.
- val cache = mkCache[GridCacheAffinityKey[UUID], Person]
+ val cache = mkCache[CacheAffinityKey[UUID], Person]
// Using distributed queries for partitioned cache and local queries for replicated cache.
// Since in replicated caches data is available on all nodes, including local one,
@@ -91,7 +91,7 @@ object ScalarCacheQueryExample {
cache.textReduce(
prj,
"Master",
- (e: Iterable[(GridCacheAffinityKey[UUID], Person)]) => (e.map(_._2.salary).sum, e.size),
+ (e: Iterable[(CacheAffinityKey[UUID], Person)]) => (e.map(_._2.salary).sum, e.size),
(e: Iterable[(Double, Int)]) => e.map(_._1).sum / e.map(_._2).sum
)
)
@@ -125,7 +125,7 @@ object ScalarCacheQueryExample {
orgCache += (org2.id -> org2)
// Person cache projection.
- val prnCache = mkCache[GridCacheAffinityKey[UUID], Person]
+ val prnCache = mkCache[CacheAffinityKey[UUID], Person]
// People.
val p1 = Person(org1, "John", "Doe", 2000, "John Doe has Master Degree.")
@@ -192,7 +192,7 @@ private case class Person(
val orgId = org.id
/** Affinity key for this person. */
- val key = new GridCacheAffinityKey[UUID](id, org.id)
+ val key = new CacheAffinityKey[UUID](id, org.id)
/**
* `toString` implementation.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/modules/clients/src/test/java/org/gridgain/client/GridClientAbstractMultiThreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/gridgain/client/GridClientAbstractMultiThreadedSelfTest.java b/modules/clients/src/test/java/org/gridgain/client/GridClientAbstractMultiThreadedSelfTest.java
index dfa8a5b..95274a1 100644
--- a/modules/clients/src/test/java/org/gridgain/client/GridClientAbstractMultiThreadedSelfTest.java
+++ b/modules/clients/src/test/java/org/gridgain/client/GridClientAbstractMultiThreadedSelfTest.java
@@ -26,9 +26,8 @@ import org.apache.ignite.resources.*;
import org.gridgain.client.balancer.*;
import org.gridgain.client.impl.*;
import org.gridgain.client.ssl.*;
-import org.gridgain.grid.*;
import org.gridgain.grid.cache.*;
-import org.gridgain.grid.cache.affinity.*;
+import org.apache.ignite.cache.affinity.*;
import org.gridgain.grid.kernal.*;
import org.gridgain.grid.kernal.processors.affinity.*;
import org.apache.ignite.spi.discovery.tcp.*;
@@ -283,8 +282,8 @@ public abstract class GridClientAbstractMultiThreadedSelfTest extends GridCommon
final String key = "k0";
Collection<UUID> affNodesIds = F.viewReadOnly(
- grid(0).cache(data.cacheName()).affinity().mapKeyToPrimaryAndBackups(key),
- F.node2id());
+ grid(0).affinity(data.cacheName()).mapKeyToPrimaryAndBackups(key),
+ F.node2id());
final GridClientData dataFirst = data.pinNodes(F.first(client.compute().nodes()));
@@ -510,7 +509,7 @@ public abstract class GridClientAbstractMultiThreadedSelfTest extends GridCommon
((GridKernal)g).internalCache(PARTITIONED_CACHE_NAME).context().affinity(),
"aff");
- GridCacheAffinityFunction aff = getFieldValue(affCache, "aff");
+ CacheAffinityFunction aff = getFieldValue(affCache, "aff");
info("Affinity [nodeId=" + g.cluster().localNode().id() + ", affinity=" + aff + "]");
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/modules/clients/src/test/java/org/gridgain/client/GridClientTestPortableAffinityKeyTask.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/gridgain/client/GridClientTestPortableAffinityKeyTask.java b/modules/clients/src/test/java/org/gridgain/client/GridClientTestPortableAffinityKeyTask.java
index 1cac4a5..96c001e 100644
--- a/modules/clients/src/test/java/org/gridgain/client/GridClientTestPortableAffinityKeyTask.java
+++ b/modules/clients/src/test/java/org/gridgain/client/GridClientTestPortableAffinityKeyTask.java
@@ -73,12 +73,12 @@ public class GridClientTestPortableAffinityKeyTask extends ComputeTaskAdapter<Ob
String expAffKey = (String)it.next();
- Object affKey = ignite.cache(cacheName).affinity().affinityKey(obj);
+ Object affKey = ignite.affinity(cacheName).affinityKey(obj);
if (!expAffKey.equals(affKey))
throw new IgniteCheckedException("Unexpected affinity key: " + affKey);
- if (!ignite.cache(cacheName).affinity().mapKeyToNode(obj).isLocal())
+ if (!ignite.affinity(cacheName).mapKeyToNode(obj).isLocal())
throw new IgniteCheckedException("Job is not run on primary node.");
return true;
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/modules/clients/src/test/java/org/gridgain/client/impl/GridClientPartitionAffinitySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/gridgain/client/impl/GridClientPartitionAffinitySelfTest.java b/modules/clients/src/test/java/org/gridgain/client/impl/GridClientPartitionAffinitySelfTest.java
index 134ff03..a593801 100644
--- a/modules/clients/src/test/java/org/gridgain/client/impl/GridClientPartitionAffinitySelfTest.java
+++ b/modules/clients/src/test/java/org/gridgain/client/impl/GridClientPartitionAffinitySelfTest.java
@@ -19,8 +19,8 @@ package org.gridgain.client.impl;
import org.apache.ignite.cluster.*;
import org.gridgain.client.*;
-import org.gridgain.grid.cache.affinity.*;
-import org.gridgain.grid.cache.affinity.consistenthash.*;
+import org.apache.ignite.cache.affinity.*;
+import org.apache.ignite.cache.affinity.consistenthash.*;
import org.gridgain.grid.kernal.processors.affinity.*;
import org.gridgain.grid.util.typedef.*;
import org.gridgain.testframework.*;
@@ -28,7 +28,7 @@ import org.gridgain.testframework.junits.common.*;
import java.util.*;
-import static org.gridgain.grid.cache.affinity.consistenthash.GridCacheConsistentHashAffinityFunction.*;
+import static org.apache.ignite.cache.affinity.consistenthash.CacheConsistentHashAffinityFunction.*;
/**
* Client's partitioned affinity tests.
@@ -285,11 +285,11 @@ public class GridClientPartitionAffinitySelfTest extends GridCommonAbstractTest
aff.setHashIdResolver(HASH_ID_RSLVR);
- GridCacheConsistentHashAffinityFunction srvAff = new GridCacheConsistentHashAffinityFunction();
+ CacheConsistentHashAffinityFunction srvAff = new CacheConsistentHashAffinityFunction();
getTestResources().inject(srvAff);
- srvAff.setHashIdResolver(new GridCacheAffinityNodeIdHashResolver());
+ srvAff.setHashIdResolver(new CacheAffinityNodeIdHashResolver());
// Define keys to test affinity for.
Collection<String> keys = new ArrayList<>(
@@ -339,12 +339,12 @@ public class GridClientPartitionAffinitySelfTest extends GridCommonAbstractTest
* @param nodes Client topology.
* @param srvNodes Server topology.
*/
- private void assertSameAffinity(Object key, GridClientDataAffinity aff, GridCacheAffinityFunction srvAff,
+ private void assertSameAffinity(Object key, GridClientDataAffinity aff, CacheAffinityFunction srvAff,
Collection<? extends GridClientNode> nodes, Collection<ClusterNode> srvNodes) {
GridClientNode node = aff.node(key, nodes);
int part = srvAff.partition(key);
- GridCacheAffinityFunctionContext ctx = new GridCacheAffinityFunctionContextImpl(new ArrayList<>(srvNodes),
+ CacheAffinityFunctionContext ctx = new CacheAffinityFunctionContextImpl(new ArrayList<>(srvNodes),
null, null, 1, 0);
ClusterNode srvNode = F.first(srvAff.assignPartitions(ctx).get(part));
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/modules/clients/src/test/java/org/gridgain/client/integration/GridClientAbstractMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/gridgain/client/integration/GridClientAbstractMultiNodeSelfTest.java b/modules/clients/src/test/java/org/gridgain/client/integration/GridClientAbstractMultiNodeSelfTest.java
index 90fbb5c..21b04df 100644
--- a/modules/clients/src/test/java/org/gridgain/client/integration/GridClientAbstractMultiNodeSelfTest.java
+++ b/modules/clients/src/test/java/org/gridgain/client/integration/GridClientAbstractMultiNodeSelfTest.java
@@ -405,7 +405,7 @@ public abstract class GridClientAbstractMultiNodeSelfTest extends GridCommonAbst
String key = null;
for (int i = 0; i < 10_000; i++) {
- if (!cache.affinity().isPrimaryOrBackup(g0.localNode(), String.valueOf(i))) {
+ if (!g0.affinity(PARTITIONED_CACHE_NAME).isPrimaryOrBackup(g0.localNode(), String.valueOf(i))) {
key = String.valueOf(i);
break;
@@ -425,7 +425,7 @@ public abstract class GridClientAbstractMultiNodeSelfTest extends GridCommonAbst
for (Ignite g : G.allGrids()) {
cache = g.cache(PARTITIONED_CACHE_NAME);
- if (cache.affinity().isPrimaryOrBackup(g.cluster().localNode(), key))
+ if (g.affinity(PARTITIONED_CACHE_NAME).isPrimaryOrBackup(g.cluster().localNode(), key))
assertEquals("zzz", cache.peek(key));
else
assertNull(cache.peek(key));
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/modules/clients/src/test/java/org/gridgain/client/integration/GridClientAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/gridgain/client/integration/GridClientAbstractSelfTest.java b/modules/clients/src/test/java/org/gridgain/client/integration/GridClientAbstractSelfTest.java
index 58d6894..d424365 100644
--- a/modules/clients/src/test/java/org/gridgain/client/integration/GridClientAbstractSelfTest.java
+++ b/modules/clients/src/test/java/org/gridgain/client/integration/GridClientAbstractSelfTest.java
@@ -31,7 +31,7 @@ import org.apache.ignite.transactions.*;
import org.gridgain.client.*;
import org.gridgain.client.ssl.*;
import org.gridgain.grid.cache.*;
-import org.gridgain.grid.cache.affinity.consistenthash.*;
+import org.apache.ignite.cache.affinity.consistenthash.*;
import org.gridgain.grid.cache.store.*;
import org.gridgain.grid.util.typedef.*;
import org.gridgain.grid.util.typedef.internal.*;
@@ -1088,10 +1088,10 @@ public abstract class GridClientAbstractSelfTest extends GridCommonAbstractTest
assertEquals(grid().localNode().id(), node.nodeId());
assertEquals(4, node.caches().size());
- Integer replica = grid().localNode().attribute(GridCacheConsistentHashAffinityFunction.DFLT_REPLICA_COUNT_ATTR_NAME);
+ Integer replica = grid().localNode().attribute(CacheConsistentHashAffinityFunction.DFLT_REPLICA_COUNT_ATTR_NAME);
if (replica == null)
- replica = GridCacheConsistentHashAffinityFunction.DFLT_REPLICA_COUNT;
+ replica = CacheConsistentHashAffinityFunction.DFLT_REPLICA_COUNT;
assertEquals((int)replica, node.replicaCount());
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/modules/clients/src/test/java/org/gridgain/jdbc/GridJdbcComplexQuerySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/gridgain/jdbc/GridJdbcComplexQuerySelfTest.java b/modules/clients/src/test/java/org/gridgain/jdbc/GridJdbcComplexQuerySelfTest.java
index f6db0d2..3e98c21 100644
--- a/modules/clients/src/test/java/org/gridgain/jdbc/GridJdbcComplexQuerySelfTest.java
+++ b/modules/clients/src/test/java/org/gridgain/jdbc/GridJdbcComplexQuerySelfTest.java
@@ -19,7 +19,7 @@ package org.gridgain.jdbc;
import org.apache.ignite.configuration.*;
import org.gridgain.grid.cache.*;
-import org.gridgain.grid.cache.affinity.*;
+import org.apache.ignite.cache.affinity.*;
import org.gridgain.grid.cache.query.*;
import org.apache.ignite.spi.discovery.tcp.*;
import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
@@ -84,13 +84,13 @@ public class GridJdbcComplexQuerySelfTest extends GridCommonAbstractTest {
orgCache.put("o1", new Organization(1, "A"));
orgCache.put("o2", new Organization(2, "B"));
- GridCache<GridCacheAffinityKey<String>, Person> personCache = grid(0).cache(null);
+ GridCache<CacheAffinityKey<String>, Person> personCache = grid(0).cache(null);
assert personCache != null;
- personCache.put(new GridCacheAffinityKey<>("p1", "o1"), new Person(1, "John White", 25, 1));
- personCache.put(new GridCacheAffinityKey<>("p2", "o1"), new Person(2, "Joe Black", 35, 1));
- personCache.put(new GridCacheAffinityKey<>("p3", "o2"), new Person(3, "Mike Green", 40, 2));
+ personCache.put(new CacheAffinityKey<>("p1", "o1"), new Person(1, "John White", 25, 1));
+ personCache.put(new CacheAffinityKey<>("p2", "o1"), new Person(2, "Joe Black", 35, 1));
+ personCache.put(new CacheAffinityKey<>("p3", "o2"), new Person(3, "Mike Green", 40, 2));
Class.forName("org.gridgain.jdbc.GridJdbcDriver");
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/modules/clients/src/test/java/org/gridgain/jdbc/GridJdbcMetadataSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/gridgain/jdbc/GridJdbcMetadataSelfTest.java b/modules/clients/src/test/java/org/gridgain/jdbc/GridJdbcMetadataSelfTest.java
index 8667ae6..af4de14 100644
--- a/modules/clients/src/test/java/org/gridgain/jdbc/GridJdbcMetadataSelfTest.java
+++ b/modules/clients/src/test/java/org/gridgain/jdbc/GridJdbcMetadataSelfTest.java
@@ -19,7 +19,7 @@ package org.gridgain.jdbc;
import org.apache.ignite.configuration.*;
import org.gridgain.grid.cache.*;
-import org.gridgain.grid.cache.affinity.*;
+import org.apache.ignite.cache.affinity.*;
import org.gridgain.grid.cache.query.*;
import org.apache.ignite.spi.discovery.tcp.*;
import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
@@ -79,13 +79,13 @@ public class GridJdbcMetadataSelfTest extends GridCommonAbstractTest {
orgCache.put("o1", new Organization(1, "A"));
orgCache.put("o2", new Organization(2, "B"));
- GridCache<GridCacheAffinityKey<String>, Person> personCache = grid(0).cache(null);
+ GridCache<CacheAffinityKey<String>, Person> personCache = grid(0).cache(null);
assert personCache != null;
- personCache.put(new GridCacheAffinityKey<>("p1", "o1"), new Person("John White", 25, 1));
- personCache.put(new GridCacheAffinityKey<>("p2", "o1"), new Person("Joe Black", 35, 1));
- personCache.put(new GridCacheAffinityKey<>("p3", "o2"), new Person("Mike Green", 40, 2));
+ personCache.put(new CacheAffinityKey<>("p1", "o1"), new Person("John White", 25, 1));
+ personCache.put(new CacheAffinityKey<>("p2", "o1"), new Person("Joe Black", 35, 1));
+ personCache.put(new CacheAffinityKey<>("p3", "o2"), new Person("Mike Green", 40, 2));
Class.forName("org.gridgain.jdbc.GridJdbcDriver");
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/modules/clients/src/test/resources/spring-server-node.xml
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/resources/spring-server-node.xml b/modules/clients/src/test/resources/spring-server-node.xml
index 8cb61b7..7a2ae01 100644
--- a/modules/clients/src/test/resources/spring-server-node.xml
+++ b/modules/clients/src/test/resources/spring-server-node.xml
@@ -142,7 +142,7 @@
<property name="writeSynchronizationMode" value="FULL_SYNC"/>
<property name="affinity">
- <bean class="org.gridgain.grid.cache.affinity.consistenthash.GridCacheConsistentHashAffinityFunction">
+ <bean class="org.apache.ignite.cache.affinity.consistenthash.CacheConsistentHashAffinityFunction">
<constructor-arg value="1"/>
</bean>
</property>
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/modules/clients/src/test/resources/spring-server-ssl-node.xml
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/resources/spring-server-ssl-node.xml b/modules/clients/src/test/resources/spring-server-ssl-node.xml
index 5f5ca5d..927e6e3 100644
--- a/modules/clients/src/test/resources/spring-server-ssl-node.xml
+++ b/modules/clients/src/test/resources/spring-server-ssl-node.xml
@@ -126,7 +126,7 @@
<property name="writeSynchronizationMode" value="FULL_SYNC"/>
<property name="affinity">
- <bean class="org.gridgain.grid.cache.affinity.consistenthash.GridCacheConsistentHashAffinityFunction">
+ <bean class="org.apache.ignite.cache.affinity.consistenthash.CacheConsistentHashAffinityFunction">
<constructor-arg value="1"/>
</bean>
</property>
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/modules/core/src/main/java/org/apache/ignite/Ignite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/Ignite.java b/modules/core/src/main/java/org/apache/ignite/Ignite.java
index d1e1a55..6c4e19c 100644
--- a/modules/core/src/main/java/org/apache/ignite/Ignite.java
+++ b/modules/core/src/main/java/org/apache/ignite/Ignite.java
@@ -22,7 +22,6 @@ import org.apache.ignite.configuration.*;
import org.apache.ignite.fs.IgniteFsConfiguration;
import org.apache.ignite.plugin.*;
import org.apache.ignite.product.*;
-import org.gridgain.grid.*;
import org.gridgain.grid.cache.*;
import org.gridgain.grid.hadoop.*;
import org.apache.ignite.plugin.security.*;
@@ -320,4 +319,13 @@ public interface Ignite extends AutoCloseable {
* @throws IgniteCheckedException If failed to stop grid.
*/
@Override public void close() throws IgniteCheckedException;
+
+ /**
+ * Gets affinity service to provide information about data partitioning
+ * and distribution.
+ * @param cacheName Cache name.
+ * @param <K> Cache key type.
+ * @return
+ */
+ public <K> IgniteCacheAffinity<K> affinity(String cacheName);
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
index 2988005..dd5a0c1 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
@@ -45,7 +45,7 @@ import java.util.concurrent.locks.*;
* data based on the optionally passed in arguments.
* </li>
* <li>
- * Method {@link #affinity()} provides {@link org.gridgain.grid.cache.affinity.GridCacheAffinityFunction} service for information on
+ * Method {@link #affinity()} provides {@link org.apache.ignite.cache.affinity.CacheAffinityFunction} service for information on
* data partitioning and mapping keys to grid nodes responsible for caching those keys.
* </li>
* <li>
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/modules/core/src/main/java/org/apache/ignite/IgniteCacheAffinity.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCacheAffinity.java b/modules/core/src/main/java/org/apache/ignite/IgniteCacheAffinity.java
new file mode 100644
index 0000000..eb74e1b
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteCacheAffinity.java
@@ -0,0 +1,262 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite;
+
+import org.apache.ignite.cluster.*;
+import org.gridgain.grid.cache.*;
+import org.jetbrains.annotations.*;
+
+import java.util.*;
+
+/**
+ * Provides affinity information to detect which node is primary and which nodes are
+ * backups for a partitioned cache. You can get an instance of this interface by calling
+ * {@code GridCache.affinity()} method.
+ * <p>
+ * Mapping of a key to a node is a three-step operation. First step will get an affinity key for given key
+ * using {@link org.apache.ignite.cache.affinity.CacheAffinityKeyMapper}. If mapper is not specified, the original key will be used. Second step
+ * will map affinity key to partition using {@link org.apache.ignite.cache.affinity.CacheAffinityFunction#partition(Object)} method. Third step
+ * will map obtained partition to nodes for current grid topology version.
+ * <p>
+ * Interface provides various {@code 'mapKeysToNodes(..)'} methods which provide node affinity mapping for
+ * given keys. All {@code 'mapKeysToNodes(..)'} methods are not transactional and will not enlist
+ * keys into ongoing transaction.
+ */
+public interface IgniteCacheAffinity<K> {
+ /**
+ * Gets number of partitions in cache according to configured affinity function.
+ *
+ * @return Number of cache partitions.
+ * @see org.apache.ignite.cache.affinity.CacheAffinityFunction
+ * @see GridCacheConfiguration#getAffinity()
+ * @see GridCacheConfiguration#setAffinity(org.apache.ignite.cache.affinity.CacheAffinityFunction)
+ */
+ public int partitions();
+
+ /**
+ * Gets partition id for the given key.
+ *
+ * @param key Key to get partition id for.
+ * @return Partition id.
+ * @see org.apache.ignite.cache.affinity.CacheAffinityFunction
+ * @see GridCacheConfiguration#getAffinity()
+ * @see GridCacheConfiguration#setAffinity(org.apache.ignite.cache.affinity.CacheAffinityFunction)
+ */
+ public int partition(K key);
+
+ /**
+ * Returns {@code true} if given node is the primary node for given key.
+ * To check if local node is primary for given key, pass
+ * {@link org.apache.ignite.Ignite#localNode()} as first parameter.
+ *
+ * @param n Node to check.
+ * @param key Key to check.
+ * @return {@code True} if local node is the primary node for given key.
+ */
+ public boolean isPrimary(ClusterNode n, K key);
+
+ /**
+ * Returns {@code true} if local node is one of the backup nodes for given key.
+ * To check if local node is primary for given key, pass {@link org.apache.ignite.Ignite#localNode()}
+ * as first parameter.
+ *
+ * @param n Node to check.
+ * @param key Key to check.
+ * @return {@code True} if local node is one of the backup nodes for given key.
+ */
+ public boolean isBackup(ClusterNode n, K key);
+
+ /**
+ * Returns {@code true} if local node is primary or one of the backup nodes
+ * for given key. To check if local node is primary or backup for given key, pass
+ * {@link org.apache.ignite.Ignite#localNode()} as first parameter.
+ * <p>
+ * This method is essentially equivalent to calling
+ * <i>"{@link #isPrimary(org.apache.ignite.cluster.ClusterNode, Object)} || {@link #isBackup(org.apache.ignite.cluster.ClusterNode, Object)})"</i>,
+ * however it is more efficient as it makes both checks at once.
+ *
+ * @param n Node to check.
+ * @param key Key to check.
+ * @return {@code True} if local node is primary or backup for given key.
+ */
+ public boolean isPrimaryOrBackup(ClusterNode n, K key);
+
+ /**
+ * Gets partition ids for which nodes of the given projection has primary
+ * ownership.
+ * <p>
+ * Note that since {@link org.apache.ignite.cluster.ClusterNode} implements {@link org.apache.ignite.cluster.ClusterGroup},
+ * to find out primary partitions for a single node just pass
+ * a single node into this method.
+ * <p>
+ * This method may return an empty array if none of nodes in the projection
+ * have nearOnly disabled.
+ *
+ * @param n Grid node.
+ * @return Partition ids for which given projection has primary ownership.
+ * @see org.apache.ignite.cache.affinity.CacheAffinityFunction
+ * @see GridCacheConfiguration#getAffinity()
+ * @see GridCacheConfiguration#setAffinity(org.apache.ignite.cache.affinity.CacheAffinityFunction)
+ */
+ public int[] primaryPartitions(ClusterNode n);
+
+ /**
+ * Gets partition ids for which nodes of the given projection has backup
+ * ownership. Note that you can find a back up at a certain level, e.g.
+ * {@code first} backup or {@code third} backup by specifying the
+ * {@code 'levels} parameter. If no {@code 'level'} is specified then
+ * all backup partitions are returned.
+ * <p>
+ * Note that since {@link org.apache.ignite.cluster.ClusterNode} implements {@link org.apache.ignite.cluster.ClusterGroup},
+ * to find out backup partitions for a single node, just pass that single
+ * node into this method.
+ * <p>
+ * This method may return an empty array if none of nodes in the projection
+ * have nearOnly disabled.
+ *
+ * @param n Grid node.
+ * @return Partition ids for which given projection has backup ownership.
+ * @see org.apache.ignite.cache.affinity.CacheAffinityFunction
+ * @see GridCacheConfiguration#getAffinity()
+ * @see GridCacheConfiguration#setAffinity(org.apache.ignite.cache.affinity.CacheAffinityFunction)
+ */
+ public int[] backupPartitions(ClusterNode n);
+
+ /**
+ * Gets partition ids for which nodes of the given projection has ownership
+ * (either primary or backup).
+ * <p>
+ * Note that since {@link org.apache.ignite.cluster.ClusterNode} implements {@link org.apache.ignite.cluster.ClusterGroup},
+ * to find out all partitions for a single node, just pass that single
+ * node into this method.
+ * <p>
+ * This method may return an empty array if none of nodes in the projection
+ * have nearOnly disabled.
+ *
+ * @param n Grid node.
+ * @return Partition ids for which given projection has ownership.
+ * @see org.apache.ignite.cache.affinity.CacheAffinityFunction
+ * @see GridCacheConfiguration#getAffinity()
+ * @see GridCacheConfiguration#setAffinity(org.apache.ignite.cache.affinity.CacheAffinityFunction)
+ */
+ public int[] allPartitions(ClusterNode n);
+
+ /**
+ * Maps passed in key to a key which will be used for node affinity. The affinity
+ * key may be different from actual key if some field in the actual key was
+ * designated for affinity mapping via {@link org.apache.ignite.cache.affinity.CacheAffinityKeyMapped} annotation
+ * or if a custom {@link org.apache.ignite.cache.affinity.CacheAffinityKeyMapper} was configured.
+ *
+ * @param key Key to map.
+ * @return Key to be used for node-to-affinity mapping (may be the same
+ * key as passed in).
+ */
+ public Object affinityKey(K key);
+
+ /**
+ * This method provides ability to detect which keys are mapped to which nodes.
+ * Use it to determine which nodes are storing which keys prior to sending
+ * jobs that access these keys.
+ * <p>
+ * This method works as following:
+ * <ul>
+ * <li>For local caches it returns only local node mapped to all keys.</li>
+ * <li>
+ * For fully replicated caches {@link org.apache.ignite.cache.affinity.CacheAffinityFunction} is
+ * used to determine which keys are mapped to which nodes.
+ * </li>
+ * <li>For partitioned caches, the returned map represents node-to-key affinity.</li>
+ * </ul>
+ *
+ * @param keys Keys to map to nodes.
+ * @return Map of nodes to keys or empty map if there are no alive nodes for this cache.
+ */
+ public Map<ClusterNode, Collection<K>> mapKeysToNodes(@Nullable Collection<? extends K> keys);
+
+ /**
+ * This method provides ability to detect to which primary node the given key
+ * is mapped. Use it to determine which nodes are storing which keys prior to sending
+ * jobs that access these keys.
+ * <p>
+ * This method works as following:
+ * <ul>
+ * <li>For local caches it returns only local node ID.</li>
+ * <li>
+ * For fully replicated caches first node ID returned by {@link org.apache.ignite.cache.affinity.CacheAffinityFunction}
+ * is returned.
+ * </li>
+ * <li>For partitioned caches, primary node for the given key is returned.</li>
+ * </ul>
+ *
+ * @param key Keys to map to a node.
+ * @return Primary node for the key or {@code null} if there are no alive nodes for this cache.
+ */
+ @Nullable public ClusterNode mapKeyToNode(K key);
+
+ /**
+ * Gets primary and backup nodes for the key. Note that primary node is always
+ * first in the returned collection.
+ * <p>
+ * If there are only cache nodes in the projection with
+ * {@link GridCacheConfiguration#getDistributionMode()} property set to {@code NEAR_ONLY}, then this
+ * method will return an empty collection.
+ *
+ * @param key Key to get affinity nodes for.
+ * @return Collection of primary and backup nodes for the key with primary node
+ * always first, or an empty collection if this projection contains only nodes with
+ * {@link GridCacheConfiguration#getDistributionMode()} property set to {@code NEAR_ONLY}.
+ */
+ public Collection<ClusterNode> mapKeyToPrimaryAndBackups(K key);
+
+ /**
+ * Gets primary node for the given partition.
+ *
+ * @param part Partition id.
+ * @return Primary node for the given partition.
+ * @see org.apache.ignite.cache.affinity.CacheAffinityFunction
+ * @see GridCacheConfiguration#getAffinity()
+ * @see GridCacheConfiguration#setAffinity(org.apache.ignite.cache.affinity.CacheAffinityFunction)
+ */
+ public ClusterNode mapPartitionToNode(int part);
+
+ /**
+ * Gets primary nodes for the given partitions.
+ *
+ * @param parts Partition ids.
+ * @return Mapping of given partitions to their primary nodes.
+ * @see org.apache.ignite.cache.affinity.CacheAffinityFunction
+ * @see GridCacheConfiguration#getAffinity()
+ * @see GridCacheConfiguration#setAffinity(org.apache.ignite.cache.affinity.CacheAffinityFunction)
+ */
+ public Map<Integer, ClusterNode> mapPartitionsToNodes(Collection<Integer> parts);
+
+ /**
+ * Gets primary and backup nodes for partition. Note that primary node is always
+ * first in the returned collection.
+ * <p>
+ * If there are only cache nodes in the projection with
+ * {@link GridCacheConfiguration#getDistributionMode()} property set to {@code NEAR_ONLY}, then this
+ * method will return an empty collection.
+ *
+ * @param part Partition to get affinity nodes for.
+ * @return Collection of primary and backup nodes for partition with primary node
+ * always first, or an empty collection if this projection contains only nodes with
+ * {@link GridCacheConfiguration#getDistributionMode()} property set to {@code NEAR_ONLY}.
+ */
+ public Collection<ClusterNode> mapPartitionToPrimaryAndBackups(int part);
+}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/modules/core/src/main/java/org/apache/ignite/IgniteCluster.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCluster.java b/modules/core/src/main/java/org/apache/ignite/IgniteCluster.java
index df6c6fc..ced1256 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteCluster.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteCluster.java
@@ -19,8 +19,6 @@ package org.apache.ignite;
import org.apache.ignite.cluster.*;
import org.apache.ignite.lang.*;
-import org.gridgain.grid.*;
-import org.gridgain.grid.cache.affinity.*;
import org.gridgain.grid.util.lang.*;
import org.jetbrains.annotations.*;
@@ -110,7 +108,7 @@ public interface IgniteCluster extends ClusterGroup, IgniteAsyncSupport {
* <ul>
* <li>For local caches it returns only local node mapped to all keys.</li>
* <li>
- * For fully replicated caches, {@link GridCacheAffinityFunction} is
+ * For fully replicated caches, {@link org.apache.ignite.cache.affinity.CacheAffinityFunction} is
* used to determine which keys are mapped to which groups of nodes.
* </li>
* <li>For partitioned caches, the returned map represents node-to-key affinity.</li>
@@ -133,7 +131,7 @@ public interface IgniteCluster extends ClusterGroup, IgniteAsyncSupport {
* <ul>
* <li>For local caches it returns only local node ID.</li>
* <li>
- * For fully replicated caches first node ID returned by {@link GridCacheAffinityFunction}
+ * For fully replicated caches first node ID returned by {@link org.apache.ignite.cache.affinity.CacheAffinityFunction}
* is returned.
* </li>
* <li>For partitioned caches, the returned node ID is the primary node for the key.</li>
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/modules/core/src/main/java/org/apache/ignite/cache/affinity/CacheAffinityFunction.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/affinity/CacheAffinityFunction.java b/modules/core/src/main/java/org/apache/ignite/cache/affinity/CacheAffinityFunction.java
new file mode 100644
index 0000000..d3a4aac
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/cache/affinity/CacheAffinityFunction.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.affinity;
+
+import org.apache.ignite.cluster.*;
+import org.gridgain.grid.cache.*;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * 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 {@link GridCacheConfiguration#getAffinity()} method.
+ * <p>
+ * Whenever a key is given to cache, it is first passed to a pluggable
+ * {@link CacheAffinityKeyMapper} which may potentially map this key to an alternate
+ * key which should be used for affinity. The key returned from
+ * {@link CacheAffinityKeyMapper#affinityKey(Object)} method is then passed to
+ * {@link #partition(Object) partition(Object)} method to find out the partition for the key.
+ * On each topology change, partition-to-node mapping is calculated using
+ * {@link #assignPartitions(CacheAffinityFunctionContext)} method, which assigns a collection
+ * of nodes to each partition.
+ * This collection of nodes is used for node affinity. In {@link GridCacheMode#REPLICATED REPLICATED}
+ * cache mode the key will be cached on all returned nodes; generally, all caching nodes
+ * participate in caching every key in replicated mode. In {@link GridCacheMode#PARTITIONED PARTITIONED}
+ * mode, only primary and backup nodes are returned with primary node always in the
+ * first position. So if there is {@code 1} backup node, then the returned collection will
+ * have {@code 2} nodes in it - {@code primary} node in first position, and {@code backup}
+ * node in second.
+ * <p>
+ * For more information about cache affinity and examples refer to {@link CacheAffinityKeyMapper} and
+ * {@link CacheAffinityKeyMapped @GridCacheAffinityKeyMapped} documentation.
+ * @see CacheAffinityKeyMapped
+ * @see CacheAffinityKeyMapper
+ */
+public interface CacheAffinityFunction extends Serializable {
+ /**
+ * 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.
+ */
+ public void reset();
+
+ /**
+ * 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} inclusively to
+ * {@code N} exclusively without any gaps.
+ *
+ * @return Total partition count.
+ */
+ public int partitions();
+
+ /**
+ * Gets partition number for a given key starting from {@code 0}. Partitioned caches
+ * should make sure that keys are about evenly distributed across all partitions
+ * from {@code 0} to {@link #partitions() partition count} 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.
+ *
+ * @param key Key to get partition for.
+ * @return Partition number for a given key.
+ */
+ public int partition(Object key);
+
+ /**
+ * 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>.
+ *
+ * @param affCtx Affinity function context. Will provide all required information to calculate
+ * new partition assignments.
+ * @return 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.
+ */
+ public List<List<ClusterNode>> assignPartitions(CacheAffinityFunctionContext affCtx);
+
+ /**
+ * Removes node from affinity. This method is called when it is safe to remove left node from
+ * affinity mapping.
+ *
+ * @param nodeId ID of node to remove.
+ */
+ public void removeNode(UUID nodeId);
+}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/modules/core/src/main/java/org/apache/ignite/cache/affinity/CacheAffinityFunctionContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/affinity/CacheAffinityFunctionContext.java b/modules/core/src/main/java/org/apache/ignite/cache/affinity/CacheAffinityFunctionContext.java
new file mode 100644
index 0000000..70a0c2d
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/cache/affinity/CacheAffinityFunctionContext.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.affinity;
+
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.events.*;
+import org.jetbrains.annotations.*;
+
+import java.util.*;
+
+/**
+ * Affinity function context. This context is passed to {@link CacheAffinityFunction} for
+ * partition reassignment on every topology change event.
+ */
+public interface CacheAffinityFunctionContext {
+ /**
+ * Gets affinity assignment for given partition on previous topology version. First node in returned list is
+ * a primary node, other nodes are backups.
+ *
+ * @param part Partition to get previous assignment for.
+ * @return List of nodes assigned to given partition on previous topology version or {@code null}
+ * if this information is not available.
+ */
+ @Nullable public List<ClusterNode> previousAssignment(int part);
+
+ /**
+ * Gets number of backups for new assignment.
+ *
+ * @return Number of backups for new assignment.
+ */
+ public int backups();
+
+ /**
+ * Gets current topology snapshot. Snapshot will contain only nodes on which particular cache is configured.
+ * List of passed nodes is guaranteed to be sorted in a same order on all nodes on which partition assignment
+ * is performed.
+ *
+ * @return Cache topology snapshot.
+ */
+ public List<ClusterNode> currentTopologySnapshot();
+
+ /**
+ * Gets current topology version number.
+ *
+ * @return Current topology version number.
+ */
+ public long currentTopologyVersion();
+
+ /**
+ * Gets discovery event caused topology change.
+ *
+ * @return Discovery event caused latest topology change or {@code null} if this information is
+ * not available.
+ */
+ @Nullable public IgniteDiscoveryEvent discoveryEvent();
+}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/modules/core/src/main/java/org/apache/ignite/cache/affinity/CacheAffinityKey.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/affinity/CacheAffinityKey.java b/modules/core/src/main/java/org/apache/ignite/cache/affinity/CacheAffinityKey.java
new file mode 100644
index 0000000..d793f6e
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/cache/affinity/CacheAffinityKey.java
@@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.affinity;
+
+import org.gridgain.grid.util.typedef.internal.*;
+import org.gridgain.grid.util.tostring.*;
+
+import java.io.*;
+
+/**
+ * Optional wrapper for cache keys to provide support
+ * for custom affinity mapping. The value returned by
+ * {@link #affinityKey(Object)} method will be used for key-to-node
+ * affinity.
+ * <p>
+ * Note that the {@link #equals(Object)} and {@link #hashCode()} methods
+ * delegate directly to the wrapped cache key provided by {@link #key()}
+ * method.
+ * <p>
+ * This class is optional and does not have to be used. It only provides
+ * extra convenience whenever custom affinity mapping is required. Here is
+ * an example of how {@code Person} objects can be collocated with
+ * {@code Company} objects they belong to:
+ * <pre name="code" class="java">
+ * Object personKey = new GridCacheAffinityKey(myPersonId, myCompanyId);
+ *
+ * // Both, the company and the person objects will be cached on the same node.
+ * cache.put(myCompanyId, new Company(..));
+ * cache.put(personKey, new Person(..));
+ * </pre>
+ * <p>
+ * For more information and examples of cache affinity refer to
+ * {@link CacheAffinityKeyMapper} and {@link CacheAffinityKeyMapped @GridCacheAffinityKeyMapped}
+ * documentation.
+ * @see CacheAffinityKeyMapped
+ * @see CacheAffinityKeyMapper
+ * @see CacheAffinityFunction
+ */
+public class CacheAffinityKey<K> implements Externalizable {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** Key. */
+ @GridToStringInclude
+ private K key;
+
+ /** Affinity key. */
+ @GridToStringInclude
+ private Object affKey;
+
+ /**
+ * Empty constructor.
+ */
+ public CacheAffinityKey() {
+ // No-op.
+ }
+
+ /**
+ * Initializes key wrapper for a given key. If affinity key
+ * is not initialized, then this key will be used for affinity.
+ *
+ * @param key Key.
+ */
+ public CacheAffinityKey(K key) {
+ A.notNull(key, "key");
+
+ this.key = key;
+ }
+
+ /**
+ * Initializes key together with its affinity key counter-part.
+ *
+ * @param key Key.
+ * @param affKey Affinity key.
+ */
+ public CacheAffinityKey(K key, Object affKey) {
+ A.notNull(key, "key");
+
+ this.key = key;
+ this.affKey = affKey;
+ }
+
+ /**
+ * Gets wrapped key.
+ *
+ * @return Wrapped key.
+ */
+ public K key() {
+ return key;
+ }
+
+ /**
+ * Sets wrapped key.
+ *
+ * @param key Wrapped key.
+ */
+ public void key(K key) {
+ this.key = key;
+ }
+
+ /**
+ * Gets affinity key to use for affinity mapping. If affinity key is not provided,
+ * then {@code key} value will be returned.
+ * <p>
+ * This method is annotated with {@link CacheAffinityKeyMapped} and will be picked up
+ * by {@link org.gridgain.grid.kernal.processors.cache.CacheDefaultAffinityKeyMapper} automatically.
+ *
+ * @return Affinity key to use for affinity mapping.
+ */
+ @CacheAffinityKeyMapped
+ @SuppressWarnings({"unchecked"})
+ public <T> T affinityKey() {
+ A.notNull(key, "key");
+
+ return (T)(affKey == null ? key : affKey);
+ }
+
+ /**
+ * Sets affinity key to use for affinity mapping. If affinity key is not provided,
+ * then {@code key} value will be returned.
+ *
+ * @param affKey Affinity key to use for affinity mapping.
+ */
+ public void affinityKey(Object affKey) {
+ this.affKey = affKey;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(key);
+ out.writeObject(affKey);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ key = (K)in.readObject();
+ affKey = in.readObject();
+ }
+
+ /**
+ * Hash code implementation which delegates to the underlying {@link #key()}. Note, however,
+ * that different subclasses of {@code GridCacheAffinityKey} will produce different hash codes.
+ * <p>
+ * Users should override this method if different behavior is desired.
+ *
+ * @return Hash code.
+ */
+ @Override public int hashCode() {
+ A.notNull(key, "key");
+
+ return 31 * key.hashCode() + getClass().getName().hashCode();
+ }
+
+ /**
+ * Equality check which delegates to the underlying key equality. Note, however, that
+ * different subclasses of {@code GridCacheAffinityKey} will never be equal.
+ * <p>
+ * Users should override this method if different behavior is desired.
+ *
+ * @param obj Object to check for equality.
+ * @return {@code True} if objects are equal.
+ */
+ @Override public boolean equals(Object obj) {
+ A.notNull(key, "key");
+
+ return obj != null && getClass() == obj.getClass() && key.equals(((CacheAffinityKey)obj).key);
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(CacheAffinityKey.class, this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25609651/modules/core/src/main/java/org/apache/ignite/cache/affinity/CacheAffinityKeyMapped.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/affinity/CacheAffinityKeyMapped.java b/modules/core/src/main/java/org/apache/ignite/cache/affinity/CacheAffinityKeyMapped.java
new file mode 100644
index 0000000..fbcc8a0
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/cache/affinity/CacheAffinityKeyMapped.java
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.affinity;
+
+import org.gridgain.grid.cache.*;
+
+import java.lang.annotation.*;
+import java.util.concurrent.*;
+
+/**
+ * Optional annotation to specify custom key-to-node affinity. Affinity key is a key
+ * which will be used to determine a node on which given cache key will be stored. This
+ * annotation allows to mark a field or a method in the cache key object that will be
+ * used as an affinity key (instead of the entire cache key object that is used for
+ * affinity by default). Note that a class can have only one field or method annotated
+ * with {@code @GridCacheAffinityKeyMapped} annotation.
+ * <p>
+ * One of the major use cases for this annotation is the routing of grid computations
+ * to the nodes where the data for this computation is cached, the concept
+ * otherwise known as {@code Collocation Of Computations And Data}.
+ * <p>
+ * <h1 class="header">Mapping Cache Keys</h1>
+ * The default implementation of {@link CacheAffinityKeyMapper}, which will be used
+ * if no explicit affinity mapper is specified in cache configuration, will first look
+ * for any field or method annotated with {@code @GridCacheAffinityKeyMapped} annotation.
+ * If such field or method is not found, then the cache key itself will be used for
+ * key-to-node affinity (this means that all objects with the same cache key will always
+ * be routed to the same node). If such field or method is found, then the value of this
+ * field or method will be used for key-to-node affinity. This allows to specify alternate
+ * affinity key, other than the cache key itself, whenever needed.
+ * <p>
+ * For example, if a {@code Person} object is always accessed together with a {@code Company} object
+ * for which this person is an employee, then for better performance and scalability it makes sense to
+ * collocate {@code Person} objects together with their {@code Company} object when storing them in
+ * cache. To achieve that, cache key used to cache {@code Person} objects should have a field or method
+ * annotated with {@code @GridCacheAffinityKeyMapped} annotation, which will provide the value of
+ * the company key for which that person works, like so:
+ * <pre name="code" class="java">
+ * public class PersonKey {
+ * // Person ID used to identify a person.
+ * private String personId;
+ *
+ * // Company ID which will be used for affinity.
+ * @GridCacheAffinityKeyMapped
+ * private String companyId;
+ * ...
+ * }
+ * ...
+ * // Instantiate person keys.
+ * Object personKey1 = new PersonKey("myPersonId1", "myCompanyId");
+ * Object personKey2 = new PersonKey("myPersonId2", "myCompanyId");
+ *
+ * // Both, the company and the person objects will be cached on the same node.
+ * cache.put("myCompanyId", new Company(..));
+ * cache.put(personKey1, new Person(..));
+ * cache.put(personKey2, new Person(..));
+ * </pre>
+ * <p>
+ * <h2 class="header">GridCacheAffinityKey</h2>
+ * For convenience, you can also optionally use {@link CacheAffinityKey} class. Here is how a
+ * {@code PersonKey} defined above would look using {@link CacheAffinityKey}:
+ * <pre name="code" class="java">
+ * Object personKey1 = new GridCacheAffinityKey("myPersonId1", "myCompanyId");
+ * Object personKey2 = new GridCacheAffinityKey("myPersonId2", "myCompanyId");
+ *
+ * // Both, the company and the person objects will be cached on the same node.
+ * cache.put(myCompanyId, new Company(..));
+ * cache.put(personKey1, new Person(..));
+ * cache.put(personKey2, new Person(..));
+ * </pre>
+ * <p>
+ * <h1 class="header">Collocating Computations And Data</h1>
+ * It is also possible to route computations to the nodes where the data is cached. This concept
+ * is otherwise known as {@code Collocation Of Computations And Data}. In this case,
+ * {@code @GridCacheAffinityKeyMapped} annotation allows to specify a routing affinity key for a
+ * {@link org.apache.ignite.compute.ComputeJob} or any other grid computation, such as {@link Runnable}, {@link Callable}, or
+ * {@link org.apache.ignite.lang.IgniteClosure}. It should be attached to a method or field that provides affinity key
+ * for the computation. Only one annotation per class is allowed. Whenever such annotation is detected,
+ * then {@link org.apache.ignite.spi.loadbalancing.LoadBalancingSpi} will be bypassed, and computation will be routed to the grid node
+ * where the specified affinity key is cached. You can also use optional {@link GridCacheName @GridCacheName}
+ * annotation whenever non-default cache name needs to be specified.
+ * <p>
+ * Here is how this annotation can be used to route a job to a node where Person object
+ * is cached with ID "1234":
+ * <pre name="code" class="java">
+ * G.grid().run(new Runnable() {
+ * // This annotation is optional. If omitted, then default
+ * // no-name cache will be used.
+ * @GridCacheName
+ * private String cacheName = "myCache";
+ *
+ * // This annotation specifies that computation should be routed
+ * // precisely to the node where key '1234' is cached.
+ * @GridCacheAffinityKeyMapped
+ * private String personKey = "1234";
+ *
+ * @Override public void run() {
+ * // Some computation logic here.
+ * ...
+ * }
+ * };
+ * </pre>
+ * The same can be achieved by annotating method instead of field as follows:
+ * <pre name="code" class="java">
+ * G.grid().run(new Runnable() {
+ * @Override public void run() {
+ * // Some computation logic here.
+ * ...
+ * }
+ *
+ * // This annotation is optional. If omitted, then default
+ * // no-name cache will be used.
+ * @GridCacheName
+ * public String cacheName() {
+ * return "myCache";
+ * }
+ *
+ * // This annotation specifies that computation should be routed
+ * // precisely to the node where key '1234' is cached.
+ * @GridCacheAffinityKeyMapped
+ * public String personKey() {
+ * return "1234";
+ * }
+ * };
+ * </pre>
+ * <p>
+ * For more information about cache affinity also see {@link CacheAffinityKeyMapper} and
+ * {@link CacheAffinityFunction} documentation.
+ * Affinity for a key can be found from any node, regardless of whether it has cache started
+ * or not. If cache is not started, affinity function will be fetched from the remote node
+ * which does have the cache running.
+ *
+ * @see GridCacheName
+ * @see CacheAffinityFunction
+ * @see CacheAffinityKeyMapper
+ * @see CacheAffinityKey
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.FIELD, ElementType.METHOD})
+public @interface CacheAffinityKeyMapped {
+ // No-op.
+}