Uploaded image for project: 'HBase'
  1. HBase
  2. HBASE-15835

HBaseTestingUtility#startMiniCluster throws "HMasterAddress already in use" RuntimeException when a local instance of HBase is running

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.0
    • 2.0.0
    • API
    • Reviewed
    • Hide
      Always force random port assignment if user has not explicitly defined an alternate port:
      {code}
          Configuration conf = this.getConfiguration();
          if (conf.getInt(HConstants.MASTER_INFO_PORT, HConstants.DEFAULT_MASTER_INFOPORT)
                  == HConstants.DEFAULT_MASTER_INFOPORT) {
            conf.setInt(HConstants.MASTER_INFO_PORT, -1);
          }
          if (conf.getInt(HConstants.REGIONSERVER_PORT, HConstants.DEFAULT_REGIONSERVER_PORT)
                  == HConstants.DEFAULT_REGIONSERVER_PORT) {
            conf.setInt(HConstants.REGIONSERVER_PORT, -1);
          }
      {code}
      Show
      Always force random port assignment if user has not explicitly defined an alternate port: {code}     Configuration conf = this.getConfiguration();     if (conf.getInt(HConstants.MASTER_INFO_PORT, HConstants.DEFAULT_MASTER_INFOPORT)             == HConstants.DEFAULT_MASTER_INFOPORT) {       conf.setInt(HConstants.MASTER_INFO_PORT, -1);     }     if (conf.getInt(HConstants.REGIONSERVER_PORT, HConstants.DEFAULT_REGIONSERVER_PORT)             == HConstants.DEFAULT_REGIONSERVER_PORT) {       conf.setInt(HConstants.REGIONSERVER_PORT, -1);     } {code}
    • HBaseTestingUtility

    Description

      When a MiniCluster is being started with the HBaseTestUtility#startMiniCluster method (most typically in the context of JUnit testing), if a local HBase instance is already running (or for that matter, another thread with another MiniCluster is already running), the startup will fail with a RuntimeException saying "HMasterAddress already in use", referring explicitly to contention for the same default master info port (16010).

      This problem most recently came up in conjunction with HBASE-14876 and its sub-JIRAs (development of new HBase-oriented Maven archetypes), but this is apparently a known issue to veteran developers, who tend to set up the @BeforeClass sections of their test modules with code similar to the following:

          UTIL = HBaseTestingUtility.createLocalHTU();
          // disable UI's on test cluster.
          UTIL.getConfiguration().setInt("hbase.master.info.port", -1);
          UTIL.getConfiguration().setInt("hbase.regionserver.info.port", -1);
          UTIL.startMiniCluster();
      

      A comprehensive solution modeled on this should be put directly into HBaseTestUtility's main constructor, using one of the following options:

      OPTION 1 (always force random port assignment):

          this.getConfiguration().setInt(HConstants.MASTER_INFO_PORT, -1);
          this.getConfiguration().setInt(HConstants.REGIONSERVER_PORT, -1);
      

      OPTION 2 (always force random port assignment if user has not explicitly defined alternate port):

          Configuration conf = this.getConfiguration();
          if (conf.getInt(HConstants.MASTER_INFO_PORT, HConstants.DEFAULT_MASTER_INFOPORT)
                  == HConstants.DEFAULT_MASTER_INFOPORT) {
            conf.setInt(HConstants.MASTER_INFO_PORT, -1);
          }
          if (conf.getInt(HConstants.REGIONSERVER_PORT, HConstants.DEFAULT_REGIONSERVER_PORT)
                  == HConstants.DEFAULT_REGIONSERVER_PORT) {
            conf.setInt(HConstants.REGIONSERVER_PORT, -1);
          }
      

      Attachments

        1. HBASE-15835-v3.patch
          18 kB
          Daniel Vimont
        2. HBASE-15835-v2.patch
          2 kB
          Daniel Vimont
        3. HBASE-15835-v1.patch
          2 kB
          Daniel Vimont

        Issue Links

          Activity

            People

              daniel_vimont Daniel Vimont
              daniel_vimont Daniel Vimont
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: