• Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.7.1
    • Fix Version/s: 2.8.0, 2.7.3, 2.6.5, 3.0.0-alpha1
    • Component/s: None
    • Labels:
    • Target Version/s:


      updateJmxCache() was updated in HADOOP-11301. However the patch introduced a race condition. In updateJmxCache() function in

        private void updateJmxCache() {
          boolean getAllMetrics = false;
          synchronized (this) {
            if ( - jmxCacheTS >= jmxCacheTTL) {
              // temporarilly advance the expiry while updating the cache
              jmxCacheTS = + jmxCacheTTL;
              if (lastRecs == null) {
                getAllMetrics = true;
            } else {
            if (getAllMetrics) {
              MetricsCollectorImpl builder = new MetricsCollectorImpl();
              getMetrics(builder, true);
            if (getAllMetrics) {
            jmxCacheTS =;
            lastRecs = null; // in case regular interval update is not running

      Notice that getAllMetrics is set to true when:

      1. jmxCacheTTL has passed
      2. lastRecs == null

      lastRecs is set to null in the same function, but gets reassigned by getMetrics().

      However getMetrics() can be called from a different thread:

      1. MetricsSystemImpl.onTimerEvent()
      2. MetricsSystemImpl.publishMetricsNow()

      Consider the following sequence:

      1. updateJmxCache() is called by getMBeanInfo() from a thread getting cached info.
        • lastRecs is set to null.
      2. metrics sources is updated with new value/field.
      3. getMetrics() is called by publishMetricsNow() or onTimerEvent() from a different thread getting the latest metrics.
        • lastRecs is updated (!= null).
      4. jmxCacheTTL passed.
      5. updateJmxCache() is called again via getMBeanInfo().
        • However because lastRecs is already updated (!= null), getAllMetrics will not be set to true. So updateInfoCache() is not called and getMBeanInfo() returns the old cached info.

      We ran into this issue on a cluster where a new metric did not get published until much later.

      The case can be made worse by a periodic call to getMetrics() (driven by an external program or script). In such case getMBeanInfo() may never be able to retrieve the new record.

      The desired behavior should be that updateJmxCache() will guarantee to call updateInfoCache() once after jmxCacheTTL, if lastRecs has been set to null by updateJmxCache() itself.


        1. HADOOP-12482.006.patch
          10 kB
          Tony Wu
        2. HADOOP-12482.005.patch
          10 kB
          Tony Wu
        3. HADOOP-12482.004.patch
          10 kB
          Tony Wu
        4. HADOOP-12482.003.patch
          6 kB
          Tony Wu
        5. HADOOP-12482.002.patch
          6 kB
          Tony Wu
        6. HADOOP-12482.001.patch
          6 kB
          Tony Wu



            • Assignee:
              twu Tony Wu
              twu Tony Wu
            • Votes:
              0 Vote for this issue
              9 Start watching this issue


              • Created: