You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by dg...@apache.org on 2019/03/20 14:09:43 UTC

[ignite] branch master updated: IGNITE-11545 Logging baseline auto-adjust

This is an automated email from the ASF dual-hosted git repository.

dgovorukhin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new b221ab8  IGNITE-11545 Logging baseline auto-adjust
b221ab8 is described below

commit b221ab8dd1ff0f25b1a8ebb7fe1ad1b5ac910b52
Author: Anton Kalashnikov <ka...@yandex.ru>
AuthorDate: Wed Mar 20 17:09:21 2019 +0300

    IGNITE-11545 Logging baseline auto-adjust
    
    Signed-off-by: Dmitriy Govorukhin <dm...@gmail.com>
---
 .../org/apache/ignite/IgniteSystemProperties.java  |   5 +
 .../cluster/DistributedBaselineConfiguration.java  |   2 -
 .../autoadjust/BaselineAutoAdjustExecutor.java     |  12 +-
 .../autoadjust/BaselineAutoAdjustScheduler.java    | 121 +++++++++++++++++++--
 .../baseline/autoadjust/ChangeTopologyWatcher.java |   6 +-
 5 files changed, 129 insertions(+), 17 deletions(-)

diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
index 9f1e063..8f4f640 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
@@ -1148,6 +1148,11 @@ public final class IgniteSystemProperties {
     public static final String IGNITE_SQL_ALLOW_KEY_VAL_UPDATES = "IGNITE_SQL_ALLOW_KEY_VAL_UPDATES";
 
     /**
+     * Interval between logging of time of next auto-adjust.
+     */
+    public static final String IGNITE_BASELINE_AUTO_ADJUST_LOG_INTERVAL = "IGNITE_BASELINE_AUTO_ADJUST_LOG_INTERVAL";
+
+    /**
      * Enforces singleton.
      */
     private IgniteSystemProperties() {
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cluster/DistributedBaselineConfiguration.java b/modules/core/src/main/java/org/apache/ignite/internal/cluster/DistributedBaselineConfiguration.java
index 9686a3a..924550f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cluster/DistributedBaselineConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cluster/DistributedBaselineConfiguration.java
@@ -19,7 +19,6 @@ package org.apache.ignite.internal.cluster;
 
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.IgniteSystemProperties;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.processors.configuration.distributed.DistributedBooleanProperty;
 import org.apache.ignite.internal.processors.configuration.distributed.DistributedLongProperty;
@@ -28,7 +27,6 @@ import org.apache.ignite.internal.util.future.GridFutureAdapter;
 import org.apache.ignite.internal.util.typedef.internal.CU;
 
 import static org.apache.ignite.IgniteSystemProperties.IGNITE_BASELINE_AUTO_ADJUST_ENABLED;
-import static org.apache.ignite.IgniteSystemProperties.IGNITE_RECOVERY_SEMAPHORE_PERMITS;
 import static org.apache.ignite.IgniteSystemProperties.getBoolean;
 import static org.apache.ignite.internal.processors.configuration.distributed.DistributedBooleanProperty.detachedBooleanProperty;
 import static org.apache.ignite.internal.processors.configuration.distributed.DistributedLongProperty.detachedLongProperty;
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/baseline/autoadjust/BaselineAutoAdjustExecutor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/baseline/autoadjust/BaselineAutoAdjustExecutor.java
index b90df68..627bb41 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/baseline/autoadjust/BaselineAutoAdjustExecutor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/baseline/autoadjust/BaselineAutoAdjustExecutor.java
@@ -62,12 +62,12 @@ class BaselineAutoAdjustExecutor {
     public void execute(BaselineAutoAdjustData data) {
         executorService.submit(() ->
             {
-                if (data.isInvalidated() || !isBaselineAutoAdjustEnabled.getAsBoolean())
+                if (isExecutionExpired(data))
                     return;
 
                 executionGuard.lock();
                 try {
-                    if (data.isInvalidated() || !isBaselineAutoAdjustEnabled.getAsBoolean())
+                    if (isExecutionExpired(data))
                         return;
 
                     cluster.triggerBaselineAutoAdjust(data.getTargetTopologyVersion());
@@ -83,4 +83,12 @@ class BaselineAutoAdjustExecutor {
             }
         );
     }
+
+    /**
+     * @param data Baseline data for adjust.
+     * @return {@code true} If baseline auto-adjust shouldn't be executed for given data.
+     */
+    public boolean isExecutionExpired(BaselineAutoAdjustData data) {
+        return data.isInvalidated() || !isBaselineAutoAdjustEnabled.getAsBoolean();
+    }
 }
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/baseline/autoadjust/BaselineAutoAdjustScheduler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/baseline/autoadjust/BaselineAutoAdjustScheduler.java
index f6e41db..bd9c6d1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/baseline/autoadjust/BaselineAutoAdjustScheduler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/baseline/autoadjust/BaselineAutoAdjustScheduler.java
@@ -17,9 +17,14 @@
 
 package org.apache.ignite.internal.processors.cluster.baseline.autoadjust;
 
+import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.internal.processors.timeout.GridTimeoutObject;
-import org.apache.ignite.internal.processors.timeout.GridTimeoutObjectAdapter;
 import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteUuid;
+
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_BASELINE_AUTO_ADJUST_LOG_INTERVAL;
+import static org.apache.ignite.IgniteSystemProperties.getLong;
 
 /**
  * This class able to add task of set baseline with timeout to queue. In one time only one task can be in queue. Every
@@ -31,16 +36,20 @@ class BaselineAutoAdjustScheduler {
     /** Executor of set baseline operation. */
     private final BaselineAutoAdjustExecutor baselineAutoAdjustExecutor;
     /** Last scheduled task for adjust new baseline. It needed for removing from queue. */
-    private GridTimeoutObject baselineTimeoutObj;
+    private BaselineMultiplyUseTimeoutObject baselineTimeoutObj;
+    /** */
+    private final IgniteLogger log;
 
     /**
      * @param timeoutProcessor Timeout processor.
      * @param baselineAutoAdjustExecutor Executor of set baseline operation.
+     * @param log Log object.
      */
     public BaselineAutoAdjustScheduler(GridTimeoutProcessor timeoutProcessor,
-        BaselineAutoAdjustExecutor baselineAutoAdjustExecutor) {
+        BaselineAutoAdjustExecutor baselineAutoAdjustExecutor, IgniteLogger log) {
         this.timeoutProcessor = timeoutProcessor;
         this.baselineAutoAdjustExecutor = baselineAutoAdjustExecutor;
+        this.log = log;
     }
 
     /**
@@ -54,11 +63,12 @@ class BaselineAutoAdjustScheduler {
             timeoutProcessor.removeTimeoutObject(baselineTimeoutObj);
 
         timeoutProcessor.addTimeoutObject(
-            baselineTimeoutObj = new GridTimeoutObjectAdapter(delay) {
-                @Override public void onTimeout() {
-                    baselineAutoAdjustExecutor.execute(baselineAutoAdjustData);
-                }
-            }
+            baselineTimeoutObj = new BaselineMultiplyUseTimeoutObject(
+                baselineAutoAdjustData,
+                delay, baselineAutoAdjustExecutor,
+                timeoutProcessor,
+                log
+            )
         );
     }
 
@@ -69,8 +79,101 @@ class BaselineAutoAdjustScheduler {
         if (baselineTimeoutObj == null)
             return -1;
 
-        long lastScheduledTaskTime = baselineTimeoutObj.endTime() - System.currentTimeMillis();
+        long lastScheduledTaskTime = baselineTimeoutObj.getTotalEndTime() - System.currentTimeMillis();
 
         return lastScheduledTaskTime < 0 ? -1 : lastScheduledTaskTime;
     }
+
+    /**
+     * Timeout object of baseline auto-adjust operation. This object able executing several times: some first times for
+     * logging of expecting auto-adjust and last time for baseline adjust.
+     */
+    private static class BaselineMultiplyUseTimeoutObject implements GridTimeoutObject {
+        /** Interval between logging of info about next baseline auto-adjust. */
+        private static final long AUTO_ADJUST_LOG_INTERVAL =
+            getLong(IGNITE_BASELINE_AUTO_ADJUST_LOG_INTERVAL, 60_000);
+        /** Last data for set new baseline. */
+        private final BaselineAutoAdjustData baselineAutoAdjustData;
+        /** Executor of set baseline operation. */
+        private final BaselineAutoAdjustExecutor baselineAutoAdjustExecutor;
+        /** Timeout processor. */
+        private final GridTimeoutProcessor timeoutProcessor;
+        /** */
+        private final IgniteLogger log;
+
+        /** End time of whole life of this object. It represent time when auto-adjust will be executed. */
+        private final long totalEndTime;
+        /** Timeout ID. */
+        private final IgniteUuid id = IgniteUuid.randomUuid();
+        /** End time of one iteration of this timeout object. */
+        private long endTime;
+
+        /**
+         * @param data Data for changing baseline.
+         * @param executionTimeout Delay after which set baseline should be started.
+         * @param executor Executor of set baseline operation.
+         * @param processor Timeout processor.
+         * @param log Log object.
+         */
+        protected BaselineMultiplyUseTimeoutObject(
+            BaselineAutoAdjustData data,
+            long executionTimeout,
+            BaselineAutoAdjustExecutor executor,
+            GridTimeoutProcessor processor,
+            IgniteLogger log
+        ) {
+            baselineAutoAdjustData = data;
+            baselineAutoAdjustExecutor = executor;
+            timeoutProcessor = processor;
+            this.log = log;
+            endTime = calculateEndTime(executionTimeout);
+            this.totalEndTime = U.currentTimeMillis() + executionTimeout;
+        }
+
+        /**
+         * @param timeout Remaining time to baseline adjust.
+         * @return Calculated end time to next iteration.
+         */
+        private long calculateEndTime(long timeout) {
+            return U.currentTimeMillis() + (AUTO_ADJUST_LOG_INTERVAL < timeout ? AUTO_ADJUST_LOG_INTERVAL : timeout);
+        }
+
+        /** {@inheritDoc}. */
+        @Override public IgniteUuid timeoutId() {
+            return id;
+        }
+
+        /** {@inheritDoc}. */
+        @Override public long endTime() {
+            return endTime;
+        }
+
+        /** {@inheritDoc}. */
+        @Override public void onTimeout() {
+            if (baselineAutoAdjustExecutor.isExecutionExpired(baselineAutoAdjustData))
+                return;
+
+            long lastScheduledTaskTime = totalEndTime - System.currentTimeMillis();
+
+            if (lastScheduledTaskTime <= 0) {
+                log.info("Baseline auto-adjust will be executed right now.");
+
+                baselineAutoAdjustExecutor.execute(baselineAutoAdjustData);
+            }
+            else {
+                log.info("Baseline auto-adjust will be executed in '" + lastScheduledTaskTime + "' ms.");
+
+                endTime = calculateEndTime(lastScheduledTaskTime);
+
+                timeoutProcessor.addTimeoutObject(this);
+            }
+        }
+
+        /**
+         * @return End time of whole life of this object. It represent time when auto-adjust will be executed.
+         */
+        public long getTotalEndTime() {
+            return totalEndTime;
+        }
+    }
 }
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/baseline/autoadjust/ChangeTopologyWatcher.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/baseline/autoadjust/ChangeTopologyWatcher.java
index 2448810..13eb685 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/baseline/autoadjust/ChangeTopologyWatcher.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/baseline/autoadjust/ChangeTopologyWatcher.java
@@ -32,8 +32,6 @@ import org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor;
 import org.apache.ignite.lang.IgniteInClosure;
 
 import static org.apache.ignite.internal.processors.cluster.baseline.autoadjust.BaselineAutoAdjustData.NULL_BASELINE_DATA;
-import static org.apache.ignite.internal.processors.cluster.baseline.autoadjust.BaselineAutoAdjustStatistic.TaskState.IN_PROGRESS;
-import static org.apache.ignite.internal.processors.cluster.baseline.autoadjust.BaselineAutoAdjustStatistic.TaskState.NOT_SCHEDULED;
 import static org.apache.ignite.internal.util.IgniteUtils.isLocalNodeCoordinator;
 
 /**
@@ -72,7 +70,7 @@ public class ChangeTopologyWatcher implements GridLocalEventListener {
             cluster,
             ctx.getSystemExecutorService(),
             this::isBaselineAutoAdjustEnabled
-        ));
+        ), ctx.log(BaselineAutoAdjustScheduler.class));
         this.discoveryMgr = ctx.discovery();
     }
 
@@ -108,7 +106,7 @@ public class ChangeTopologyWatcher implements GridLocalEventListener {
 
                         long timeout = baselineConfiguration.getBaselineAutoAdjustTimeout();
 
-                        log.warning("Baseline will be changed in '" + timeout + "' ms");
+                        log.warning("Baseline auto-adjust will be executed in '" + timeout + "' ms");
 
                         baselineAutoAdjustScheduler.schedule(lastBaselineData, timeout);
                     });