Uploaded image for project: 'Hive'
  1. Hive
  2. HIVE-20740

Remove global lock in ObjectStore.setConf method

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 3.2.0, 4.0.0-alpha-1
    • None
    • None

    Description

      The ObjectStore#setConf method has a global lock which can block other clients in concurrent workloads.

      @Override
        @SuppressWarnings("nls")
        public void setConf(Configuration conf) {
          // Although an instance of ObjectStore is accessed by one thread, there may
          // be many threads with ObjectStore instances. So the static variables
          // pmf and prop need to be protected with locks.
          pmfPropLock.lock();
          try {
            isInitialized = false;
            this.conf = conf;
            this.areTxnStatsSupported = MetastoreConf.getBoolVar(conf, ConfVars.HIVE_TXN_STATS_ENABLED);
            configureSSL(conf);
            Properties propsFromConf = getDataSourceProps(conf);
            boolean propsChanged = !propsFromConf.equals(prop);
      
            if (propsChanged) {
              if (pmf != null){
                clearOutPmfClassLoaderCache(pmf);
                if (!forTwoMetastoreTesting) {
                  // close the underlying connection pool to avoid leaks
                  pmf.close();
                }
              }
              pmf = null;
              prop = null;
            }
      
            assert(!isActiveTransaction());
            shutdown();
            // Always want to re-create pm as we don't know if it were created by the
            // most recent instance of the pmf
            pm = null;
            directSql = null;
            expressionProxy = null;
            openTrasactionCalls = 0;
            currentTransaction = null;
            transactionStatus = TXN_STATUS.NO_STATE;
      
            initialize(propsFromConf);
      
            String partitionValidationRegex =
                MetastoreConf.getVar(this.conf, ConfVars.PARTITION_NAME_WHITELIST_PATTERN);
            if (partitionValidationRegex != null && !partitionValidationRegex.isEmpty()) {
              partitionValidationPattern = Pattern.compile(partitionValidationRegex);
            } else {
              partitionValidationPattern = null;
            }
      
            // Note, if metrics have not been initialized this will return null, which means we aren't
            // using metrics.  Thus we should always check whether this is non-null before using.
            MetricRegistry registry = Metrics.getRegistry();
            if (registry != null) {
              directSqlErrors = Metrics.getOrCreateCounter(MetricsConstants.DIRECTSQL_ERRORS);
            }
      
            this.batchSize = MetastoreConf.getIntVar(conf, ConfVars.RAWSTORE_PARTITION_BATCH_SIZE);
      
            if (!isInitialized) {
              throw new RuntimeException(
              "Unable to create persistence manager. Check dss.log for details");
            } else {
              LOG.debug("Initialized ObjectStore");
            }
          } finally {
            pmfPropLock.unlock();
          }
        }
      

      The pmfPropLock is a static object and it disallows any other new connection to HMS which is trying to instantiate ObjectStore. We should either remove the lock or reduce the scope of the lock so that it is held for a very small amount of time.

      Attachments

        1. HIVE-20740.01.patch
          18 kB
          Vihang Karajgaonkar
        2. HIVE-20740.02.patch
          19 kB
          Vihang Karajgaonkar
        3. HIVE-20740.04.patch
          19 kB
          Vihang Karajgaonkar
        4. HIVE-20740.05.patch
          55 kB
          Vihang Karajgaonkar
        5. HIVE-20740.06.patch
          55 kB
          Vihang Karajgaonkar
        6. HIVE-20740.08.patch
          60 kB
          Vihang Karajgaonkar
        7. HIVE-20740.09.patch
          60 kB
          Vihang Karajgaonkar
        8. HIVE-20740.10.patch
          60 kB
          Vihang Karajgaonkar
        9. HIVE-20740.11.patch
          60 kB
          Vihang Karajgaonkar
        10. HIVE-20740.12.patch
          60 kB
          Vihang Karajgaonkar
        11. HIVE-20740.13.patch
          60 kB
          Vihang Karajgaonkar
        12. HIVE-20740.14.patch
          60 kB
          Vihang Karajgaonkar

        Issue Links

          Activity

            People

              vihangk1 Vihang Karajgaonkar
              vihangk1 Vihang Karajgaonkar
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: