use of org.apache.ignite.internal.processors.odbc.jdbc.JdbcCachePartitionsRequest in project ignite by apache.
the class JdbcThinConnection method retrieveCacheDistribution.
/**
* Retrieve cache distribution for specified cache Id.
*
* @param cacheId Cache Id.
* @param partCnt Partitions count.
* @return Partitions cache distribution.
* @throws IOException If Exception occurred during the network partition distribution retrieval.
*/
private UUID[] retrieveCacheDistribution(int cacheId, int partCnt) throws IOException {
UUID[] cacheDistr = affinityCache.cacheDistribution(cacheId);
if (cacheDistr != null)
return cacheDistr;
JdbcResponse res;
res = cliIo(null).sendRequest(new JdbcCachePartitionsRequest(Collections.singleton(cacheId)), null);
assert res.status() == ClientListenerResponse.STATUS_SUCCESS;
AffinityTopologyVersion resAffinityVer = res.affinityVersion();
if (affinityCache.version().compareTo(resAffinityVer) < 0) {
affinityCache = new AffinityCache(resAffinityVer, connProps.getPartitionAwarenessPartitionDistributionsCacheSize(), connProps.getPartitionAwarenessSqlCacheSize());
} else if (affinityCache.version().compareTo(resAffinityVer) > 0) {
// possible in single-threaded jdbc thin client, so it's a reserve for the future.
return null;
}
List<JdbcThinPartitionAwarenessMappingGroup> mappings = ((JdbcCachePartitionsResult) res.response()).getMappings();
// we might retrieve multiple caches but exactly with same distribution.
assert mappings.size() == 1;
JdbcThinPartitionAwarenessMappingGroup mappingGrp = mappings.get(0);
cacheDistr = mappingGrp.revertMappings(partCnt);
for (int mpCacheId : mappingGrp.cacheIds()) affinityCache.addCacheDistribution(mpCacheId, cacheDistr);
return cacheDistr;
}
Aggregations