Vladsz83 commented on code in PR #11650: URL: https://github.com/apache/ignite/pull/11650#discussion_r1840259415
########## modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/AbstractCacheScan.java: ########## @@ -0,0 +1,152 @@ +/* + * 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.internal.processors.query.calcite.exec; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import org.apache.ignite.cluster.ClusterTopologyException; +import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture; +import org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition; +import org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState; +import org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology; +import org.apache.ignite.internal.util.typedef.F; + +/** */ +public abstract class AbstractCacheScan<Row> implements Iterable<Row>, AutoCloseable { + /** */ + protected final GridCacheContext<?, ?> cctx; + + /** */ + protected final ExecutionContext<Row> ectx; + + /** */ + protected final AffinityTopologyVersion topVer; + + /** */ + protected final int[] parts; + + /** */ + protected volatile List<GridDhtLocalPartition> reserved; + + /** */ + AbstractCacheScan(ExecutionContext<Row> ectx, GridCacheContext<?, ?> cctx, int[] parts) { + this.ectx = ectx; + this.cctx = cctx; + this.parts = parts; + + topVer = ectx.topologyVersion(); + } + + /** {@inheritDoc} */ + @Override public final Iterator<Row> iterator() { + reserve(); + + try { + return createIterator(); + } + catch (Exception e) { + release(); + + throw e; + } + } + + /** Rows iterator.*/ + protected abstract Iterator<Row> createIterator(); + + /** */ + @Override public void close() { + release(); + } + + /** */ + private synchronized void reserve() { + if (reserved != null) + return; + + GridDhtPartitionTopology top = cctx.topology(); + top.readLock(); + + GridDhtTopologyFuture topFut = top.topologyVersionFuture(); + + boolean done = topFut.isDone(); + + if (!done || !(topFut.topologyVersion().compareTo(topVer) >= 0 + && cctx.shared().exchange().lastAffinityChangedTopologyVersion(topFut.initialVersion()).compareTo(topVer) <= 0)) { + top.readUnlock(); + + throw new ClusterTopologyException("Topology was changed. Please retry on stable topology."); + } + + List<GridDhtLocalPartition> toReserve; + + if (cctx.isReplicated()) { Review Comment: Let's use line breaks below -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org