You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "alievmirza (via GitHub)" <gi...@apache.org> on 2023/02/08 10:42:44 UTC

[GitHub] [ignite-3] alievmirza commented on a diff in pull request #1631: IGNITE-18132 add scale down scheduler

alievmirza commented on code in PR #1631:
URL: https://github.com/apache/ignite-3/pull/1631#discussion_r1099955650


##########
modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/DistributionZoneManager.java:
##########
@@ -557,24 +561,57 @@ public CompletableFuture<?> onUpdate(ConfigurationNotificationEvent<Distribution
 
             int oldScaleUp;
 
+            int oldScaleDown;
+
             // ctx.oldValue() could be null for the default zone on a first start.
             if (ctx.oldValue() == null) {
                 oldScaleUp = Integer.MAX_VALUE;
+
+                oldScaleDown = Integer.MAX_VALUE;
             } else {
                 oldScaleUp = ctx.oldValue().dataNodesAutoAdjustScaleUp();
+
+                oldScaleDown = ctx.oldValue().dataNodesAutoAdjustScaleDown();
             }
 
             int newScaleUp = ctx.newValue().dataNodesAutoAdjustScaleUp();
 
-            if (newScaleUp != Integer.MAX_VALUE && oldScaleUp != newScaleUp) {
-                // It is safe to zonesTimers.get(zoneId) in term of NPE because meta storage notifications are one-threaded
-                zonesState.get(zoneId).rescheduleScaleUp(
-                        newScaleUp,
-                        () -> CompletableFuture.supplyAsync(
-                                () -> saveDataNodesToMetaStorageOnScaleUp(zoneId, ctx.storageRevision()),
-                                Runnable::run
-                        )
-                );
+            int newScaleDown = ctx.newValue().dataNodesAutoAdjustScaleDown();
+
+            // It is safe to zonesTimers.get(zoneId) in term of NPE because meta storage notifications are one-threaded
+            // and this map will me initialized on a manager start or with onCreate configuration notification
+            ZoneState zoneState = zonesState.get(zoneId);
+
+            if (oldScaleUp != newScaleUp) {
+                if (newScaleUp != Integer.MAX_VALUE) {
+                    Optional<Long> highestRevision = zoneState.highestRevision(true);
+
+                    highestRevision.ifPresent(rev -> zoneState.rescheduleScaleUp(
+                            newScaleUp,
+                            () -> CompletableFuture.supplyAsync(
+                                    () -> saveDataNodesToMetaStorageOnScaleUp(zoneId, rev),
+                                    Runnable::run

Review Comment:
   This is the way to run supplier in the executors thread 



-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org