Search in sources :

Example 1 with PartitionClientContext

use of org.apache.ignite.internal.sql.optimizer.affinity.PartitionClientContext in project ignite by apache.

the class JdbcThinConnection method updateAffinityCache.

/**
 * Recreates affinity cache if affinity topology version was changed and adds partition result to sql cache.
 *
 * @param qryReq Query request.
 * @param res Jdbc Response.
 */
private void updateAffinityCache(JdbcQueryExecuteRequest qryReq, JdbcResponse res) {
    if (partitionAwareness) {
        AffinityTopologyVersion resAffVer = res.affinityVersion();
        if (resAffVer != null && (affinityCache == null || affinityCache.version().compareTo(resAffVer) < 0)) {
            affinityCache = new AffinityCache(resAffVer, connProps.getPartitionAwarenessPartitionDistributionsCacheSize(), connProps.getPartitionAwarenessSqlCacheSize());
        }
        // Partition result was requested.
        if (res.response() instanceof JdbcQueryExecuteResult && qryReq.partitionResponseRequest()) {
            PartitionResult partRes = ((JdbcQueryExecuteResult) res.response()).partitionResult();
            if (partRes == null || affinityCache.version().equals(partRes.topologyVersion())) {
                int cacheId = (partRes != null && partRes.tree() != null) ? GridCacheUtils.cacheId(partRes.cacheName()) : -1;
                PartitionClientContext partClientCtx = partRes != null ? new PartitionClientContext(partRes.partitionsCount()) : null;
                QualifiedSQLQuery qry = new QualifiedSQLQuery(qryReq.schemaName(), qryReq.sqlQuery());
                JdbcThinPartitionResultDescriptor partResDescr = new JdbcThinPartitionResultDescriptor(partRes, cacheId, partClientCtx);
                affinityCache.addSqlQuery(qry, partResDescr);
            }
        }
    }
}
Also used : PartitionClientContext(org.apache.ignite.internal.sql.optimizer.affinity.PartitionClientContext) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) JdbcQueryExecuteResult(org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryExecuteResult) PartitionResult(org.apache.ignite.internal.sql.optimizer.affinity.PartitionResult) Savepoint(java.sql.Savepoint)

Aggregations

Savepoint (java.sql.Savepoint)1 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)1 JdbcQueryExecuteResult (org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryExecuteResult)1 PartitionClientContext (org.apache.ignite.internal.sql.optimizer.affinity.PartitionClientContext)1 PartitionResult (org.apache.ignite.internal.sql.optimizer.affinity.PartitionResult)1