sergeyuttsel commented on code in PR #1729:
URL: https://github.com/apache/ignite-3/pull/1729#discussion_r1163049629


##########
modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/DistributionZoneManager.java:
##########
@@ -505,6 +543,133 @@ public int getZoneId(String name) {
         }
     }
 
+    /**
+     * The method for obtaining data nodes of the specified zone.
+     * The flow for the future completion:
+     * Waiting for DistributionZoneManager observe passed topology version or 
greater version in topologyWatchListener.
+     * If the {@link 
DistributionZoneConfigurationSchema#dataNodesAutoAdjustScaleUp} equals to 0 
than wait for writing data nodes triggered
+     * by started nodes and corresponding to the passed topology version or 
greater topology version
+     * to the data nodes into the meta storage.
+     * If the {@link 
DistributionZoneConfigurationSchema#dataNodesAutoAdjustScaleDown} equals to 0 
than wait for writing data nodes
+     * triggered by stopped nodes and corresponding to the passed topology 
version or greater topology version
+     * to the data nodes into the meta storage.
+     * After waiting it completes the future with data nodes of the specified 
zone.
+     * This method must be invoked in a change configuration closure to 
guarantee that the zone is exists and values of scaleUp/scaleDown
+     * timers are up to date.
+     * The returned future can be completed with {@link 
DistributionZoneNotFoundException} and {@link 
DistributionZoneWasRemovedException}
+     * in case when the distribution zone was removed during method execution.
+     *
+     * @param zoneId Zone id.
+     * @param topVer Topology version.
+     * @return The data nodes future.
+     */
+    public CompletableFuture<Set<String>> topologyVersionedDataNodes(int 
zoneId, long topVer) {
+        CompletableFuture<IgniteBiTuple<Boolean, Boolean>> timerValuesFut = 
awaitTopologyVersion(topVer)
+                .thenCompose(ignored -> getImmediateTimers(zoneId));
+
+        return allOf(
+                timerValuesFut.thenCompose(timerValues -> 
scaleUpAwaiting(zoneId, timerValues.get1())),
+                timerValuesFut.thenCompose(timerValues -> 
scaleDownAwaiting(zoneId, timerValues.get2()))
+        ).thenCompose(ignored -> getDataNodesFuture(zoneId));
+    }
+
+    /**
+     * Waits for DistributionZoneManager observe passed topology version or 
greater version in topologyWatchListener.
+     *
+     * @param topVer Topology version.
+     * @return Future for chaining.
+     */
+    private CompletableFuture<Void> awaitTopologyVersion(long topVer) {
+        return inBusyLock(busyLock, () -> topVerTracker.waitFor(topVer));
+    }
+
+    /**
+     * Transforms {@link 
DistributionZoneConfigurationSchema#dataNodesAutoAdjustScaleUp}
+     * and {@link 
DistributionZoneConfigurationSchema#dataNodesAutoAdjustScaleDown} values to 
boolean values.
+     * True if it equals to zero and false if it greater than zero. Zero means 
that data nodes changing must be started immediate.
+     *
+     * @param zoneId Zone id.
+     * @return Future with the result.
+     */
+    private CompletableFuture<IgniteBiTuple<Boolean, Boolean>> 
getImmediateTimers(int zoneId) {
+        return inBusyLock(busyLock, () -> {
+            DistributionZoneConfiguration zoneCfg = 
getZoneById(zonesConfiguration, zoneId);
+
+            return completedFuture(new IgniteBiTuple<>(
+                    zoneCfg.dataNodesAutoAdjustScaleUp().value() == 
IMMEDIATE_TIMER_VALUE,
+                    zoneCfg.dataNodesAutoAdjustScaleDown().value() == 
IMMEDIATE_TIMER_VALUE
+            ));
+        });
+    }
+
+    /**
+     * If the {@link 
DistributionZoneConfigurationSchema#dataNodesAutoAdjustScaleUp} equals to 0 
than waits for writing data nodes triggered

Review Comment:
   Fixed.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to