You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2019/06/26 14:12:47 UTC

[GitHub] [ignite] nizhikov commented on a change in pull request #6627: IGNITE-11925: QueryMetrics migration.

nizhikov commented on a change in pull request #6627: IGNITE-11925: QueryMetrics migration.
URL: https://github.com/apache/ignite/pull/6627#discussion_r297688915
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/internal/processors/metric/impl/MetricUtils.java
 ##########
 @@ -83,6 +83,32 @@ public static boolean compareAndSet(LongMetricImpl m, long expect, long update)
         return LongMetricImpl.updater.compareAndSet(m, expect, update);
     }
 
+    /**
+     * Update metrics value only if current value if less then {@code update}.
+     *
+     * @param m Metric to update.
+     * @param update New value.
+     */
+    public static void setIfLess(LongMetricImpl m, long update) {
+        long v = m.value();
+
+        while (v > update && !LongMetricImpl.updater.compareAndSet(m, v, update))
+            v = m.value();
+    }
+
+    /**
+     * Update metrics value only if current value if greater then {@code update}.
+     *
+     * @param m Metric to update.
+     * @param update New value.
+     */
+    public static void setIfGreater(LongMetricImpl m, long update) {
+        long v = m.value();
+
+        while (v < update && !LongMetricImpl.updater.compareAndSet(m, v, update))
 
 Review comment:
   Proposed implementation is less efficient then current because `updateAndGet` implementation executes at least one CAS operation(see `AtomicLongFieldUpdater#updateAndGet` sources) event value is not change. And my implementation returns immediately in the case we don't want to update the value.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services