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

Race condition in JMX cache update

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.7.1
    • 2.8.0, 2.7.3, 2.6.5, 3.0.0-alpha1
    • None
    • None

    Description

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

        private void updateJmxCache() {
          boolean getAllMetrics = false;
          synchronized (this) {
            if (Time.now() - jmxCacheTS >= jmxCacheTTL) {
              // temporarilly advance the expiry while updating the cache
              jmxCacheTS = Time.now() + jmxCacheTTL;
              if (lastRecs == null) {
                getAllMetrics = true;
              }
            } else {
              return;
            }
      
            if (getAllMetrics) {
              MetricsCollectorImpl builder = new MetricsCollectorImpl();
              getMetrics(builder, true);
            }
      
            updateAttrCache();
            if (getAllMetrics) {
              updateInfoCache();
            }
            jmxCacheTS = Time.now();
            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.

      Attachments

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

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: