Uploaded image for project: 'Hadoop Common'
  1. Hadoop Common
  2. HADOOP-18429

MutableGaugeFloat#incr(float) get stuck in an infinite loop

    XMLWordPrintableJSON

Details

    • Reviewed

    Description

      The current implementation converts the value from int to float, causing the compareAndSet method to get stuck.

      private final boolean compareAndSet(float expect, float update) {
        return value.compareAndSet(Float.floatToIntBits(expect),
            Float.floatToIntBits(update));
      }
      
      private void incr(float delta) {
        while (true) {
          float current = value.get();
          float next = current + delta;
          if (compareAndSet(current, next)) {
            setChanged();
            return;
          }
        }
      } 

       

      Perhaps it could be:

      private void incr(float delta) {
        while (true) {
          float current = Float.intBitsToFloat(value.get());
          float next = current + delta;
          if (compareAndSet(current, next)) {
            setChanged();
            return;
          }
        }
      } 

       

      The unit test looks like this

      MutableGaugeFloat mgf = new MutableGaugeFloat(Context,3.2f);
      assertEquals(3.2f, mgf.value(), 0.0);
      mgf.incr();
      assertEquals(4.2f, mgf.value(), 0.0); 

       

      Attachments

        Issue Links

          Activity

            People

              groot Ashutosh Gupta
              xinqiu asdfgh19
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: