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 13:00:34 UTC

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

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

 ##########
 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:
   I think it's better to use Java 8 approach here with UnarnaryOperator - 
   
   `oldVal.updateAndGet(x -> x < newVal ? newVal : x) == newVal;`

----------------------------------------------------------------
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