hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [19/32] hbase-site git commit: Published site at .
Date Sat, 02 Dec 2017 15:18:07 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/29b27596/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegionServer.CompactionChecker.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegionServer.CompactionChecker.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegionServer.CompactionChecker.html
index 269105b..1198d94 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegionServer.CompactionChecker.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegionServer.CompactionChecker.html
@@ -1524,2213 +1524,2214 @@
 <span class="sourceLineNo">1516</span>      // This call sets up an initialized replication and WAL. Later we start it up.<a name="line.1516"></a>
 <span class="sourceLineNo">1517</span>      setupWALAndReplication();<a name="line.1517"></a>
 <span class="sourceLineNo">1518</span>      // Init in here rather than in constructor after thread name has been set<a name="line.1518"></a>
-<span class="sourceLineNo">1519</span>      this.metricsRegionServer = new MetricsRegionServer(new MetricsRegionServerWrapperImpl(this));<a name="line.1519"></a>
-<span class="sourceLineNo">1520</span>      this.metricsTable = new MetricsTable(new MetricsTableWrapperAggregateImpl(this));<a name="line.1520"></a>
-<span class="sourceLineNo">1521</span>      // Now that we have a metrics source, start the pause monitor<a name="line.1521"></a>
-<span class="sourceLineNo">1522</span>      this.pauseMonitor = new JvmPauseMonitor(conf, getMetrics().getMetricsSource());<a name="line.1522"></a>
-<span class="sourceLineNo">1523</span>      pauseMonitor.start();<a name="line.1523"></a>
-<span class="sourceLineNo">1524</span><a name="line.1524"></a>
-<span class="sourceLineNo">1525</span>      // There is a rare case where we do NOT want services to start. Check config.<a name="line.1525"></a>
-<span class="sourceLineNo">1526</span>      if (getConfiguration().getBoolean("hbase.regionserver.workers", true)) {<a name="line.1526"></a>
-<span class="sourceLineNo">1527</span>        startServices();<a name="line.1527"></a>
-<span class="sourceLineNo">1528</span>      }<a name="line.1528"></a>
-<span class="sourceLineNo">1529</span>      // In here we start up the replication Service. Above we initialized it. TODO. Reconcile.<a name="line.1529"></a>
-<span class="sourceLineNo">1530</span>      // or make sense of it.<a name="line.1530"></a>
-<span class="sourceLineNo">1531</span>      startReplicationService();<a name="line.1531"></a>
-<span class="sourceLineNo">1532</span><a name="line.1532"></a>
+<span class="sourceLineNo">1519</span>      this.metricsRegionServer = new MetricsRegionServer(<a name="line.1519"></a>
+<span class="sourceLineNo">1520</span>          new MetricsRegionServerWrapperImpl(this), conf);<a name="line.1520"></a>
+<span class="sourceLineNo">1521</span>      this.metricsTable = new MetricsTable(new MetricsTableWrapperAggregateImpl(this));<a name="line.1521"></a>
+<span class="sourceLineNo">1522</span>      // Now that we have a metrics source, start the pause monitor<a name="line.1522"></a>
+<span class="sourceLineNo">1523</span>      this.pauseMonitor = new JvmPauseMonitor(conf, getMetrics().getMetricsSource());<a name="line.1523"></a>
+<span class="sourceLineNo">1524</span>      pauseMonitor.start();<a name="line.1524"></a>
+<span class="sourceLineNo">1525</span><a name="line.1525"></a>
+<span class="sourceLineNo">1526</span>      // There is a rare case where we do NOT want services to start. Check config.<a name="line.1526"></a>
+<span class="sourceLineNo">1527</span>      if (getConfiguration().getBoolean("hbase.regionserver.workers", true)) {<a name="line.1527"></a>
+<span class="sourceLineNo">1528</span>        startServices();<a name="line.1528"></a>
+<span class="sourceLineNo">1529</span>      }<a name="line.1529"></a>
+<span class="sourceLineNo">1530</span>      // In here we start up the replication Service. Above we initialized it. TODO. Reconcile.<a name="line.1530"></a>
+<span class="sourceLineNo">1531</span>      // or make sense of it.<a name="line.1531"></a>
+<span class="sourceLineNo">1532</span>      startReplicationService();<a name="line.1532"></a>
 <span class="sourceLineNo">1533</span><a name="line.1533"></a>
-<span class="sourceLineNo">1534</span>      // Set up ZK<a name="line.1534"></a>
-<span class="sourceLineNo">1535</span>      LOG.info("Serving as " + this.serverName + ", RpcServer on " + rpcServices.isa +<a name="line.1535"></a>
-<span class="sourceLineNo">1536</span>          ", sessionid=0x" +<a name="line.1536"></a>
-<span class="sourceLineNo">1537</span>          Long.toHexString(this.zooKeeper.getRecoverableZooKeeper().getSessionId()));<a name="line.1537"></a>
-<span class="sourceLineNo">1538</span><a name="line.1538"></a>
-<span class="sourceLineNo">1539</span>      // Wake up anyone waiting for this server to online<a name="line.1539"></a>
-<span class="sourceLineNo">1540</span>      synchronized (online) {<a name="line.1540"></a>
-<span class="sourceLineNo">1541</span>        online.set(true);<a name="line.1541"></a>
-<span class="sourceLineNo">1542</span>        online.notifyAll();<a name="line.1542"></a>
-<span class="sourceLineNo">1543</span>      }<a name="line.1543"></a>
-<span class="sourceLineNo">1544</span>    } catch (Throwable e) {<a name="line.1544"></a>
-<span class="sourceLineNo">1545</span>      stop("Failed initialization");<a name="line.1545"></a>
-<span class="sourceLineNo">1546</span>      throw convertThrowableToIOE(cleanup(e, "Failed init"),<a name="line.1546"></a>
-<span class="sourceLineNo">1547</span>          "Region server startup failed");<a name="line.1547"></a>
-<span class="sourceLineNo">1548</span>    } finally {<a name="line.1548"></a>
-<span class="sourceLineNo">1549</span>      sleeper.skipSleepCycle();<a name="line.1549"></a>
-<span class="sourceLineNo">1550</span>    }<a name="line.1550"></a>
-<span class="sourceLineNo">1551</span>  }<a name="line.1551"></a>
-<span class="sourceLineNo">1552</span><a name="line.1552"></a>
-<span class="sourceLineNo">1553</span>  protected void initializeMemStoreChunkCreator() {<a name="line.1553"></a>
-<span class="sourceLineNo">1554</span>    if (MemStoreLAB.isEnabled(conf)) {<a name="line.1554"></a>
-<span class="sourceLineNo">1555</span>      // MSLAB is enabled. So initialize MemStoreChunkPool<a name="line.1555"></a>
-<span class="sourceLineNo">1556</span>      // By this time, the MemstoreFlusher is already initialized. We can get the global limits from<a name="line.1556"></a>
-<span class="sourceLineNo">1557</span>      // it.<a name="line.1557"></a>
-<span class="sourceLineNo">1558</span>      Pair&lt;Long, MemoryType&gt; pair = MemorySizeUtil.getGlobalMemStoreSize(conf);<a name="line.1558"></a>
-<span class="sourceLineNo">1559</span>      long globalMemStoreSize = pair.getFirst();<a name="line.1559"></a>
-<span class="sourceLineNo">1560</span>      boolean offheap = this.regionServerAccounting.isOffheap();<a name="line.1560"></a>
-<span class="sourceLineNo">1561</span>      // When off heap memstore in use, take full area for chunk pool.<a name="line.1561"></a>
-<span class="sourceLineNo">1562</span>      float poolSizePercentage = offheap? 1.0F:<a name="line.1562"></a>
-<span class="sourceLineNo">1563</span>          conf.getFloat(MemStoreLAB.CHUNK_POOL_MAXSIZE_KEY, MemStoreLAB.POOL_MAX_SIZE_DEFAULT);<a name="line.1563"></a>
-<span class="sourceLineNo">1564</span>      float initialCountPercentage = conf.getFloat(MemStoreLAB.CHUNK_POOL_INITIALSIZE_KEY,<a name="line.1564"></a>
-<span class="sourceLineNo">1565</span>          MemStoreLAB.POOL_INITIAL_SIZE_DEFAULT);<a name="line.1565"></a>
-<span class="sourceLineNo">1566</span>      int chunkSize = conf.getInt(MemStoreLAB.CHUNK_SIZE_KEY, MemStoreLAB.CHUNK_SIZE_DEFAULT);<a name="line.1566"></a>
-<span class="sourceLineNo">1567</span>      // init the chunkCreator<a name="line.1567"></a>
-<span class="sourceLineNo">1568</span>      ChunkCreator chunkCreator =<a name="line.1568"></a>
-<span class="sourceLineNo">1569</span>          ChunkCreator.initialize(chunkSize, offheap, globalMemStoreSize, poolSizePercentage,<a name="line.1569"></a>
-<span class="sourceLineNo">1570</span>      initialCountPercentage, this.hMemManager);<a name="line.1570"></a>
-<span class="sourceLineNo">1571</span>    }<a name="line.1571"></a>
-<span class="sourceLineNo">1572</span>  }<a name="line.1572"></a>
-<span class="sourceLineNo">1573</span><a name="line.1573"></a>
-<span class="sourceLineNo">1574</span>  private void startHeapMemoryManager() {<a name="line.1574"></a>
-<span class="sourceLineNo">1575</span>    this.hMemManager = HeapMemoryManager.create(this.conf, this.cacheFlusher, this,<a name="line.1575"></a>
-<span class="sourceLineNo">1576</span>        this.regionServerAccounting);<a name="line.1576"></a>
-<span class="sourceLineNo">1577</span>    if (this.hMemManager != null) {<a name="line.1577"></a>
-<span class="sourceLineNo">1578</span>      this.hMemManager.start(getChoreService());<a name="line.1578"></a>
-<span class="sourceLineNo">1579</span>    }<a name="line.1579"></a>
-<span class="sourceLineNo">1580</span>  }<a name="line.1580"></a>
-<span class="sourceLineNo">1581</span><a name="line.1581"></a>
-<span class="sourceLineNo">1582</span>  private void createMyEphemeralNode() throws KeeperException, IOException {<a name="line.1582"></a>
-<span class="sourceLineNo">1583</span>    RegionServerInfo.Builder rsInfo = RegionServerInfo.newBuilder();<a name="line.1583"></a>
-<span class="sourceLineNo">1584</span>    rsInfo.setInfoPort(infoServer != null ? infoServer.getPort() : -1);<a name="line.1584"></a>
-<span class="sourceLineNo">1585</span>    rsInfo.setVersionInfo(ProtobufUtil.getVersionInfo());<a name="line.1585"></a>
-<span class="sourceLineNo">1586</span>    byte[] data = ProtobufUtil.prependPBMagic(rsInfo.build().toByteArray());<a name="line.1586"></a>
-<span class="sourceLineNo">1587</span>    ZKUtil.createEphemeralNodeAndWatch(this.zooKeeper, getMyEphemeralNodePath(), data);<a name="line.1587"></a>
-<span class="sourceLineNo">1588</span>  }<a name="line.1588"></a>
-<span class="sourceLineNo">1589</span><a name="line.1589"></a>
-<span class="sourceLineNo">1590</span>  private void deleteMyEphemeralNode() throws KeeperException {<a name="line.1590"></a>
-<span class="sourceLineNo">1591</span>    ZKUtil.deleteNode(this.zooKeeper, getMyEphemeralNodePath());<a name="line.1591"></a>
-<span class="sourceLineNo">1592</span>  }<a name="line.1592"></a>
-<span class="sourceLineNo">1593</span><a name="line.1593"></a>
-<span class="sourceLineNo">1594</span>  @Override<a name="line.1594"></a>
-<span class="sourceLineNo">1595</span>  public RegionServerAccounting getRegionServerAccounting() {<a name="line.1595"></a>
-<span class="sourceLineNo">1596</span>    return regionServerAccounting;<a name="line.1596"></a>
-<span class="sourceLineNo">1597</span>  }<a name="line.1597"></a>
-<span class="sourceLineNo">1598</span><a name="line.1598"></a>
-<span class="sourceLineNo">1599</span>  /*<a name="line.1599"></a>
-<span class="sourceLineNo">1600</span>   * @param r Region to get RegionLoad for.<a name="line.1600"></a>
-<span class="sourceLineNo">1601</span>   * @param regionLoadBldr the RegionLoad.Builder, can be null<a name="line.1601"></a>
-<span class="sourceLineNo">1602</span>   * @param regionSpecifier the RegionSpecifier.Builder, can be null<a name="line.1602"></a>
-<span class="sourceLineNo">1603</span>   * @return RegionLoad instance.<a name="line.1603"></a>
-<span class="sourceLineNo">1604</span>   *<a name="line.1604"></a>
-<span class="sourceLineNo">1605</span>   * @throws IOException<a name="line.1605"></a>
-<span class="sourceLineNo">1606</span>   */<a name="line.1606"></a>
-<span class="sourceLineNo">1607</span>  RegionLoad createRegionLoad(final HRegion r, RegionLoad.Builder regionLoadBldr,<a name="line.1607"></a>
-<span class="sourceLineNo">1608</span>      RegionSpecifier.Builder regionSpecifier) throws IOException {<a name="line.1608"></a>
-<span class="sourceLineNo">1609</span>    byte[] name = r.getRegionInfo().getRegionName();<a name="line.1609"></a>
-<span class="sourceLineNo">1610</span>    int stores = 0;<a name="line.1610"></a>
-<span class="sourceLineNo">1611</span>    int storefiles = 0;<a name="line.1611"></a>
-<span class="sourceLineNo">1612</span>    int storeUncompressedSizeMB = 0;<a name="line.1612"></a>
-<span class="sourceLineNo">1613</span>    int storefileSizeMB = 0;<a name="line.1613"></a>
-<span class="sourceLineNo">1614</span>    int memstoreSizeMB = (int) (r.getMemStoreSize() / 1024 / 1024);<a name="line.1614"></a>
-<span class="sourceLineNo">1615</span>    long storefileIndexSizeKB = 0;<a name="line.1615"></a>
-<span class="sourceLineNo">1616</span>    int rootIndexSizeKB = 0;<a name="line.1616"></a>
-<span class="sourceLineNo">1617</span>    int totalStaticIndexSizeKB = 0;<a name="line.1617"></a>
-<span class="sourceLineNo">1618</span>    int totalStaticBloomSizeKB = 0;<a name="line.1618"></a>
-<span class="sourceLineNo">1619</span>    long totalCompactingKVs = 0;<a name="line.1619"></a>
-<span class="sourceLineNo">1620</span>    long currentCompactedKVs = 0;<a name="line.1620"></a>
-<span class="sourceLineNo">1621</span>    List&lt;HStore&gt; storeList = r.getStores();<a name="line.1621"></a>
-<span class="sourceLineNo">1622</span>    stores += storeList.size();<a name="line.1622"></a>
-<span class="sourceLineNo">1623</span>    for (HStore store : storeList) {<a name="line.1623"></a>
-<span class="sourceLineNo">1624</span>      storefiles += store.getStorefilesCount();<a name="line.1624"></a>
-<span class="sourceLineNo">1625</span>      storeUncompressedSizeMB += (int) (store.getStoreSizeUncompressed() / 1024 / 1024);<a name="line.1625"></a>
-<span class="sourceLineNo">1626</span>      storefileSizeMB += (int) (store.getStorefilesSize() / 1024 / 1024);<a name="line.1626"></a>
-<span class="sourceLineNo">1627</span>      storefileIndexSizeKB += store.getStorefilesIndexSize() / 1024;<a name="line.1627"></a>
-<span class="sourceLineNo">1628</span>      CompactionProgress progress = store.getCompactionProgress();<a name="line.1628"></a>
-<span class="sourceLineNo">1629</span>      if (progress != null) {<a name="line.1629"></a>
-<span class="sourceLineNo">1630</span>        totalCompactingKVs += progress.totalCompactingKVs;<a name="line.1630"></a>
-<span class="sourceLineNo">1631</span>        currentCompactedKVs += progress.currentCompactedKVs;<a name="line.1631"></a>
-<span class="sourceLineNo">1632</span>      }<a name="line.1632"></a>
-<span class="sourceLineNo">1633</span>      rootIndexSizeKB += (int) (store.getStorefilesIndexSize() / 1024);<a name="line.1633"></a>
-<span class="sourceLineNo">1634</span>      totalStaticIndexSizeKB += (int) (store.getTotalStaticIndexSize() / 1024);<a name="line.1634"></a>
-<span class="sourceLineNo">1635</span>      totalStaticBloomSizeKB += (int) (store.getTotalStaticBloomSize() / 1024);<a name="line.1635"></a>
-<span class="sourceLineNo">1636</span>    }<a name="line.1636"></a>
-<span class="sourceLineNo">1637</span><a name="line.1637"></a>
-<span class="sourceLineNo">1638</span>    float dataLocality =<a name="line.1638"></a>
-<span class="sourceLineNo">1639</span>        r.getHDFSBlocksDistribution().getBlockLocalityIndex(serverName.getHostname());<a name="line.1639"></a>
-<span class="sourceLineNo">1640</span>    if (regionLoadBldr == null) {<a name="line.1640"></a>
-<span class="sourceLineNo">1641</span>      regionLoadBldr = RegionLoad.newBuilder();<a name="line.1641"></a>
-<span class="sourceLineNo">1642</span>    }<a name="line.1642"></a>
-<span class="sourceLineNo">1643</span>    if (regionSpecifier == null) {<a name="line.1643"></a>
-<span class="sourceLineNo">1644</span>      regionSpecifier = RegionSpecifier.newBuilder();<a name="line.1644"></a>
-<span class="sourceLineNo">1645</span>    }<a name="line.1645"></a>
-<span class="sourceLineNo">1646</span>    regionSpecifier.setType(RegionSpecifierType.REGION_NAME);<a name="line.1646"></a>
-<span class="sourceLineNo">1647</span>    regionSpecifier.setValue(UnsafeByteOperations.unsafeWrap(name));<a name="line.1647"></a>
-<span class="sourceLineNo">1648</span>    regionLoadBldr.setRegionSpecifier(regionSpecifier.build())<a name="line.1648"></a>
-<span class="sourceLineNo">1649</span>      .setStores(stores)<a name="line.1649"></a>
-<span class="sourceLineNo">1650</span>      .setStorefiles(storefiles)<a name="line.1650"></a>
-<span class="sourceLineNo">1651</span>      .setStoreUncompressedSizeMB(storeUncompressedSizeMB)<a name="line.1651"></a>
-<span class="sourceLineNo">1652</span>      .setStorefileSizeMB(storefileSizeMB)<a name="line.1652"></a>
-<span class="sourceLineNo">1653</span>      .setMemStoreSizeMB(memstoreSizeMB)<a name="line.1653"></a>
-<span class="sourceLineNo">1654</span>      .setStorefileIndexSizeKB(storefileIndexSizeKB)<a name="line.1654"></a>
-<span class="sourceLineNo">1655</span>      .setRootIndexSizeKB(rootIndexSizeKB)<a name="line.1655"></a>
-<span class="sourceLineNo">1656</span>      .setTotalStaticIndexSizeKB(totalStaticIndexSizeKB)<a name="line.1656"></a>
-<span class="sourceLineNo">1657</span>      .setTotalStaticBloomSizeKB(totalStaticBloomSizeKB)<a name="line.1657"></a>
-<span class="sourceLineNo">1658</span>      .setReadRequestsCount(r.getReadRequestsCount())<a name="line.1658"></a>
-<span class="sourceLineNo">1659</span>      .setFilteredReadRequestsCount(r.getFilteredReadRequestsCount())<a name="line.1659"></a>
-<span class="sourceLineNo">1660</span>      .setWriteRequestsCount(r.getWriteRequestsCount())<a name="line.1660"></a>
-<span class="sourceLineNo">1661</span>      .setTotalCompactingKVs(totalCompactingKVs)<a name="line.1661"></a>
-<span class="sourceLineNo">1662</span>      .setCurrentCompactedKVs(currentCompactedKVs)<a name="line.1662"></a>
-<span class="sourceLineNo">1663</span>      .setDataLocality(dataLocality)<a name="line.1663"></a>
-<span class="sourceLineNo">1664</span>      .setLastMajorCompactionTs(r.getOldestHfileTs(true));<a name="line.1664"></a>
-<span class="sourceLineNo">1665</span>    ((HRegion)r).setCompleteSequenceId(regionLoadBldr);<a name="line.1665"></a>
-<span class="sourceLineNo">1666</span><a name="line.1666"></a>
-<span class="sourceLineNo">1667</span>    return regionLoadBldr.build();<a name="line.1667"></a>
-<span class="sourceLineNo">1668</span>  }<a name="line.1668"></a>
-<span class="sourceLineNo">1669</span><a name="line.1669"></a>
-<span class="sourceLineNo">1670</span>  /**<a name="line.1670"></a>
-<span class="sourceLineNo">1671</span>   * @param encodedRegionName<a name="line.1671"></a>
-<span class="sourceLineNo">1672</span>   * @return An instance of RegionLoad.<a name="line.1672"></a>
-<span class="sourceLineNo">1673</span>   */<a name="line.1673"></a>
-<span class="sourceLineNo">1674</span>  public RegionLoad createRegionLoad(final String encodedRegionName) throws IOException {<a name="line.1674"></a>
-<span class="sourceLineNo">1675</span>    HRegion r = onlineRegions.get(encodedRegionName);<a name="line.1675"></a>
-<span class="sourceLineNo">1676</span>    return r != null ? createRegionLoad(r, null, null) : null;<a name="line.1676"></a>
-<span class="sourceLineNo">1677</span>  }<a name="line.1677"></a>
-<span class="sourceLineNo">1678</span><a name="line.1678"></a>
-<span class="sourceLineNo">1679</span>  /*<a name="line.1679"></a>
-<span class="sourceLineNo">1680</span>   * Inner class that runs on a long period checking if regions need compaction.<a name="line.1680"></a>
-<span class="sourceLineNo">1681</span>   */<a name="line.1681"></a>
-<span class="sourceLineNo">1682</span>  private static class CompactionChecker extends ScheduledChore {<a name="line.1682"></a>
-<span class="sourceLineNo">1683</span>    private final HRegionServer instance;<a name="line.1683"></a>
-<span class="sourceLineNo">1684</span>    private final int majorCompactPriority;<a name="line.1684"></a>
-<span class="sourceLineNo">1685</span>    private final static int DEFAULT_PRIORITY = Integer.MAX_VALUE;<a name="line.1685"></a>
-<span class="sourceLineNo">1686</span>    //Iteration is 1-based rather than 0-based so we don't check for compaction<a name="line.1686"></a>
-<span class="sourceLineNo">1687</span>    // immediately upon region server startup<a name="line.1687"></a>
-<span class="sourceLineNo">1688</span>    private long iteration = 1;<a name="line.1688"></a>
-<span class="sourceLineNo">1689</span><a name="line.1689"></a>
-<span class="sourceLineNo">1690</span>    CompactionChecker(final HRegionServer h, final int sleepTime, final Stoppable stopper) {<a name="line.1690"></a>
-<span class="sourceLineNo">1691</span>      super("CompactionChecker", stopper, sleepTime);<a name="line.1691"></a>
-<span class="sourceLineNo">1692</span>      this.instance = h;<a name="line.1692"></a>
-<span class="sourceLineNo">1693</span>      LOG.info(this.getName() + " runs every " + StringUtils.formatTime(sleepTime));<a name="line.1693"></a>
-<span class="sourceLineNo">1694</span><a name="line.1694"></a>
-<span class="sourceLineNo">1695</span>      /* MajorCompactPriority is configurable.<a name="line.1695"></a>
-<span class="sourceLineNo">1696</span>       * If not set, the compaction will use default priority.<a name="line.1696"></a>
-<span class="sourceLineNo">1697</span>       */<a name="line.1697"></a>
-<span class="sourceLineNo">1698</span>      this.majorCompactPriority = this.instance.conf.<a name="line.1698"></a>
-<span class="sourceLineNo">1699</span>          getInt("hbase.regionserver.compactionChecker.majorCompactPriority",<a name="line.1699"></a>
-<span class="sourceLineNo">1700</span>              DEFAULT_PRIORITY);<a name="line.1700"></a>
-<span class="sourceLineNo">1701</span>    }<a name="line.1701"></a>
-<span class="sourceLineNo">1702</span><a name="line.1702"></a>
-<span class="sourceLineNo">1703</span>    @Override<a name="line.1703"></a>
-<span class="sourceLineNo">1704</span>    protected void chore() {<a name="line.1704"></a>
-<span class="sourceLineNo">1705</span>      for (Region r : this.instance.onlineRegions.values()) {<a name="line.1705"></a>
-<span class="sourceLineNo">1706</span>        if (r == null) {<a name="line.1706"></a>
-<span class="sourceLineNo">1707</span>          continue;<a name="line.1707"></a>
-<span class="sourceLineNo">1708</span>        }<a name="line.1708"></a>
-<span class="sourceLineNo">1709</span>        HRegion hr = (HRegion) r;<a name="line.1709"></a>
-<span class="sourceLineNo">1710</span>        for (HStore s : hr.stores.values()) {<a name="line.1710"></a>
-<span class="sourceLineNo">1711</span>          try {<a name="line.1711"></a>
-<span class="sourceLineNo">1712</span>            long multiplier = s.getCompactionCheckMultiplier();<a name="line.1712"></a>
-<span class="sourceLineNo">1713</span>            assert multiplier &gt; 0;<a name="line.1713"></a>
-<span class="sourceLineNo">1714</span>            if (iteration % multiplier != 0) {<a name="line.1714"></a>
-<span class="sourceLineNo">1715</span>              continue;<a name="line.1715"></a>
-<span class="sourceLineNo">1716</span>            }<a name="line.1716"></a>
-<span class="sourceLineNo">1717</span>            if (s.needsCompaction()) {<a name="line.1717"></a>
-<span class="sourceLineNo">1718</span>              // Queue a compaction. Will recognize if major is needed.<a name="line.1718"></a>
-<span class="sourceLineNo">1719</span>              this.instance.compactSplitThread.requestSystemCompaction(hr, s,<a name="line.1719"></a>
-<span class="sourceLineNo">1720</span>                getName() + " requests compaction");<a name="line.1720"></a>
-<span class="sourceLineNo">1721</span>            } else if (s.shouldPerformMajorCompaction()) {<a name="line.1721"></a>
-<span class="sourceLineNo">1722</span>              s.triggerMajorCompaction();<a name="line.1722"></a>
-<span class="sourceLineNo">1723</span>              if (majorCompactPriority == DEFAULT_PRIORITY ||<a name="line.1723"></a>
-<span class="sourceLineNo">1724</span>                  majorCompactPriority &gt; hr.getCompactPriority()) {<a name="line.1724"></a>
-<span class="sourceLineNo">1725</span>                this.instance.compactSplitThread.requestCompaction(hr, s,<a name="line.1725"></a>
-<span class="sourceLineNo">1726</span>                    getName() + " requests major compaction; use default priority",<a name="line.1726"></a>
-<span class="sourceLineNo">1727</span>                    Store.NO_PRIORITY,<a name="line.1727"></a>
-<span class="sourceLineNo">1728</span>                CompactionLifeCycleTracker.DUMMY, null);<a name="line.1728"></a>
-<span class="sourceLineNo">1729</span>              } else {<a name="line.1729"></a>
-<span class="sourceLineNo">1730</span>                this.instance.compactSplitThread.requestCompaction(hr, s,<a name="line.1730"></a>
-<span class="sourceLineNo">1731</span>                    getName() + " requests major compaction; use configured priority",<a name="line.1731"></a>
-<span class="sourceLineNo">1732</span>                    this.majorCompactPriority, CompactionLifeCycleTracker.DUMMY, null);<a name="line.1732"></a>
-<span class="sourceLineNo">1733</span>              }<a name="line.1733"></a>
-<span class="sourceLineNo">1734</span>            }<a name="line.1734"></a>
-<span class="sourceLineNo">1735</span>          } catch (IOException e) {<a name="line.1735"></a>
-<span class="sourceLineNo">1736</span>            LOG.warn("Failed major compaction check on " + r, e);<a name="line.1736"></a>
-<span class="sourceLineNo">1737</span>          }<a name="line.1737"></a>
-<span class="sourceLineNo">1738</span>        }<a name="line.1738"></a>
-<span class="sourceLineNo">1739</span>      }<a name="line.1739"></a>
-<span class="sourceLineNo">1740</span>      iteration = (iteration == Long.MAX_VALUE) ? 0 : (iteration + 1);<a name="line.1740"></a>
-<span class="sourceLineNo">1741</span>    }<a name="line.1741"></a>
-<span class="sourceLineNo">1742</span>  }<a name="line.1742"></a>
-<span class="sourceLineNo">1743</span><a name="line.1743"></a>
-<span class="sourceLineNo">1744</span>  static class PeriodicMemStoreFlusher extends ScheduledChore {<a name="line.1744"></a>
-<span class="sourceLineNo">1745</span>    final HRegionServer server;<a name="line.1745"></a>
-<span class="sourceLineNo">1746</span>    final static int RANGE_OF_DELAY = 5 * 60 * 1000; // 5 min in milliseconds<a name="line.1746"></a>
-<span class="sourceLineNo">1747</span>    final static int MIN_DELAY_TIME = 0; // millisec<a name="line.1747"></a>
-<span class="sourceLineNo">1748</span>    public PeriodicMemStoreFlusher(int cacheFlushInterval, final HRegionServer server) {<a name="line.1748"></a>
-<span class="sourceLineNo">1749</span>      super("MemstoreFlusherChore", server, cacheFlushInterval);<a name="line.1749"></a>
-<span class="sourceLineNo">1750</span>      this.server = server;<a name="line.1750"></a>
-<span class="sourceLineNo">1751</span>    }<a name="line.1751"></a>
-<span class="sourceLineNo">1752</span><a name="line.1752"></a>
-<span class="sourceLineNo">1753</span>    @Override<a name="line.1753"></a>
-<span class="sourceLineNo">1754</span>    protected void chore() {<a name="line.1754"></a>
-<span class="sourceLineNo">1755</span>      final StringBuffer whyFlush = new StringBuffer();<a name="line.1755"></a>
-<span class="sourceLineNo">1756</span>      for (HRegion r : this.server.onlineRegions.values()) {<a name="line.1756"></a>
-<span class="sourceLineNo">1757</span>        if (r == null) continue;<a name="line.1757"></a>
-<span class="sourceLineNo">1758</span>        if (r.shouldFlush(whyFlush)) {<a name="line.1758"></a>
-<span class="sourceLineNo">1759</span>          FlushRequester requester = server.getFlushRequester();<a name="line.1759"></a>
-<span class="sourceLineNo">1760</span>          if (requester != null) {<a name="line.1760"></a>
-<span class="sourceLineNo">1761</span>            long randomDelay = RandomUtils.nextInt(0, RANGE_OF_DELAY) + MIN_DELAY_TIME;<a name="line.1761"></a>
-<span class="sourceLineNo">1762</span>            LOG.info(getName() + " requesting flush of " +<a name="line.1762"></a>
-<span class="sourceLineNo">1763</span>              r.getRegionInfo().getRegionNameAsString() + " because " +<a name="line.1763"></a>
-<span class="sourceLineNo">1764</span>              whyFlush.toString() +<a name="line.1764"></a>
-<span class="sourceLineNo">1765</span>              " after random delay " + randomDelay + "ms");<a name="line.1765"></a>
-<span class="sourceLineNo">1766</span>            //Throttle the flushes by putting a delay. If we don't throttle, and there<a name="line.1766"></a>
-<span class="sourceLineNo">1767</span>            //is a balanced write-load on the regions in a table, we might end up<a name="line.1767"></a>
-<span class="sourceLineNo">1768</span>            //overwhelming the filesystem with too many flushes at once.<a name="line.1768"></a>
-<span class="sourceLineNo">1769</span>            requester.requestDelayedFlush(r, randomDelay, false);<a name="line.1769"></a>
-<span class="sourceLineNo">1770</span>          }<a name="line.1770"></a>
-<span class="sourceLineNo">1771</span>        }<a name="line.1771"></a>
-<span class="sourceLineNo">1772</span>      }<a name="line.1772"></a>
-<span class="sourceLineNo">1773</span>    }<a name="line.1773"></a>
-<span class="sourceLineNo">1774</span>  }<a name="line.1774"></a>
-<span class="sourceLineNo">1775</span><a name="line.1775"></a>
-<span class="sourceLineNo">1776</span>  /**<a name="line.1776"></a>
-<span class="sourceLineNo">1777</span>   * Report the status of the server. A server is online once all the startup is<a name="line.1777"></a>
-<span class="sourceLineNo">1778</span>   * completed (setting up filesystem, starting executorService threads, etc.). This<a name="line.1778"></a>
-<span class="sourceLineNo">1779</span>   * method is designed mostly to be useful in tests.<a name="line.1779"></a>
-<span class="sourceLineNo">1780</span>   *<a name="line.1780"></a>
-<span class="sourceLineNo">1781</span>   * @return true if online, false if not.<a name="line.1781"></a>
-<span class="sourceLineNo">1782</span>   */<a name="line.1782"></a>
-<span class="sourceLineNo">1783</span>  public boolean isOnline() {<a name="line.1783"></a>
-<span class="sourceLineNo">1784</span>    return online.get();<a name="line.1784"></a>
-<span class="sourceLineNo">1785</span>  }<a name="line.1785"></a>
-<span class="sourceLineNo">1786</span><a name="line.1786"></a>
-<span class="sourceLineNo">1787</span>  /**<a name="line.1787"></a>
-<span class="sourceLineNo">1788</span>   * Setup WAL log and replication if enabled.<a name="line.1788"></a>
-<span class="sourceLineNo">1789</span>   * Replication setup is done in here because it wants to be hooked up to WAL.<a name="line.1789"></a>
-<span class="sourceLineNo">1790</span>   *<a name="line.1790"></a>
-<span class="sourceLineNo">1791</span>   * @throws IOException<a name="line.1791"></a>
-<span class="sourceLineNo">1792</span>   */<a name="line.1792"></a>
-<span class="sourceLineNo">1793</span>  private void setupWALAndReplication() throws IOException {<a name="line.1793"></a>
-<span class="sourceLineNo">1794</span>    // TODO Replication make assumptions here based on the default filesystem impl<a name="line.1794"></a>
-<span class="sourceLineNo">1795</span>    Path oldLogDir = new Path(walRootDir, HConstants.HREGION_OLDLOGDIR_NAME);<a name="line.1795"></a>
-<span class="sourceLineNo">1796</span>    String logName = AbstractFSWALProvider.getWALDirectoryName(this.serverName.toString());<a name="line.1796"></a>
-<span class="sourceLineNo">1797</span><a name="line.1797"></a>
-<span class="sourceLineNo">1798</span>    Path logDir = new Path(walRootDir, logName);<a name="line.1798"></a>
-<span class="sourceLineNo">1799</span>    if (LOG.isDebugEnabled()) LOG.debug("logDir=" + logDir);<a name="line.1799"></a>
-<span class="sourceLineNo">1800</span>    if (this.walFs.exists(logDir)) {<a name="line.1800"></a>
-<span class="sourceLineNo">1801</span>      throw new RegionServerRunningException("Region server has already " +<a name="line.1801"></a>
-<span class="sourceLineNo">1802</span>          "created directory at " + this.serverName.toString());<a name="line.1802"></a>
-<span class="sourceLineNo">1803</span>    }<a name="line.1803"></a>
-<span class="sourceLineNo">1804</span><a name="line.1804"></a>
-<span class="sourceLineNo">1805</span>    // Instantiate replication if replication enabled.  Pass it the log directories.<a name="line.1805"></a>
-<span class="sourceLineNo">1806</span>    // In here we create the Replication instances. Later they are initialized and started up.<a name="line.1806"></a>
-<span class="sourceLineNo">1807</span>    createNewReplicationInstance(conf, this, this.walFs, logDir, oldLogDir);<a name="line.1807"></a>
-<span class="sourceLineNo">1808</span><a name="line.1808"></a>
-<span class="sourceLineNo">1809</span>    // listeners the wal factory will add to wals it creates.<a name="line.1809"></a>
-<span class="sourceLineNo">1810</span>    List&lt;WALActionsListener&gt; listeners = new ArrayList&lt;&gt;();<a name="line.1810"></a>
-<span class="sourceLineNo">1811</span>    listeners.add(new MetricsWAL());<a name="line.1811"></a>
-<span class="sourceLineNo">1812</span>    if (this.replicationSourceHandler != null &amp;&amp;<a name="line.1812"></a>
-<span class="sourceLineNo">1813</span>        this.replicationSourceHandler.getWALActionsListener() != null) {<a name="line.1813"></a>
-<span class="sourceLineNo">1814</span>      // Replication handler is an implementation of WALActionsListener.<a name="line.1814"></a>
-<span class="sourceLineNo">1815</span>      listeners.add(this.replicationSourceHandler.getWALActionsListener());<a name="line.1815"></a>
-<span class="sourceLineNo">1816</span>    }<a name="line.1816"></a>
-<span class="sourceLineNo">1817</span><a name="line.1817"></a>
-<span class="sourceLineNo">1818</span>    // There is a cyclic dependency between ReplicationSourceHandler and WALFactory.<a name="line.1818"></a>
-<span class="sourceLineNo">1819</span>    // We use WALActionsListener to get the newly rolled WALs, so we need to get the<a name="line.1819"></a>
-<span class="sourceLineNo">1820</span>    // WALActionsListeners from ReplicationSourceHandler before constructing WALFactory. And then<a name="line.1820"></a>
-<span class="sourceLineNo">1821</span>    // ReplicationSourceHandler need to use WALFactory get the length of the wal file being written.<a name="line.1821"></a>
-<span class="sourceLineNo">1822</span>    // So we here we need to construct WALFactory first, and then pass it to the initialized method<a name="line.1822"></a>
-<span class="sourceLineNo">1823</span>    // of ReplicationSourceHandler.<a name="line.1823"></a>
-<span class="sourceLineNo">1824</span>    // TODO: I can't follow replication; it has initialize and then later on we start it!<a name="line.1824"></a>
-<span class="sourceLineNo">1825</span>    WALFactory factory = new WALFactory(conf, listeners, serverName.toString());<a name="line.1825"></a>
-<span class="sourceLineNo">1826</span>    this.walFactory = factory;<a name="line.1826"></a>
-<span class="sourceLineNo">1827</span>    if (this.replicationSourceHandler != null) {<a name="line.1827"></a>
-<span class="sourceLineNo">1828</span>      this.replicationSourceHandler.initialize(this, walFs, logDir, oldLogDir, factory);<a name="line.1828"></a>
-<span class="sourceLineNo">1829</span>    }<a name="line.1829"></a>
-<span class="sourceLineNo">1830</span>    if (this.replicationSinkHandler != null &amp;&amp;<a name="line.1830"></a>
-<span class="sourceLineNo">1831</span>        this.replicationSinkHandler != this.replicationSourceHandler) {<a name="line.1831"></a>
-<span class="sourceLineNo">1832</span>      this.replicationSinkHandler.initialize(this, walFs, logDir, oldLogDir, factory);<a name="line.1832"></a>
-<span class="sourceLineNo">1833</span>    }<a name="line.1833"></a>
-<span class="sourceLineNo">1834</span>  }<a name="line.1834"></a>
-<span class="sourceLineNo">1835</span><a name="line.1835"></a>
-<span class="sourceLineNo">1836</span>  /**<a name="line.1836"></a>
-<span class="sourceLineNo">1837</span>   * Start up replication source and sink handlers.<a name="line.1837"></a>
-<span class="sourceLineNo">1838</span>   * @throws IOException<a name="line.1838"></a>
-<span class="sourceLineNo">1839</span>   */<a name="line.1839"></a>
-<span class="sourceLineNo">1840</span>  private void startReplicationService() throws IOException {<a name="line.1840"></a>
-<span class="sourceLineNo">1841</span>    if (this.replicationSourceHandler == this.replicationSinkHandler &amp;&amp;<a name="line.1841"></a>
-<span class="sourceLineNo">1842</span>        this.replicationSourceHandler != null) {<a name="line.1842"></a>
-<span class="sourceLineNo">1843</span>      this.replicationSourceHandler.startReplicationService();<a name="line.1843"></a>
-<span class="sourceLineNo">1844</span>    } else {<a name="line.1844"></a>
-<span class="sourceLineNo">1845</span>      if (this.replicationSourceHandler != null) {<a name="line.1845"></a>
-<span class="sourceLineNo">1846</span>        this.replicationSourceHandler.startReplicationService();<a name="line.1846"></a>
-<span class="sourceLineNo">1847</span>      }<a name="line.1847"></a>
-<span class="sourceLineNo">1848</span>      if (this.replicationSinkHandler != null) {<a name="line.1848"></a>
-<span class="sourceLineNo">1849</span>        this.replicationSinkHandler.startReplicationService();<a name="line.1849"></a>
-<span class="sourceLineNo">1850</span>      }<a name="line.1850"></a>
-<span class="sourceLineNo">1851</span>    }<a name="line.1851"></a>
-<span class="sourceLineNo">1852</span>  }<a name="line.1852"></a>
-<span class="sourceLineNo">1853</span><a name="line.1853"></a>
+<span class="sourceLineNo">1534</span><a name="line.1534"></a>
+<span class="sourceLineNo">1535</span>      // Set up ZK<a name="line.1535"></a>
+<span class="sourceLineNo">1536</span>      LOG.info("Serving as " + this.serverName + ", RpcServer on " + rpcServices.isa +<a name="line.1536"></a>
+<span class="sourceLineNo">1537</span>          ", sessionid=0x" +<a name="line.1537"></a>
+<span class="sourceLineNo">1538</span>          Long.toHexString(this.zooKeeper.getRecoverableZooKeeper().getSessionId()));<a name="line.1538"></a>
+<span class="sourceLineNo">1539</span><a name="line.1539"></a>
+<span class="sourceLineNo">1540</span>      // Wake up anyone waiting for this server to online<a name="line.1540"></a>
+<span class="sourceLineNo">1541</span>      synchronized (online) {<a name="line.1541"></a>
+<span class="sourceLineNo">1542</span>        online.set(true);<a name="line.1542"></a>
+<span class="sourceLineNo">1543</span>        online.notifyAll();<a name="line.1543"></a>
+<span class="sourceLineNo">1544</span>      }<a name="line.1544"></a>
+<span class="sourceLineNo">1545</span>    } catch (Throwable e) {<a name="line.1545"></a>
+<span class="sourceLineNo">1546</span>      stop("Failed initialization");<a name="line.1546"></a>
+<span class="sourceLineNo">1547</span>      throw convertThrowableToIOE(cleanup(e, "Failed init"),<a name="line.1547"></a>
+<span class="sourceLineNo">1548</span>          "Region server startup failed");<a name="line.1548"></a>
+<span class="sourceLineNo">1549</span>    } finally {<a name="line.1549"></a>
+<span class="sourceLineNo">1550</span>      sleeper.skipSleepCycle();<a name="line.1550"></a>
+<span class="sourceLineNo">1551</span>    }<a name="line.1551"></a>
+<span class="sourceLineNo">1552</span>  }<a name="line.1552"></a>
+<span class="sourceLineNo">1553</span><a name="line.1553"></a>
+<span class="sourceLineNo">1554</span>  protected void initializeMemStoreChunkCreator() {<a name="line.1554"></a>
+<span class="sourceLineNo">1555</span>    if (MemStoreLAB.isEnabled(conf)) {<a name="line.1555"></a>
+<span class="sourceLineNo">1556</span>      // MSLAB is enabled. So initialize MemStoreChunkPool<a name="line.1556"></a>
+<span class="sourceLineNo">1557</span>      // By this time, the MemstoreFlusher is already initialized. We can get the global limits from<a name="line.1557"></a>
+<span class="sourceLineNo">1558</span>      // it.<a name="line.1558"></a>
+<span class="sourceLineNo">1559</span>      Pair&lt;Long, MemoryType&gt; pair = MemorySizeUtil.getGlobalMemStoreSize(conf);<a name="line.1559"></a>
+<span class="sourceLineNo">1560</span>      long globalMemStoreSize = pair.getFirst();<a name="line.1560"></a>
+<span class="sourceLineNo">1561</span>      boolean offheap = this.regionServerAccounting.isOffheap();<a name="line.1561"></a>
+<span class="sourceLineNo">1562</span>      // When off heap memstore in use, take full area for chunk pool.<a name="line.1562"></a>
+<span class="sourceLineNo">1563</span>      float poolSizePercentage = offheap? 1.0F:<a name="line.1563"></a>
+<span class="sourceLineNo">1564</span>          conf.getFloat(MemStoreLAB.CHUNK_POOL_MAXSIZE_KEY, MemStoreLAB.POOL_MAX_SIZE_DEFAULT);<a name="line.1564"></a>
+<span class="sourceLineNo">1565</span>      float initialCountPercentage = conf.getFloat(MemStoreLAB.CHUNK_POOL_INITIALSIZE_KEY,<a name="line.1565"></a>
+<span class="sourceLineNo">1566</span>          MemStoreLAB.POOL_INITIAL_SIZE_DEFAULT);<a name="line.1566"></a>
+<span class="sourceLineNo">1567</span>      int chunkSize = conf.getInt(MemStoreLAB.CHUNK_SIZE_KEY, MemStoreLAB.CHUNK_SIZE_DEFAULT);<a name="line.1567"></a>
+<span class="sourceLineNo">1568</span>      // init the chunkCreator<a name="line.1568"></a>
+<span class="sourceLineNo">1569</span>      ChunkCreator chunkCreator =<a name="line.1569"></a>
+<span class="sourceLineNo">1570</span>          ChunkCreator.initialize(chunkSize, offheap, globalMemStoreSize, poolSizePercentage,<a name="line.1570"></a>
+<span class="sourceLineNo">1571</span>      initialCountPercentage, this.hMemManager);<a name="line.1571"></a>
+<span class="sourceLineNo">1572</span>    }<a name="line.1572"></a>
+<span class="sourceLineNo">1573</span>  }<a name="line.1573"></a>
+<span class="sourceLineNo">1574</span><a name="line.1574"></a>
+<span class="sourceLineNo">1575</span>  private void startHeapMemoryManager() {<a name="line.1575"></a>
+<span class="sourceLineNo">1576</span>    this.hMemManager = HeapMemoryManager.create(this.conf, this.cacheFlusher, this,<a name="line.1576"></a>
+<span class="sourceLineNo">1577</span>        this.regionServerAccounting);<a name="line.1577"></a>
+<span class="sourceLineNo">1578</span>    if (this.hMemManager != null) {<a name="line.1578"></a>
+<span class="sourceLineNo">1579</span>      this.hMemManager.start(getChoreService());<a name="line.1579"></a>
+<span class="sourceLineNo">1580</span>    }<a name="line.1580"></a>
+<span class="sourceLineNo">1581</span>  }<a name="line.1581"></a>
+<span class="sourceLineNo">1582</span><a name="line.1582"></a>
+<span class="sourceLineNo">1583</span>  private void createMyEphemeralNode() throws KeeperException, IOException {<a name="line.1583"></a>
+<span class="sourceLineNo">1584</span>    RegionServerInfo.Builder rsInfo = RegionServerInfo.newBuilder();<a name="line.1584"></a>
+<span class="sourceLineNo">1585</span>    rsInfo.setInfoPort(infoServer != null ? infoServer.getPort() : -1);<a name="line.1585"></a>
+<span class="sourceLineNo">1586</span>    rsInfo.setVersionInfo(ProtobufUtil.getVersionInfo());<a name="line.1586"></a>
+<span class="sourceLineNo">1587</span>    byte[] data = ProtobufUtil.prependPBMagic(rsInfo.build().toByteArray());<a name="line.1587"></a>
+<span class="sourceLineNo">1588</span>    ZKUtil.createEphemeralNodeAndWatch(this.zooKeeper, getMyEphemeralNodePath(), data);<a name="line.1588"></a>
+<span class="sourceLineNo">1589</span>  }<a name="line.1589"></a>
+<span class="sourceLineNo">1590</span><a name="line.1590"></a>
+<span class="sourceLineNo">1591</span>  private void deleteMyEphemeralNode() throws KeeperException {<a name="line.1591"></a>
+<span class="sourceLineNo">1592</span>    ZKUtil.deleteNode(this.zooKeeper, getMyEphemeralNodePath());<a name="line.1592"></a>
+<span class="sourceLineNo">1593</span>  }<a name="line.1593"></a>
+<span class="sourceLineNo">1594</span><a name="line.1594"></a>
+<span class="sourceLineNo">1595</span>  @Override<a name="line.1595"></a>
+<span class="sourceLineNo">1596</span>  public RegionServerAccounting getRegionServerAccounting() {<a name="line.1596"></a>
+<span class="sourceLineNo">1597</span>    return regionServerAccounting;<a name="line.1597"></a>
+<span class="sourceLineNo">1598</span>  }<a name="line.1598"></a>
+<span class="sourceLineNo">1599</span><a name="line.1599"></a>
+<span class="sourceLineNo">1600</span>  /*<a name="line.1600"></a>
+<span class="sourceLineNo">1601</span>   * @param r Region to get RegionLoad for.<a name="line.1601"></a>
+<span class="sourceLineNo">1602</span>   * @param regionLoadBldr the RegionLoad.Builder, can be null<a name="line.1602"></a>
+<span class="sourceLineNo">1603</span>   * @param regionSpecifier the RegionSpecifier.Builder, can be null<a name="line.1603"></a>
+<span class="sourceLineNo">1604</span>   * @return RegionLoad instance.<a name="line.1604"></a>
+<span class="sourceLineNo">1605</span>   *<a name="line.1605"></a>
+<span class="sourceLineNo">1606</span>   * @throws IOException<a name="line.1606"></a>
+<span class="sourceLineNo">1607</span>   */<a name="line.1607"></a>
+<span class="sourceLineNo">1608</span>  RegionLoad createRegionLoad(final HRegion r, RegionLoad.Builder regionLoadBldr,<a name="line.1608"></a>
+<span class="sourceLineNo">1609</span>      RegionSpecifier.Builder regionSpecifier) throws IOException {<a name="line.1609"></a>
+<span class="sourceLineNo">1610</span>    byte[] name = r.getRegionInfo().getRegionName();<a name="line.1610"></a>
+<span class="sourceLineNo">1611</span>    int stores = 0;<a name="line.1611"></a>
+<span class="sourceLineNo">1612</span>    int storefiles = 0;<a name="line.1612"></a>
+<span class="sourceLineNo">1613</span>    int storeUncompressedSizeMB = 0;<a name="line.1613"></a>
+<span class="sourceLineNo">1614</span>    int storefileSizeMB = 0;<a name="line.1614"></a>
+<span class="sourceLineNo">1615</span>    int memstoreSizeMB = (int) (r.getMemStoreSize() / 1024 / 1024);<a name="line.1615"></a>
+<span class="sourceLineNo">1616</span>    long storefileIndexSizeKB = 0;<a name="line.1616"></a>
+<span class="sourceLineNo">1617</span>    int rootIndexSizeKB = 0;<a name="line.1617"></a>
+<span class="sourceLineNo">1618</span>    int totalStaticIndexSizeKB = 0;<a name="line.1618"></a>
+<span class="sourceLineNo">1619</span>    int totalStaticBloomSizeKB = 0;<a name="line.1619"></a>
+<span class="sourceLineNo">1620</span>    long totalCompactingKVs = 0;<a name="line.1620"></a>
+<span class="sourceLineNo">1621</span>    long currentCompactedKVs = 0;<a name="line.1621"></a>
+<span class="sourceLineNo">1622</span>    List&lt;HStore&gt; storeList = r.getStores();<a name="line.1622"></a>
+<span class="sourceLineNo">1623</span>    stores += storeList.size();<a name="line.1623"></a>
+<span class="sourceLineNo">1624</span>    for (HStore store : storeList) {<a name="line.1624"></a>
+<span class="sourceLineNo">1625</span>      storefiles += store.getStorefilesCount();<a name="line.1625"></a>
+<span class="sourceLineNo">1626</span>      storeUncompressedSizeMB += (int) (store.getStoreSizeUncompressed() / 1024 / 1024);<a name="line.1626"></a>
+<span class="sourceLineNo">1627</span>      storefileSizeMB += (int) (store.getStorefilesSize() / 1024 / 1024);<a name="line.1627"></a>
+<span class="sourceLineNo">1628</span>      storefileIndexSizeKB += store.getStorefilesIndexSize() / 1024;<a name="line.1628"></a>
+<span class="sourceLineNo">1629</span>      CompactionProgress progress = store.getCompactionProgress();<a name="line.1629"></a>
+<span class="sourceLineNo">1630</span>      if (progress != null) {<a name="line.1630"></a>
+<span class="sourceLineNo">1631</span>        totalCompactingKVs += progress.totalCompactingKVs;<a name="line.1631"></a>
+<span class="sourceLineNo">1632</span>        currentCompactedKVs += progress.currentCompactedKVs;<a name="line.1632"></a>
+<span class="sourceLineNo">1633</span>      }<a name="line.1633"></a>
+<span class="sourceLineNo">1634</span>      rootIndexSizeKB += (int) (store.getStorefilesIndexSize() / 1024);<a name="line.1634"></a>
+<span class="sourceLineNo">1635</span>      totalStaticIndexSizeKB += (int) (store.getTotalStaticIndexSize() / 1024);<a name="line.1635"></a>
+<span class="sourceLineNo">1636</span>      totalStaticBloomSizeKB += (int) (store.getTotalStaticBloomSize() / 1024);<a name="line.1636"></a>
+<span class="sourceLineNo">1637</span>    }<a name="line.1637"></a>
+<span class="sourceLineNo">1638</span><a name="line.1638"></a>
+<span class="sourceLineNo">1639</span>    float dataLocality =<a name="line.1639"></a>
+<span class="sourceLineNo">1640</span>        r.getHDFSBlocksDistribution().getBlockLocalityIndex(serverName.getHostname());<a name="line.1640"></a>
+<span class="sourceLineNo">1641</span>    if (regionLoadBldr == null) {<a name="line.1641"></a>
+<span class="sourceLineNo">1642</span>      regionLoadBldr = RegionLoad.newBuilder();<a name="line.1642"></a>
+<span class="sourceLineNo">1643</span>    }<a name="line.1643"></a>
+<span class="sourceLineNo">1644</span>    if (regionSpecifier == null) {<a name="line.1644"></a>
+<span class="sourceLineNo">1645</span>      regionSpecifier = RegionSpecifier.newBuilder();<a name="line.1645"></a>
+<span class="sourceLineNo">1646</span>    }<a name="line.1646"></a>
+<span class="sourceLineNo">1647</span>    regionSpecifier.setType(RegionSpecifierType.REGION_NAME);<a name="line.1647"></a>
+<span class="sourceLineNo">1648</span>    regionSpecifier.setValue(UnsafeByteOperations.unsafeWrap(name));<a name="line.1648"></a>
+<span class="sourceLineNo">1649</span>    regionLoadBldr.setRegionSpecifier(regionSpecifier.build())<a name="line.1649"></a>
+<span class="sourceLineNo">1650</span>      .setStores(stores)<a name="line.1650"></a>
+<span class="sourceLineNo">1651</span>      .setStorefiles(storefiles)<a name="line.1651"></a>
+<span class="sourceLineNo">1652</span>      .setStoreUncompressedSizeMB(storeUncompressedSizeMB)<a name="line.1652"></a>
+<span class="sourceLineNo">1653</span>      .setStorefileSizeMB(storefileSizeMB)<a name="line.1653"></a>
+<span class="sourceLineNo">1654</span>      .setMemStoreSizeMB(memstoreSizeMB)<a name="line.1654"></a>
+<span class="sourceLineNo">1655</span>      .setStorefileIndexSizeKB(storefileIndexSizeKB)<a name="line.1655"></a>
+<span class="sourceLineNo">1656</span>      .setRootIndexSizeKB(rootIndexSizeKB)<a name="line.1656"></a>
+<span class="sourceLineNo">1657</span>      .setTotalStaticIndexSizeKB(totalStaticIndexSizeKB)<a name="line.1657"></a>
+<span class="sourceLineNo">1658</span>      .setTotalStaticBloomSizeKB(totalStaticBloomSizeKB)<a name="line.1658"></a>
+<span class="sourceLineNo">1659</span>      .setReadRequestsCount(r.getReadRequestsCount())<a name="line.1659"></a>
+<span class="sourceLineNo">1660</span>      .setFilteredReadRequestsCount(r.getFilteredReadRequestsCount())<a name="line.1660"></a>
+<span class="sourceLineNo">1661</span>      .setWriteRequestsCount(r.getWriteRequestsCount())<a name="line.1661"></a>
+<span class="sourceLineNo">1662</span>      .setTotalCompactingKVs(totalCompactingKVs)<a name="line.1662"></a>
+<span class="sourceLineNo">1663</span>      .setCurrentCompactedKVs(currentCompactedKVs)<a name="line.1663"></a>
+<span class="sourceLineNo">1664</span>      .setDataLocality(dataLocality)<a name="line.1664"></a>
+<span class="sourceLineNo">1665</span>      .setLastMajorCompactionTs(r.getOldestHfileTs(true));<a name="line.1665"></a>
+<span class="sourceLineNo">1666</span>    ((HRegion)r).setCompleteSequenceId(regionLoadBldr);<a name="line.1666"></a>
+<span class="sourceLineNo">1667</span><a name="line.1667"></a>
+<span class="sourceLineNo">1668</span>    return regionLoadBldr.build();<a name="line.1668"></a>
+<span class="sourceLineNo">1669</span>  }<a name="line.1669"></a>
+<span class="sourceLineNo">1670</span><a name="line.1670"></a>
+<span class="sourceLineNo">1671</span>  /**<a name="line.1671"></a>
+<span class="sourceLineNo">1672</span>   * @param encodedRegionName<a name="line.1672"></a>
+<span class="sourceLineNo">1673</span>   * @return An instance of RegionLoad.<a name="line.1673"></a>
+<span class="sourceLineNo">1674</span>   */<a name="line.1674"></a>
+<span class="sourceLineNo">1675</span>  public RegionLoad createRegionLoad(final String encodedRegionName) throws IOException {<a name="line.1675"></a>
+<span class="sourceLineNo">1676</span>    HRegion r = onlineRegions.get(encodedRegionName);<a name="line.1676"></a>
+<span class="sourceLineNo">1677</span>    return r != null ? createRegionLoad(r, null, null) : null;<a name="line.1677"></a>
+<span class="sourceLineNo">1678</span>  }<a name="line.1678"></a>
+<span class="sourceLineNo">1679</span><a name="line.1679"></a>
+<span class="sourceLineNo">1680</span>  /*<a name="line.1680"></a>
+<span class="sourceLineNo">1681</span>   * Inner class that runs on a long period checking if regions need compaction.<a name="line.1681"></a>
+<span class="sourceLineNo">1682</span>   */<a name="line.1682"></a>
+<span class="sourceLineNo">1683</span>  private static class CompactionChecker extends ScheduledChore {<a name="line.1683"></a>
+<span class="sourceLineNo">1684</span>    private final HRegionServer instance;<a name="line.1684"></a>
+<span class="sourceLineNo">1685</span>    private final int majorCompactPriority;<a name="line.1685"></a>
+<span class="sourceLineNo">1686</span>    private final static int DEFAULT_PRIORITY = Integer.MAX_VALUE;<a name="line.1686"></a>
+<span class="sourceLineNo">1687</span>    //Iteration is 1-based rather than 0-based so we don't check for compaction<a name="line.1687"></a>
+<span class="sourceLineNo">1688</span>    // immediately upon region server startup<a name="line.1688"></a>
+<span class="sourceLineNo">1689</span>    private long iteration = 1;<a name="line.1689"></a>
+<span class="sourceLineNo">1690</span><a name="line.1690"></a>
+<span class="sourceLineNo">1691</span>    CompactionChecker(final HRegionServer h, final int sleepTime, final Stoppable stopper) {<a name="line.1691"></a>
+<span class="sourceLineNo">1692</span>      super("CompactionChecker", stopper, sleepTime);<a name="line.1692"></a>
+<span class="sourceLineNo">1693</span>      this.instance = h;<a name="line.1693"></a>
+<span class="sourceLineNo">1694</span>      LOG.info(this.getName() + " runs every " + StringUtils.formatTime(sleepTime));<a name="line.1694"></a>
+<span class="sourceLineNo">1695</span><a name="line.1695"></a>
+<span class="sourceLineNo">1696</span>      /* MajorCompactPriority is configurable.<a name="line.1696"></a>
+<span class="sourceLineNo">1697</span>       * If not set, the compaction will use default priority.<a name="line.1697"></a>
+<span class="sourceLineNo">1698</span>       */<a name="line.1698"></a>
+<span class="sourceLineNo">1699</span>      this.majorCompactPriority = this.instance.conf.<a name="line.1699"></a>
+<span class="sourceLineNo">1700</span>          getInt("hbase.regionserver.compactionChecker.majorCompactPriority",<a name="line.1700"></a>
+<span class="sourceLineNo">1701</span>              DEFAULT_PRIORITY);<a name="line.1701"></a>
+<span class="sourceLineNo">1702</span>    }<a name="line.1702"></a>
+<span class="sourceLineNo">1703</span><a name="line.1703"></a>
+<span class="sourceLineNo">1704</span>    @Override<a name="line.1704"></a>
+<span class="sourceLineNo">1705</span>    protected void chore() {<a name="line.1705"></a>
+<span class="sourceLineNo">1706</span>      for (Region r : this.instance.onlineRegions.values()) {<a name="line.1706"></a>
+<span class="sourceLineNo">1707</span>        if (r == null) {<a name="line.1707"></a>
+<span class="sourceLineNo">1708</span>          continue;<a name="line.1708"></a>
+<span class="sourceLineNo">1709</span>        }<a name="line.1709"></a>
+<span class="sourceLineNo">1710</span>        HRegion hr = (HRegion) r;<a name="line.1710"></a>
+<span class="sourceLineNo">1711</span>        for (HStore s : hr.stores.values()) {<a name="line.1711"></a>
+<span class="sourceLineNo">1712</span>          try {<a name="line.1712"></a>
+<span class="sourceLineNo">1713</span>            long multiplier = s.getCompactionCheckMultiplier();<a name="line.1713"></a>
+<span class="sourceLineNo">1714</span>            assert multiplier &gt; 0;<a name="line.1714"></a>
+<span class="sourceLineNo">1715</span>            if (iteration % multiplier != 0) {<a name="line.1715"></a>
+<span class="sourceLineNo">1716</span>              continue;<a name="line.1716"></a>
+<span class="sourceLineNo">1717</span>            }<a name="line.1717"></a>
+<span class="sourceLineNo">1718</span>            if (s.needsCompaction()) {<a name="line.1718"></a>
+<span class="sourceLineNo">1719</span>              // Queue a compaction. Will recognize if major is needed.<a name="line.1719"></a>
+<span class="sourceLineNo">1720</span>              this.instance.compactSplitThread.requestSystemCompaction(hr, s,<a name="line.1720"></a>
+<span class="sourceLineNo">1721</span>                getName() + " requests compaction");<a name="line.1721"></a>
+<span class="sourceLineNo">1722</span>            } else if (s.shouldPerformMajorCompaction()) {<a name="line.1722"></a>
+<span class="sourceLineNo">1723</span>              s.triggerMajorCompaction();<a name="line.1723"></a>
+<span class="sourceLineNo">1724</span>              if (majorCompactPriority == DEFAULT_PRIORITY ||<a name="line.1724"></a>
+<span class="sourceLineNo">1725</span>                  majorCompactPriority &gt; hr.getCompactPriority()) {<a name="line.1725"></a>
+<span class="sourceLineNo">1726</span>                this.instance.compactSplitThread.requestCompaction(hr, s,<a name="line.1726"></a>
+<span class="sourceLineNo">1727</span>                    getName() + " requests major compaction; use default priority",<a name="line.1727"></a>
+<span class="sourceLineNo">1728</span>                    Store.NO_PRIORITY,<a name="line.1728"></a>
+<span class="sourceLineNo">1729</span>                CompactionLifeCycleTracker.DUMMY, null);<a name="line.1729"></a>
+<span class="sourceLineNo">1730</span>              } else {<a name="line.1730"></a>
+<span class="sourceLineNo">1731</span>                this.instance.compactSplitThread.requestCompaction(hr, s,<a name="line.1731"></a>
+<span class="sourceLineNo">1732</span>                    getName() + " requests major compaction; use configured priority",<a name="line.1732"></a>
+<span class="sourceLineNo">1733</span>                    this.majorCompactPriority, CompactionLifeCycleTracker.DUMMY, null);<a name="line.1733"></a>
+<span class="sourceLineNo">1734</span>              }<a name="line.1734"></a>
+<span class="sourceLineNo">1735</span>            }<a name="line.1735"></a>
+<span class="sourceLineNo">1736</span>          } catch (IOException e) {<a name="line.1736"></a>
+<span class="sourceLineNo">1737</span>            LOG.warn("Failed major compaction check on " + r, e);<a name="line.1737"></a>
+<span class="sourceLineNo">1738</span>          }<a name="line.1738"></a>
+<span class="sourceLineNo">1739</span>        }<a name="line.1739"></a>
+<span class="sourceLineNo">1740</span>      }<a name="line.1740"></a>
+<span class="sourceLineNo">1741</span>      iteration = (iteration == Long.MAX_VALUE) ? 0 : (iteration + 1);<a name="line.1741"></a>
+<span class="sourceLineNo">1742</span>    }<a name="line.1742"></a>
+<span class="sourceLineNo">1743</span>  }<a name="line.1743"></a>
+<span class="sourceLineNo">1744</span><a name="line.1744"></a>
+<span class="sourceLineNo">1745</span>  static class PeriodicMemStoreFlusher extends ScheduledChore {<a name="line.1745"></a>
+<span class="sourceLineNo">1746</span>    final HRegionServer server;<a name="line.1746"></a>
+<span class="sourceLineNo">1747</span>    final static int RANGE_OF_DELAY = 5 * 60 * 1000; // 5 min in milliseconds<a name="line.1747"></a>
+<span class="sourceLineNo">1748</span>    final static int MIN_DELAY_TIME = 0; // millisec<a name="line.1748"></a>
+<span class="sourceLineNo">1749</span>    public PeriodicMemStoreFlusher(int cacheFlushInterval, final HRegionServer server) {<a name="line.1749"></a>
+<span class="sourceLineNo">1750</span>      super("MemstoreFlusherChore", server, cacheFlushInterval);<a name="line.1750"></a>
+<span class="sourceLineNo">1751</span>      this.server = server;<a name="line.1751"></a>
+<span class="sourceLineNo">1752</span>    }<a name="line.1752"></a>
+<span class="sourceLineNo">1753</span><a name="line.1753"></a>
+<span class="sourceLineNo">1754</span>    @Override<a name="line.1754"></a>
+<span class="sourceLineNo">1755</span>    protected void chore() {<a name="line.1755"></a>
+<span class="sourceLineNo">1756</span>      final StringBuffer whyFlush = new StringBuffer();<a name="line.1756"></a>
+<span class="sourceLineNo">1757</span>      for (HRegion r : this.server.onlineRegions.values()) {<a name="line.1757"></a>
+<span class="sourceLineNo">1758</span>        if (r == null) continue;<a name="line.1758"></a>
+<span class="sourceLineNo">1759</span>        if (r.shouldFlush(whyFlush)) {<a name="line.1759"></a>
+<span class="sourceLineNo">1760</span>          FlushRequester requester = server.getFlushRequester();<a name="line.1760"></a>
+<span class="sourceLineNo">1761</span>          if (requester != null) {<a name="line.1761"></a>
+<span class="sourceLineNo">1762</span>            long randomDelay = RandomUtils.nextInt(0, RANGE_OF_DELAY) + MIN_DELAY_TIME;<a name="line.1762"></a>
+<span class="sourceLineNo">1763</span>            LOG.info(getName() + " requesting flush of " +<a name="line.1763"></a>
+<span class="sourceLineNo">1764</span>              r.getRegionInfo().getRegionNameAsString() + " because " +<a name="line.1764"></a>
+<span class="sourceLineNo">1765</span>              whyFlush.toString() +<a name="line.1765"></a>
+<span class="sourceLineNo">1766</span>              " after random delay " + randomDelay + "ms");<a name="line.1766"></a>
+<span class="sourceLineNo">1767</span>            //Throttle the flushes by putting a delay. If we don't throttle, and there<a name="line.1767"></a>
+<span class="sourceLineNo">1768</span>            //is a balanced write-load on the regions in a table, we might end up<a name="line.1768"></a>
+<span class="sourceLineNo">1769</span>            //overwhelming the filesystem with too many flushes at once.<a name="line.1769"></a>
+<span class="sourceLineNo">1770</span>            requester.requestDelayedFlush(r, randomDelay, false);<a name="line.1770"></a>
+<span class="sourceLineNo">1771</span>          }<a name="line.1771"></a>
+<span class="sourceLineNo">1772</span>        }<a name="line.1772"></a>
+<span class="sourceLineNo">1773</span>      }<a name="line.1773"></a>
+<span class="sourceLineNo">1774</span>    }<a name="line.1774"></a>
+<span class="sourceLineNo">1775</span>  }<a name="line.1775"></a>
+<span class="sourceLineNo">1776</span><a name="line.1776"></a>
+<span class="sourceLineNo">1777</span>  /**<a name="line.1777"></a>
+<span class="sourceLineNo">1778</span>   * Report the status of the server. A server is online once all the startup is<a name="line.1778"></a>
+<span class="sourceLineNo">1779</span>   * completed (setting up filesystem, starting executorService threads, etc.). This<a name="line.1779"></a>
+<span class="sourceLineNo">1780</span>   * method is designed mostly to be useful in tests.<a name="line.1780"></a>
+<span class="sourceLineNo">1781</span>   *<a name="line.1781"></a>
+<span class="sourceLineNo">1782</span>   * @return true if online, false if not.<a name="line.1782"></a>
+<span class="sourceLineNo">1783</span>   */<a name="line.1783"></a>
+<span class="sourceLineNo">1784</span>  public boolean isOnline() {<a name="line.1784"></a>
+<span class="sourceLineNo">1785</span>    return online.get();<a name="line.1785"></a>
+<span class="sourceLineNo">1786</span>  }<a name="line.1786"></a>
+<span class="sourceLineNo">1787</span><a name="line.1787"></a>
+<span class="sourceLineNo">1788</span>  /**<a name="line.1788"></a>
+<span class="sourceLineNo">1789</span>   * Setup WAL log and replication if enabled.<a name="line.1789"></a>
+<span class="sourceLineNo">1790</span>   * Replication setup is done in here because it wants to be hooked up to WAL.<a name="line.1790"></a>
+<span class="sourceLineNo">1791</span>   *<a name="line.1791"></a>
+<span class="sourceLineNo">1792</span>   * @throws IOException<a name="line.1792"></a>
+<span class="sourceLineNo">1793</span>   */<a name="line.1793"></a>
+<span class="sourceLineNo">1794</span>  private void setupWALAndReplication() throws IOException {<a name="line.1794"></a>
+<span class="sourceLineNo">1795</span>    // TODO Replication make assumptions here based on the default filesystem impl<a name="line.1795"></a>
+<span class="sourceLineNo">1796</span>    Path oldLogDir = new Path(walRootDir, HConstants.HREGION_OLDLOGDIR_NAME);<a name="line.1796"></a>
+<span class="sourceLineNo">1797</span>    String logName = AbstractFSWALProvider.getWALDirectoryName(this.serverName.toString());<a name="line.1797"></a>
+<span class="sourceLineNo">1798</span><a name="line.1798"></a>
+<span class="sourceLineNo">1799</span>    Path logDir = new Path(walRootDir, logName);<a name="line.1799"></a>
+<span class="sourceLineNo">1800</span>    if (LOG.isDebugEnabled()) LOG.debug("logDir=" + logDir);<a name="line.1800"></a>
+<span class="sourceLineNo">1801</span>    if (this.walFs.exists(logDir)) {<a name="line.1801"></a>
+<span class="sourceLineNo">1802</span>      throw new RegionServerRunningException("Region server has already " +<a name="line.1802"></a>
+<span class="sourceLineNo">1803</span>          "created directory at " + this.serverName.toString());<a name="line.1803"></a>
+<span class="sourceLineNo">1804</span>    }<a name="line.1804"></a>
+<span class="sourceLineNo">1805</span><a name="line.1805"></a>
+<span class="sourceLineNo">1806</span>    // Instantiate replication if replication enabled.  Pass it the log directories.<a name="line.1806"></a>
+<span class="sourceLineNo">1807</span>    // In here we create the Replication instances. Later they are initialized and started up.<a name="line.1807"></a>
+<span class="sourceLineNo">1808</span>    createNewReplicationInstance(conf, this, this.walFs, logDir, oldLogDir);<a name="line.1808"></a>
+<span class="sourceLineNo">1809</span><a name="line.1809"></a>
+<span class="sourceLineNo">1810</span>    // listeners the wal factory will add to wals it creates.<a name="line.1810"></a>
+<span class="sourceLineNo">1811</span>    List&lt;WALActionsListener&gt; listeners = new ArrayList&lt;&gt;();<a name="line.1811"></a>
+<span class="sourceLineNo">1812</span>    listeners.add(new MetricsWAL());<a name="line.1812"></a>
+<span class="sourceLineNo">1813</span>    if (this.replicationSourceHandler != null &amp;&amp;<a name="line.1813"></a>
+<span class="sourceLineNo">1814</span>        this.replicationSourceHandler.getWALActionsListener() != null) {<a name="line.1814"></a>
+<span class="sourceLineNo">1815</span>      // Replication handler is an implementation of WALActionsListener.<a name="line.1815"></a>
+<span class="sourceLineNo">1816</span>      listeners.add(this.replicationSourceHandler.getWALActionsListener());<a name="line.1816"></a>
+<span class="sourceLineNo">1817</span>    }<a name="line.1817"></a>
+<span class="sourceLineNo">1818</span><a name="line.1818"></a>
+<span class="sourceLineNo">1819</span>    // There is a cyclic dependency between ReplicationSourceHandler and WALFactory.<a name="line.1819"></a>
+<span class="sourceLineNo">1820</span>    // We use WALActionsListener to get the newly rolled WALs, so we need to get the<a name="line.1820"></a>
+<span class="sourceLineNo">1821</span>    // WALActionsListeners from ReplicationSourceHandler before constructing WALFactory. And then<a name="line.1821"></a>
+<span class="sourceLineNo">1822</span>    // ReplicationSourceHandler need to use WALFactory get the length of the wal file being written.<a name="line.1822"></a>
+<span class="sourceLineNo">1823</span>    // So we here we need to construct WALFactory first, and then pass it to the initialized method<a name="line.1823"></a>
+<span class="sourceLineNo">1824</span>    // of ReplicationSourceHandler.<a name="line.1824"></a>
+<span class="sourceLineNo">1825</span>    // TODO: I can't follow replication; it has initialize and then later on we start it!<a name="line.1825"></a>
+<span class="sourceLineNo">1826</span>    WALFactory factory = new WALFactory(conf, listeners, serverName.toString());<a name="line.1826"></a>
+<span class="sourceLineNo">1827</span>    this.walFactory = factory;<a name="line.1827"></a>
+<span class="sourceLineNo">1828</span>    if (this.replicationSourceHandler != null) {<a name="line.1828"></a>
+<span class="sourceLineNo">1829</span>      this.replicationSourceHandler.initialize(this, walFs, logDir, oldLogDir, factory);<a name="line.1829"></a>
+<span class="sourceLineNo">1830</span>    }<a name="line.1830"></a>
+<span class="sourceLineNo">1831</span>    if (this.replicationSinkHandler != null &amp;&amp;<a name="line.1831"></a>
+<span class="sourceLineNo">1832</span>        this.replicationSinkHandler != this.replicationSourceHandler) {<a name="line.1832"></a>
+<span class="sourceLineNo">1833</span>      this.replicationSinkHandler.initialize(this, walFs, logDir, oldLogDir, factory);<a name="line.1833"></a>
+<span class="sourceLineNo">1834</span>    }<a name="line.1834"></a>
+<span class="sourceLineNo">1835</span>  }<a name="line.1835"></a>
+<span class="sourceLineNo">1836</span><a name="line.1836"></a>
+<span class="sourceLineNo">1837</span>  /**<a name="line.1837"></a>
+<span class="sourceLineNo">1838</span>   * Start up replication source and sink handlers.<a name="line.1838"></a>
+<span class="sourceLineNo">1839</span>   * @throws IOException<a name="line.1839"></a>
+<span class="sourceLineNo">1840</span>   */<a name="line.1840"></a>
+<span class="sourceLineNo">1841</span>  private void startReplicationService() throws IOException {<a name="line.1841"></a>
+<span class="sourceLineNo">1842</span>    if (this.replicationSourceHandler == this.replicationSinkHandler &amp;&amp;<a name="line.1842"></a>
+<span class="sourceLineNo">1843</span>        this.replicationSourceHandler != null) {<a name="line.1843"></a>
+<span class="sourceLineNo">1844</span>      this.replicationSourceHandler.startReplicationService();<a name="line.1844"></a>
+<span class="sourceLineNo">1845</span>    } else {<a name="line.1845"></a>
+<span class="sourceLineNo">1846</span>      if (this.replicationSourceHandler != null) {<a name="line.1846"></a>
+<span class="sourceLineNo">1847</span>        this.replicationSourceHandler.startReplicationService();<a name="line.1847"></a>
+<span class="sourceLineNo">1848</span>      }<a name="line.1848"></a>
+<span class="sourceLineNo">1849</span>      if (this.replicationSinkHandler != null) {<a name="line.1849"></a>
+<span class="sourceLineNo">1850</span>        this.replicationSinkHandler.startReplicationService();<a name="line.1850"></a>
+<span class="sourceLineNo">1851</span>      }<a name="line.1851"></a>
+<span class="sourceLineNo">1852</span>    }<a name="line.1852"></a>
+<span class="sourceLineNo">1853</span>  }<a name="line.1853"></a>
 <span class="sourceLineNo">1854</span><a name="line.1854"></a>
-<span class="sourceLineNo">1855</span>  public MetricsRegionServer getRegionServerMetrics() {<a name="line.1855"></a>
-<span class="sourceLineNo">1856</span>    return this.metricsRegionServer;<a name="line.1856"></a>
-<span class="sourceLineNo">1857</span>  }<a name="line.1857"></a>
-<span class="sourceLineNo">1858</span><a name="line.1858"></a>
-<span class="sourceLineNo">1859</span>  /**<a name="line.1859"></a>
-<span class="sourceLineNo">1860</span>   * @return Master address tracker instance.<a name="line.1860"></a>
-<span class="sourceLineNo">1861</span>   */<a name="line.1861"></a>
-<span class="sourceLineNo">1862</span>  public MasterAddressTracker getMasterAddressTracker() {<a name="line.1862"></a>
-<span class="sourceLineNo">1863</span>    return this.masterAddressTracker;<a name="line.1863"></a>
-<span class="sourceLineNo">1864</span>  }<a name="line.1864"></a>
-<span class="sourceLineNo">1865</span><a name="line.1865"></a>
-<span class="sourceLineNo">1866</span>  /*<a name="line.1866"></a>
-<span class="sourceLineNo">1867</span>   * Start maintenance Threads, Server, Worker and lease checker threads.<a name="line.1867"></a>
-<span class="sourceLineNo">1868</span>   * Start all threads we need to run. This is called after we've successfully<a name="line.1868"></a>
-<span class="sourceLineNo">1869</span>   * registered with the Master.<a name="line.1869"></a>
-<span class="sourceLineNo">1870</span>   * Install an UncaughtExceptionHandler that calls abort of RegionServer if we<a name="line.1870"></a>
-<span class="sourceLineNo">1871</span>   * get an unhandled exception. We cannot set the handler on all threads.<a name="line.1871"></a>
-<span class="sourceLineNo">1872</span>   * Server's internal Listener thread is off limits. For Server, if an OOME, it<a name="line.1872"></a>
-<span class="sourceLineNo">1873</span>   * waits a while then retries. Meantime, a flush or a compaction that tries to<a name="line.1873"></a>
-<span class="sourceLineNo">1874</span>   * run should trigger same critical condition and the shutdown will run. On<a name="line.1874"></a>
-<span class="sourceLineNo">1875</span>   * its way out, this server will shut down Server. Leases are sort of<a name="line.1875"></a>
-<span class="sourceLineNo">1876</span>   * inbetween. It has an internal thread that while it inherits from Chore, it<a name="line.1876"></a>
-<span class="sourceLineNo">1877</span>   * keeps its own internal stop mechanism so needs to be stopped by this<a name="line.1877"></a>
-<span class="sourceLineNo">1878</span>   * hosting server. Worker logs the exception and exits.<a name="line.1878"></a>
-<span class="sourceLineNo">1879</span>   */<a name="line.1879"></a>
-<span class="sourceLineNo">1880</span>  private void startServices() throws IOException {<a name="line.1880"></a>
-<span class="sourceLineNo">1881</span>    if (!isStopped() &amp;&amp; !isAborted()) {<a name="line.1881"></a>
-<span class="sourceLineNo">1882</span>      initializeThreads();<a name="line.1882"></a>
-<span class="sourceLineNo">1883</span>    }<a name="line.1883"></a>
-<span class="sourceLineNo">1884</span>    this.secureBulkLoadManager = new SecureBulkLoadManager(this.conf, clusterConnection);<a name="line.1884"></a>
-<span class="sourceLineNo">1885</span>    this.secureBulkLoadManager.start();<a name="line.1885"></a>
-<span class="sourceLineNo">1886</span><a name="line.1886"></a>
-<span class="sourceLineNo">1887</span>    // Health checker thread.<a name="line.1887"></a>
-<span class="sourceLineNo">1888</span>    if (isHealthCheckerConfigured()) {<a name="line.1888"></a>
-<span class="sourceLineNo">1889</span>      int sleepTime = this.conf.getInt(HConstants.HEALTH_CHORE_WAKE_FREQ,<a name="line.1889"></a>
-<span class="sourceLineNo">1890</span>      HConstants.DEFAULT_THREAD_WAKE_FREQUENCY);<a name="line.1890"></a>
-<span class="sourceLineNo">1891</span>      healthCheckChore = new HealthCheckChore(sleepTime, this, getConfiguration());<a name="line.1891"></a>
-<span class="sourceLineNo">1892</span>    }<a name="line.1892"></a>
-<span class="sourceLineNo">1893</span><a name="line.1893"></a>
-<span class="sourceLineNo">1894</span>    this.walRoller = new LogRoller(this, this);<a name="line.1894"></a>
-<span class="sourceLineNo">1895</span>    this.flushThroughputController = FlushThroughputControllerFactory.create(this, conf);<a name="line.1895"></a>
-<span class="sourceLineNo">1896</span><a name="line.1896"></a>
-<span class="sourceLineNo">1897</span>    // Create the CompactedFileDischarger chore executorService. This chore helps to<a name="line.1897"></a>
-<span class="sourceLineNo">1898</span>    // remove the compacted files<a name="line.1898"></a>
-<span class="sourceLineNo">1899</span>    // that will no longer be used in reads.<a name="line.1899"></a>
-<span class="sourceLineNo">1900</span>    // Default is 2 mins. The default value for TTLCleaner is 5 mins so we set this to<a name="line.1900"></a>
-<span class="sourceLineNo">1901</span>    // 2 mins so that compacted files can be archived before the TTLCleaner runs<a name="line.1901"></a>
-<span class="sourceLineNo">1902</span>    int cleanerInterval =<a name="line.1902"></a>
-<span class="sourceLineNo">1903</span>    conf.getInt("hbase.hfile.compaction.discharger.interval", 2 * 60 * 1000);<a name="line.1903"></a>
-<span class="sourceLineNo">1904</span>    this.compactedFileDischarger =<a name="line.1904"></a>
-<span class="sourceLineNo">1905</span>    new CompactedHFilesDischarger(cleanerInterval, this, this);<a name="line.1905"></a>
-<span class="sourceLineNo">1906</span>    choreService.scheduleChore(compactedFileDischarger);<a name="line.1906"></a>
-<span class="sourceLineNo">1907</span><a name="line.1907"></a>
-<span class="sourceLineNo">1908</span>    // Start executor services<a name="line.1908"></a>
-<span class="sourceLineNo">1909</span>    this.executorService.startExecutorService(ExecutorType.RS_OPEN_REGION,<a name="line.1909"></a>
-<span class="sourceLineNo">1910</span>        conf.getInt("hbase.regionserver.executor.openregion.threads", 3));<a name="line.1910"></a>
-<span class="sourceLineNo">1911</span>    this.executorService.startExecutorService(ExecutorType.RS_OPEN_META,<a name="line.1911"></a>
-<span class="sourceLineNo">1912</span>        conf.getInt("hbase.regionserver.executor.openmeta.threads", 1));<a name="line.1912"></a>
-<span class="sourceLineNo">1913</span>    this.executorService.startExecutorService(ExecutorType.RS_OPEN_PRIORITY_REGION,<a name="line.1913"></a>
-<span class="sourceLineNo">1914</span>        conf.getInt("hbase.regionserver.executor.openpriorityregion.threads", 3));<a name="line.1914"></a>
-<span class="sourceLineNo">1915</span>    this.executorService.startExecutorService(ExecutorType.RS_CLOSE_REGION,<a name="line.1915"></a>
-<span class="sourceLineNo">1916</span>        conf.getInt("hbase.regionserver.executor.closeregion.threads", 3));<a name="line.1916"></a>
-<span class="sourceLineNo">1917</span>    this.executorService.startExecutorService(ExecutorType.RS_CLOSE_META,<a name="line.1917"></a>
-<span class="sourceLineNo">1918</span>        conf.getInt("hbase.regionserver.executor.closemeta.threads", 1));<a name="line.1918"></a>
-<span class="sourceLineNo">1919</span>    if (conf.getBoolean(StoreScanner.STORESCANNER_PARALLEL_SEEK_ENABLE, false)) {<a name="line.1919"></a>
-<span class="sourceLineNo">1920</span>      this.executorService.startExecutorService(ExecutorType.RS_PARALLEL_SEEK,<a name="line.1920"></a>
-<span class="sourceLineNo">1921</span>          conf.getInt("hbase.storescanner.parallel.seek.threads", 10));<a name="line.1921"></a>
-<span class="sourceLineNo">1922</span>    }<a name="line.1922"></a>
-<span class="sourceLineNo">1923</span>    this.executorService.startExecutorService(ExecutorType.RS_LOG_REPLAY_OPS, conf.getInt(<a name="line.1923"></a>
-<span class="sourceLineNo">1924</span>    "hbase.regionserver.wal.max.splitters", SplitLogWorkerCoordination.DEFAULT_MAX_SPLITTERS));<a name="line.1924"></a>
-<span class="sourceLineNo">1925</span>    // Start the threads for compacted files discharger<a name="line.1925"></a>
-<span class="sourceLineNo">1926</span>    this.executorService.startExecutorService(ExecutorType.RS_COMPACTED_FILES_DISCHARGER,<a name="line.1926"></a>
-<span class="sourceLineNo">1927</span>        conf.getInt(CompactionConfiguration.HBASE_HFILE_COMPACTION_DISCHARGER_THREAD_COUNT, 10));<a name="line.1927"></a>
-<span class="sourceLineNo">1928</span>    if (ServerRegionReplicaUtil.isRegionReplicaWaitForPrimaryFlushEnabled(conf)) {<a name="line.1928"></a>
-<span class="sourceLineNo">1929</span>      this.executorService.startExecutorService(ExecutorType.RS_REGION_REPLICA_FLUSH_OPS,<a name="line.1929"></a>
-<span class="sourceLineNo">1930</span>          conf.getInt("hbase.regionserver.region.replica.flusher.threads",<a name="line.1930"></a>
-<span class="sourceLineNo">1931</span>              conf.getInt("hbase.regionserver.executor.openregion.threads", 3)));<a name="line.1931"></a>
-<span class="sourceLineNo">1932</span>    }<a name="line.1932"></a>
-<span class="sourceLineNo">1933</span><a name="line.1933"></a>
-<span class="sourceLineNo">1934</span>    Threads.setDaemonThreadRunning(this.walRoller.getThread(), getName() + ".logRoller",<a name="line.1934"></a>
-<span class="sourceLineNo">1935</span>    uncaughtExceptionHandler);<a name="line.1935"></a>
-<span class="sourceLineNo">1936</span>    this.cacheFlusher.start(uncaughtExceptionHandler);<a name="line.1936"></a>
-<span class="sourceLineNo">1937</span><a name="line.1937"></a>
-<span class="sourceLineNo">1938</span>    if (this.compactionChecker != null) choreService.scheduleChore(compactionChecker);<a name="line.1938"></a>
-<span class="sourceLineNo">1939</span>    if (this.periodicFlusher != null) choreService.scheduleChore(periodicFlusher);<a name="line.1939"></a>
-<span class="sourceLineNo">1940</span>    if (this.healthCheckChore != null) choreService.scheduleChore(healthCheckChore);<a name="line.1940"></a>
-<span class="sourceLineNo">1941</span>    if (this.nonceManagerChore != null) choreService.scheduleChore(nonceManagerChore);<a name="line.1941"></a>
-<span class="sourceLineNo">1942</span>    if (this.storefileRefresher != null) choreService.scheduleChore(storefileRefresher);<a name="line.1942"></a>
-<span class="sourceLineNo">1943</span>    if (this.movedRegionsCleaner != null) choreService.scheduleChore(movedRegionsCleaner);<a name="line.1943"></a>
-<span class="sourceLineNo">1944</span>    if (this.fsUtilizationChore != null) choreService.scheduleChore(fsUtilizationChore);<a name="line.1944"></a>
-<span class="sourceLineNo">1945</span><a name="line.1945"></a>
-<span class="sourceLineNo">1946</span>    // Leases is not a Thread. Internally it runs a daemon thread. If it gets<a name="line.1946"></a>
-<span class="sourceLineNo">1947</span>    // an unhandled exception, it will just exit.<a name="line.1947"></a>
-<span class="sourceLineNo">1948</span>    Threads.setDaemonThreadRunning(this.leases.getThread(), getName() + ".leaseChecker",<a name="line.1948"></a>
-<span class="sourceLineNo">1949</span>    uncaughtExceptionHandler);<a name="line.1949"></a>
-<span class="sourceLineNo">1950</span><a name="line.1950"></a>
-<span class="sourceLineNo">1951</span>    // Create the log splitting worker and start it<a name="line.1951"></a>
-<span class="sourceLineNo">1952</span>    // set a smaller retries to fast fail otherwise splitlogworker could be blocked for<a name="line.1952"></a>
-<span class="sourceLineNo">1953</span>    // quite a while inside Connection layer. The worker won't be available for other<a name="line.1953"></a>
-<span class="sourceLineNo">1954</span>    // tasks even after current task is preempted after a split task times out.<a name="line.1954"></a>
-<span class="sourceLineNo">1955</span>    Configuration sinkConf = HBaseConfiguration.create(conf);<a name="line.1955"></a>
-<span class="sourceLineNo">1956</span>    sinkConf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,<a name="line.1956"></a>
-<span class="sourceLineNo">1957</span>        conf.getInt("hbase.log.replay.retries.number", 8)); // 8 retries take about 23 seconds<a name="line.1957"></a>
-<span class="sourceLineNo">1958</span>    sinkConf.setInt(HConstants.HBASE_RPC_TIMEOUT_KEY,<a name="line.1958"></a>
-<span class="sourceLineNo">1959</span>        conf.getInt("hbase.log.replay.rpc.timeout", 30000)); // default 30 seconds<a name="line.1959"></a>
-<span class="sourceLineNo">1960</span>    sinkConf.setInt(HConstants.HBASE_CLIENT_SERVERSIDE_RETRIES_MULTIPLIER, 1);<a name="line.1960"></a>
-<span class="sourceLineNo">1961</span>    if (this.csm != null) {<a name="line.1961"></a>
-<span class="sourceLineNo">1962</span>      // SplitLogWorker needs csm. If none, don't start this.<a name="line.1962"></a>
-<span class="sourceLineNo">1963</span>      this.splitLogWorker = new SplitLogWorker(this, sinkConf, this,<a name="line.1963"></a>
-<span class="sourceLineNo">1964</span>          this, walFactory);<a name="line.1964"></a>
-<span class="sourceLineNo">1965</span>      splitLogWorker.start();<a name="line.1965"></a>
-<span class="sourceLineNo">1966</span>    } else {<a name="line.1966"></a>
-<span class="sourceLineNo">1967</span>      LOG.warn("SplitLogWorker Service NOT started; CoordinatedStateManager is null");<a name="line.1967"></a>
-<span class="sourceLineNo">1968</span>    }<a name="line.1968"></a>
-<span class="sourceLineNo">1969</span><a name="line.1969"></a>
-<span class="sourceLineNo">1970</span>    // Memstore services.<a name="line.1970"></a>
-<span class="sourceLineNo">1971</span>    startHeapMemoryManager();<a name="line.1971"></a>
-<span class="sourceLineNo">1972</span>    // Call it after starting HeapMemoryManager.<a name="line.1972"></a>
-<span class="sourceLineNo">1973</span>    initializeMemStoreChunkCreator();<a name="line.1973"></a>
-<span class="sourceLineNo">1974</span>  }<a name="line.1974"></a>
-<span class="sourceLineNo">1975</span><a name="line.1975"></a>
-<span class="sourceLineNo">1976</span>  private void initializeThreads() throws IOException {<a name="line.1976"></a>
-<span class="sourceLineNo">1977</span>    // Cache flushing thread.<a name="line.1977"></a>
-<span class="sourceLineNo">1978</span>    this.cacheFlusher = new MemStoreFlusher(conf, this);<a name="line.1978"></a>
-<span class="sourceLineNo">1979</span><a name="line.1979"></a>
-<span class="sourceLineNo">1980</span>    // Compaction thread<a name="line.1980"></a>
-<span class="sourceLineNo">1981</span>    this.compactSplitThread = new CompactSplit(this);<a name="line.1981"></a>
-<span class="sourceLineNo">1982</span><a name="line.1982"></a>
-<span class="sourceLineNo">1983</span>    // Background thread to check for compactions; needed if region has not gotten updates<a name="line.1983"></a>
-<span class="sourceLineNo">1984</span>    // in a while. It will take care of not checking too frequently on store-by-store basis.<a name="line.1984"></a>
-<span class="sourceLineNo">1985</span>    this.compactionChecker = new CompactionChecker(this, this.threadWakeFrequency, this);<a name="line.1985"></a>
-<span class="sourceLineNo">1986</span>    this.periodicFlusher = new PeriodicMemStoreFlusher(this.threadWakeFrequency, this);<a name="line.1986"></a>
-<span class="sourceLineNo">1987</span>    this.leases = new Leases(this.threadWakeFrequency);<a name="line.1987"></a>
-<span class="sourceLineNo">1988</span><a name="line.1988"></a>
-<span class="sourceLineNo">1989</span>    // Create the thread to clean the moved regions list<a name="line.1989"></a>
-<span class="sourceLineNo">1990</span>    movedRegionsCleaner = MovedRegionsCleaner.create(this);<a name="line.1990"></a>
-<span class="sourceLineNo">1991</span><a name="line.1991"></a>
-<span class="sourceLineNo">1992</span>    if (this.nonceManager != null) {<a name="line.1992"></a>
-<span class="sourceLineNo">1993</span>      // Create the scheduled chore that cleans up nonces.<a name="line.1993"></a>
-<span class="sourceLineNo">1994</span>      nonceManagerChore = this.nonceManager.createCleanupScheduledChore(this);<a name="line.1994"></a>
-<span class="sourceLineNo">1995</span>    }<a name="line.1995"></a>
-<span class="sourceLineNo">1996</span><a name="line.1996"></a>
-<span class="sourceLineNo">1997</span>    // Setup the Quota Manager<a name="line.1997"></a>
-<span class="sourceLineNo">1998</span>    rsQuotaManager = new RegionServerRpcQuotaManager(this);<a name="line.1998"></a>
-<span class="sourceLineNo">1999</span>    rsSpaceQuotaManager = new RegionServerSpaceQuotaManager(this);<a name="line.1999"></a>
-<span class="sourceLineNo">2000</span><a name="line.2000"></a>
-<span class="sourceLineNo">2001</span>    if (QuotaUtil.isQuotaEnabled(conf)) {<a name="line.2001"></a>
-<span class="sourceLineNo">2002</span>      this.fsUtilizationChore = new FileSystemUtilizationChore(this);<a name="line.2002"></a>
-<span class="sourceLineNo">2003</span>    }<a name="line.2003"></a>
-<span class="sourceLineNo">2004</span><a name="line.2004"></a>
+<span class="sourceLineNo">1855</span><a name="line.1855"></a>
+<span class="sourceLineNo">1856</span>  public MetricsRegionServer getRegionServerMetrics() {<a name="line.1856"></a>
+<span class="sourceLine

<TRUNCATED>

Mime
View raw message