hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [16/20] hbase-site git commit: Published site at .
Date Wed, 31 Jan 2018 15:14:32 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/24918eea/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HStore.StoreFlusherImpl.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HStore.StoreFlusherImpl.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HStore.StoreFlusherImpl.html
index 7a14a30..408bec3 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HStore.StoreFlusherImpl.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HStore.StoreFlusherImpl.html
@@ -1459,1125 +1459,1131 @@
 <span class="sourceLineNo">1451</span>    this.lock.writeLock().lock();<a name="line.1451"></a>
 <span class="sourceLineNo">1452</span>    try {<a name="line.1452"></a>
 <span class="sourceLineNo">1453</span>      this.storeEngine.getStoreFileManager().addCompactionResults(compactedFiles, result);<a name="line.1453"></a>
-<span class="sourceLineNo">1454</span>      filesCompacting.removeAll(compactedFiles); // safe bc: lock.writeLock();<a name="line.1454"></a>
-<span class="sourceLineNo">1455</span>    } finally {<a name="line.1455"></a>
-<span class="sourceLineNo">1456</span>      this.lock.writeLock().unlock();<a name="line.1456"></a>
-<span class="sourceLineNo">1457</span>    }<a name="line.1457"></a>
-<span class="sourceLineNo">1458</span>  }<a name="line.1458"></a>
-<span class="sourceLineNo">1459</span><a name="line.1459"></a>
-<span class="sourceLineNo">1460</span>  /**<a name="line.1460"></a>
-<span class="sourceLineNo">1461</span>   * Log a very elaborate compaction completion message.<a name="line.1461"></a>
-<span class="sourceLineNo">1462</span>   * @param cr Request.<a name="line.1462"></a>
-<span class="sourceLineNo">1463</span>   * @param sfs Resulting files.<a name="line.1463"></a>
-<span class="sourceLineNo">1464</span>   * @param compactionStartTime Start time.<a name="line.1464"></a>
-<span class="sourceLineNo">1465</span>   */<a name="line.1465"></a>
-<span class="sourceLineNo">1466</span>  private void logCompactionEndMessage(<a name="line.1466"></a>
-<span class="sourceLineNo">1467</span>      CompactionRequestImpl cr, List&lt;HStoreFile&gt; sfs, long now, long compactionStartTime) {<a name="line.1467"></a>
-<span class="sourceLineNo">1468</span>    StringBuilder message = new StringBuilder(<a name="line.1468"></a>
-<span class="sourceLineNo">1469</span>      "Completed" + (cr.isMajor() ? " major" : "") + " compaction of "<a name="line.1469"></a>
-<span class="sourceLineNo">1470</span>      + cr.getFiles().size() + (cr.isAllFiles() ? " (all)" : "") + " file(s) in "<a name="line.1470"></a>
-<span class="sourceLineNo">1471</span>      + this + " of " + this.getRegionInfo().getShortNameToLog() + " into ");<a name="line.1471"></a>
-<span class="sourceLineNo">1472</span>    if (sfs.isEmpty()) {<a name="line.1472"></a>
-<span class="sourceLineNo">1473</span>      message.append("none, ");<a name="line.1473"></a>
-<span class="sourceLineNo">1474</span>    } else {<a name="line.1474"></a>
-<span class="sourceLineNo">1475</span>      for (HStoreFile sf: sfs) {<a name="line.1475"></a>
-<span class="sourceLineNo">1476</span>        message.append(sf.getPath().getName());<a name="line.1476"></a>
-<span class="sourceLineNo">1477</span>        message.append("(size=");<a name="line.1477"></a>
-<span class="sourceLineNo">1478</span>        message.append(TraditionalBinaryPrefix.long2String(sf.getReader().length(), "", 1));<a name="line.1478"></a>
-<span class="sourceLineNo">1479</span>        message.append("), ");<a name="line.1479"></a>
-<span class="sourceLineNo">1480</span>      }<a name="line.1480"></a>
-<span class="sourceLineNo">1481</span>    }<a name="line.1481"></a>
-<span class="sourceLineNo">1482</span>    message.append("total size for store is ")<a name="line.1482"></a>
-<span class="sourceLineNo">1483</span>      .append(StringUtils.TraditionalBinaryPrefix.long2String(storeSize.get(), "", 1))<a name="line.1483"></a>
-<span class="sourceLineNo">1484</span>      .append(". This selection was in queue for ")<a name="line.1484"></a>
-<span class="sourceLineNo">1485</span>      .append(StringUtils.formatTimeDiff(compactionStartTime, cr.getSelectionTime()))<a name="line.1485"></a>
-<span class="sourceLineNo">1486</span>      .append(", and took ").append(StringUtils.formatTimeDiff(now, compactionStartTime))<a name="line.1486"></a>
-<span class="sourceLineNo">1487</span>      .append(" to execute.");<a name="line.1487"></a>
-<span class="sourceLineNo">1488</span>    LOG.info(message.toString());<a name="line.1488"></a>
-<span class="sourceLineNo">1489</span>    if (LOG.isTraceEnabled()) {<a name="line.1489"></a>
-<span class="sourceLineNo">1490</span>      int fileCount = storeEngine.getStoreFileManager().getStorefileCount();<a name="line.1490"></a>
-<span class="sourceLineNo">1491</span>      long resultSize = getTotalSize(sfs);<a name="line.1491"></a>
-<span class="sourceLineNo">1492</span>      String traceMessage = "COMPACTION start,end,size out,files in,files out,store size,"<a name="line.1492"></a>
-<span class="sourceLineNo">1493</span>        + "store files [" + compactionStartTime + "," + now + "," + resultSize + ","<a name="line.1493"></a>
-<span class="sourceLineNo">1494</span>          + cr.getFiles().size() + "," + sfs.size() + "," +  storeSize + "," + fileCount + "]";<a name="line.1494"></a>
-<span class="sourceLineNo">1495</span>      LOG.trace(traceMessage);<a name="line.1495"></a>
-<span class="sourceLineNo">1496</span>    }<a name="line.1496"></a>
-<span class="sourceLineNo">1497</span>  }<a name="line.1497"></a>
-<span class="sourceLineNo">1498</span><a name="line.1498"></a>
-<span class="sourceLineNo">1499</span>  /**<a name="line.1499"></a>
-<span class="sourceLineNo">1500</span>   * Call to complete a compaction. Its for the case where we find in the WAL a compaction<a name="line.1500"></a>
-<span class="sourceLineNo">1501</span>   * that was not finished.  We could find one recovering a WAL after a regionserver crash.<a name="line.1501"></a>
-<span class="sourceLineNo">1502</span>   * See HBASE-2231.<a name="line.1502"></a>
-<span class="sourceLineNo">1503</span>   * @param compaction<a name="line.1503"></a>
-<span class="sourceLineNo">1504</span>   */<a name="line.1504"></a>
-<span class="sourceLineNo">1505</span>  public void replayCompactionMarker(CompactionDescriptor compaction, boolean pickCompactionFiles,<a name="line.1505"></a>
-<span class="sourceLineNo">1506</span>      boolean removeFiles) throws IOException {<a name="line.1506"></a>
-<span class="sourceLineNo">1507</span>    LOG.debug("Completing compaction from the WAL marker");<a name="line.1507"></a>
-<span class="sourceLineNo">1508</span>    List&lt;String&gt; compactionInputs = compaction.getCompactionInputList();<a name="line.1508"></a>
-<span class="sourceLineNo">1509</span>    List&lt;String&gt; compactionOutputs = Lists.newArrayList(compaction.getCompactionOutputList());<a name="line.1509"></a>
-<span class="sourceLineNo">1510</span><a name="line.1510"></a>
-<span class="sourceLineNo">1511</span>    // The Compaction Marker is written after the compaction is completed,<a name="line.1511"></a>
-<span class="sourceLineNo">1512</span>    // and the files moved into the region/family folder.<a name="line.1512"></a>
-<span class="sourceLineNo">1513</span>    //<a name="line.1513"></a>
-<span class="sourceLineNo">1514</span>    // If we crash after the entry is written, we may not have removed the<a name="line.1514"></a>
-<span class="sourceLineNo">1515</span>    // input files, but the output file is present.<a name="line.1515"></a>
-<span class="sourceLineNo">1516</span>    // (The unremoved input files will be removed by this function)<a name="line.1516"></a>
-<span class="sourceLineNo">1517</span>    //<a name="line.1517"></a>
-<span class="sourceLineNo">1518</span>    // If we scan the directory and the file is not present, it can mean that:<a name="line.1518"></a>
-<span class="sourceLineNo">1519</span>    //   - The file was manually removed by the user<a name="line.1519"></a>
-<span class="sourceLineNo">1520</span>    //   - The file was removed as consequence of subsequent compaction<a name="line.1520"></a>
-<span class="sourceLineNo">1521</span>    // so, we can't do anything with the "compaction output list" because those<a name="line.1521"></a>
-<span class="sourceLineNo">1522</span>    // files have already been loaded when opening the region (by virtue of<a name="line.1522"></a>
-<span class="sourceLineNo">1523</span>    // being in the store's folder) or they may be missing due to a compaction.<a name="line.1523"></a>
-<span class="sourceLineNo">1524</span><a name="line.1524"></a>
-<span class="sourceLineNo">1525</span>    String familyName = this.getColumnFamilyName();<a name="line.1525"></a>
-<span class="sourceLineNo">1526</span>    Set&lt;String&gt; inputFiles = new HashSet&lt;&gt;();<a name="line.1526"></a>
-<span class="sourceLineNo">1527</span>    for (String compactionInput : compactionInputs) {<a name="line.1527"></a>
-<span class="sourceLineNo">1528</span>      Path inputPath = fs.getStoreFilePath(familyName, compactionInput);<a name="line.1528"></a>
-<span class="sourceLineNo">1529</span>      inputFiles.add(inputPath.getName());<a name="line.1529"></a>
-<span class="sourceLineNo">1530</span>    }<a name="line.1530"></a>
-<span class="sourceLineNo">1531</span><a name="line.1531"></a>
-<span class="sourceLineNo">1532</span>    //some of the input files might already be deleted<a name="line.1532"></a>
-<span class="sourceLineNo">1533</span>    List&lt;HStoreFile&gt; inputStoreFiles = new ArrayList&lt;&gt;(compactionInputs.size());<a name="line.1533"></a>
-<span class="sourceLineNo">1534</span>    for (HStoreFile sf : this.getStorefiles()) {<a name="line.1534"></a>
-<span class="sourceLineNo">1535</span>      if (inputFiles.contains(sf.getPath().getName())) {<a name="line.1535"></a>
-<span class="sourceLineNo">1536</span>        inputStoreFiles.add(sf);<a name="line.1536"></a>
-<span class="sourceLineNo">1537</span>      }<a name="line.1537"></a>
-<span class="sourceLineNo">1538</span>    }<a name="line.1538"></a>
-<span class="sourceLineNo">1539</span><a name="line.1539"></a>
-<span class="sourceLineNo">1540</span>    // check whether we need to pick up the new files<a name="line.1540"></a>
-<span class="sourceLineNo">1541</span>    List&lt;HStoreFile&gt; outputStoreFiles = new ArrayList&lt;&gt;(compactionOutputs.size());<a name="line.1541"></a>
-<span class="sourceLineNo">1542</span><a name="line.1542"></a>
-<span class="sourceLineNo">1543</span>    if (pickCompactionFiles) {<a name="line.1543"></a>
-<span class="sourceLineNo">1544</span>      for (HStoreFile sf : this.getStorefiles()) {<a name="line.1544"></a>
-<span class="sourceLineNo">1545</span>        compactionOutputs.remove(sf.getPath().getName());<a name="line.1545"></a>
-<span class="sourceLineNo">1546</span>      }<a name="line.1546"></a>
-<span class="sourceLineNo">1547</span>      for (String compactionOutput : compactionOutputs) {<a name="line.1547"></a>
-<span class="sourceLineNo">1548</span>        StoreFileInfo storeFileInfo = fs.getStoreFileInfo(getColumnFamilyName(), compactionOutput);<a name="line.1548"></a>
-<span class="sourceLineNo">1549</span>        HStoreFile storeFile = createStoreFileAndReader(storeFileInfo);<a name="line.1549"></a>
-<span class="sourceLineNo">1550</span>        outputStoreFiles.add(storeFile);<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>    if (!inputStoreFiles.isEmpty() || !outputStoreFiles.isEmpty()) {<a name="line.1554"></a>
-<span class="sourceLineNo">1555</span>      LOG.info("Replaying compaction marker, replacing input files: " +<a name="line.1555"></a>
-<span class="sourceLineNo">1556</span>          inputStoreFiles + " with output files : " + outputStoreFiles);<a name="line.1556"></a>
-<span class="sourceLineNo">1557</span>      this.replaceStoreFiles(inputStoreFiles, outputStoreFiles);<a name="line.1557"></a>
-<span class="sourceLineNo">1558</span>      this.completeCompaction(inputStoreFiles);<a name="line.1558"></a>
-<span class="sourceLineNo">1559</span>    }<a name="line.1559"></a>
-<span class="sourceLineNo">1560</span>  }<a name="line.1560"></a>
-<span class="sourceLineNo">1561</span><a name="line.1561"></a>
-<span class="sourceLineNo">1562</span>  /**<a name="line.1562"></a>
-<span class="sourceLineNo">1563</span>   * This method tries to compact N recent files for testing.<a name="line.1563"></a>
-<span class="sourceLineNo">1564</span>   * Note that because compacting "recent" files only makes sense for some policies,<a name="line.1564"></a>
-<span class="sourceLineNo">1565</span>   * e.g. the default one, it assumes default policy is used. It doesn't use policy,<a name="line.1565"></a>
-<span class="sourceLineNo">1566</span>   * but instead makes a compaction candidate list by itself.<a name="line.1566"></a>
-<span class="sourceLineNo">1567</span>   * @param N Number of files.<a name="line.1567"></a>
-<span class="sourceLineNo">1568</span>   */<a name="line.1568"></a>
-<span class="sourceLineNo">1569</span>  @VisibleForTesting<a name="line.1569"></a>
-<span class="sourceLineNo">1570</span>  public void compactRecentForTestingAssumingDefaultPolicy(int N) throws IOException {<a name="line.1570"></a>
-<span class="sourceLineNo">1571</span>    List&lt;HStoreFile&gt; filesToCompact;<a name="line.1571"></a>
-<span class="sourceLineNo">1572</span>    boolean isMajor;<a name="line.1572"></a>
-<span class="sourceLineNo">1573</span><a name="line.1573"></a>
-<span class="sourceLineNo">1574</span>    this.lock.readLock().lock();<a name="line.1574"></a>
-<span class="sourceLineNo">1575</span>    try {<a name="line.1575"></a>
-<span class="sourceLineNo">1576</span>      synchronized (filesCompacting) {<a name="line.1576"></a>
-<span class="sourceLineNo">1577</span>        filesToCompact = Lists.newArrayList(storeEngine.getStoreFileManager().getStorefiles());<a name="line.1577"></a>
-<span class="sourceLineNo">1578</span>        if (!filesCompacting.isEmpty()) {<a name="line.1578"></a>
-<span class="sourceLineNo">1579</span>          // exclude all files older than the newest file we're currently<a name="line.1579"></a>
-<span class="sourceLineNo">1580</span>          // compacting. this allows us to preserve contiguity (HBASE-2856)<a name="line.1580"></a>
-<span class="sourceLineNo">1581</span>          HStoreFile last = filesCompacting.get(filesCompacting.size() - 1);<a name="line.1581"></a>
-<span class="sourceLineNo">1582</span>          int idx = filesToCompact.indexOf(last);<a name="line.1582"></a>
-<span class="sourceLineNo">1583</span>          Preconditions.checkArgument(idx != -1);<a name="line.1583"></a>
-<span class="sourceLineNo">1584</span>          filesToCompact.subList(0, idx + 1).clear();<a name="line.1584"></a>
-<span class="sourceLineNo">1585</span>        }<a name="line.1585"></a>
-<span class="sourceLineNo">1586</span>        int count = filesToCompact.size();<a name="line.1586"></a>
-<span class="sourceLineNo">1587</span>        if (N &gt; count) {<a name="line.1587"></a>
-<span class="sourceLineNo">1588</span>          throw new RuntimeException("Not enough files");<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>        filesToCompact = filesToCompact.subList(count - N, count);<a name="line.1591"></a>
-<span class="sourceLineNo">1592</span>        isMajor = (filesToCompact.size() == storeEngine.getStoreFileManager().getStorefileCount());<a name="line.1592"></a>
-<span class="sourceLineNo">1593</span>        filesCompacting.addAll(filesToCompact);<a name="line.1593"></a>
-<span class="sourceLineNo">1594</span>        Collections.sort(filesCompacting, storeEngine.getStoreFileManager()<a name="line.1594"></a>
-<span class="sourceLineNo">1595</span>            .getStoreFileComparator());<a name="line.1595"></a>
-<span class="sourceLineNo">1596</span>      }<a name="line.1596"></a>
-<span class="sourceLineNo">1597</span>    } finally {<a name="line.1597"></a>
-<span class="sourceLineNo">1598</span>      this.lock.readLock().unlock();<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>    try {<a name="line.1601"></a>
-<span class="sourceLineNo">1602</span>      // Ready to go. Have list of files to compact.<a name="line.1602"></a>
-<span class="sourceLineNo">1603</span>      List&lt;Path&gt; newFiles = ((DefaultCompactor)this.storeEngine.getCompactor())<a name="line.1603"></a>
-<span class="sourceLineNo">1604</span>          .compactForTesting(filesToCompact, isMajor);<a name="line.1604"></a>
-<span class="sourceLineNo">1605</span>      for (Path newFile: newFiles) {<a name="line.1605"></a>
-<span class="sourceLineNo">1606</span>        // Move the compaction into place.<a name="line.1606"></a>
-<span class="sourceLineNo">1607</span>        HStoreFile sf = moveFileIntoPlace(newFile);<a name="line.1607"></a>
-<span class="sourceLineNo">1608</span>        if (this.getCoprocessorHost() != null) {<a name="line.1608"></a>
-<span class="sourceLineNo">1609</span>          this.getCoprocessorHost().postCompact(this, sf, null, null, null);<a name="line.1609"></a>
-<span class="sourceLineNo">1610</span>        }<a name="line.1610"></a>
-<span class="sourceLineNo">1611</span>        replaceStoreFiles(filesToCompact, Collections.singletonList(sf));<a name="line.1611"></a>
-<span class="sourceLineNo">1612</span>        completeCompaction(filesToCompact);<a name="line.1612"></a>
-<span class="sourceLineNo">1613</span>      }<a name="line.1613"></a>
-<span class="sourceLineNo">1614</span>    } finally {<a name="line.1614"></a>
-<span class="sourceLineNo">1615</span>      synchronized (filesCompacting) {<a name="line.1615"></a>
-<span class="sourceLineNo">1616</span>        filesCompacting.removeAll(filesToCompact);<a name="line.1616"></a>
-<span class="sourceLineNo">1617</span>      }<a name="line.1617"></a>
-<span class="sourceLineNo">1618</span>    }<a name="line.1618"></a>
-<span class="sourceLineNo">1619</span>  }<a name="line.1619"></a>
-<span class="sourceLineNo">1620</span><a name="line.1620"></a>
-<span class="sourceLineNo">1621</span>  @Override<a name="line.1621"></a>
-<span class="sourceLineNo">1622</span>  public boolean hasReferences() {<a name="line.1622"></a>
-<span class="sourceLineNo">1623</span>    return StoreUtils.hasReferences(this.storeEngine.getStoreFileManager().getStorefiles());<a name="line.1623"></a>
-<span class="sourceLineNo">1624</span>  }<a name="line.1624"></a>
-<span class="sourceLineNo">1625</span><a name="line.1625"></a>
-<span class="sourceLineNo">1626</span>  /**<a name="line.1626"></a>
-<span class="sourceLineNo">1627</span>   * getter for CompactionProgress object<a name="line.1627"></a>
-<span class="sourceLineNo">1628</span>   * @return CompactionProgress object; can be null<a name="line.1628"></a>
-<span class="sourceLineNo">1629</span>   */<a name="line.1629"></a>
-<span class="sourceLineNo">1630</span>  public CompactionProgress getCompactionProgress() {<a name="line.1630"></a>
-<span class="sourceLineNo">1631</span>    return this.storeEngine.getCompactor().getProgress();<a name="line.1631"></a>
-<span class="sourceLineNo">1632</span>  }<a name="line.1632"></a>
-<span class="sourceLineNo">1633</span><a name="line.1633"></a>
-<span class="sourceLineNo">1634</span>  @Override<a name="line.1634"></a>
-<span class="sourceLineNo">1635</span>  public boolean shouldPerformMajorCompaction() throws IOException {<a name="line.1635"></a>
-<span class="sourceLineNo">1636</span>    for (HStoreFile sf : this.storeEngine.getStoreFileManager().getStorefiles()) {<a name="line.1636"></a>
-<span class="sourceLineNo">1637</span>      // TODO: what are these reader checks all over the place?<a name="line.1637"></a>
-<span class="sourceLineNo">1638</span>      if (sf.getReader() == null) {<a name="line.1638"></a>
-<span class="sourceLineNo">1639</span>        LOG.debug("StoreFile {} has null Reader", sf);<a name="line.1639"></a>
-<span class="sourceLineNo">1640</span>        return false;<a name="line.1640"></a>
-<span class="sourceLineNo">1641</span>      }<a name="line.1641"></a>
-<span class="sourceLineNo">1642</span>    }<a name="line.1642"></a>
-<span class="sourceLineNo">1643</span>    return storeEngine.getCompactionPolicy().shouldPerformMajorCompaction(<a name="line.1643"></a>
-<span class="sourceLineNo">1644</span>        this.storeEngine.getStoreFileManager().getStorefiles());<a name="line.1644"></a>
-<span class="sourceLineNo">1645</span>  }<a name="line.1645"></a>
-<span class="sourceLineNo">1646</span><a name="line.1646"></a>
-<span class="sourceLineNo">1647</span>  public Optional&lt;CompactionContext&gt; requestCompaction() throws IOException {<a name="line.1647"></a>
-<span class="sourceLineNo">1648</span>    return requestCompaction(NO_PRIORITY, CompactionLifeCycleTracker.DUMMY, null);<a name="line.1648"></a>
-<span class="sourceLineNo">1649</span>  }<a name="line.1649"></a>
-<span class="sourceLineNo">1650</span><a name="line.1650"></a>
-<span class="sourceLineNo">1651</span>  public Optional&lt;CompactionContext&gt; requestCompaction(int priority,<a name="line.1651"></a>
-<span class="sourceLineNo">1652</span>      CompactionLifeCycleTracker tracker, User user) throws IOException {<a name="line.1652"></a>
-<span class="sourceLineNo">1653</span>    // don't even select for compaction if writes are disabled<a name="line.1653"></a>
-<span class="sourceLineNo">1654</span>    if (!this.areWritesEnabled()) {<a name="line.1654"></a>
-<span class="sourceLineNo">1655</span>      return Optional.empty();<a name="line.1655"></a>
-<span class="sourceLineNo">1656</span>    }<a name="line.1656"></a>
-<span class="sourceLineNo">1657</span>    // Before we do compaction, try to get rid of unneeded files to simplify things.<a name="line.1657"></a>
-<span class="sourceLineNo">1658</span>    removeUnneededFiles();<a name="line.1658"></a>
-<span class="sourceLineNo">1659</span><a name="line.1659"></a>
-<span class="sourceLineNo">1660</span>    final CompactionContext compaction = storeEngine.createCompaction();<a name="line.1660"></a>
-<span class="sourceLineNo">1661</span>    CompactionRequestImpl request = null;<a name="line.1661"></a>
-<span class="sourceLineNo">1662</span>    this.lock.readLock().lock();<a name="line.1662"></a>
-<span class="sourceLineNo">1663</span>    try {<a name="line.1663"></a>
-<span class="sourceLineNo">1664</span>      synchronized (filesCompacting) {<a name="line.1664"></a>
-<span class="sourceLineNo">1665</span>        // First, see if coprocessor would want to override selection.<a name="line.1665"></a>
-<span class="sourceLineNo">1666</span>        if (this.getCoprocessorHost() != null) {<a name="line.1666"></a>
-<span class="sourceLineNo">1667</span>          final List&lt;HStoreFile&gt; candidatesForCoproc = compaction.preSelect(this.filesCompacting);<a name="line.1667"></a>
-<span class="sourceLineNo">1668</span>          boolean override = getCoprocessorHost().preCompactSelection(this,<a name="line.1668"></a>
-<span class="sourceLineNo">1669</span>              candidatesForCoproc, tracker, user);<a name="line.1669"></a>
-<span class="sourceLineNo">1670</span>          if (override) {<a name="line.1670"></a>
-<span class="sourceLineNo">1671</span>            // Coprocessor is overriding normal file selection.<a name="line.1671"></a>
-<span class="sourceLineNo">1672</span>            compaction.forceSelect(new CompactionRequestImpl(candidatesForCoproc));<a name="line.1672"></a>
-<span class="sourceLineNo">1673</span>          }<a name="line.1673"></a>
-<span class="sourceLineNo">1674</span>        }<a name="line.1674"></a>
-<span class="sourceLineNo">1675</span><a name="line.1675"></a>
-<span class="sourceLineNo">1676</span>        // Normal case - coprocessor is not overriding file selection.<a name="line.1676"></a>
-<span class="sourceLineNo">1677</span>        if (!compaction.hasSelection()) {<a name="line.1677"></a>
-<span class="sourceLineNo">1678</span>          boolean isUserCompaction = priority == Store.PRIORITY_USER;<a name="line.1678"></a>
-<span class="sourceLineNo">1679</span>          boolean mayUseOffPeak = offPeakHours.isOffPeakHour() &amp;&amp;<a name="line.1679"></a>
-<span class="sourceLineNo">1680</span>              offPeakCompactionTracker.compareAndSet(false, true);<a name="line.1680"></a>
-<span class="sourceLineNo">1681</span>          try {<a name="line.1681"></a>
-<span class="sourceLineNo">1682</span>            compaction.select(this.filesCompacting, isUserCompaction,<a name="line.1682"></a>
-<span class="sourceLineNo">1683</span>              mayUseOffPeak, forceMajor &amp;&amp; filesCompacting.isEmpty());<a name="line.1683"></a>
-<span class="sourceLineNo">1684</span>          } catch (IOException e) {<a name="line.1684"></a>
-<span class="sourceLineNo">1685</span>            if (mayUseOffPeak) {<a name="line.1685"></a>
-<span class="sourceLineNo">1686</span>              offPeakCompactionTracker.set(false);<a name="line.1686"></a>
-<span class="sourceLineNo">1687</span>            }<a name="line.1687"></a>
-<span class="sourceLineNo">1688</span>            throw e;<a name="line.1688"></a>
-<span class="sourceLineNo">1689</span>          }<a name="line.1689"></a>
-<span class="sourceLineNo">1690</span>          assert compaction.hasSelection();<a name="line.1690"></a>
-<span class="sourceLineNo">1691</span>          if (mayUseOffPeak &amp;&amp; !compaction.getRequest().isOffPeak()) {<a name="line.1691"></a>
-<span class="sourceLineNo">1692</span>            // Compaction policy doesn't want to take advantage of off-peak.<a name="line.1692"></a>
-<span class="sourceLineNo">1693</span>            offPeakCompactionTracker.set(false);<a name="line.1693"></a>
-<span class="sourceLineNo">1694</span>          }<a name="line.1694"></a>
-<span class="sourceLineNo">1695</span>        }<a name="line.1695"></a>
-<span class="sourceLineNo">1696</span>        if (this.getCoprocessorHost() != null) {<a name="line.1696"></a>
-<span class="sourceLineNo">1697</span>          this.getCoprocessorHost().postCompactSelection(<a name="line.1697"></a>
-<span class="sourceLineNo">1698</span>              this, ImmutableList.copyOf(compaction.getRequest().getFiles()), tracker,<a name="line.1698"></a>
-<span class="sourceLineNo">1699</span>              compaction.getRequest(), user);<a name="line.1699"></a>
-<span class="sourceLineNo">1700</span>        }<a name="line.1700"></a>
-<span class="sourceLineNo">1701</span>        // Finally, we have the resulting files list. Check if we have any files at all.<a name="line.1701"></a>
-<span class="sourceLineNo">1702</span>        request = compaction.getRequest();<a name="line.1702"></a>
-<span class="sourceLineNo">1703</span>        Collection&lt;HStoreFile&gt; selectedFiles = request.getFiles();<a name="line.1703"></a>
-<span class="sourceLineNo">1704</span>        if (selectedFiles.isEmpty()) {<a name="line.1704"></a>
-<span class="sourceLineNo">1705</span>          return Optional.empty();<a name="line.1705"></a>
-<span class="sourceLineNo">1706</span>        }<a name="line.1706"></a>
-<span class="sourceLineNo">1707</span><a name="line.1707"></a>
-<span class="sourceLineNo">1708</span>        addToCompactingFiles(selectedFiles);<a name="line.1708"></a>
+<span class="sourceLineNo">1454</span>      synchronized (filesCompacting) {<a name="line.1454"></a>
+<span class="sourceLineNo">1455</span>        filesCompacting.removeAll(compactedFiles);<a name="line.1455"></a>
+<span class="sourceLineNo">1456</span>      }<a name="line.1456"></a>
+<span class="sourceLineNo">1457</span>    } finally {<a name="line.1457"></a>
+<span class="sourceLineNo">1458</span>      this.lock.writeLock().unlock();<a name="line.1458"></a>
+<span class="sourceLineNo">1459</span>    }<a name="line.1459"></a>
+<span class="sourceLineNo">1460</span>  }<a name="line.1460"></a>
+<span class="sourceLineNo">1461</span><a name="line.1461"></a>
+<span class="sourceLineNo">1462</span>  /**<a name="line.1462"></a>
+<span class="sourceLineNo">1463</span>   * Log a very elaborate compaction completion message.<a name="line.1463"></a>
+<span class="sourceLineNo">1464</span>   * @param cr Request.<a name="line.1464"></a>
+<span class="sourceLineNo">1465</span>   * @param sfs Resulting files.<a name="line.1465"></a>
+<span class="sourceLineNo">1466</span>   * @param compactionStartTime Start time.<a name="line.1466"></a>
+<span class="sourceLineNo">1467</span>   */<a name="line.1467"></a>
+<span class="sourceLineNo">1468</span>  private void logCompactionEndMessage(<a name="line.1468"></a>
+<span class="sourceLineNo">1469</span>      CompactionRequestImpl cr, List&lt;HStoreFile&gt; sfs, long now, long compactionStartTime) {<a name="line.1469"></a>
+<span class="sourceLineNo">1470</span>    StringBuilder message = new StringBuilder(<a name="line.1470"></a>
+<span class="sourceLineNo">1471</span>      "Completed" + (cr.isMajor() ? " major" : "") + " compaction of "<a name="line.1471"></a>
+<span class="sourceLineNo">1472</span>      + cr.getFiles().size() + (cr.isAllFiles() ? " (all)" : "") + " file(s) in "<a name="line.1472"></a>
+<span class="sourceLineNo">1473</span>      + this + " of " + this.getRegionInfo().getShortNameToLog() + " into ");<a name="line.1473"></a>
+<span class="sourceLineNo">1474</span>    if (sfs.isEmpty()) {<a name="line.1474"></a>
+<span class="sourceLineNo">1475</span>      message.append("none, ");<a name="line.1475"></a>
+<span class="sourceLineNo">1476</span>    } else {<a name="line.1476"></a>
+<span class="sourceLineNo">1477</span>      for (HStoreFile sf: sfs) {<a name="line.1477"></a>
+<span class="sourceLineNo">1478</span>        message.append(sf.getPath().getName());<a name="line.1478"></a>
+<span class="sourceLineNo">1479</span>        message.append("(size=");<a name="line.1479"></a>
+<span class="sourceLineNo">1480</span>        message.append(TraditionalBinaryPrefix.long2String(sf.getReader().length(), "", 1));<a name="line.1480"></a>
+<span class="sourceLineNo">1481</span>        message.append("), ");<a name="line.1481"></a>
+<span class="sourceLineNo">1482</span>      }<a name="line.1482"></a>
+<span class="sourceLineNo">1483</span>    }<a name="line.1483"></a>
+<span class="sourceLineNo">1484</span>    message.append("total size for store is ")<a name="line.1484"></a>
+<span class="sourceLineNo">1485</span>      .append(StringUtils.TraditionalBinaryPrefix.long2String(storeSize.get(), "", 1))<a name="line.1485"></a>
+<span class="sourceLineNo">1486</span>      .append(". This selection was in queue for ")<a name="line.1486"></a>
+<span class="sourceLineNo">1487</span>      .append(StringUtils.formatTimeDiff(compactionStartTime, cr.getSelectionTime()))<a name="line.1487"></a>
+<span class="sourceLineNo">1488</span>      .append(", and took ").append(StringUtils.formatTimeDiff(now, compactionStartTime))<a name="line.1488"></a>
+<span class="sourceLineNo">1489</span>      .append(" to execute.");<a name="line.1489"></a>
+<span class="sourceLineNo">1490</span>    LOG.info(message.toString());<a name="line.1490"></a>
+<span class="sourceLineNo">1491</span>    if (LOG.isTraceEnabled()) {<a name="line.1491"></a>
+<span class="sourceLineNo">1492</span>      int fileCount = storeEngine.getStoreFileManager().getStorefileCount();<a name="line.1492"></a>
+<span class="sourceLineNo">1493</span>      long resultSize = getTotalSize(sfs);<a name="line.1493"></a>
+<span class="sourceLineNo">1494</span>      String traceMessage = "COMPACTION start,end,size out,files in,files out,store size,"<a name="line.1494"></a>
+<span class="sourceLineNo">1495</span>        + "store files [" + compactionStartTime + "," + now + "," + resultSize + ","<a name="line.1495"></a>
+<span class="sourceLineNo">1496</span>          + cr.getFiles().size() + "," + sfs.size() + "," +  storeSize + "," + fileCount + "]";<a name="line.1496"></a>
+<span class="sourceLineNo">1497</span>      LOG.trace(traceMessage);<a name="line.1497"></a>
+<span class="sourceLineNo">1498</span>    }<a name="line.1498"></a>
+<span class="sourceLineNo">1499</span>  }<a name="line.1499"></a>
+<span class="sourceLineNo">1500</span><a name="line.1500"></a>
+<span class="sourceLineNo">1501</span>  /**<a name="line.1501"></a>
+<span class="sourceLineNo">1502</span>   * Call to complete a compaction. Its for the case where we find in the WAL a compaction<a name="line.1502"></a>
+<span class="sourceLineNo">1503</span>   * that was not finished.  We could find one recovering a WAL after a regionserver crash.<a name="line.1503"></a>
+<span class="sourceLineNo">1504</span>   * See HBASE-2231.<a name="line.1504"></a>
+<span class="sourceLineNo">1505</span>   * @param compaction<a name="line.1505"></a>
+<span class="sourceLineNo">1506</span>   */<a name="line.1506"></a>
+<span class="sourceLineNo">1507</span>  public void replayCompactionMarker(CompactionDescriptor compaction, boolean pickCompactionFiles,<a name="line.1507"></a>
+<span class="sourceLineNo">1508</span>      boolean removeFiles) throws IOException {<a name="line.1508"></a>
+<span class="sourceLineNo">1509</span>    LOG.debug("Completing compaction from the WAL marker");<a name="line.1509"></a>
+<span class="sourceLineNo">1510</span>    List&lt;String&gt; compactionInputs = compaction.getCompactionInputList();<a name="line.1510"></a>
+<span class="sourceLineNo">1511</span>    List&lt;String&gt; compactionOutputs = Lists.newArrayList(compaction.getCompactionOutputList());<a name="line.1511"></a>
+<span class="sourceLineNo">1512</span><a name="line.1512"></a>
+<span class="sourceLineNo">1513</span>    // The Compaction Marker is written after the compaction is completed,<a name="line.1513"></a>
+<span class="sourceLineNo">1514</span>    // and the files moved into the region/family folder.<a name="line.1514"></a>
+<span class="sourceLineNo">1515</span>    //<a name="line.1515"></a>
+<span class="sourceLineNo">1516</span>    // If we crash after the entry is written, we may not have removed the<a name="line.1516"></a>
+<span class="sourceLineNo">1517</span>    // input files, but the output file is present.<a name="line.1517"></a>
+<span class="sourceLineNo">1518</span>    // (The unremoved input files will be removed by this function)<a name="line.1518"></a>
+<span class="sourceLineNo">1519</span>    //<a name="line.1519"></a>
+<span class="sourceLineNo">1520</span>    // If we scan the directory and the file is not present, it can mean that:<a name="line.1520"></a>
+<span class="sourceLineNo">1521</span>    //   - The file was manually removed by the user<a name="line.1521"></a>
+<span class="sourceLineNo">1522</span>    //   - The file was removed as consequence of subsequent compaction<a name="line.1522"></a>
+<span class="sourceLineNo">1523</span>    // so, we can't do anything with the "compaction output list" because those<a name="line.1523"></a>
+<span class="sourceLineNo">1524</span>    // files have already been loaded when opening the region (by virtue of<a name="line.1524"></a>
+<span class="sourceLineNo">1525</span>    // being in the store's folder) or they may be missing due to a compaction.<a name="line.1525"></a>
+<span class="sourceLineNo">1526</span><a name="line.1526"></a>
+<span class="sourceLineNo">1527</span>    String familyName = this.getColumnFamilyName();<a name="line.1527"></a>
+<span class="sourceLineNo">1528</span>    Set&lt;String&gt; inputFiles = new HashSet&lt;&gt;();<a name="line.1528"></a>
+<span class="sourceLineNo">1529</span>    for (String compactionInput : compactionInputs) {<a name="line.1529"></a>
+<span class="sourceLineNo">1530</span>      Path inputPath = fs.getStoreFilePath(familyName, compactionInput);<a name="line.1530"></a>
+<span class="sourceLineNo">1531</span>      inputFiles.add(inputPath.getName());<a name="line.1531"></a>
+<span class="sourceLineNo">1532</span>    }<a name="line.1532"></a>
+<span class="sourceLineNo">1533</span><a name="line.1533"></a>
+<span class="sourceLineNo">1534</span>    //some of the input files might already be deleted<a name="line.1534"></a>
+<span class="sourceLineNo">1535</span>    List&lt;HStoreFile&gt; inputStoreFiles = new ArrayList&lt;&gt;(compactionInputs.size());<a name="line.1535"></a>
+<span class="sourceLineNo">1536</span>    for (HStoreFile sf : this.getStorefiles()) {<a name="line.1536"></a>
+<span class="sourceLineNo">1537</span>      if (inputFiles.contains(sf.getPath().getName())) {<a name="line.1537"></a>
+<span class="sourceLineNo">1538</span>        inputStoreFiles.add(sf);<a name="line.1538"></a>
+<span class="sourceLineNo">1539</span>      }<a name="line.1539"></a>
+<span class="sourceLineNo">1540</span>    }<a name="line.1540"></a>
+<span class="sourceLineNo">1541</span><a name="line.1541"></a>
+<span class="sourceLineNo">1542</span>    // check whether we need to pick up the new files<a name="line.1542"></a>
+<span class="sourceLineNo">1543</span>    List&lt;HStoreFile&gt; outputStoreFiles = new ArrayList&lt;&gt;(compactionOutputs.size());<a name="line.1543"></a>
+<span class="sourceLineNo">1544</span><a name="line.1544"></a>
+<span class="sourceLineNo">1545</span>    if (pickCompactionFiles) {<a name="line.1545"></a>
+<span class="sourceLineNo">1546</span>      for (HStoreFile sf : this.getStorefiles()) {<a name="line.1546"></a>
+<span class="sourceLineNo">1547</span>        compactionOutputs.remove(sf.getPath().getName());<a name="line.1547"></a>
+<span class="sourceLineNo">1548</span>      }<a name="line.1548"></a>
+<span class="sourceLineNo">1549</span>      for (String compactionOutput : compactionOutputs) {<a name="line.1549"></a>
+<span class="sourceLineNo">1550</span>        StoreFileInfo storeFileInfo = fs.getStoreFileInfo(getColumnFamilyName(), compactionOutput);<a name="line.1550"></a>
+<span class="sourceLineNo">1551</span>        HStoreFile storeFile = createStoreFileAndReader(storeFileInfo);<a name="line.1551"></a>
+<span class="sourceLineNo">1552</span>        outputStoreFiles.add(storeFile);<a name="line.1552"></a>
+<span class="sourceLineNo">1553</span>      }<a name="line.1553"></a>
+<span class="sourceLineNo">1554</span>    }<a name="line.1554"></a>
+<span class="sourceLineNo">1555</span><a name="line.1555"></a>
+<span class="sourceLineNo">1556</span>    if (!inputStoreFiles.isEmpty() || !outputStoreFiles.isEmpty()) {<a name="line.1556"></a>
+<span class="sourceLineNo">1557</span>      LOG.info("Replaying compaction marker, replacing input files: " +<a name="line.1557"></a>
+<span class="sourceLineNo">1558</span>          inputStoreFiles + " with output files : " + outputStoreFiles);<a name="line.1558"></a>
+<span class="sourceLineNo">1559</span>      this.replaceStoreFiles(inputStoreFiles, outputStoreFiles);<a name="line.1559"></a>
+<span class="sourceLineNo">1560</span>      this.completeCompaction(inputStoreFiles);<a name="line.1560"></a>
+<span class="sourceLineNo">1561</span>    }<a name="line.1561"></a>
+<span class="sourceLineNo">1562</span>  }<a name="line.1562"></a>
+<span class="sourceLineNo">1563</span><a name="line.1563"></a>
+<span class="sourceLineNo">1564</span>  /**<a name="line.1564"></a>
+<span class="sourceLineNo">1565</span>   * This method tries to compact N recent files for testing.<a name="line.1565"></a>
+<span class="sourceLineNo">1566</span>   * Note that because compacting "recent" files only makes sense for some policies,<a name="line.1566"></a>
+<span class="sourceLineNo">1567</span>   * e.g. the default one, it assumes default policy is used. It doesn't use policy,<a name="line.1567"></a>
+<span class="sourceLineNo">1568</span>   * but instead makes a compaction candidate list by itself.<a name="line.1568"></a>
+<span class="sourceLineNo">1569</span>   * @param N Number of files.<a name="line.1569"></a>
+<span class="sourceLineNo">1570</span>   */<a name="line.1570"></a>
+<span class="sourceLineNo">1571</span>  @VisibleForTesting<a name="line.1571"></a>
+<span class="sourceLineNo">1572</span>  public void compactRecentForTestingAssumingDefaultPolicy(int N) throws IOException {<a name="line.1572"></a>
+<span class="sourceLineNo">1573</span>    List&lt;HStoreFile&gt; filesToCompact;<a name="line.1573"></a>
+<span class="sourceLineNo">1574</span>    boolean isMajor;<a name="line.1574"></a>
+<span class="sourceLineNo">1575</span><a name="line.1575"></a>
+<span class="sourceLineNo">1576</span>    this.lock.readLock().lock();<a name="line.1576"></a>
+<span class="sourceLineNo">1577</span>    try {<a name="line.1577"></a>
+<span class="sourceLineNo">1578</span>      synchronized (filesCompacting) {<a name="line.1578"></a>
+<span class="sourceLineNo">1579</span>        filesToCompact = Lists.newArrayList(storeEngine.getStoreFileManager().getStorefiles());<a name="line.1579"></a>
+<span class="sourceLineNo">1580</span>        if (!filesCompacting.isEmpty()) {<a name="line.1580"></a>
+<span class="sourceLineNo">1581</span>          // exclude all files older than the newest file we're currently<a name="line.1581"></a>
+<span class="sourceLineNo">1582</span>          // compacting. this allows us to preserve contiguity (HBASE-2856)<a name="line.1582"></a>
+<span class="sourceLineNo">1583</span>          HStoreFile last = filesCompacting.get(filesCompacting.size() - 1);<a name="line.1583"></a>
+<span class="sourceLineNo">1584</span>          int idx = filesToCompact.indexOf(last);<a name="line.1584"></a>
+<span class="sourceLineNo">1585</span>          Preconditions.checkArgument(idx != -1);<a name="line.1585"></a>
+<span class="sourceLineNo">1586</span>          filesToCompact.subList(0, idx + 1).clear();<a name="line.1586"></a>
+<span class="sourceLineNo">1587</span>        }<a name="line.1587"></a>
+<span class="sourceLineNo">1588</span>        int count = filesToCompact.size();<a name="line.1588"></a>
+<span class="sourceLineNo">1589</span>        if (N &gt; count) {<a name="line.1589"></a>
+<span class="sourceLineNo">1590</span>          throw new RuntimeException("Not enough files");<a name="line.1590"></a>
+<span class="sourceLineNo">1591</span>        }<a name="line.1591"></a>
+<span class="sourceLineNo">1592</span><a name="line.1592"></a>
+<span class="sourceLineNo">1593</span>        filesToCompact = filesToCompact.subList(count - N, count);<a name="line.1593"></a>
+<span class="sourceLineNo">1594</span>        isMajor = (filesToCompact.size() == storeEngine.getStoreFileManager().getStorefileCount());<a name="line.1594"></a>
+<span class="sourceLineNo">1595</span>        filesCompacting.addAll(filesToCompact);<a name="line.1595"></a>
+<span class="sourceLineNo">1596</span>        Collections.sort(filesCompacting, storeEngine.getStoreFileManager()<a name="line.1596"></a>
+<span class="sourceLineNo">1597</span>            .getStoreFileComparator());<a name="line.1597"></a>
+<span class="sourceLineNo">1598</span>      }<a name="line.1598"></a>
+<span class="sourceLineNo">1599</span>    } finally {<a name="line.1599"></a>
+<span class="sourceLineNo">1600</span>      this.lock.readLock().unlock();<a name="line.1600"></a>
+<span class="sourceLineNo">1601</span>    }<a name="line.1601"></a>
+<span class="sourceLineNo">1602</span><a name="line.1602"></a>
+<span class="sourceLineNo">1603</span>    try {<a name="line.1603"></a>
+<span class="sourceLineNo">1604</span>      // Ready to go. Have list of files to compact.<a name="line.1604"></a>
+<span class="sourceLineNo">1605</span>      List&lt;Path&gt; newFiles = ((DefaultCompactor)this.storeEngine.getCompactor())<a name="line.1605"></a>
+<span class="sourceLineNo">1606</span>          .compactForTesting(filesToCompact, isMajor);<a name="line.1606"></a>
+<span class="sourceLineNo">1607</span>      for (Path newFile: newFiles) {<a name="line.1607"></a>
+<span class="sourceLineNo">1608</span>        // Move the compaction into place.<a name="line.1608"></a>
+<span class="sourceLineNo">1609</span>        HStoreFile sf = moveFileIntoPlace(newFile);<a name="line.1609"></a>
+<span class="sourceLineNo">1610</span>        if (this.getCoprocessorHost() != null) {<a name="line.1610"></a>
+<span class="sourceLineNo">1611</span>          this.getCoprocessorHost().postCompact(this, sf, null, null, null);<a name="line.1611"></a>
+<span class="sourceLineNo">1612</span>        }<a name="line.1612"></a>
+<span class="sourceLineNo">1613</span>        replaceStoreFiles(filesToCompact, Collections.singletonList(sf));<a name="line.1613"></a>
+<span class="sourceLineNo">1614</span>        completeCompaction(filesToCompact);<a name="line.1614"></a>
+<span class="sourceLineNo">1615</span>      }<a name="line.1615"></a>
+<span class="sourceLineNo">1616</span>    } finally {<a name="line.1616"></a>
+<span class="sourceLineNo">1617</span>      synchronized (filesCompacting) {<a name="line.1617"></a>
+<span class="sourceLineNo">1618</span>        filesCompacting.removeAll(filesToCompact);<a name="line.1618"></a>
+<span class="sourceLineNo">1619</span>      }<a name="line.1619"></a>
+<span class="sourceLineNo">1620</span>    }<a name="line.1620"></a>
+<span class="sourceLineNo">1621</span>  }<a name="line.1621"></a>
+<span class="sourceLineNo">1622</span><a name="line.1622"></a>
+<span class="sourceLineNo">1623</span>  @Override<a name="line.1623"></a>
+<span class="sourceLineNo">1624</span>  public boolean hasReferences() {<a name="line.1624"></a>
+<span class="sourceLineNo">1625</span>    return StoreUtils.hasReferences(this.storeEngine.getStoreFileManager().getStorefiles());<a name="line.1625"></a>
+<span class="sourceLineNo">1626</span>  }<a name="line.1626"></a>
+<span class="sourceLineNo">1627</span><a name="line.1627"></a>
+<span class="sourceLineNo">1628</span>  /**<a name="line.1628"></a>
+<span class="sourceLineNo">1629</span>   * getter for CompactionProgress object<a name="line.1629"></a>
+<span class="sourceLineNo">1630</span>   * @return CompactionProgress object; can be null<a name="line.1630"></a>
+<span class="sourceLineNo">1631</span>   */<a name="line.1631"></a>
+<span class="sourceLineNo">1632</span>  public CompactionProgress getCompactionProgress() {<a name="line.1632"></a>
+<span class="sourceLineNo">1633</span>    return this.storeEngine.getCompactor().getProgress();<a name="line.1633"></a>
+<span class="sourceLineNo">1634</span>  }<a name="line.1634"></a>
+<span class="sourceLineNo">1635</span><a name="line.1635"></a>
+<span class="sourceLineNo">1636</span>  @Override<a name="line.1636"></a>
+<span class="sourceLineNo">1637</span>  public boolean shouldPerformMajorCompaction() throws IOException {<a name="line.1637"></a>
+<span class="sourceLineNo">1638</span>    for (HStoreFile sf : this.storeEngine.getStoreFileManager().getStorefiles()) {<a name="line.1638"></a>
+<span class="sourceLineNo">1639</span>      // TODO: what are these reader checks all over the place?<a name="line.1639"></a>
+<span class="sourceLineNo">1640</span>      if (sf.getReader() == null) {<a name="line.1640"></a>
+<span class="sourceLineNo">1641</span>        LOG.debug("StoreFile {} has null Reader", sf);<a name="line.1641"></a>
+<span class="sourceLineNo">1642</span>        return false;<a name="line.1642"></a>
+<span class="sourceLineNo">1643</span>      }<a name="line.1643"></a>
+<span class="sourceLineNo">1644</span>    }<a name="line.1644"></a>
+<span class="sourceLineNo">1645</span>    return storeEngine.getCompactionPolicy().shouldPerformMajorCompaction(<a name="line.1645"></a>
+<span class="sourceLineNo">1646</span>        this.storeEngine.getStoreFileManager().getStorefiles());<a name="line.1646"></a>
+<span class="sourceLineNo">1647</span>  }<a name="line.1647"></a>
+<span class="sourceLineNo">1648</span><a name="line.1648"></a>
+<span class="sourceLineNo">1649</span>  public Optional&lt;CompactionContext&gt; requestCompaction() throws IOException {<a name="line.1649"></a>
+<span class="sourceLineNo">1650</span>    return requestCompaction(NO_PRIORITY, CompactionLifeCycleTracker.DUMMY, null);<a name="line.1650"></a>
+<span class="sourceLineNo">1651</span>  }<a name="line.1651"></a>
+<span class="sourceLineNo">1652</span><a name="line.1652"></a>
+<span class="sourceLineNo">1653</span>  public Optional&lt;CompactionContext&gt; requestCompaction(int priority,<a name="line.1653"></a>
+<span class="sourceLineNo">1654</span>      CompactionLifeCycleTracker tracker, User user) throws IOException {<a name="line.1654"></a>
+<span class="sourceLineNo">1655</span>    // don't even select for compaction if writes are disabled<a name="line.1655"></a>
+<span class="sourceLineNo">1656</span>    if (!this.areWritesEnabled()) {<a name="line.1656"></a>
+<span class="sourceLineNo">1657</span>      return Optional.empty();<a name="line.1657"></a>
+<span class="sourceLineNo">1658</span>    }<a name="line.1658"></a>
+<span class="sourceLineNo">1659</span>    // Before we do compaction, try to get rid of unneeded files to simplify things.<a name="line.1659"></a>
+<span class="sourceLineNo">1660</span>    removeUnneededFiles();<a name="line.1660"></a>
+<span class="sourceLineNo">1661</span><a name="line.1661"></a>
+<span class="sourceLineNo">1662</span>    final CompactionContext compaction = storeEngine.createCompaction();<a name="line.1662"></a>
+<span class="sourceLineNo">1663</span>    CompactionRequestImpl request = null;<a name="line.1663"></a>
+<span class="sourceLineNo">1664</span>    this.lock.readLock().lock();<a name="line.1664"></a>
+<span class="sourceLineNo">1665</span>    try {<a name="line.1665"></a>
+<span class="sourceLineNo">1666</span>      synchronized (filesCompacting) {<a name="line.1666"></a>
+<span class="sourceLineNo">1667</span>        // First, see if coprocessor would want to override selection.<a name="line.1667"></a>
+<span class="sourceLineNo">1668</span>        if (this.getCoprocessorHost() != null) {<a name="line.1668"></a>
+<span class="sourceLineNo">1669</span>          final List&lt;HStoreFile&gt; candidatesForCoproc = compaction.preSelect(this.filesCompacting);<a name="line.1669"></a>
+<span class="sourceLineNo">1670</span>          boolean override = getCoprocessorHost().preCompactSelection(this,<a name="line.1670"></a>
+<span class="sourceLineNo">1671</span>              candidatesForCoproc, tracker, user);<a name="line.1671"></a>
+<span class="sourceLineNo">1672</span>          if (override) {<a name="line.1672"></a>
+<span class="sourceLineNo">1673</span>            // Coprocessor is overriding normal file selection.<a name="line.1673"></a>
+<span class="sourceLineNo">1674</span>            compaction.forceSelect(new CompactionRequestImpl(candidatesForCoproc));<a name="line.1674"></a>
+<span class="sourceLineNo">1675</span>          }<a name="line.1675"></a>
+<span class="sourceLineNo">1676</span>        }<a name="line.1676"></a>
+<span class="sourceLineNo">1677</span><a name="line.1677"></a>
+<span class="sourceLineNo">1678</span>        // Normal case - coprocessor is not overriding file selection.<a name="line.1678"></a>
+<span class="sourceLineNo">1679</span>        if (!compaction.hasSelection()) {<a name="line.1679"></a>
+<span class="sourceLineNo">1680</span>          boolean isUserCompaction = priority == Store.PRIORITY_USER;<a name="line.1680"></a>
+<span class="sourceLineNo">1681</span>          boolean mayUseOffPeak = offPeakHours.isOffPeakHour() &amp;&amp;<a name="line.1681"></a>
+<span class="sourceLineNo">1682</span>              offPeakCompactionTracker.compareAndSet(false, true);<a name="line.1682"></a>
+<span class="sourceLineNo">1683</span>          try {<a name="line.1683"></a>
+<span class="sourceLineNo">1684</span>            compaction.select(this.filesCompacting, isUserCompaction,<a name="line.1684"></a>
+<span class="sourceLineNo">1685</span>              mayUseOffPeak, forceMajor &amp;&amp; filesCompacting.isEmpty());<a name="line.1685"></a>
+<span class="sourceLineNo">1686</span>          } catch (IOException e) {<a name="line.1686"></a>
+<span class="sourceLineNo">1687</span>            if (mayUseOffPeak) {<a name="line.1687"></a>
+<span class="sourceLineNo">1688</span>              offPeakCompactionTracker.set(false);<a name="line.1688"></a>
+<span class="sourceLineNo">1689</span>            }<a name="line.1689"></a>
+<span class="sourceLineNo">1690</span>            throw e;<a name="line.1690"></a>
+<span class="sourceLineNo">1691</span>          }<a name="line.1691"></a>
+<span class="sourceLineNo">1692</span>          assert compaction.hasSelection();<a name="line.1692"></a>
+<span class="sourceLineNo">1693</span>          if (mayUseOffPeak &amp;&amp; !compaction.getRequest().isOffPeak()) {<a name="line.1693"></a>
+<span class="sourceLineNo">1694</span>            // Compaction policy doesn't want to take advantage of off-peak.<a name="line.1694"></a>
+<span class="sourceLineNo">1695</span>            offPeakCompactionTracker.set(false);<a name="line.1695"></a>
+<span class="sourceLineNo">1696</span>          }<a name="line.1696"></a>
+<span class="sourceLineNo">1697</span>        }<a name="line.1697"></a>
+<span class="sourceLineNo">1698</span>        if (this.getCoprocessorHost() != null) {<a name="line.1698"></a>
+<span class="sourceLineNo">1699</span>          this.getCoprocessorHost().postCompactSelection(<a name="line.1699"></a>
+<span class="sourceLineNo">1700</span>              this, ImmutableList.copyOf(compaction.getRequest().getFiles()), tracker,<a name="line.1700"></a>
+<span class="sourceLineNo">1701</span>              compaction.getRequest(), user);<a name="line.1701"></a>
+<span class="sourceLineNo">1702</span>        }<a name="line.1702"></a>
+<span class="sourceLineNo">1703</span>        // Finally, we have the resulting files list. Check if we have any files at all.<a name="line.1703"></a>
+<span class="sourceLineNo">1704</span>        request = compaction.getRequest();<a name="line.1704"></a>
+<span class="sourceLineNo">1705</span>        Collection&lt;HStoreFile&gt; selectedFiles = request.getFiles();<a name="line.1705"></a>
+<span class="sourceLineNo">1706</span>        if (selectedFiles.isEmpty()) {<a name="line.1706"></a>
+<span class="sourceLineNo">1707</span>          return Optional.empty();<a name="line.1707"></a>
+<span class="sourceLineNo">1708</span>        }<a name="line.1708"></a>
 <span class="sourceLineNo">1709</span><a name="line.1709"></a>
-<span class="sourceLineNo">1710</span>        // If we're enqueuing a major, clear the force flag.<a name="line.1710"></a>
-<span class="sourceLineNo">1711</span>        this.forceMajor = this.forceMajor &amp;&amp; !request.isMajor();<a name="line.1711"></a>
-<span class="sourceLineNo">1712</span><a name="line.1712"></a>
-<span class="sourceLineNo">1713</span>        // Set common request properties.<a name="line.1713"></a>
-<span class="sourceLineNo">1714</span>        // Set priority, either override value supplied by caller or from store.<a name="line.1714"></a>
-<span class="sourceLineNo">1715</span>        request.setPriority((priority != Store.NO_PRIORITY) ? priority : getCompactPriority());<a name="line.1715"></a>
-<span class="sourceLineNo">1716</span>        request.setDescription(getRegionInfo().getRegionNameAsString(), getColumnFamilyName());<a name="line.1716"></a>
-<span class="sourceLineNo">1717</span>        request.setTracker(tracker);<a name="line.1717"></a>
-<span class="sourceLineNo">1718</span>      }<a name="line.1718"></a>
-<span class="sourceLineNo">1719</span>    } finally {<a name="line.1719"></a>
-<span class="sourceLineNo">1720</span>      this.lock.readLock().unlock();<a name="line.1720"></a>
-<span class="sourceLineNo">1721</span>    }<a name="line.1721"></a>
-<span class="sourceLineNo">1722</span><a name="line.1722"></a>
-<span class="sourceLineNo">1723</span>    if (LOG.isDebugEnabled()) {<a name="line.1723"></a>
-<span class="sourceLineNo">1724</span>      LOG.debug(getRegionInfo().getEncodedName() + " - " + getColumnFamilyName()<a name="line.1724"></a>
-<span class="sourceLineNo">1725</span>          + ": Initiating " + (request.isMajor() ? "major" : "minor") + " compaction"<a name="line.1725"></a>
-<span class="sourceLineNo">1726</span>          + (request.isAllFiles() ? " (all files)" : ""));<a name="line.1726"></a>
-<span class="sourceLineNo">1727</span>    }<a name="line.1727"></a>
-<span class="sourceLineNo">1728</span>    this.region.reportCompactionRequestStart(request.isMajor());<a name="line.1728"></a>
-<span class="sourceLineNo">1729</span>    return Optional.of(compaction);<a name="line.1729"></a>
-<span class="sourceLineNo">1730</span>  }<a name="line.1730"></a>
-<span class="sourceLineNo">1731</span><a name="line.1731"></a>
-<span class="sourceLineNo">1732</span>  /** Adds the files to compacting files. filesCompacting must be locked. */<a name="line.1732"></a>
-<span class="sourceLineNo">1733</span>  private void addToCompactingFiles(Collection&lt;HStoreFile&gt; filesToAdd) {<a name="line.1733"></a>
-<span class="sourceLineNo">1734</span>    if (CollectionUtils.isEmpty(filesToAdd)) {<a name="line.1734"></a>
-<span class="sourceLineNo">1735</span>      return;<a name="line.1735"></a>
-<span class="sourceLineNo">1736</span>    }<a name="line.1736"></a>
-<span class="sourceLineNo">1737</span>    // Check that we do not try to compact the same StoreFile twice.<a name="line.1737"></a>
-<span class="sourceLineNo">1738</span>    if (!Collections.disjoint(filesCompacting, filesToAdd)) {<a name="line.1738"></a>
-<span class="sourceLineNo">1739</span>      Preconditions.checkArgument(false, "%s overlaps with %s", filesToAdd, filesCompacting);<a name="line.1739"></a>
-<span class="sourceLineNo">1740</span>    }<a name="line.1740"></a>
-<span class="sourceLineNo">1741</span>    filesCompacting.addAll(filesToAdd);<a name="line.1741"></a>
-<span class="sourceLineNo">1742</span>    Collections.sort(filesCompacting, storeEngine.getStoreFileManager().getStoreFileComparator());<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>  private void removeUnneededFiles() throws IOException {<a name="line.1745"></a>
-<span class="sourceLineNo">1746</span>    if (!conf.getBoolean("hbase.store.delete.expired.storefile", true)) return;<a name="line.1746"></a>
-<span class="sourceLineNo">1747</span>    if (getColumnFamilyDescriptor().getMinVersions() &gt; 0) {<a name="line.1747"></a>
-<span class="sourceLineNo">1748</span>      LOG.debug("Skipping expired store file removal due to min version being {}",<a name="line.1748"></a>
-<span class="sourceLineNo">1749</span>          getColumnFamilyDescriptor().getMinVersions());<a name="line.1749"></a>
-<span class="sourceLineNo">1750</span>      return;<a name="line.1750"></a>
-<span class="sourceLineNo">1751</span>    }<a name="line.1751"></a>
-<span class="sourceLineNo">1752</span>    this.lock.readLock().lock();<a name="line.1752"></a>
-<span class="sourceLineNo">1753</span>    Collection&lt;HStoreFile&gt; delSfs = null;<a name="line.1753"></a>
-<span class="sourceLineNo">1754</span>    try {<a name="line.1754"></a>
-<span class="sourceLineNo">1755</span>      synchronized (filesCompacting) {<a name="line.1755"></a>
-<span class="sourceLineNo">1756</span>        long cfTtl = getStoreFileTtl();<a name="line.1756"></a>
-<span class="sourceLineNo">1757</span>        if (cfTtl != Long.MAX_VALUE) {<a name="line.1757"></a>
-<span class="sourceLineNo">1758</span>          delSfs = storeEngine.getStoreFileManager().getUnneededFiles(<a name="line.1758"></a>
-<span class="sourceLineNo">1759</span>              EnvironmentEdgeManager.currentTime() - cfTtl, filesCompacting);<a name="line.1759"></a>
-<span class="sourceLineNo">1760</span>          addToCompactingFiles(delSfs);<a name="line.1760"></a>
-<span class="sourceLineNo">1761</span>        }<a name="line.1761"></a>
-<span class="sourceLineNo">1762</span>      }<a name="line.1762"></a>
-<span class="sourceLineNo">1763</span>    } finally {<a name="line.1763"></a>
-<span class="sourceLineNo">1764</span>      this.lock.readLock().unlock();<a name="line.1764"></a>
-<span class="sourceLineNo">1765</span>    }<a name="line.1765"></a>
-<span class="sourceLineNo">1766</span><a name="line.1766"></a>
-<span class="sourceLineNo">1767</span>    if (CollectionUtils.isEmpty(delSfs)) {<a name="line.1767"></a>
-<span class="sourceLineNo">1768</span>      return;<a name="line.1768"></a>
-<span class="sourceLineNo">1769</span>    }<a name="line.1769"></a>
-<span class="sourceLineNo">1770</span><a name="line.1770"></a>
-<span class="sourceLineNo">1771</span>    Collection&lt;HStoreFile&gt; newFiles = Collections.emptyList(); // No new files.<a name="line.1771"></a>
-<span class="sourceLineNo">1772</span>    writeCompactionWalRecord(delSfs, newFiles);<a name="line.1772"></a>
-<span class="sourceLineNo">1773</span>    replaceStoreFiles(delSfs, newFiles);<a name="line.1773"></a>
-<span class="sourceLineNo">1774</span>    completeCompaction(delSfs);<a name="line.1774"></a>
-<span class="sourceLineNo">1775</span>    LOG.info("Completed removal of " + delSfs.size() + " unnecessary (expired) file(s) in "<a name="line.1775"></a>
-<span class="sourceLineNo">1776</span>        + this + " of " + this.getRegionInfo().getRegionNameAsString()<a name="line.1776"></a>
-<span class="sourceLineNo">1777</span>        + "; total size for store is "<a name="line.1777"></a>
-<span class="sourceLineNo">1778</span>        + TraditionalBinaryPrefix.long2String(storeSize.get(), "", 1));<a name="line.1778"></a>
-<span class="sourceLineNo">1779</span>  }<a name="line.1779"></a>
-<span class="sourceLineNo">1780</span><a name="line.1780"></a>
-<span class="sourceLineNo">1781</span>  public void cancelRequestedCompaction(CompactionContext compaction) {<a name="line.1781"></a>
-<span class="sourceLineNo">1782</span>    finishCompactionRequest(compaction.getRequest());<a name="line.1782"></a>
-<span class="sourceLineNo">1783</span>  }<a name="line.1783"></a>
-<span class="sourceLineNo">1784</span><a name="line.1784"></a>
-<span class="sourceLineNo">1785</span>  private void finishCompactionRequest(CompactionRequestImpl cr) {<a name="line.1785"></a>
-<span class="sourceLineNo">1786</span>    this.region.reportCompactionRequestEnd(cr.isMajor(), cr.getFiles().size(), cr.getSize());<a name="line.1786"></a>
-<span class="sourceLineNo">1787</span>    if (cr.isOffPeak()) {<a name="line.1787"></a>
-<span class="sourceLineNo">1788</span>      offPeakCompactionTracker.set(false);<a name="line.1788"></a>
-<span class="sourceLineNo">1789</span>      cr.setOffPeak(false);<a name="line.1789"></a>
-<span class="sourceLineNo">1790</span>    }<a name="line.1790"></a>
-<span class="sourceLineNo">1791</span>    synchronized (filesCompacting) {<a name="line.1791"></a>
-<span class="sourceLineNo">1792</span>      filesCompacting.removeAll(cr.getFiles());<a name="line.1792"></a>
-<span class="sourceLineNo">1793</span>    }<a name="line.1793"></a>
-<span class="sourceLineNo">1794</span>  }<a name="line.1794"></a>
-<span class="sourceLineNo">1795</span><a name="line.1795"></a>
-<span class="sourceLineNo">1796</span>  /**<a name="line.1796"></a>
-<span class="sourceLineNo">1797</span>   * Validates a store file by opening and closing it. In HFileV2 this should not be an expensive<a name="line.1797"></a>
-<span class="sourceLineNo">1798</span>   * operation.<a name="line.1798"></a>
-<span class="sourceLineNo">1799</span>   * @param path the path to the store file<a name="line.1799"></a>
-<span class="sourceLineNo">1800</span>   */<a name="line.1800"></a>
-<span class="sourceLineNo">1801</span>  private void validateStoreFile(Path path) throws IOException {<a name="line.1801"></a>
-<span class="sourceLineNo">1802</span>    HStoreFile storeFile = null;<a name="line.1802"></a>
-<span class="sourceLineNo">1803</span>    try {<a name="line.1803"></a>
-<span class="sourceLineNo">1804</span>      storeFile = createStoreFileAndReader(path);<a name="line.1804"></a>
-<span class="sourceLineNo">1805</span>    } catch (IOException e) {<a name="line.1805"></a>
-<span class="sourceLineNo">1806</span>      LOG.error("Failed to open store file : {}, keeping it in tmp location", path, e);<a name="line.1806"></a>
-<span class="sourceLineNo">1807</span>      throw e;<a name="line.1807"></a>
-<span class="sourceLineNo">1808</span>    } finally {<a name="line.1808"></a>
-<span class="sourceLineNo">1809</span>      if (storeFile != null) {<a name="line.1809"></a>
-<span class="sourceLineNo">1810</span>        storeFile.closeStoreFile(false);<a name="line.1810"></a>
-<span class="sourceLineNo">1811</span>      }<a name="line.1811"></a>
-<span class="sourceLineNo">1812</span>    }<a name="line.1812"></a>
-<span class="sourceLineNo">1813</span>  }<a name="line.1813"></a>
-<span class="sourceLineNo">1814</span><a name="line.1814"></a>
-<span class="sourceLineNo">1815</span>  /**<a name="line.1815"></a>
-<span class="sourceLineNo">1816</span>   * &lt;p&gt;It works by processing a compaction that's been written to disk.<a name="line.1816"></a>
-<span class="sourceLineNo">1817</span>   *<a name="line.1817"></a>
-<span class="sourceLineNo">1818</span>   * &lt;p&gt;It is usually invoked at the end of a compaction, but might also be<a name="line.1818"></a>
-<span class="sourceLineNo">1819</span>   * invoked at HStore startup, if the prior execution died midway through.<a name="line.1819"></a>
-<span class="sourceLineNo">1820</span>   *<a name="line.1820"></a>
-<span class="sourceLineNo">1821</span>   * &lt;p&gt;Moving the compacted TreeMap into place means:<a name="line.1821"></a>
-<span class="sourceLineNo">1822</span>   * &lt;pre&gt;<a name="line.1822"></a>
-<span class="sourceLineNo">1823</span>   * 1) Unload all replaced StoreFile, close and collect list to delete.<a name="line.1823"></a>
-<span class="sourceLineNo">1824</span>   * 2) Compute new store size<a name="line.1824"></a>
-<span class="sourceLineNo">1825</span>   * &lt;/pre&gt;<a name="line.1825"></a>
-<span class="sourceLineNo">1826</span>   *<a name="line.1826"></a>
-<span class="sourceLineNo">1827</span>   * @param compactedFiles list of files that were compacted<a name="line.1827"></a>
-<span class="sourceLineNo">1828</span>   */<a name="line.1828"></a>
-<span class="sourceLineNo">1829</span>  @VisibleForTesting<a name="line.1829"></a>
-<span class="sourceLineNo">1830</span>  protected void completeCompaction(Collection&lt;HStoreFile&gt; compactedFiles)<a name="line.1830"></a>
-<span class="sourceLineNo">1831</span>    throws IOException {<a name="line.1831"></a>
-<span class="sourceLineNo">1832</span>    this.storeSize.set(0L);<a name="line.1832"></a>
-<span class="sourceLineNo">1833</span>    this.totalUncompressedBytes.set(0L);<a name="line.1833"></a>
-<span class="sourceLineNo">1834</span>    for (HStoreFile hsf : this.storeEngine.getStoreFileManager().getStorefiles()) {<a name="line.1834"></a>
-<span class="sourceLineNo">1835</span>      StoreFileReader r = hsf.getReader();<a name="line.1835"></a>
-<span class="sourceLineNo">1836</span>      if (r == null) {<a name="line.1836"></a>
-<span class="sourceLineNo">1837</span>        LOG.warn("StoreFile {} has a null Reader", hsf);<a name="line.1837"></a>
-<span class="sourceLineNo">1838</span>        continue;<a name="line.1838"></a>
-<span class="sourceLineNo">1839</span>      }<a name="line.1839"></a>
-<span class="sourceLineNo">1840</span>      this.storeSize.addAndGet(r.length());<a name="line.1840"></a>
-<span class="sourceLineNo">1841</span>      this.totalUncompressedBytes.addAndGet(r.getTotalUncompressedBytes());<a name="line.1841"></a>
-<span class="sourceLineNo">1842</span>    }<a name="line.1842"></a>
-<span class="sourceLineNo">1843</span>  }<a name="line.1843"></a>
-<span class="sourceLineNo">1844</span><a name="line.1844"></a>
-<span class="sourceLineNo">1845</span>  /*<a name="line.1845"></a>
-<span class="sourceLineNo">1846</span>   * @param wantedVersions How many versions were asked for.<a name="line.1846"></a>
-<span class="sourceLineNo">1847</span>   * @return wantedVersions or this families' {@link HConstants#VERSIONS}.<a name="line.1847"></a>
-<span class="sourceLineNo">1848</span>   */<a name="line.1848"></a>
-<span class="sourceLineNo">1849</span>  int versionsToReturn(final int wantedVersions) {<a name="line.1849"></a>
-<span class="sourceLineNo">1850</span>    if (wantedVersions &lt;= 0) {<a name="line.1850"></a>
-<span class="sourceLineNo">1851</span>      throw new IllegalArgumentException("Number of versions must be &gt; 0");<a name="line.1851"></a>
-<span class="sourceLineNo">1852</span>    }<a name="line.1852"></a>
-<span class="sourceLineNo">1853</span>    // Make sure we do not return more than maximum versions for this store.<a name="line.1853"></a>
-<span class="sourceLineNo">1854</span>    int maxVersions = this.family.getMaxVersions();<a name="line.1854"></a>
-<span class="sourceLineNo">1855</span>    return wantedVersions &gt; maxVersions ? maxVersions: wantedVersions;<a name="line.1855"></a>
-<span class="sourceLineNo">1856</span>  }<a name="line.1856"></a>
-<span class="sourceLineNo">1857</span><a name="line.1857"></a>
-<span class="sourceLineNo">1858</span>  @Override<a name="line.1858"></a>
-<span class="sourceLineNo">1859</span>  public boolean canSplit() {<a name="line.1859"></a>
-<span class="sourceLineNo">1860</span>    this.lock.readLock().lock();<a name="line.1860"></a>
-<span class="sourceLineNo">1861</span>    try {<a name="line.1861"></a>
-<span class="sourceLineNo">1862</span>      // Not split-able if we find a reference store file present in the store.<a name="line.1862"></a>
-<span class="sourceLineNo">1863</span>      boolean result = !hasReferences();<a name="line.1863"></a>
-<span class="sourceLineNo">1864</span>      if (!result) {<a name="line.1864"></a>
-<span class="sourceLineNo">1865</span>        LOG.trace("Not splittable; has references: {}", this);<a name="line.1865"></a>
-<span class="sourceLineNo">1866</span>      }<a name="line.1866"></a>
-<span class="sourceLineNo">1867</span>      return result;<a name="line.1867"></a>
-<span class="sourceLineNo">1868</span>    } finally {<a name="line.1868"></a>
-<span class="sourceLineNo">1869</span>      this.lock.readLock().unlock();<a name="line.1869"></a>
-<span class="sourceLineNo">1870</span>    }<a name="line.1870"></a>
-<span class="sourceLineNo">1871</span>  }<a name="line.1871"></a>
-<span class="sourceLineNo">1872</span><a name="line.1872"></a>
-<span class="sourceLineNo">1873</span>  /**<a name="line.1873"></a>
-<span class="sourceLineNo">1874</span>   * Determines if Store should be split.<a name="line.1874"></a>
-<span class="sourceLineNo">1875</span>   */<a name="line.1875"></a>
-<span class="sourceLineNo">1876</span>  public Optional&lt;byte[]&gt; getSplitPoint() {<a name="line.1876"></a>
-<span class="sourceLineNo">1877</span>    this.lock.readLock().lock();<a name="line.1877"></a>
-<span class="sourceLineNo">1878</span>    try {<a name="line.1878"></a>
-<span class="sourceLineNo">1879</span>      // Should already be enforced by the split policy!<a name="line.1879"></a>
-<span class="sourceLineNo">1880</span>      assert !this.getRegionInfo().isMetaRegion();<a name="line.1880"></a>
-<span class="sourceLineNo">1881</span>      // Not split-able if we find a reference store file present in the store.<a name="line.1881"></a>
-<span class="sourceLineNo">1882</span>      if (hasReferences()) {<a name="line.1882"></a>
-<span class="sourceLineNo">1883</span>        LOG.trace("Not splittable; has references: {}", this);<a name="line.1883"></a>
-<span class="sourceLineNo">1884</span>        return Optional.empty();<a name="line.1884"></a>
-<span class="sourceLineNo">1885</span>      }<a name="line.1885"></a>
-<span class="sourceLineNo">1886</span>      return this.storeEngine.getStoreFileManager().getSplitPoint();<a name="line.1886"></a>
-<span class="sourceLineNo">1887</span>    } catch(IOException e) {<a name="line.1887"></a>
-<span class="sourceLineNo">1888</span>      LOG.warn("Failed getting store size for {}", this, e);<a name="line.1888"></a>
-<span class="sourceLineNo">1889</span>    } finally {<a name="line.1889"></a>
-<span class="sourceLineNo">1890</span>      this.lock.readLock().unlock();<a name="line.1890"></a>
-<span class="sourceLineNo">1891</span>    }<a name="line.1891"></a>
-<span class="sourceLineNo">1892</span>    return Optional.empty();<a name="line.1892"></a>
-<span class="sourceLineNo">1893</span>  }<a name="line.1893"></a>
-<span class="sourceLineNo">1894</span><a name="line.1894"></a>
-<span class="sourceLineNo">1895</span>  @Override<a name="line.1895"></a>
-<span class="sourceLineNo">1896</span>  public long getLastCompactSize() {<a name="line.1896"></a>
-<span class="sourceLineNo">1897</span>    return this.lastCompactSize;<a name="line.1897"></a>
-<span class="sourceLineNo">1898</span>  }<a name="line.1898"></a>
-<span class="sourceLineNo">1899</span><a name="line.1899"></a>
-<span class="sourceLineNo">1900</span>  @Override<a name="line.1900"></a>
-<span class="sourceLineNo">1901</span>  public long getSize() {<a name="line.1901"></a>
-<span class="sourceLineNo">1902</span>    return storeSize.get();<a name="line.1902"></a>
-<span class="sourceLineNo">1903</span>  }<a name="line.1903"></a>
-<span class="sourceLineNo">1904</span><a name="line.1904"></a>
-<span class="sourceLineNo">1905</span>  public void triggerMajorCompaction() {<a name="line.1905"></a>
-<span class="sourceLineNo">1906</span>    this.forceMajor = true;<a name="line.1906"></a>
-<span class="sourceLineNo">1907</span>  }<a name="line.1907"></a>
-<span class="sourceLineNo">1908</span><a name="line.1908"></a>
-<span class="sourceLineNo">1909</span>  //////////////////////////////////////////////////////////////////////////////<a name="line.1909"></a>
-<span class="sourceLineNo">1910</span>  // File administration<a name="line.1910"></a>
+<span class="sourceLineNo">1710</span>        addToCompactingFiles(selectedFiles);<a name="line.1710"></a>
+<span class="sourceLineNo">1711</span><a name="line.1711"></a>
+<span class="sourceLineNo">1712</span>        // If we're enqueuing a major, clear the force flag.<a name="line.1712"></a>
+<span class="sourceLineNo">1713</span>        this.forceMajor = this.forceMajor &amp;&amp; !request.isMajor();<a name="line.1713"></a>
+<span class="sourceLineNo">1714</span><a name="line.1714"></a>
+<span class="sourceLineNo">1715</span>        // Set common request properties.<a name="line.1715"></a>
+<span class="sourceLineNo">1716</span>        // Set priority, either override value supplied by caller or from store.<a name="line.1716"></a>
+<span class="sourceLineNo">1717</span>        request.setPriority((priority != Store.NO_PRIORITY) ? priority : getCompactPriority());<a name="line.1717"></a>
+<span class="sourceLineNo">1718</span>        request.setDescription(getRegionInfo().getRegionNameAsString(), getColumnFamilyName());<a name="line.1718"></a>
+<span class="sourceLineNo">1719</span>        request.setTracker(tracker);<a name="line.1719"></a>
+<span class="sourceLineNo">1720</span>      }<a name="line.1720"></a>
+<span class="sourceLineNo">1721</span>    } finally {<a name="line.1721"></a>
+<span class="sourceLineNo">1722</span>      this.lock.readLock().unlock();<a name="line.1722"></a>
+<span class="sourceLineNo">1723</span>    }<a name="line.1723"></a>
+<span class="sourceLineNo">1724</span><a name="line.1724"></a>
+<span class="sourceLineNo">1725</span>    if (LOG.isDebugEnabled()) {<a name="line.1725"></a>
+<span class="sourceLineNo">1726</span>      LOG.debug(getRegionInfo().getEncodedName() + " - " + getColumnFamilyName()<a name="line.1726"></a>
+<span class="sourceLineNo">1727</span>          + ": Initiating " + (request.isMajor() ? "major" : "minor") + " compaction"<a name="line.1727"></a>
+<span class="sourceLineNo">1728</span>          + (request.isAllFiles() ? " (all files)" : ""));<a name="line.1728"></a>
+<span class="sourceLineNo">1729</span>    }<a name="line.1729"></a>
+<span class="sourceLineNo">1730</span>    this.region.reportCompactionRequestStart(request.isMajor());<a name="line.1730"></a>
+<span class="sourceLineNo">1731</span>    return Optional.of(compaction);<a name="line.1731"></a>
+<span class="sourceLineNo">1732</span>  }<a name="line.1732"></a>
+<span class="sourceLineNo">1733</span><a name="line.1733"></a>
+<span class="sourceLineNo">1734</span>  /** Adds the files to compacting files. filesCompacting must be locked. */<a name="line.1734"></a>
+<span class="sourceLineNo">1735</span>  private void addToCompactingFiles(Collection&lt;HStoreFile&gt; filesToAdd) {<a name="line.1735"></a>
+<span class="sourceLineNo">1736</span>    if (CollectionUtils.isEmpty(filesToAdd)) {<a name="line.1736"></a>
+<span class="sourceLineNo">1737</span>      return;<a name="line.1737"></a>
+<span class="sourceLineNo">1738</span>    }<a name="line.1738"></a>
+<span class="sourceLineNo">1739</span>    // Check that we do not try to compact the same StoreFile twice.<a name="line.1739"></a>
+<span class="sourceLineNo">1740</span>    if (!Collections.disjoint(filesCompacting, filesToAdd)) {<a name="line.1740"></a>
+<span class="sourceLineNo">1741</span>      Preconditions.checkArgument(false, "%s overlaps with %s", filesToAdd, filesCompacting);<a name="line.1741"></a>
+<span class="sourceLineNo">1742</span>    }<a name="line.1742"></a>
+<span class="sourceLineNo">1743</span>    filesCompacting.addAll(filesToAdd);<a name="line.1743"></a>
+<span class="sourceLineNo">1744</span>    Collections.sort(filesCompacting, storeEngine.getStoreFileManager().getStoreFileComparator());<a name="line.1744"></a>
+<span class="sourceLineNo">1745</span>  }<a name="line.1745"></a>
+<span class="sourceLineNo">1746</span><a name="line.1746"></a>
+<span class="sourceLineNo">1747</span>  private void removeUnneededFiles() throws IOException {<a name="line.1747"></a>
+<span class="sourceLineNo">1748</span>    if (!conf.getBoolean("hbase.store.delete.expired.storefile", true)) return;<a name="line.1748"></a>
+<span class="sourceLineNo">1749</span>    if (getColumnFamilyDescriptor().getMinVersions() &gt; 0) {<a name="line.1749"></a>
+<span class="sourceLineNo">1750</span>      LOG.debug("Skipping expired store file removal due to min version being {}",<a name="line.1750"></a>
+<span class="sourceLineNo">1751</span>          getColumnFamilyDescriptor().getMinVersions());<a name="line.1751"></a>
+<span class="sourceLineNo">1752</span>      return;<a name="line.1752"></a>
+<span class="sourceLineNo">1753</span>    }<a name="line.1753"></a>
+<span class="sourceLineNo">1754</span>    this.lock.readLock().lock();<a name="line.1754"></a>
+<span class="sourceLineNo">1755</span>    Collection&lt;HStoreFile&gt; delSfs = null;<a name="line.1755"></a>
+<span class="sourceLineNo">1756</span>    try {<a name="line.1756"></a>
+<span class="sourceLineNo">1757</span>      synchronized (filesCompacting) {<a name="line.1757"></a>
+<span class="sourceLineNo">1758</span>        long cfTtl = getStoreFileTtl();<a name="line.1758"></a>
+<span class="sourceLineNo">1759</span>        if (cfTtl != Long.MAX_VALUE) {<a name="line.1759"></a>
+<span class="sourceLineNo">1760</span>          delSfs = storeEngine.getStoreFileManager().getUnneededFiles(<a name="line.1760"></a>
+<span class="sourceLineNo">1761</span>              EnvironmentEdgeManager.currentTime() - cfTtl, filesCompacting);<a name="line.1761"></a>
+<span class="sourceLineNo">1762</span>          addToCompactingFiles(delSfs);<a name="line.1762"></a>
+<span class="sourceLineNo">1763</span>        }<a name="line.1763"></a>
+<span class="sourceLineNo">1764</span>      }<a name="line.1764"></a>
+<span class="sourceLineNo">1765</span>    } finally {<a name="line.1765"></a>
+<span class="sourceLineNo">1766</span>      this.lock.readLock().unlock();<a name="line.1766"></a>
+<span class="sourceLineNo">1767</span>    }<a name="line.1767"></a>
+<span class="sourceLineNo">1768</span><a name="line.1768"></a>
+<span class="sourceLineNo">1769</span>    if (CollectionUtils.isEmpty(delSfs)) {<a name="line.1769"></a>
+<span class="sourceLineNo">1770</span>      return;<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>    Collection&lt;HStoreFile&gt; newFiles = Collections.emptyList(); // No new files.<a name="line.1773"></a>
+<span class="sourceLineNo">1774</span>    writeCompactionWalRecord(delSfs, newFiles);<a name="line.1774"></a>
+<span class="sourceLineNo">1775</span>    replaceStoreFiles(delSfs, newFiles);<a name="line.1775"></a>
+<span class="sourceLineNo">1776</span>    completeCompaction(delSfs);<a name="line.1776"></a>
+<span class="sourceLineNo">1777</span>    LOG.info("Completed removal of " + delSfs.size() + " unnecessary (expired) file(s) in "<a name="line.1777"></a>
+<span class="sourceLineNo">1778</span>        + this + " of " + this.getRegionInfo().getRegionNameAsString()<a name="line.1778"></a>
+<span class="sourceLineNo">1779</span>        + "; total size for store is "<a name="line.1779"></a>
+<span class="sourceLineNo">1780</span>        + TraditionalBinaryPrefix.long2String(storeSize.get(), "", 1));<a name="line.1780"></a>
+<span class="sourceLineNo">1781</span>  }<a name="line.1781"></a>
+<span class="sourceLineNo">1782</span><a name="line.1782"></a>
+<span class="sourceLineNo">1783</span>  public void cancelRequestedCompaction(CompactionContext compaction) {<a name="line.1783"></a>
+<span class="sourceLineNo">1784</span>    finishCompactionRequest(compaction.getRequest());<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>  private void finishCompactionRequest(CompactionRequestImpl cr) {<a name="line.1787"></a>
+<span class="sourceLineNo">1788</span>    this.region.reportCompactionRequestEnd(cr.isMajor(), cr.getFiles().size(), cr.getSize());<a name="line.1788"></a>
+<span class="sourceLineNo">1789</span>    if (cr.isOffPeak()) {<a name="line.1789"></a>
+<span class="sourceLineNo">1790</span>      offPeakCompactionTracker.set(false);<a name="line.1790"></a>
+<span class="sourceLineNo">1791</span>      cr.setOffPeak(false);<a name="line.1791"></a>
+<span class="sourceLineNo">1792</span>    }<a name="line.1792"></a>
+<span class="sourceLineNo">1793</span>    synchronized (filesCompacting) {<a name="line.1793"></a>
+<span class="sourceLineNo">1794</span>      filesCompacting.removeAll(cr.getFiles());<a name="line.1794"></a>
+<span class="sourceLineNo">1795</span>    }<a name="line.1795"></a>
+<span class="sourceLineNo">1796</span>  }<a name="line.1796"></a>
+<span class="sourceLineNo">1797</span><a name="line.1797"></a>
+<span class="sourceLineNo">1798</span>  /**<a name="line.1798"></a>
+<span class="sourceLineNo">1799</span>   * Validates a store file by opening and closing it. In HFileV2 this should not be an expensive<a name="line.1799"></a>
+<span class="sourceLineNo">1800</span>   * operation.<a name="line.1800"></a>
+<span class="sourceLineNo">1801</span>   * @param path the path to the store file<a name="line.1801"></a>
+<span class="sourceLineNo">1802</span>   */<a name="line.1802"></a>
+<span class="sourceLineNo">1803</span>  private void validateStoreFile(Path path) throws IOException {<a name="line.1803"></a>
+<span class="sourceLineNo">1804</span>    HStoreFile storeFile = null;<a name="line.1804"></a>
+<span class="sourceLineNo">1805</span>    try {<a name="line.1805"></a>
+<span class="sourceLineNo">1806</span>      storeFile = createStoreFileAndReader(path);<a name="line.1806"></a>
+<span class="sourceLineNo">1807</span>    } catch (IOException e) {<a name="line.1807"></a>
+<span class="sourceLineNo">1808</span>      LOG.error("Failed to open store file : {}, keeping it in tmp location", path, e);<a name="line.1808"></a>
+<span class="sourceLineNo">1809</span>      throw e;<a name="line.1809"></a>
+<span class="sourceLineNo">1810</span>    } finally {<a name="line.1810"></a>
+<span class="sourceLineNo">1811</span>      if (storeFile != null) {<a name="line.1811"></a>
+<span class="sourceLineNo">1812</span>        storeFile.closeStoreFile(false);<a name="line.1812"></a>
+<span class="sourceLineNo">1813</span>      }<a name="line.1813"></a>
+<span class="sourceLineNo">1814</span>    }<a name="line.1814"></a>
+<span class="sourceLineNo">1815</span>  }<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>   * &lt;p&gt;It works by processing a compaction that's been written to disk.<a name="line.1818"></a>
+<span class="sourceLineNo">1819</span>   *<a name="line.1819"></a>
+<span class="sourceLineNo">1820</span>   * &lt;p&gt;It is usually invoked at the end of a compaction, but might also be<a name="line.1820"></a>
+<span class="sourceLineNo">1821</span>   * invoked at HStore startup, if the prior execution died midway through.<a name="line.1821"></a>
+<span class="sourceLineNo">1822</span>   *<a name="line.1822"></a>
+<span class="sourceLineNo">1823</span>   * &lt;p&gt;Moving the compacted TreeMap into place means:<a name="line.1823"></a>
+<span class="sourceLineNo">1824</span>   * &lt;pre&gt;<a name="line.1824"></a>
+<span class="sourceLineNo">1825</span>   * 1) Unload all replaced StoreFile, close and collect list to delete.<a name="line.1825"></a>
+<span class="sourceLineNo">1826</span>   * 2) Compute new store size<a name="line.1826"></a>
+<span class="sourceLineNo">1827</span>   * &lt;/pre&gt;<a name="line.1827"></a>
+<span class="sourceLineNo">1828</span>   *<a name="line.1828"></a>
+<span class="sourceLineNo">1829</span>   * @param compactedFiles list of files that were compacted<a name="line.1829"></a>
+<span class="sourceLineNo">1830</span>   */<a name="line.1830"></a>
+<span class="sourceLineNo">1831</span>  @VisibleForTesting<a name="line.1831"></a>
+<span class="sourceLineNo">1832</span>  protected void completeCompaction(Collection&lt;HStoreFile&gt; compactedFiles)<a name="line.1832"></a>
+<span class="sourceLineNo">1833</span>    throws IOException {<a name="line.1833"></a>
+<span class="sourceLineNo">1834</span>    this.storeSize.set(0L);<a name="line.1834"></a>
+<span class="sourceLineNo">1835</span>    this.totalUncompressedBytes.set(0L);<a name="line.1835"></a>
+<span class="sourceLineNo">1836</span>    for (HStoreFile hsf : this.storeEngine.getStoreFileManager().getStorefiles()) {<a name="line.1836"></a>
+<span class="sourceLineNo">1837</span>      StoreFileReader r = hsf.getReader();<a name="line.1837"></a>
+<span class="sourceLineNo">1838</span>      if (r == null) {<a name="line.1838"></a>
+<span class="sourceLineNo">1839</span>        LOG.warn("StoreFile {} has a null Reader", hsf);<a name="line.1839"></a>
+<span class="sourceLineNo">1840</span>        continue;<a name="line.1840"></a>
+<span class="sourceLineNo">1841</span>      }<a name="line.1841"></a>
+<span class="sourceLineNo">1842</span>      this.storeSize.addAndGet(r.length());<a name="line.1842"></a>
+<span class="sourceLineNo">1843</span>      this.totalUncompressedBytes.addAndGet(r.getTotalUncompressedBytes());<a name="line.1843"></a>
+<span class="sourceLineNo">1844</span>    }<a name="line.1844"></a>
+<span class="sourceLineNo">1845</span>  }<a name="line.1845"></a>
+<span class="sourceLineNo">1846</span><a name="line.1846"></a>
+<span class="sourceLineNo">1847</span>  /*<a name="line.1847"></a>
+<span class="sourceLineNo">1848</span>   * @param wantedVersions How many versions were asked for.<a name="line.1848"></a>
+<span class="sourceLineNo">1849</span>   * @return wantedVersions or this families' {@link HConstants#VERSIONS}.<a name="line.1849"></a>
+<span class="sourceLineNo">1850</span>   */<a name="line.1850"></a>
+<span class="sourceLineNo">1851</span>  int versionsToReturn(final int wantedVersions) {<a name="line.1851"></a>
+<span class="sourceLineNo">1852</span>    if (wantedVersions &lt;= 0) {<a name="line.1852"></a>
+<span class="sourceLineNo">1853</span>      throw new IllegalArgumentException("Number of versions must be &gt; 0");<a name="line.1853"></a>
+<span class="sourceLineNo">1854</span>    }<a name="line.1854"></a>
+<span class="sourceLineNo">1855</span>    // Make sure we do not return more than maximum versions for this store.<a name="line.1855"></a>
+<span class="sourceLineNo">1856</span>    int maxVersions = this.family.getMaxV

<TRUNCATED>

Mime
View raw message