Search in sources :

Example 1 with JdbcCachePartitionsResult

use of org.apache.ignite.internal.processors.odbc.jdbc.JdbcCachePartitionsResult 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;
}
Also used : JdbcCachePartitionsRequest(org.apache.ignite.internal.processors.odbc.jdbc.JdbcCachePartitionsRequest) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) JdbcResponse(org.apache.ignite.internal.processors.odbc.jdbc.JdbcResponse) UUID(java.util.UUID) JdbcCachePartitionsResult(org.apache.ignite.internal.processors.odbc.jdbc.JdbcCachePartitionsResult) Savepoint(java.sql.Savepoint)

Aggregations

Savepoint (java.sql.Savepoint)1 UUID (java.util.UUID)1 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)1 JdbcCachePartitionsRequest (org.apache.ignite.internal.processors.odbc.jdbc.JdbcCachePartitionsRequest)1 JdbcCachePartitionsResult (org.apache.ignite.internal.processors.odbc.jdbc.JdbcCachePartitionsResult)1 JdbcResponse (org.apache.ignite.internal.processors.odbc.jdbc.JdbcResponse)1