hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [28/49] hbase-site git commit: Published site at 82d554e3783372cc6b05489452c815b57c06f6cd.
Date Fri, 16 Jun 2017 15:00:54 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/cd7ae54c/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.ObservedExceptionsInBatch.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.ObservedExceptionsInBatch.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.ObservedExceptionsInBatch.html
index 959e3ef..ac32645 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.ObservedExceptionsInBatch.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.ObservedExceptionsInBatch.html
@@ -1401,6821 +1401,6830 @@
 <span class="sourceLineNo">1393</span>  @Override<a name="line.1393"></a>
 <span class="sourceLineNo">1394</span>  public boolean isSplittable() {<a name="line.1394"></a>
 <span class="sourceLineNo">1395</span>    boolean result = isAvailable() &amp;&amp; !hasReferences();<a name="line.1395"></a>
-<span class="sourceLineNo">1396</span>    LOG.info("ASKED IF SPLITTABLE " + result, new Throwable("LOGGING"));<a name="line.1396"></a>
-<span class="sourceLineNo">1397</span>    return result;<a name="line.1397"></a>
-<span class="sourceLineNo">1398</span>  }<a name="line.1398"></a>
-<span class="sourceLineNo">1399</span><a name="line.1399"></a>
-<span class="sourceLineNo">1400</span>  @Override<a name="line.1400"></a>
-<span class="sourceLineNo">1401</span>  public boolean isMergeable() {<a name="line.1401"></a>
-<span class="sourceLineNo">1402</span>    if (!isAvailable()) {<a name="line.1402"></a>
-<span class="sourceLineNo">1403</span>      LOG.debug("Region " + this<a name="line.1403"></a>
-<span class="sourceLineNo">1404</span>          + " is not mergeable because it is closing or closed");<a name="line.1404"></a>
-<span class="sourceLineNo">1405</span>      return false;<a name="line.1405"></a>
-<span class="sourceLineNo">1406</span>    }<a name="line.1406"></a>
-<span class="sourceLineNo">1407</span>    if (hasReferences()) {<a name="line.1407"></a>
-<span class="sourceLineNo">1408</span>      LOG.debug("Region " + this<a name="line.1408"></a>
-<span class="sourceLineNo">1409</span>          + " is not mergeable because it has references");<a name="line.1409"></a>
-<span class="sourceLineNo">1410</span>      return false;<a name="line.1410"></a>
-<span class="sourceLineNo">1411</span>    }<a name="line.1411"></a>
-<span class="sourceLineNo">1412</span><a name="line.1412"></a>
-<span class="sourceLineNo">1413</span>    return true;<a name="line.1413"></a>
-<span class="sourceLineNo">1414</span>  }<a name="line.1414"></a>
-<span class="sourceLineNo">1415</span><a name="line.1415"></a>
-<span class="sourceLineNo">1416</span>  public boolean areWritesEnabled() {<a name="line.1416"></a>
-<span class="sourceLineNo">1417</span>    synchronized(this.writestate) {<a name="line.1417"></a>
-<span class="sourceLineNo">1418</span>      return this.writestate.writesEnabled;<a name="line.1418"></a>
-<span class="sourceLineNo">1419</span>    }<a name="line.1419"></a>
-<span class="sourceLineNo">1420</span>  }<a name="line.1420"></a>
+<span class="sourceLineNo">1396</span>    LOG.info("ASKED IF SPLITTABLE " + result + " " + getRegionInfo().getShortNameToLog(),<a name="line.1396"></a>
+<span class="sourceLineNo">1397</span>      new Throwable("LOGGING: REMOVE"));<a name="line.1397"></a>
+<span class="sourceLineNo">1398</span>    // REMOVE BELOW!!!!<a name="line.1398"></a>
+<span class="sourceLineNo">1399</span>    LOG.info("DEBUG LIST ALL FILES");<a name="line.1399"></a>
+<span class="sourceLineNo">1400</span>    for (Store store: this.stores.values()) {<a name="line.1400"></a>
+<span class="sourceLineNo">1401</span>      LOG.info("store " + store.getColumnFamilyName());<a name="line.1401"></a>
+<span class="sourceLineNo">1402</span>      for (StoreFile sf: store.getStorefiles()) {<a name="line.1402"></a>
+<span class="sourceLineNo">1403</span>        LOG.info(sf.toStringDetailed());<a name="line.1403"></a>
+<span class="sourceLineNo">1404</span>      }<a name="line.1404"></a>
+<span class="sourceLineNo">1405</span>    }<a name="line.1405"></a>
+<span class="sourceLineNo">1406</span>    return result;<a name="line.1406"></a>
+<span class="sourceLineNo">1407</span>  }<a name="line.1407"></a>
+<span class="sourceLineNo">1408</span><a name="line.1408"></a>
+<span class="sourceLineNo">1409</span>  @Override<a name="line.1409"></a>
+<span class="sourceLineNo">1410</span>  public boolean isMergeable() {<a name="line.1410"></a>
+<span class="sourceLineNo">1411</span>    if (!isAvailable()) {<a name="line.1411"></a>
+<span class="sourceLineNo">1412</span>      LOG.debug("Region " + this<a name="line.1412"></a>
+<span class="sourceLineNo">1413</span>          + " is not mergeable because it is closing or closed");<a name="line.1413"></a>
+<span class="sourceLineNo">1414</span>      return false;<a name="line.1414"></a>
+<span class="sourceLineNo">1415</span>    }<a name="line.1415"></a>
+<span class="sourceLineNo">1416</span>    if (hasReferences()) {<a name="line.1416"></a>
+<span class="sourceLineNo">1417</span>      LOG.debug("Region " + this<a name="line.1417"></a>
+<span class="sourceLineNo">1418</span>          + " is not mergeable because it has references");<a name="line.1418"></a>
+<span class="sourceLineNo">1419</span>      return false;<a name="line.1419"></a>
+<span class="sourceLineNo">1420</span>    }<a name="line.1420"></a>
 <span class="sourceLineNo">1421</span><a name="line.1421"></a>
-<span class="sourceLineNo">1422</span>  @VisibleForTesting<a name="line.1422"></a>
-<span class="sourceLineNo">1423</span>  public MultiVersionConcurrencyControl getMVCC() {<a name="line.1423"></a>
-<span class="sourceLineNo">1424</span>    return mvcc;<a name="line.1424"></a>
-<span class="sourceLineNo">1425</span>  }<a name="line.1425"></a>
-<span class="sourceLineNo">1426</span><a name="line.1426"></a>
-<span class="sourceLineNo">1427</span>  @Override<a name="line.1427"></a>
-<span class="sourceLineNo">1428</span>  public long getMaxFlushedSeqId() {<a name="line.1428"></a>
-<span class="sourceLineNo">1429</span>    return maxFlushedSeqId;<a name="line.1429"></a>
-<span class="sourceLineNo">1430</span>  }<a name="line.1430"></a>
-<span class="sourceLineNo">1431</span><a name="line.1431"></a>
-<span class="sourceLineNo">1432</span>  @Override<a name="line.1432"></a>
-<span class="sourceLineNo">1433</span>  public long getReadPoint(IsolationLevel isolationLevel) {<a name="line.1433"></a>
-<span class="sourceLineNo">1434</span>    if (isolationLevel != null &amp;&amp; isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1434"></a>
-<span class="sourceLineNo">1435</span>      // This scan can read even uncommitted transactions<a name="line.1435"></a>
-<span class="sourceLineNo">1436</span>      return Long.MAX_VALUE;<a name="line.1436"></a>
-<span class="sourceLineNo">1437</span>    }<a name="line.1437"></a>
-<span class="sourceLineNo">1438</span>    return mvcc.getReadPoint();<a name="line.1438"></a>
+<span class="sourceLineNo">1422</span>    return true;<a name="line.1422"></a>
+<span class="sourceLineNo">1423</span>  }<a name="line.1423"></a>
+<span class="sourceLineNo">1424</span><a name="line.1424"></a>
+<span class="sourceLineNo">1425</span>  public boolean areWritesEnabled() {<a name="line.1425"></a>
+<span class="sourceLineNo">1426</span>    synchronized(this.writestate) {<a name="line.1426"></a>
+<span class="sourceLineNo">1427</span>      return this.writestate.writesEnabled;<a name="line.1427"></a>
+<span class="sourceLineNo">1428</span>    }<a name="line.1428"></a>
+<span class="sourceLineNo">1429</span>  }<a name="line.1429"></a>
+<span class="sourceLineNo">1430</span><a name="line.1430"></a>
+<span class="sourceLineNo">1431</span>  @VisibleForTesting<a name="line.1431"></a>
+<span class="sourceLineNo">1432</span>  public MultiVersionConcurrencyControl getMVCC() {<a name="line.1432"></a>
+<span class="sourceLineNo">1433</span>    return mvcc;<a name="line.1433"></a>
+<span class="sourceLineNo">1434</span>  }<a name="line.1434"></a>
+<span class="sourceLineNo">1435</span><a name="line.1435"></a>
+<span class="sourceLineNo">1436</span>  @Override<a name="line.1436"></a>
+<span class="sourceLineNo">1437</span>  public long getMaxFlushedSeqId() {<a name="line.1437"></a>
+<span class="sourceLineNo">1438</span>    return maxFlushedSeqId;<a name="line.1438"></a>
 <span class="sourceLineNo">1439</span>  }<a name="line.1439"></a>
 <span class="sourceLineNo">1440</span><a name="line.1440"></a>
 <span class="sourceLineNo">1441</span>  @Override<a name="line.1441"></a>
-<span class="sourceLineNo">1442</span>  public long getReadpoint(IsolationLevel isolationLevel) {<a name="line.1442"></a>
-<span class="sourceLineNo">1443</span>    return getReadPoint(isolationLevel);<a name="line.1443"></a>
-<span class="sourceLineNo">1444</span>  }<a name="line.1444"></a>
-<span class="sourceLineNo">1445</span><a name="line.1445"></a>
-<span class="sourceLineNo">1446</span>  @Override<a name="line.1446"></a>
-<span class="sourceLineNo">1447</span>  public boolean isLoadingCfsOnDemandDefault() {<a name="line.1447"></a>
-<span class="sourceLineNo">1448</span>    return this.isLoadingCfsOnDemandDefault;<a name="line.1448"></a>
-<span class="sourceLineNo">1449</span>  }<a name="line.1449"></a>
-<span class="sourceLineNo">1450</span><a name="line.1450"></a>
-<span class="sourceLineNo">1451</span>  /**<a name="line.1451"></a>
-<span class="sourceLineNo">1452</span>   * Close down this HRegion.  Flush the cache, shut down each HStore, don't<a name="line.1452"></a>
-<span class="sourceLineNo">1453</span>   * service any more calls.<a name="line.1453"></a>
-<span class="sourceLineNo">1454</span>   *<a name="line.1454"></a>
-<span class="sourceLineNo">1455</span>   * &lt;p&gt;This method could take some time to execute, so don't call it from a<a name="line.1455"></a>
-<span class="sourceLineNo">1456</span>   * time-sensitive thread.<a name="line.1456"></a>
-<span class="sourceLineNo">1457</span>   *<a name="line.1457"></a>
-<span class="sourceLineNo">1458</span>   * @return Vector of all the storage files that the HRegion's component<a name="line.1458"></a>
-<span class="sourceLineNo">1459</span>   * HStores make use of.  It's a list of all StoreFile objects. Returns empty<a name="line.1459"></a>
-<span class="sourceLineNo">1460</span>   * vector if already closed and null if judged that it should not close.<a name="line.1460"></a>
-<span class="sourceLineNo">1461</span>   *<a name="line.1461"></a>
-<span class="sourceLineNo">1462</span>   * @throws IOException e<a name="line.1462"></a>
-<span class="sourceLineNo">1463</span>   * @throws DroppedSnapshotException Thrown when replay of wal is required<a name="line.1463"></a>
-<span class="sourceLineNo">1464</span>   * because a Snapshot was not properly persisted. The region is put in closing mode, and the<a name="line.1464"></a>
-<span class="sourceLineNo">1465</span>   * caller MUST abort after this.<a name="line.1465"></a>
-<span class="sourceLineNo">1466</span>   */<a name="line.1466"></a>
-<span class="sourceLineNo">1467</span>  public Map&lt;byte[], List&lt;StoreFile&gt;&gt; close() throws IOException {<a name="line.1467"></a>
-<span class="sourceLineNo">1468</span>    return close(false);<a name="line.1468"></a>
-<span class="sourceLineNo">1469</span>  }<a name="line.1469"></a>
-<span class="sourceLineNo">1470</span><a name="line.1470"></a>
-<span class="sourceLineNo">1471</span>  private final Object closeLock = new Object();<a name="line.1471"></a>
-<span class="sourceLineNo">1472</span><a name="line.1472"></a>
-<span class="sourceLineNo">1473</span>  /** Conf key for the periodic flush interval */<a name="line.1473"></a>
-<span class="sourceLineNo">1474</span>  public static final String MEMSTORE_PERIODIC_FLUSH_INTERVAL =<a name="line.1474"></a>
-<span class="sourceLineNo">1475</span>      "hbase.regionserver.optionalcacheflushinterval";<a name="line.1475"></a>
-<span class="sourceLineNo">1476</span>  /** Default interval for the memstore flush */<a name="line.1476"></a>
-<span class="sourceLineNo">1477</span>  public static final int DEFAULT_CACHE_FLUSH_INTERVAL = 3600000;<a name="line.1477"></a>
-<span class="sourceLineNo">1478</span>  /** Default interval for System tables memstore flush */<a name="line.1478"></a>
-<span class="sourceLineNo">1479</span>  public static final int SYSTEM_CACHE_FLUSH_INTERVAL = 300000; // 5 minutes<a name="line.1479"></a>
-<span class="sourceLineNo">1480</span><a name="line.1480"></a>
-<span class="sourceLineNo">1481</span>  /** Conf key to force a flush if there are already enough changes for one region in memstore */<a name="line.1481"></a>
-<span class="sourceLineNo">1482</span>  public static final String MEMSTORE_FLUSH_PER_CHANGES =<a name="line.1482"></a>
-<span class="sourceLineNo">1483</span>      "hbase.regionserver.flush.per.changes";<a name="line.1483"></a>
-<span class="sourceLineNo">1484</span>  public static final long DEFAULT_FLUSH_PER_CHANGES = 30000000; // 30 millions<a name="line.1484"></a>
-<span class="sourceLineNo">1485</span>  /**<a name="line.1485"></a>
-<span class="sourceLineNo">1486</span>   * The following MAX_FLUSH_PER_CHANGES is large enough because each KeyValue has 20+ bytes<a name="line.1486"></a>
-<span class="sourceLineNo">1487</span>   * overhead. Therefore, even 1G empty KVs occupy at least 20GB memstore size for a single region<a name="line.1487"></a>
-<span class="sourceLineNo">1488</span>   */<a name="line.1488"></a>
-<span class="sourceLineNo">1489</span>  public static final long MAX_FLUSH_PER_CHANGES = 1000000000; // 1G<a name="line.1489"></a>
-<span class="sourceLineNo">1490</span><a name="line.1490"></a>
-<span class="sourceLineNo">1491</span>  /**<a name="line.1491"></a>
-<span class="sourceLineNo">1492</span>   * Close down this HRegion.  Flush the cache unless abort parameter is true,<a name="line.1492"></a>
-<span class="sourceLineNo">1493</span>   * Shut down each HStore, don't service any more calls.<a name="line.1493"></a>
-<span class="sourceLineNo">1494</span>   *<a name="line.1494"></a>
-<span class="sourceLineNo">1495</span>   * This method could take some time to execute, so don't call it from a<a name="line.1495"></a>
-<span class="sourceLineNo">1496</span>   * time-sensitive thread.<a name="line.1496"></a>
-<span class="sourceLineNo">1497</span>   *<a name="line.1497"></a>
-<span class="sourceLineNo">1498</span>   * @param abort true if server is aborting (only during testing)<a name="line.1498"></a>
-<span class="sourceLineNo">1499</span>   * @return Vector of all the storage files that the HRegion's component<a name="line.1499"></a>
-<span class="sourceLineNo">1500</span>   * HStores make use of.  It's a list of StoreFile objects.  Can be null if<a name="line.1500"></a>
-<span class="sourceLineNo">1501</span>   * we are not to close at this time or we are already closed.<a name="line.1501"></a>
-<span class="sourceLineNo">1502</span>   *<a name="line.1502"></a>
-<span class="sourceLineNo">1503</span>   * @throws IOException e<a name="line.1503"></a>
-<span class="sourceLineNo">1504</span>   * @throws DroppedSnapshotException Thrown when replay of wal is required<a name="line.1504"></a>
-<span class="sourceLineNo">1505</span>   * because a Snapshot was not properly persisted. The region is put in closing mode, and the<a name="line.1505"></a>
-<span class="sourceLineNo">1506</span>   * caller MUST abort after this.<a name="line.1506"></a>
-<span class="sourceLineNo">1507</span>   */<a name="line.1507"></a>
-<span class="sourceLineNo">1508</span>  public Map&lt;byte[], List&lt;StoreFile&gt;&gt; close(final boolean abort) throws IOException {<a name="line.1508"></a>
-<span class="sourceLineNo">1509</span>    // Only allow one thread to close at a time. Serialize them so dual<a name="line.1509"></a>
-<span class="sourceLineNo">1510</span>    // threads attempting to close will run up against each other.<a name="line.1510"></a>
-<span class="sourceLineNo">1511</span>    MonitoredTask status = TaskMonitor.get().createStatus(<a name="line.1511"></a>
-<span class="sourceLineNo">1512</span>        "Closing region " + this +<a name="line.1512"></a>
-<span class="sourceLineNo">1513</span>        (abort ? " due to abort" : ""));<a name="line.1513"></a>
-<span class="sourceLineNo">1514</span><a name="line.1514"></a>
-<span class="sourceLineNo">1515</span>    status.setStatus("Waiting for close lock");<a name="line.1515"></a>
-<span class="sourceLineNo">1516</span>    try {<a name="line.1516"></a>
-<span class="sourceLineNo">1517</span>      synchronized (closeLock) {<a name="line.1517"></a>
-<span class="sourceLineNo">1518</span>        return doClose(abort, status);<a name="line.1518"></a>
-<span class="sourceLineNo">1519</span>      }<a name="line.1519"></a>
-<span class="sourceLineNo">1520</span>    } finally {<a name="line.1520"></a>
-<span class="sourceLineNo">1521</span>      status.cleanup();<a name="line.1521"></a>
-<span class="sourceLineNo">1522</span>    }<a name="line.1522"></a>
-<span class="sourceLineNo">1523</span>  }<a name="line.1523"></a>
-<span class="sourceLineNo">1524</span><a name="line.1524"></a>
-<span class="sourceLineNo">1525</span>  /**<a name="line.1525"></a>
-<span class="sourceLineNo">1526</span>   * Exposed for some very specific unit tests.<a name="line.1526"></a>
-<span class="sourceLineNo">1527</span>   */<a name="line.1527"></a>
-<span class="sourceLineNo">1528</span>  @VisibleForTesting<a name="line.1528"></a>
-<span class="sourceLineNo">1529</span>  public void setClosing(boolean closing) {<a name="line.1529"></a>
-<span class="sourceLineNo">1530</span>    this.closing.set(closing);<a name="line.1530"></a>
-<span class="sourceLineNo">1531</span>  }<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>   * The {@link HRegion#doClose} will block forever if someone tries proving the dead lock via the unit test.<a name="line.1534"></a>
-<span class="sourceLineNo">1535</span>   * Instead of blocking, the {@link HRegion#doClose} will throw exception if you set the timeout.<a name="line.1535"></a>
-<span class="sourceLineNo">1536</span>   * @param timeoutForWriteLock the second time to wait for the write lock in {@link HRegion#doClose}<a name="line.1536"></a>
-<span class="sourceLineNo">1537</span>   */<a name="line.1537"></a>
-<span class="sourceLineNo">1538</span>  @VisibleForTesting<a name="line.1538"></a>
-<span class="sourceLineNo">1539</span>  public void setTimeoutForWriteLock(long timeoutForWriteLock) {<a name="line.1539"></a>
-<span class="sourceLineNo">1540</span>    assert timeoutForWriteLock &gt;= 0;<a name="line.1540"></a>
-<span class="sourceLineNo">1541</span>    this.timeoutForWriteLock = timeoutForWriteLock;<a name="line.1541"></a>
-<span class="sourceLineNo">1542</span>  }<a name="line.1542"></a>
-<span class="sourceLineNo">1543</span><a name="line.1543"></a>
-<span class="sourceLineNo">1544</span>  @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="UL_UNRELEASED_LOCK_EXCEPTION_PATH",<a name="line.1544"></a>
-<span class="sourceLineNo">1545</span>      justification="I think FindBugs is confused")<a name="line.1545"></a>
-<span class="sourceLineNo">1546</span>  private Map&lt;byte[], List&lt;StoreFile&gt;&gt; doClose(final boolean abort, MonitoredTask status)<a name="line.1546"></a>
-<span class="sourceLineNo">1547</span>      throws IOException {<a name="line.1547"></a>
-<span class="sourceLineNo">1548</span>    if (isClosed()) {<a name="line.1548"></a>
-<span class="sourceLineNo">1549</span>      LOG.warn("Region " + this + " already closed");<a name="line.1549"></a>
-<span class="sourceLineNo">1550</span>      return null;<a name="line.1550"></a>
-<span class="sourceLineNo">1551</span>    }<a name="line.1551"></a>
+<span class="sourceLineNo">1442</span>  public long getReadPoint(IsolationLevel isolationLevel) {<a name="line.1442"></a>
+<span class="sourceLineNo">1443</span>    if (isolationLevel != null &amp;&amp; isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1443"></a>
+<span class="sourceLineNo">1444</span>      // This scan can read even uncommitted transactions<a name="line.1444"></a>
+<span class="sourceLineNo">1445</span>      return Long.MAX_VALUE;<a name="line.1445"></a>
+<span class="sourceLineNo">1446</span>    }<a name="line.1446"></a>
+<span class="sourceLineNo">1447</span>    return mvcc.getReadPoint();<a name="line.1447"></a>
+<span class="sourceLineNo">1448</span>  }<a name="line.1448"></a>
+<span class="sourceLineNo">1449</span><a name="line.1449"></a>
+<span class="sourceLineNo">1450</span>  @Override<a name="line.1450"></a>
+<span class="sourceLineNo">1451</span>  public long getReadpoint(IsolationLevel isolationLevel) {<a name="line.1451"></a>
+<span class="sourceLineNo">1452</span>    return getReadPoint(isolationLevel);<a name="line.1452"></a>
+<span class="sourceLineNo">1453</span>  }<a name="line.1453"></a>
+<span class="sourceLineNo">1454</span><a name="line.1454"></a>
+<span class="sourceLineNo">1455</span>  @Override<a name="line.1455"></a>
+<span class="sourceLineNo">1456</span>  public boolean isLoadingCfsOnDemandDefault() {<a name="line.1456"></a>
+<span class="sourceLineNo">1457</span>    return this.isLoadingCfsOnDemandDefault;<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>   * Close down this HRegion.  Flush the cache, shut down each HStore, don't<a name="line.1461"></a>
+<span class="sourceLineNo">1462</span>   * service any more calls.<a name="line.1462"></a>
+<span class="sourceLineNo">1463</span>   *<a name="line.1463"></a>
+<span class="sourceLineNo">1464</span>   * &lt;p&gt;This method could take some time to execute, so don't call it from a<a name="line.1464"></a>
+<span class="sourceLineNo">1465</span>   * time-sensitive thread.<a name="line.1465"></a>
+<span class="sourceLineNo">1466</span>   *<a name="line.1466"></a>
+<span class="sourceLineNo">1467</span>   * @return Vector of all the storage files that the HRegion's component<a name="line.1467"></a>
+<span class="sourceLineNo">1468</span>   * HStores make use of.  It's a list of all StoreFile objects. Returns empty<a name="line.1468"></a>
+<span class="sourceLineNo">1469</span>   * vector if already closed and null if judged that it should not close.<a name="line.1469"></a>
+<span class="sourceLineNo">1470</span>   *<a name="line.1470"></a>
+<span class="sourceLineNo">1471</span>   * @throws IOException e<a name="line.1471"></a>
+<span class="sourceLineNo">1472</span>   * @throws DroppedSnapshotException Thrown when replay of wal is required<a name="line.1472"></a>
+<span class="sourceLineNo">1473</span>   * because a Snapshot was not properly persisted. The region is put in closing mode, and the<a name="line.1473"></a>
+<span class="sourceLineNo">1474</span>   * caller MUST abort after this.<a name="line.1474"></a>
+<span class="sourceLineNo">1475</span>   */<a name="line.1475"></a>
+<span class="sourceLineNo">1476</span>  public Map&lt;byte[], List&lt;StoreFile&gt;&gt; close() throws IOException {<a name="line.1476"></a>
+<span class="sourceLineNo">1477</span>    return close(false);<a name="line.1477"></a>
+<span class="sourceLineNo">1478</span>  }<a name="line.1478"></a>
+<span class="sourceLineNo">1479</span><a name="line.1479"></a>
+<span class="sourceLineNo">1480</span>  private final Object closeLock = new Object();<a name="line.1480"></a>
+<span class="sourceLineNo">1481</span><a name="line.1481"></a>
+<span class="sourceLineNo">1482</span>  /** Conf key for the periodic flush interval */<a name="line.1482"></a>
+<span class="sourceLineNo">1483</span>  public static final String MEMSTORE_PERIODIC_FLUSH_INTERVAL =<a name="line.1483"></a>
+<span class="sourceLineNo">1484</span>      "hbase.regionserver.optionalcacheflushinterval";<a name="line.1484"></a>
+<span class="sourceLineNo">1485</span>  /** Default interval for the memstore flush */<a name="line.1485"></a>
+<span class="sourceLineNo">1486</span>  public static final int DEFAULT_CACHE_FLUSH_INTERVAL = 3600000;<a name="line.1486"></a>
+<span class="sourceLineNo">1487</span>  /** Default interval for System tables memstore flush */<a name="line.1487"></a>
+<span class="sourceLineNo">1488</span>  public static final int SYSTEM_CACHE_FLUSH_INTERVAL = 300000; // 5 minutes<a name="line.1488"></a>
+<span class="sourceLineNo">1489</span><a name="line.1489"></a>
+<span class="sourceLineNo">1490</span>  /** Conf key to force a flush if there are already enough changes for one region in memstore */<a name="line.1490"></a>
+<span class="sourceLineNo">1491</span>  public static final String MEMSTORE_FLUSH_PER_CHANGES =<a name="line.1491"></a>
+<span class="sourceLineNo">1492</span>      "hbase.regionserver.flush.per.changes";<a name="line.1492"></a>
+<span class="sourceLineNo">1493</span>  public static final long DEFAULT_FLUSH_PER_CHANGES = 30000000; // 30 millions<a name="line.1493"></a>
+<span class="sourceLineNo">1494</span>  /**<a name="line.1494"></a>
+<span class="sourceLineNo">1495</span>   * The following MAX_FLUSH_PER_CHANGES is large enough because each KeyValue has 20+ bytes<a name="line.1495"></a>
+<span class="sourceLineNo">1496</span>   * overhead. Therefore, even 1G empty KVs occupy at least 20GB memstore size for a single region<a name="line.1496"></a>
+<span class="sourceLineNo">1497</span>   */<a name="line.1497"></a>
+<span class="sourceLineNo">1498</span>  public static final long MAX_FLUSH_PER_CHANGES = 1000000000; // 1G<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>   * Close down this HRegion.  Flush the cache unless abort parameter is true,<a name="line.1501"></a>
+<span class="sourceLineNo">1502</span>   * Shut down each HStore, don't service any more calls.<a name="line.1502"></a>
+<span class="sourceLineNo">1503</span>   *<a name="line.1503"></a>
+<span class="sourceLineNo">1504</span>   * This method could take some time to execute, so don't call it from a<a name="line.1504"></a>
+<span class="sourceLineNo">1505</span>   * time-sensitive thread.<a name="line.1505"></a>
+<span class="sourceLineNo">1506</span>   *<a name="line.1506"></a>
+<span class="sourceLineNo">1507</span>   * @param abort true if server is aborting (only during testing)<a name="line.1507"></a>
+<span class="sourceLineNo">1508</span>   * @return Vector of all the storage files that the HRegion's component<a name="line.1508"></a>
+<span class="sourceLineNo">1509</span>   * HStores make use of.  It's a list of StoreFile objects.  Can be null if<a name="line.1509"></a>
+<span class="sourceLineNo">1510</span>   * we are not to close at this time or we are already closed.<a name="line.1510"></a>
+<span class="sourceLineNo">1511</span>   *<a name="line.1511"></a>
+<span class="sourceLineNo">1512</span>   * @throws IOException e<a name="line.1512"></a>
+<span class="sourceLineNo">1513</span>   * @throws DroppedSnapshotException Thrown when replay of wal is required<a name="line.1513"></a>
+<span class="sourceLineNo">1514</span>   * because a Snapshot was not properly persisted. The region is put in closing mode, and the<a name="line.1514"></a>
+<span class="sourceLineNo">1515</span>   * caller MUST abort after this.<a name="line.1515"></a>
+<span class="sourceLineNo">1516</span>   */<a name="line.1516"></a>
+<span class="sourceLineNo">1517</span>  public Map&lt;byte[], List&lt;StoreFile&gt;&gt; close(final boolean abort) throws IOException {<a name="line.1517"></a>
+<span class="sourceLineNo">1518</span>    // Only allow one thread to close at a time. Serialize them so dual<a name="line.1518"></a>
+<span class="sourceLineNo">1519</span>    // threads attempting to close will run up against each other.<a name="line.1519"></a>
+<span class="sourceLineNo">1520</span>    MonitoredTask status = TaskMonitor.get().createStatus(<a name="line.1520"></a>
+<span class="sourceLineNo">1521</span>        "Closing region " + this +<a name="line.1521"></a>
+<span class="sourceLineNo">1522</span>        (abort ? " due to abort" : ""));<a name="line.1522"></a>
+<span class="sourceLineNo">1523</span><a name="line.1523"></a>
+<span class="sourceLineNo">1524</span>    status.setStatus("Waiting for close lock");<a name="line.1524"></a>
+<span class="sourceLineNo">1525</span>    try {<a name="line.1525"></a>
+<span class="sourceLineNo">1526</span>      synchronized (closeLock) {<a name="line.1526"></a>
+<span class="sourceLineNo">1527</span>        return doClose(abort, status);<a name="line.1527"></a>
+<span class="sourceLineNo">1528</span>      }<a name="line.1528"></a>
+<span class="sourceLineNo">1529</span>    } finally {<a name="line.1529"></a>
+<span class="sourceLineNo">1530</span>      status.cleanup();<a name="line.1530"></a>
+<span class="sourceLineNo">1531</span>    }<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>  /**<a name="line.1534"></a>
+<span class="sourceLineNo">1535</span>   * Exposed for some very specific unit tests.<a name="line.1535"></a>
+<span class="sourceLineNo">1536</span>   */<a name="line.1536"></a>
+<span class="sourceLineNo">1537</span>  @VisibleForTesting<a name="line.1537"></a>
+<span class="sourceLineNo">1538</span>  public void setClosing(boolean closing) {<a name="line.1538"></a>
+<span class="sourceLineNo">1539</span>    this.closing.set(closing);<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>  /**<a name="line.1542"></a>
+<span class="sourceLineNo">1543</span>   * The {@link HRegion#doClose} will block forever if someone tries proving the dead lock via the unit test.<a name="line.1543"></a>
+<span class="sourceLineNo">1544</span>   * Instead of blocking, the {@link HRegion#doClose} will throw exception if you set the timeout.<a name="line.1544"></a>
+<span class="sourceLineNo">1545</span>   * @param timeoutForWriteLock the second time to wait for the write lock in {@link HRegion#doClose}<a name="line.1545"></a>
+<span class="sourceLineNo">1546</span>   */<a name="line.1546"></a>
+<span class="sourceLineNo">1547</span>  @VisibleForTesting<a name="line.1547"></a>
+<span class="sourceLineNo">1548</span>  public void setTimeoutForWriteLock(long timeoutForWriteLock) {<a name="line.1548"></a>
+<span class="sourceLineNo">1549</span>    assert timeoutForWriteLock &gt;= 0;<a name="line.1549"></a>
+<span class="sourceLineNo">1550</span>    this.timeoutForWriteLock = timeoutForWriteLock;<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>    if (coprocessorHost != null) {<a name="line.1553"></a>
-<span class="sourceLineNo">1554</span>      status.setStatus("Running coprocessor pre-close hooks");<a name="line.1554"></a>
-<span class="sourceLineNo">1555</span>      this.coprocessorHost.preClose(abort);<a name="line.1555"></a>
-<span class="sourceLineNo">1556</span>    }<a name="line.1556"></a>
-<span class="sourceLineNo">1557</span>    status.setStatus("Disabling compacts and flushes for region");<a name="line.1557"></a>
-<span class="sourceLineNo">1558</span>    boolean canFlush = true;<a name="line.1558"></a>
-<span class="sourceLineNo">1559</span>    synchronized (writestate) {<a name="line.1559"></a>
-<span class="sourceLineNo">1560</span>      // Disable compacting and flushing by background threads for this<a name="line.1560"></a>
-<span class="sourceLineNo">1561</span>      // region.<a name="line.1561"></a>
-<span class="sourceLineNo">1562</span>      canFlush = !writestate.readOnly;<a name="line.1562"></a>
-<span class="sourceLineNo">1563</span>      writestate.writesEnabled = false;<a name="line.1563"></a>
-<span class="sourceLineNo">1564</span>      LOG.debug("Closing " + this + ": disabling compactions &amp; flushes");<a name="line.1564"></a>
-<span class="sourceLineNo">1565</span>      waitForFlushesAndCompactions();<a name="line.1565"></a>
-<span class="sourceLineNo">1566</span>    }<a name="line.1566"></a>
-<span class="sourceLineNo">1567</span>    // If we were not just flushing, is it worth doing a preflush...one<a name="line.1567"></a>
-<span class="sourceLineNo">1568</span>    // that will clear out of the bulk of the memstore before we put up<a name="line.1568"></a>
-<span class="sourceLineNo">1569</span>    // the close flag?<a name="line.1569"></a>
-<span class="sourceLineNo">1570</span>    if (!abort &amp;&amp; worthPreFlushing() &amp;&amp; canFlush) {<a name="line.1570"></a>
-<span class="sourceLineNo">1571</span>      status.setStatus("Pre-flushing region before close");<a name="line.1571"></a>
-<span class="sourceLineNo">1572</span>      LOG.info("Running close preflush of " + this);<a name="line.1572"></a>
-<span class="sourceLineNo">1573</span>      try {<a name="line.1573"></a>
-<span class="sourceLineNo">1574</span>        internalFlushcache(status);<a name="line.1574"></a>
-<span class="sourceLineNo">1575</span>      } catch (IOException ioe) {<a name="line.1575"></a>
-<span class="sourceLineNo">1576</span>        // Failed to flush the region. Keep going.<a name="line.1576"></a>
-<span class="sourceLineNo">1577</span>        status.setStatus("Failed pre-flush " + this + "; " + ioe.getMessage());<a name="line.1577"></a>
-<span class="sourceLineNo">1578</span>      }<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>    if (timeoutForWriteLock == null<a name="line.1581"></a>
-<span class="sourceLineNo">1582</span>        || timeoutForWriteLock == Long.MAX_VALUE) {<a name="line.1582"></a>
-<span class="sourceLineNo">1583</span>      // block waiting for the lock for closing<a name="line.1583"></a>
-<span class="sourceLineNo">1584</span>      lock.writeLock().lock(); // FindBugs: Complains UL_UNRELEASED_LOCK_EXCEPTION_PATH but seems fine<a name="line.1584"></a>
-<span class="sourceLineNo">1585</span>    } else {<a name="line.1585"></a>
-<span class="sourceLineNo">1586</span>      try {<a name="line.1586"></a>
-<span class="sourceLineNo">1587</span>        boolean succeed = lock.writeLock().tryLock(timeoutForWriteLock, TimeUnit.SECONDS);<a name="line.1587"></a>
-<span class="sourceLineNo">1588</span>        if (!succeed) {<a name="line.1588"></a>
-<span class="sourceLineNo">1589</span>          throw new IOException("Failed to get write lock when closing region");<a name="line.1589"></a>
-<span class="sourceLineNo">1590</span>        }<a name="line.1590"></a>
-<span class="sourceLineNo">1591</span>      } catch (InterruptedException e) {<a name="line.1591"></a>
-<span class="sourceLineNo">1592</span>        throw (InterruptedIOException) new InterruptedIOException().initCause(e);<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>    this.closing.set(true);<a name="line.1595"></a>
-<span class="sourceLineNo">1596</span>    status.setStatus("Disabling writes for close");<a name="line.1596"></a>
-<span class="sourceLineNo">1597</span>    try {<a name="line.1597"></a>
-<span class="sourceLineNo">1598</span>      if (this.isClosed()) {<a name="line.1598"></a>
-<span class="sourceLineNo">1599</span>        status.abort("Already got closed by another process");<a name="line.1599"></a>
-<span class="sourceLineNo">1600</span>        // SplitTransaction handles the null<a name="line.1600"></a>
-<span class="sourceLineNo">1601</span>        return null;<a name="line.1601"></a>
+<span class="sourceLineNo">1553</span>  @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="UL_UNRELEASED_LOCK_EXCEPTION_PATH",<a name="line.1553"></a>
+<span class="sourceLineNo">1554</span>      justification="I think FindBugs is confused")<a name="line.1554"></a>
+<span class="sourceLineNo">1555</span>  private Map&lt;byte[], List&lt;StoreFile&gt;&gt; doClose(final boolean abort, MonitoredTask status)<a name="line.1555"></a>
+<span class="sourceLineNo">1556</span>      throws IOException {<a name="line.1556"></a>
+<span class="sourceLineNo">1557</span>    if (isClosed()) {<a name="line.1557"></a>
+<span class="sourceLineNo">1558</span>      LOG.warn("Region " + this + " already closed");<a name="line.1558"></a>
+<span class="sourceLineNo">1559</span>      return null;<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>    if (coprocessorHost != null) {<a name="line.1562"></a>
+<span class="sourceLineNo">1563</span>      status.setStatus("Running coprocessor pre-close hooks");<a name="line.1563"></a>
+<span class="sourceLineNo">1564</span>      this.coprocessorHost.preClose(abort);<a name="line.1564"></a>
+<span class="sourceLineNo">1565</span>    }<a name="line.1565"></a>
+<span class="sourceLineNo">1566</span>    status.setStatus("Disabling compacts and flushes for region");<a name="line.1566"></a>
+<span class="sourceLineNo">1567</span>    boolean canFlush = true;<a name="line.1567"></a>
+<span class="sourceLineNo">1568</span>    synchronized (writestate) {<a name="line.1568"></a>
+<span class="sourceLineNo">1569</span>      // Disable compacting and flushing by background threads for this<a name="line.1569"></a>
+<span class="sourceLineNo">1570</span>      // region.<a name="line.1570"></a>
+<span class="sourceLineNo">1571</span>      canFlush = !writestate.readOnly;<a name="line.1571"></a>
+<span class="sourceLineNo">1572</span>      writestate.writesEnabled = false;<a name="line.1572"></a>
+<span class="sourceLineNo">1573</span>      LOG.debug("Closing " + this + ": disabling compactions &amp; flushes");<a name="line.1573"></a>
+<span class="sourceLineNo">1574</span>      waitForFlushesAndCompactions();<a name="line.1574"></a>
+<span class="sourceLineNo">1575</span>    }<a name="line.1575"></a>
+<span class="sourceLineNo">1576</span>    // If we were not just flushing, is it worth doing a preflush...one<a name="line.1576"></a>
+<span class="sourceLineNo">1577</span>    // that will clear out of the bulk of the memstore before we put up<a name="line.1577"></a>
+<span class="sourceLineNo">1578</span>    // the close flag?<a name="line.1578"></a>
+<span class="sourceLineNo">1579</span>    if (!abort &amp;&amp; worthPreFlushing() &amp;&amp; canFlush) {<a name="line.1579"></a>
+<span class="sourceLineNo">1580</span>      status.setStatus("Pre-flushing region before close");<a name="line.1580"></a>
+<span class="sourceLineNo">1581</span>      LOG.info("Running close preflush of " + this);<a name="line.1581"></a>
+<span class="sourceLineNo">1582</span>      try {<a name="line.1582"></a>
+<span class="sourceLineNo">1583</span>        internalFlushcache(status);<a name="line.1583"></a>
+<span class="sourceLineNo">1584</span>      } catch (IOException ioe) {<a name="line.1584"></a>
+<span class="sourceLineNo">1585</span>        // Failed to flush the region. Keep going.<a name="line.1585"></a>
+<span class="sourceLineNo">1586</span>        status.setStatus("Failed pre-flush " + this + "; " + ioe.getMessage());<a name="line.1586"></a>
+<span class="sourceLineNo">1587</span>      }<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>    if (timeoutForWriteLock == null<a name="line.1590"></a>
+<span class="sourceLineNo">1591</span>        || timeoutForWriteLock == Long.MAX_VALUE) {<a name="line.1591"></a>
+<span class="sourceLineNo">1592</span>      // block waiting for the lock for closing<a name="line.1592"></a>
+<span class="sourceLineNo">1593</span>      lock.writeLock().lock(); // FindBugs: Complains UL_UNRELEASED_LOCK_EXCEPTION_PATH but seems fine<a name="line.1593"></a>
+<span class="sourceLineNo">1594</span>    } else {<a name="line.1594"></a>
+<span class="sourceLineNo">1595</span>      try {<a name="line.1595"></a>
+<span class="sourceLineNo">1596</span>        boolean succeed = lock.writeLock().tryLock(timeoutForWriteLock, TimeUnit.SECONDS);<a name="line.1596"></a>
+<span class="sourceLineNo">1597</span>        if (!succeed) {<a name="line.1597"></a>
+<span class="sourceLineNo">1598</span>          throw new IOException("Failed to get write lock when closing region");<a name="line.1598"></a>
+<span class="sourceLineNo">1599</span>        }<a name="line.1599"></a>
+<span class="sourceLineNo">1600</span>      } catch (InterruptedException e) {<a name="line.1600"></a>
+<span class="sourceLineNo">1601</span>        throw (InterruptedIOException) new InterruptedIOException().initCause(e);<a name="line.1601"></a>
 <span class="sourceLineNo">1602</span>      }<a name="line.1602"></a>
-<span class="sourceLineNo">1603</span>      LOG.debug("Updates disabled for region " + this);<a name="line.1603"></a>
-<span class="sourceLineNo">1604</span>      // Don't flush the cache if we are aborting<a name="line.1604"></a>
-<span class="sourceLineNo">1605</span>      if (!abort &amp;&amp; canFlush) {<a name="line.1605"></a>
-<span class="sourceLineNo">1606</span>        int failedfFlushCount = 0;<a name="line.1606"></a>
-<span class="sourceLineNo">1607</span>        int flushCount = 0;<a name="line.1607"></a>
-<span class="sourceLineNo">1608</span>        long tmp = 0;<a name="line.1608"></a>
-<span class="sourceLineNo">1609</span>        long remainingSize = this.memstoreDataSize.get();<a name="line.1609"></a>
-<span class="sourceLineNo">1610</span>        while (remainingSize &gt; 0) {<a name="line.1610"></a>
-<span class="sourceLineNo">1611</span>          try {<a name="line.1611"></a>
-<span class="sourceLineNo">1612</span>            internalFlushcache(status);<a name="line.1612"></a>
-<span class="sourceLineNo">1613</span>            if(flushCount &gt;0) {<a name="line.1613"></a>
-<span class="sourceLineNo">1614</span>              LOG.info("Running extra flush, " + flushCount +<a name="line.1614"></a>
-<span class="sourceLineNo">1615</span>                  " (carrying snapshot?) " + this);<a name="line.1615"></a>
-<span class="sourceLineNo">1616</span>            }<a name="line.1616"></a>
-<span class="sourceLineNo">1617</span>            flushCount++;<a name="line.1617"></a>
-<span class="sourceLineNo">1618</span>            tmp = this.memstoreDataSize.get();<a name="line.1618"></a>
-<span class="sourceLineNo">1619</span>            if (tmp &gt;= remainingSize) {<a name="line.1619"></a>
-<span class="sourceLineNo">1620</span>              failedfFlushCount++;<a name="line.1620"></a>
-<span class="sourceLineNo">1621</span>            }<a name="line.1621"></a>
-<span class="sourceLineNo">1622</span>            remainingSize = tmp;<a name="line.1622"></a>
-<span class="sourceLineNo">1623</span>            if (failedfFlushCount &gt; 5) {<a name="line.1623"></a>
-<span class="sourceLineNo">1624</span>              // If we failed 5 times and are unable to clear memory, abort<a name="line.1624"></a>
-<span class="sourceLineNo">1625</span>              // so we do not lose data<a name="line.1625"></a>
-<span class="sourceLineNo">1626</span>              throw new DroppedSnapshotException("Failed clearing memory after " +<a name="line.1626"></a>
-<span class="sourceLineNo">1627</span>                  flushCount + " attempts on region: " +<a name="line.1627"></a>
-<span class="sourceLineNo">1628</span>                  Bytes.toStringBinary(getRegionInfo().getRegionName()));<a name="line.1628"></a>
-<span class="sourceLineNo">1629</span>            }<a name="line.1629"></a>
-<span class="sourceLineNo">1630</span>          } catch (IOException ioe) {<a name="line.1630"></a>
-<span class="sourceLineNo">1631</span>            status.setStatus("Failed flush " + this + ", putting online again");<a name="line.1631"></a>
-<span class="sourceLineNo">1632</span>            synchronized (writestate) {<a name="line.1632"></a>
-<span class="sourceLineNo">1633</span>              writestate.writesEnabled = true;<a name="line.1633"></a>
-<span class="sourceLineNo">1634</span>            }<a name="line.1634"></a>
-<span class="sourceLineNo">1635</span>            // Have to throw to upper layers.  I can't abort server from here.<a name="line.1635"></a>
-<span class="sourceLineNo">1636</span>            throw ioe;<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>      }<a name="line.1639"></a>
-<span class="sourceLineNo">1640</span><a name="line.1640"></a>
-<span class="sourceLineNo">1641</span>      Map&lt;byte[], List&lt;StoreFile&gt;&gt; result = new TreeMap&lt;&gt;(Bytes.BYTES_COMPARATOR);<a name="line.1641"></a>
-<span class="sourceLineNo">1642</span>      if (!stores.isEmpty()) {<a name="line.1642"></a>
-<span class="sourceLineNo">1643</span>        // initialize the thread pool for closing stores in parallel.<a name="line.1643"></a>
-<span class="sourceLineNo">1644</span>        ThreadPoolExecutor storeCloserThreadPool =<a name="line.1644"></a>
-<span class="sourceLineNo">1645</span>          getStoreOpenAndCloseThreadPool("StoreCloserThread-" +<a name="line.1645"></a>
-<span class="sourceLineNo">1646</span>            getRegionInfo().getRegionNameAsString());<a name="line.1646"></a>
-<span class="sourceLineNo">1647</span>        CompletionService&lt;Pair&lt;byte[], Collection&lt;StoreFile&gt;&gt;&gt; completionService =<a name="line.1647"></a>
-<span class="sourceLineNo">1648</span>          new ExecutorCompletionService&lt;&gt;(storeCloserThreadPool);<a name="line.1648"></a>
+<span class="sourceLineNo">1603</span>    }<a name="line.1603"></a>
+<span class="sourceLineNo">1604</span>    this.closing.set(true);<a name="line.1604"></a>
+<span class="sourceLineNo">1605</span>    status.setStatus("Disabling writes for close");<a name="line.1605"></a>
+<span class="sourceLineNo">1606</span>    try {<a name="line.1606"></a>
+<span class="sourceLineNo">1607</span>      if (this.isClosed()) {<a name="line.1607"></a>
+<span class="sourceLineNo">1608</span>        status.abort("Already got closed by another process");<a name="line.1608"></a>
+<span class="sourceLineNo">1609</span>        // SplitTransaction handles the null<a name="line.1609"></a>
+<span class="sourceLineNo">1610</span>        return null;<a name="line.1610"></a>
+<span class="sourceLineNo">1611</span>      }<a name="line.1611"></a>
+<span class="sourceLineNo">1612</span>      LOG.debug("Updates disabled for region " + this);<a name="line.1612"></a>
+<span class="sourceLineNo">1613</span>      // Don't flush the cache if we are aborting<a name="line.1613"></a>
+<span class="sourceLineNo">1614</span>      if (!abort &amp;&amp; canFlush) {<a name="line.1614"></a>
+<span class="sourceLineNo">1615</span>        int failedfFlushCount = 0;<a name="line.1615"></a>
+<span class="sourceLineNo">1616</span>        int flushCount = 0;<a name="line.1616"></a>
+<span class="sourceLineNo">1617</span>        long tmp = 0;<a name="line.1617"></a>
+<span class="sourceLineNo">1618</span>        long remainingSize = this.memstoreDataSize.get();<a name="line.1618"></a>
+<span class="sourceLineNo">1619</span>        while (remainingSize &gt; 0) {<a name="line.1619"></a>
+<span class="sourceLineNo">1620</span>          try {<a name="line.1620"></a>
+<span class="sourceLineNo">1621</span>            internalFlushcache(status);<a name="line.1621"></a>
+<span class="sourceLineNo">1622</span>            if(flushCount &gt;0) {<a name="line.1622"></a>
+<span class="sourceLineNo">1623</span>              LOG.info("Running extra flush, " + flushCount +<a name="line.1623"></a>
+<span class="sourceLineNo">1624</span>                  " (carrying snapshot?) " + this);<a name="line.1624"></a>
+<span class="sourceLineNo">1625</span>            }<a name="line.1625"></a>
+<span class="sourceLineNo">1626</span>            flushCount++;<a name="line.1626"></a>
+<span class="sourceLineNo">1627</span>            tmp = this.memstoreDataSize.get();<a name="line.1627"></a>
+<span class="sourceLineNo">1628</span>            if (tmp &gt;= remainingSize) {<a name="line.1628"></a>
+<span class="sourceLineNo">1629</span>              failedfFlushCount++;<a name="line.1629"></a>
+<span class="sourceLineNo">1630</span>            }<a name="line.1630"></a>
+<span class="sourceLineNo">1631</span>            remainingSize = tmp;<a name="line.1631"></a>
+<span class="sourceLineNo">1632</span>            if (failedfFlushCount &gt; 5) {<a name="line.1632"></a>
+<span class="sourceLineNo">1633</span>              // If we failed 5 times and are unable to clear memory, abort<a name="line.1633"></a>
+<span class="sourceLineNo">1634</span>              // so we do not lose data<a name="line.1634"></a>
+<span class="sourceLineNo">1635</span>              throw new DroppedSnapshotException("Failed clearing memory after " +<a name="line.1635"></a>
+<span class="sourceLineNo">1636</span>                  flushCount + " attempts on region: " +<a name="line.1636"></a>
+<span class="sourceLineNo">1637</span>                  Bytes.toStringBinary(getRegionInfo().getRegionName()));<a name="line.1637"></a>
+<span class="sourceLineNo">1638</span>            }<a name="line.1638"></a>
+<span class="sourceLineNo">1639</span>          } catch (IOException ioe) {<a name="line.1639"></a>
+<span class="sourceLineNo">1640</span>            status.setStatus("Failed flush " + this + ", putting online again");<a name="line.1640"></a>
+<span class="sourceLineNo">1641</span>            synchronized (writestate) {<a name="line.1641"></a>
+<span class="sourceLineNo">1642</span>              writestate.writesEnabled = true;<a name="line.1642"></a>
+<span class="sourceLineNo">1643</span>            }<a name="line.1643"></a>
+<span class="sourceLineNo">1644</span>            // Have to throw to upper layers.  I can't abort server from here.<a name="line.1644"></a>
+<span class="sourceLineNo">1645</span>            throw ioe;<a name="line.1645"></a>
+<span class="sourceLineNo">1646</span>          }<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><a name="line.1649"></a>
-<span class="sourceLineNo">1650</span>        // close each store in parallel<a name="line.1650"></a>
-<span class="sourceLineNo">1651</span>        for (final Store store : stores.values()) {<a name="line.1651"></a>
-<span class="sourceLineNo">1652</span>          MemstoreSize flushableSize = store.getSizeToFlush();<a name="line.1652"></a>
-<span class="sourceLineNo">1653</span>          if (!(abort || flushableSize.getDataSize() == 0 || writestate.readOnly)) {<a name="line.1653"></a>
-<span class="sourceLineNo">1654</span>            if (getRegionServerServices() != null) {<a name="line.1654"></a>
-<span class="sourceLineNo">1655</span>              getRegionServerServices().abort("Assertion failed while closing store "<a name="line.1655"></a>
-<span class="sourceLineNo">1656</span>                + getRegionInfo().getRegionNameAsString() + " " + store<a name="line.1656"></a>
-<span class="sourceLineNo">1657</span>                + ". flushableSize expected=0, actual= " + flushableSize<a name="line.1657"></a>
-<span class="sourceLineNo">1658</span>                + ". Current memstoreSize=" + getMemstoreSize() + ". Maybe a coprocessor "<a name="line.1658"></a>
-<span class="sourceLineNo">1659</span>                + "operation failed and left the memstore in a partially updated state.", null);<a name="line.1659"></a>
-<span class="sourceLineNo">1660</span>            }<a name="line.1660"></a>
-<span class="sourceLineNo">1661</span>          }<a name="line.1661"></a>
-<span class="sourceLineNo">1662</span>          completionService<a name="line.1662"></a>
-<span class="sourceLineNo">1663</span>              .submit(new Callable&lt;Pair&lt;byte[], Collection&lt;StoreFile&gt;&gt;&gt;() {<a name="line.1663"></a>
-<span class="sourceLineNo">1664</span>                @Override<a name="line.1664"></a>
-<span class="sourceLineNo">1665</span>                public Pair&lt;byte[], Collection&lt;StoreFile&gt;&gt; call() throws IOException {<a name="line.1665"></a>
-<span class="sourceLineNo">1666</span>                  return new Pair&lt;&gt;(store.getFamily().getName(), store.close());<a name="line.1666"></a>
-<span class="sourceLineNo">1667</span>                }<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>        try {<a name="line.1670"></a>
-<span class="sourceLineNo">1671</span>          for (int i = 0; i &lt; stores.size(); i++) {<a name="line.1671"></a>
-<span class="sourceLineNo">1672</span>            Future&lt;Pair&lt;byte[], Collection&lt;StoreFile&gt;&gt;&gt; future = completionService.take();<a name="line.1672"></a>
-<span class="sourceLineNo">1673</span>            Pair&lt;byte[], Collection&lt;StoreFile&gt;&gt; storeFiles = future.get();<a name="line.1673"></a>
-<span class="sourceLineNo">1674</span>            List&lt;StoreFile&gt; familyFiles = result.get(storeFiles.getFirst());<a name="line.1674"></a>
-<span class="sourceLineNo">1675</span>            if (familyFiles == null) {<a name="line.1675"></a>
-<span class="sourceLineNo">1676</span>              familyFiles = new ArrayList&lt;&gt;();<a name="line.1676"></a>
-<span class="sourceLineNo">1677</span>              result.put(storeFiles.getFirst(), familyFiles);<a name="line.1677"></a>
-<span class="sourceLineNo">1678</span>            }<a name="line.1678"></a>
-<span class="sourceLineNo">1679</span>            familyFiles.addAll(storeFiles.getSecond());<a name="line.1679"></a>
-<span class="sourceLineNo">1680</span>          }<a name="line.1680"></a>
-<span class="sourceLineNo">1681</span>        } catch (InterruptedException e) {<a name="line.1681"></a>
-<span class="sourceLineNo">1682</span>          throw (InterruptedIOException)new InterruptedIOException().initCause(e);<a name="line.1682"></a>
-<span class="sourceLineNo">1683</span>        } catch (ExecutionException e) {<a name="line.1683"></a>
-<span class="sourceLineNo">1684</span>          Throwable cause = e.getCause();<a name="line.1684"></a>
-<span class="sourceLineNo">1685</span>          if (cause instanceof IOException) {<a name="line.1685"></a>
-<span class="sourceLineNo">1686</span>            throw (IOException) cause;<a name="line.1686"></a>
-<span class="sourceLineNo">1687</span>          }<a name="line.1687"></a>
-<span class="sourceLineNo">1688</span>          throw new IOException(cause);<a name="line.1688"></a>
-<span class="sourceLineNo">1689</span>        } finally {<a name="line.1689"></a>
-<span class="sourceLineNo">1690</span>          storeCloserThreadPool.shutdownNow();<a name="line.1690"></a>
-<span class="sourceLineNo">1691</span>        }<a name="line.1691"></a>
-<span class="sourceLineNo">1692</span>      }<a name="line.1692"></a>
-<span class="sourceLineNo">1693</span><a name="line.1693"></a>
-<span class="sourceLineNo">1694</span>      status.setStatus("Writing region close event to WAL");<a name="line.1694"></a>
-<span class="sourceLineNo">1695</span>      if (!abort &amp;&amp; wal != null &amp;&amp; getRegionServerServices() != null &amp;&amp; !writestate.readOnly) {<a name="line.1695"></a>
-<span class="sourceLineNo">1696</span>        writeRegionCloseMarker(wal);<a name="line.1696"></a>
-<span class="sourceLineNo">1697</span>      }<a name="line.1697"></a>
-<span class="sourceLineNo">1698</span><a name="line.1698"></a>
-<span class="sourceLineNo">1699</span>      this.closed.set(true);<a name="line.1699"></a>
-<span class="sourceLineNo">1700</span>      if (!canFlush) {<a name="line.1700"></a>
-<span class="sourceLineNo">1701</span>        this.decrMemstoreSize(new MemstoreSize(memstoreDataSize.get(), getMemstoreHeapSize()));<a name="line.1701"></a>
-<span class="sourceLineNo">1702</span>      } else if (memstoreDataSize.get() != 0) {<a name="line.1702"></a>
-<span class="sourceLineNo">1703</span>        LOG.error("Memstore size is " + memstoreDataSize.get());<a name="line.1703"></a>
-<span class="sourceLineNo">1704</span>      }<a name="line.1704"></a>
-<span class="sourceLineNo">1705</span>      if (coprocessorHost != null) {<a name="line.1705"></a>
-<span class="sourceLineNo">1706</span>        status.setStatus("Running coprocessor post-close hooks");<a name="line.1706"></a>
-<span class="sourceLineNo">1707</span>        this.coprocessorHost.postClose(abort);<a name="line.1707"></a>
-<span class="sourceLineNo">1708</span>      }<a name="line.1708"></a>
-<span class="sourceLineNo">1709</span>      if (this.metricsRegion != null) {<a name="line.1709"></a>
-<span class="sourceLineNo">1710</span>        this.metricsRegion.close();<a name="line.1710"></a>
-<span class="sourceLineNo">1711</span>      }<a name="line.1711"></a>
-<span class="sourceLineNo">1712</span>      if (this.metricsRegionWrapper != null) {<a name="line.1712"></a>
-<span class="sourceLineNo">1713</span>        Closeables.closeQuietly(this.metricsRegionWrapper);<a name="line.1713"></a>
-<span class="sourceLineNo">1714</span>      }<a name="line.1714"></a>
-<span class="sourceLineNo">1715</span>      status.markComplete("Closed");<a name="line.1715"></a>
-<span class="sourceLineNo">1716</span>      LOG.info("Closed " + this);<a name="line.1716"></a>
-<span class="sourceLineNo">1717</span>      return result;<a name="line.1717"></a>
-<span class="sourceLineNo">1718</span>    } finally {<a name="line.1718"></a>
-<span class="sourceLineNo">1719</span>      lock.writeLock().unlock();<a name="line.1719"></a>
-<span class="sourceLineNo">1720</span>    }<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>  private long getMemstoreHeapSize() {<a name="line.1723"></a>
-<span class="sourceLineNo">1724</span>    long size = 0;<a name="line.1724"></a>
-<span class="sourceLineNo">1725</span>    for (Store s : this.stores.values()) {<a name="line.1725"></a>
-<span class="sourceLineNo">1726</span>      size += s.getSizeOfMemStore().getHeapSize();<a name="line.1726"></a>
-<span class="sourceLineNo">1727</span>    }<a name="line.1727"></a>
-<span class="sourceLineNo">1728</span>    return size;<a name="line.1728"></a>
-<span class="sourceLineNo">1729</span>  }<a name="line.1729"></a>
-<span class="sourceLineNo">1730</span><a name="line.1730"></a>
-<span class="sourceLineNo">1731</span>  @Override<a name="line.1731"></a>
-<span class="sourceLineNo">1732</span>  public void waitForFlushesAndCompactions() {<a name="line.1732"></a>
-<span class="sourceLineNo">1733</span>    synchronized (writestate) {<a name="line.1733"></a>
-<span class="sourceLineNo">1734</span>      if (this.writestate.readOnly) {<a name="line.1734"></a>
-<span class="sourceLineNo">1735</span>        // we should not wait for replayed flushed if we are read only (for example in case the<a name="line.1735"></a>
-<span class="sourceLineNo">1736</span>        // region is a secondary replica).<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>      boolean interrupted = false;<a name="line.1739"></a>
-<span class="sourceLineNo">1740</span>      try {<a name="line.1740"></a>
-<span class="sourceLineNo">1741</span>        while (writestate.compacting.get() &gt; 0 || writestate.flushing) {<a name="line.1741"></a>
-<span class="sourceLineNo">1742</span>          LOG.debug("waiting for " + writestate.compacting + " compactions"<a name="line.1742"></a>
-<span class="sourceLineNo">1743</span>            + (writestate.flushing ? " &amp; cache flush" : "") + " to complete for region " + this);<a name="line.1743"></a>
-<span class="sourceLineNo">1744</span>          try {<a name="line.1744"></a>
-<span class="sourceLineNo">1745</span>            writestate.wait();<a name="line.1745"></a>
-<span class="sourceLineNo">1746</span>          } catch (InterruptedException iex) {<a name="line.1746"></a>
-<span class="sourceLineNo">1747</span>            // essentially ignore and propagate the interrupt back up<a name="line.1747"></a>
-<span class="sourceLineNo">1748</span>            LOG.warn("Interrupted while waiting");<a name="line.1748"></a>
-<span class="sourceLineNo">1749</span>            interrupted = true;<a name="line.1749"></a>
-<span class="sourceLineNo">1750</span>          }<a name="line.1750"></a>
-<span class="sourceLineNo">1751</span>        }<a name="line.1751"></a>
-<span class="sourceLineNo">1752</span>      } finally {<a name="line.1752"></a>
-<span class="sourceLineNo">1753</span>        if (interrupted) {<a name="line.1753"></a>
-<span class="sourceLineNo">1754</span>          Thread.currentThread().interrupt();<a name="line.1754"></a>
-<span class="sourceLineNo">1755</span>        }<a name="line.1755"></a>
-<span class="sourceLineNo">1756</span>      }<a name="line.1756"></a>
-<span class="sourceLineNo">1757</span>    }<a name="line.1757"></a>
-<span class="sourceLineNo">1758</span>  }<a name="line.1758"></a>
-<span class="sourceLineNo">1759</span><a name="line.1759"></a>
-<span class="sourceLineNo">1760</span>  @Override<a name="line.1760"></a>
-<span class="sourceLineNo">1761</span>  public void waitForFlushes() {<a name="line.1761"></a>
-<span class="sourceLineNo">1762</span>    synchronized (writestate) {<a name="line.1762"></a>
-<span class="sourceLineNo">1763</span>      if (this.writestate.readOnly) {<a name="line.1763"></a>
-<span class="sourceLineNo">1764</span>        // we should not wait for replayed flushed if we are read only (for example in case the<a name="line.1764"></a>
-<span class="sourceLineNo">1765</span>        // region is a secondary replica).<a name="line.1765"></a>
-<span class="sourceLineNo">1766</span>        return;<a name="line.1766"></a>
-<span class="sourceLineNo">1767</span>      }<a name="line.1767"></a>
-<span class="sourceLineNo">1768</span>      if (!writestate.flushing) return;<a name="line.1768"></a>
-<span class="sourceLineNo">1769</span>      long start = System.currentTimeMillis();<a name="line.1769"></a>
-<span class="sourceLineNo">1770</span>      boolean interrupted = false;<a name="line.1770"></a>
-<span class="sourceLineNo">1771</span>      try {<a name="line.1771"></a>
-<span class="sourceLineNo">1772</span>        while (writestate.flushing) {<a name="line.1772"></a>
-<span class="sourceLineNo">1773</span>          LOG.debug("waiting for cache flush to complete for region " + this);<a name="line.1773"></a>
-<span class="sourceLineNo">1774</span>          try {<a name="line.1774"></a>
-<span class="sourceLineNo">1775</span>            writestate.wait();<a name="line.1775"></a>
-<span class="sourceLineNo">1776</span>          } catch (InterruptedException iex) {<a name="line.1776"></a>
-<span class="sourceLineNo">1777</span>            // essentially ignore and propagate the interrupt back up<a name="line.1777"></a>
-<span class="sourceLineNo">1778</span>            LOG.warn("Interrupted while waiting");<a name="line.1778"></a>
-<span class="sourceLineNo">1779</span>            interrupted = true;<a name="line.1779"></a>
-<span class="sourceLineNo">1780</span>          }<a name="line.1780"></a>
-<span class="sourceLineNo">1781</span>        }<a name="line.1781"></a>
-<span class="sourceLineNo">1782</span>      } finally {<a name="line.1782"></a>
-<span class="sourceLineNo">1783</span>        if (interrupted) {<a name="line.1783"></a>
-<span class="sourceLineNo">1784</span>          Thread.currentThread().interrupt();<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>      long duration = System.currentTimeMillis() - start;<a name="line.1787"></a>
-<span class="sourceLineNo">1788</span>      LOG.debug("Waited " + duration + " ms for flush to complete");<a name="line.1788"></a>
-<span class="sourceLineNo">1789</span>    }<a name="line.1789"></a>
-<span class="sourceLineNo">1790</span>  }<a name="line.1790"></a>
-<span class="sourceLineNo">1791</span>  protected ThreadPoolExecutor getStoreOpenAndCloseThreadPool(<a name="line.1791"></a>
-<span class="sourceLineNo">1792</span>      final String threadNamePrefix) {<a name="line.1792"></a>
-<span class="sourceLineNo">1793</span>    int numStores = Math.max(1, this.htableDescriptor.getFamilies().size());<a name="line.1793"></a>
-<span class="sourceLineNo">1794</span>    int maxThreads = Math.min(numStores,<a name="line.1794"></a>
-<span class="sourceLineNo">1795</span>        conf.getInt(HConstants.HSTORE_OPEN_AND_CLOSE_THREADS_MAX,<a name="line.1795"></a>
-<span class="sourceLineNo">1796</span>            HConstants.DEFAULT_HSTORE_OPEN_AND_CLOSE_THREADS_MAX));<a name="line.1796"></a>
-<span class="sourceLineNo">1797</span>    return getOpenAndCloseThreadPool(maxThreads, threadNamePrefix);<a name="line.1797"></a>
-<span class="sourceLineNo">1798</span>  }<a name="line.1798"></a>
-<span class="sourceLineNo">1799</span><a name="line.1799"></a>
-<span class="sourceLineNo">1800</span>  protected ThreadPoolExecutor getStoreFileOpenAndCloseThreadPool(<a name="line.1800"></a>
+<span class="sourceLineNo">1650</span>      Map&lt;byte[], List&lt;StoreFile&gt;&gt; result = new TreeMap&lt;&gt;(Bytes.BYTES_COMPARATOR);<a name="line.1650"></a>
+<span class="sourceLineNo">1651</span>      if (!stores.isEmpty()) {<a name="line.1651"></a>
+<span class="sourceLineNo">1652</span>        // initialize the thread pool for closing stores in parallel.<a name="line.1652"></a>
+<span class="sourceLineNo">1653</span>        ThreadPoolExecutor storeCloserThreadPool =<a name="line.1653"></a>
+<span class="sourceLineNo">1654</span>          getStoreOpenAndCloseThreadPool("StoreCloserThread-" +<a name="line.1654"></a>
+<span class="sourceLineNo">1655</span>            getRegionInfo().getRegionNameAsString());<a name="line.1655"></a>
+<span class="sourceLineNo">1656</span>        CompletionService&lt;Pair&lt;byte[], Collection&lt;StoreFile&gt;&gt;&gt; completionService =<a name="line.1656"></a>
+<span class="sourceLineNo">1657</span>          new ExecutorCompletionService&lt;&gt;(storeCloserThreadPool);<a name="line.1657"></a>
+<span class="sourceLineNo">1658</span><a name="line.1658"></a>
+<span class="sourceLineNo">1659</span>        // close each store in parallel<a name="line.1659"></a>
+<span class="sourceLineNo">1660</span>        for (final Store store : stores.values()) {<a name="line.1660"></a>
+<span class="sourceLineNo">1661</span>          MemstoreSize flushableSize = store.getSizeToFlush();<a name="line.1661"></a>
+<span class="sourceLineNo">1662</span>          if (!(abort || flushableSize.getDataSize() == 0 || writestate.readOnly)) {<a name="line.1662"></a>
+<span class="sourceLineNo">1663</span>            if (getRegionServerServices() != null) {<a name="line.1663"></a>
+<span class="sourceLineNo">1664</span>              getRegionServerServices().abort("Assertion failed while closing store "<a name="line.1664"></a>
+<span class="sourceLineNo">1665</span>                + getRegionInfo().getRegionNameAsString() + " " + store<a name="line.1665"></a>
+<span class="sourceLineNo">1666</span>                + ". flushableSize expected=0, actual= " + flushableSize<a name="line.1666"></a>
+<span class="sourceLineNo">1667</span>                + ". Current memstoreSize=" + getMemstoreSize() + ". Maybe a coprocessor "<a name="line.1667"></a>
+<span class="sourceLineNo">1668</span>                + "operation failed and left the memstore in a partially updated state.", null);<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>          completionService<a name="line.1671"></a>
+<span class="sourceLineNo">1672</span>              .submit(new Callable&lt;Pair&lt;byte[], Collection&lt;StoreFile&gt;&gt;&gt;() {<a name="line.1672"></a>
+<span class="sourceLineNo">1673</span>                @Override<a name="line.1673"></a>
+<span class="sourceLineNo">1674</span>                public Pair&lt;byte[], Collection&lt;StoreFile&gt;&gt; call() throws IOException {<a name="line.1674"></a>
+<span class="sourceLineNo">1675</span>                  return new Pair&lt;&gt;(store.getFamily().getName(), store.close());<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>        }<a name="line.1678"></a>
+<span class="sourceLineNo">1679</span>        try {<a name="line.1679"></a>
+<span class="sourceLineNo">1680</span>          for (int i = 0; i &lt; stores.size(); i++) {<a name="line.1680"></a>
+<span class="sourceLineNo">1681</span>            Future&lt;Pair&lt;byte[], Collection&lt;StoreFile&gt;&gt;&gt; future = completionService.take();<a name="line.1681"></a>
+<span class="sourceLineNo">1682</span>            Pair&lt;byte[], Collection&lt;StoreFile&gt;&gt; storeFiles = future.get();<a name="line.1682"></a>
+<span class="sourceLineNo">1683</span>            List&lt;StoreFile&gt; familyFiles = result.get(storeFiles.getFirst());<a name="line.1683"></a>
+<span class="sourceLineNo">1684</span>            if (familyFiles == null) {<a name="line.1684"></a>
+<span class="sourceLineNo">1685</span>              familyFiles = new ArrayList&lt;&gt;();<a name="line.1685"></a>
+<span class="sourceLineNo">1686</span>              result.put(storeFiles.getFirst(), familyFiles);<a name="line.1686"></a>
+<span class="sourceLineNo">1687</span>            }<a name="line.1687"></a>
+<span class="sourceLineNo">1688</span>            familyFiles.addAll(storeFiles.getSecond());<a name="line.1688"></a>
+<span class="sourceLineNo">1689</span>          }<a name="line.1689"></a>
+<span class="sourceLineNo">1690</span>        } catch (InterruptedException e) {<a name="line.1690"></a>
+<span class="sourceLineNo">1691</span>          throw (InterruptedIOException)new InterruptedIOException().initCause(e);<a name="line.1691"></a>
+<span class="sourceLineNo">1692</span>        } catch (ExecutionException e) {<a name="line.1692"></a>
+<span class="sourceLineNo">1693</span>          Throwable cause = e.getCause();<a name="line.1693"></a>
+<span class="sourceLineNo">1694</span>          if (cause instanceof IOException) {<a name="line.1694"></a>
+<span class="sourceLineNo">1695</span>            throw (IOException) cause;<a name="line.1695"></a>
+<span class="sourceLineNo">1696</span>          }<a name="line.1696"></a>
+<span class="sourceLineNo">1697</span>          throw new IOException(cause);<a name="line.1697"></a>
+<span class="sourceLineNo">1698</span>        } finally {<a name="line.1698"></a>
+<span class="sourceLineNo">1699</span>          storeCloserThreadPool.shutdownNow();<a name="line.1699"></a>
+<span class="sourceLineNo">1700</span>        }<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>      status.setStatus("Writing region close event to WAL");<a name="line.1703"></a>
+<span class="sourceLineNo">1704</span>      if (!abort &amp;&amp; wal != null &amp;&amp; getRegionServerServices() != null &amp;&amp; !writestate.readOnly) {<a name="line.1704"></a>
+<span class="sourceLineNo">1705</span>        writeRegionCloseMarker(wal);<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>      this.closed.set(true);<a name="line.1708"></a>
+<span class="sourceLineNo">1709</span>      if (!canFlush) {<a name="line.1709"></a>
+<span class="sourceLineNo">1710</span>        this.decrMemstoreSize(new MemstoreSize(memstoreDataSize.get(), getMemstoreHeapSize()));<a name="line.1710"></a>
+<span class="sourceLineNo">1711</span>      } else if (memstoreDataSize.get() != 0) {<a name="line.1711"></a>
+<span class="sourceLineNo">1712</span>        LOG.error("Memstore size is " + memstoreDataSize.get());<a name="line.1712"></a>
+<span class="sourceLineNo">1713</span>      }<a name="line.1713"></a>
+<span class="sourceLineNo">1714</span>      if (coprocessorHost != null) {<a name="line.1714"></a>
+<span class="sourceLineNo">1715</span>        status.setStatus("Running coprocessor post-close hooks");<a name="line.1715"></a>
+<span class="sourceLineNo">1716</span>        this.coprocessorHost.postClose(abort);<a name="line.1716"></a>
+<span class="sourceLineNo">1717</span>      }<a name="line.1717"></a>
+<span class="sourceLineNo">1718</span>      if (this.metricsRegion != null) {<a name="line.1718"></a>
+<span class="sourceLineNo">1719</span>        this.metricsRegion.close();<a name="line.1719"></a>
+<span class="sourceLineNo">1720</span>      }<a name="line.1720"></a>
+<span class="sourceLineNo">1721</span>      if (this.metricsRegionWrapper != null) {<a name="line.1721"></a>
+<span class="sourceLineNo">1722</span>        Closeables.closeQuietly(this.metricsRegionWrapper);<a name="line.1722"></a>
+<span class="sourceLineNo">1723</span>      }<a name="line.1723"></a>
+<span class="sourceLineNo">1724</span>      status.markComplete("Closed");<a name="line.1724"></a>
+<span class="sourceLineNo">1725</span>      LOG.info("Closed " + this);<a name="line.1725"></a>
+<span class="sourceLineNo">1726</span>      return result;<a name="line.1726"></a>
+<span class="sourceLineNo">1727</span>    } finally {<a name="line.1727"></a>
+<span class="sourceLineNo">1728</span>      lock.writeLock().unlock();<a name="line.1728"></a>
+<span class="sourceLineNo">1729</span>    }<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>  private long getMemstoreHeapSize() {<a name="line.1732"></a>
+<span class="sourceLineNo">1733</span>    long size = 0;<a name="line.1733"></a>
+<span class="sourceLineNo">1734</span>    for (Store s : this.stores.values()) {<a name="line.1734"></a>
+<span class="sourceLineNo">1735</span>      size += s.getSizeOfMemStore().getHeapSize();<a name="line.1735"></a>
+<span class="sourceLineNo">1736</span>    }<a name="line.1736"></a>
+<span class="sourceLineNo">1737</span>    return size;<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>  @Override<a name="line.1740"></a>
+<span class="sourceLineNo">1741</span>  public void waitForFlushesAndCompactions() {<a name="line.1741"></a>
+<span class="sourceLineNo">1742</span>    synchronized (writestate) {<a name="line.1742"></a>
+<span class="sourceLineNo">1743</span>      if (this.writestate.readOnly) {<a name="line.1743"></a>
+<span class="sourceLineNo">1744</span>        // we should not wait for replayed flushed if we are read only (for example in case the<a name="line.1744"></a>
+<span class="sourceLineNo">1745</span>        // region is a secondary replica).<a name="line.1745"></a>
+<span class="sourceLineNo">1746</span>        return;<a name="line.1746"></a>
+<span class="sourceLineNo">1747</span>      }<a name="line.1747"></a>
+<span class="sourceLineNo">1748</span>      boolean interrupted = false;<a name="line.1748"></a>
+<span class="sourceLineNo">1749</span>      try {<a name="line.1749"></a>
+<span class="sourceLineNo">1750</span>        while (writestate.compacting.get() &gt; 0 || writestate.flushing) {<a name="line.1750"></a>
+<span class="sourceLineNo">1751</span>          LOG.debug("waiting for " + writestate.compacting + " compactions"<a name="line.1751"></a>
+<span class="sourceLineNo">1752</span>            + (writestate.flushing ? " &amp; cache flush" : "") + " to complete for region " + this);<a name="line.1752"></a>
+<span class="sourceLineNo">1753</span>          try {<a name="line.1753"></a>
+<span class="sourceLineNo">1754</span>            writestate.wait();<a name="line.1754"></a>
+<span class="sourceLineNo">1755</span>          } catch (InterruptedException iex) {<a name="line.1755"></a>
+<span class="sourceLineNo">1756</span>            // essentially ignore and propagate the interrupt back up<a name="line.1756"></a>
+<span class="sourceLineNo">1757</span>            LOG.warn("Interrupted while waiting");<a name="line.1757"></a>
+<span class="sourceLineNo">1758</span>            interrupted = true;<a name="line.1758"></a>
+<span class="sourceLineNo">1759</span>          }<a name="line.1759"></a>
+<span class="sourceLineNo">1760</span>        }<a name="line.1760"></a>
+<span class="sourceLineNo">1761</span>      } finally {<a name="line.1761"></a>
+<span class="sourceLineNo">1762</span>        if (interrupted) {<a name="line.1762"></a>
+<span class="sourceLineNo">1763</span>          Thread.currentThread().interrupt();<a name="line.1763"></a>
+<span class="sourceLineNo">1764</span>        }<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>  }<a name="line.1767"></a>
+<span class="sourceLineNo">1768</span><a name="line.1768"></a>
+<span class="sourceLineNo">1769</span>  @Override<a name="line.1769"></a>
+<span class="sourceLineNo">1770</span>  public void waitForFlushes() {<a name="line.1770"></a>
+<span class="sourceLineNo">1771</span>    synchronized (writestate) {<a name="line.1771"></a>
+<span class="sourceLineNo">1772</span>      if (this.writestate.readOnly) {<a name="line.1772"></a>
+<span class="sourceLineNo">1773</span>        // we should not wait for replayed flushed if we are read only (for example in case the<a name="line.1773"></a>
+<span class="sourceLineNo">1774</span>        // region is a secondary replica).<a name="line.1774"></a>
+<span class="sourceLineNo">1775</span>        return;<a name="line.1775"></a>
+<span class="sourceLineNo">1776</span>      }<a name="line.1776"></a>
+<span class="sourceLineNo">1777</span>      if (!writestate.flushing) return;<a name="line.1777"></a>
+<span class="sourceLineNo">1778</span>      long start = System.currentTimeMillis();<a name="line.1778"></a>
+<span class="sourceLineNo">1779</span>      boolean interrupted = false;<a name="line.1779"></a>
+<span class="sourceLineNo">1780</span>      try {<a name="line.1780"></a>
+<span class="sourceLineNo">1781</span>        while (writestate.flushing) {<a name="line.1781"></a>
+<span class="sourceLineNo">1782</span>          LOG.debug("waiting for cache flush to complete for region " + this);<a name="line.1782"></a>
+<span class="sourceLineNo">1783</span>          try {<a name="line.1783"></a>
+<span class="sourceLineNo">1784</span>            writestate.wait();<a name="line.1784"></a>
+<span class="sourceLineNo">1785</span>          } catch (InterruptedException iex) {<a name="line.1785"></a>
+<span class="sourceLineNo">1786</span>            // essentially ignore and propagate the interrupt back up<a name="line.1786"></a>
+<span class="sourceLineNo">1787</span>            LOG.warn("Interrupted while waiting");<a name="line.1787"></a>
+<span class="sourceLineNo">1788</span>            interrupted = true;<a name="line.1788"></a>
+<span class="sourceLineNo">1789</span>          }<a name="line.1789"></a>
+<span class="sourceLineNo">1790</span>        }<a name="line.1790"></a>
+<span class="sourceLineNo">1791</span>      } finally {<a name="line.1791"></a>
+<span class="sourceLineNo">1792</span>        if (interrupted) {<a name="line.1792"></a>
+<span class="sourceLineNo">1793</span>          Thread.currentThread().interrupt();<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>      long duration = System.currentTimeMillis() - start;<a name="line.1796"></a>
+<span class="sourceLineNo">1797</span>      LOG.debug("Waited " + duration + " ms for flush to complete");<a name="line.1797"></a>
+<span class="sourceLineNo">1798</span>    }<a name="line.1798"></a>
+<span class="sourceLineNo">1799</span>  }<a name="line.1799"></a>
+<span class="sourceLineNo">1800</span>  protected ThreadPoolExecutor getStoreOpenAndCloseThreadPool(<a name="line.1800"></a>
 <span class="sourceLineNo">1801</span>      final String threadNamePrefix) {<a name="line.1801"></a>
 <span class="sourceLineNo">1802</span>    int numStores = Math.max(1, this.htableDescriptor.getFamilies().size());<a name="line.1802"></a>
-<span class="sourceLineNo">1803</span>    int maxThreads = Math.max(1,<a name="line.1803"></a>
+<span class="sourceLineNo">1803</span>    int maxThreads = Math.min(numStores,<a name="line.1803"></a>
 <span class="sourceLineNo">1804</span>        conf.getInt(HConstants.HSTORE_OPEN_AND_CLOSE_THREADS_MAX,<a name="line.1804"></a>
-<span class="sourceLineNo">1805</span>            HConstants.DEFAULT_HSTORE_OPEN_AND_CLOSE_THREADS_MAX)<a name="line.1805"></a>
-<span class="sourceLineNo">1806</span>            / numStores);<a name="line.1806"></a>
-<span class="sourceLineNo">1807</span>    return getOpenAndCloseThreadPool(maxThreads, threadNamePrefix);<a name="line.1807"></a>
-<span class="sourceLineNo">1808</span>  }<a name="line.1808"></a>
-<span class="sourceLineNo">1809</span><a name="line.1809"></a>
-<span class="sourceLineNo">1810</span>  static ThreadPoolExecutor getOpenAndCloseThreadPool(int maxThreads,<a name="line.1810"></a>
-<span class="sourceLineNo">1811</span>      final String threadNamePrefix) {<a name="line.1811"></a>
-<span class="sourceLineNo">1812</span>    return Threads.getBoundedCachedThreadPool(maxThreads, 30L, TimeUnit.SECONDS,<a name="line.1812"></a>
-<span class="sourceLineNo">1813</span>      new ThreadFactory() {<a name="line.1813"></a>
-<span class="sourceLineNo">1814</span>        private int count = 1;<a name="line.1814"></a>
-<span class="sourceLineNo">1815</span><a name="line.1815"></a>
-<span class="sourceLineNo">1816</span>        @Override<a name="line.1816"></a>
-<span class="sourceLineNo">1817</span>        public Thread newThread(Runnable r) {<a name="line.1817"></a>
-<span class="sourceLineNo">1818</span>          return new Thread(r, threadNamePrefix + "-" + count++);<a name="line.1818"></a>
-<span class="sourceLineNo">1819</span>        }<a name="line.1819"></a>
-<span class="sourceLineNo">1820</span>      });<a name="line.1820"></a>
-<span class="sourceLineNo">1821</span>  }<a name="line.1821"></a>
-<span class="sourceLineNo">1822</span><a name="line.1822"></a>
-<span class="sourceLineNo">1823</span>   /**<a name="line.1823"></a>
-<span class="sourceLineNo">1824</span>    * @return True if its worth doing a flush before we put up the close flag.<a name="line.1824"></a>
-<span class="sourceLineNo">1825</span>    */<a name="line.1825"></a>
-<span class="sourceLineNo">1826</span>  private boolean worthPreFlushing() {<a name="line.1826"></a>
-<span class="sourceLineNo">1827</span>    return this.memstoreDataSize.get() &gt;<a name="line.1827"></a>
-<span class="sourceLineNo">1828</span>      this.conf.getLong("hbase.hregion.preclose.flush.size", 1024 * 1024 * 5);<a name="line.1828"></a>
-<span class="sourceLineNo">1829</span>  }<a name="line.1829"></a>
-<span class="sourceLineNo">1830</span><a name="line.1830"></a>
-<span class="sourceLineNo">1831</span>  //////////////////////////////////////////////////////////////////////////////<a name="line.1831"></a>
-<span class="sourceLineNo">1832</span>  // HRegion accessors<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>  @Override<a name="line.1835"></a>
-<span class="sourceLineNo">1836</span>  public HTableDescriptor getTableDesc() {<a name="line.1836"></a>
-<span class="sourceLineNo">1837</span>    return this.htableDescriptor;<a name="line.1837"></a>
+<span class="sourceLineNo">1805</span>            HConstants.DEFAULT_HSTORE_OPEN_AND_CLOSE_THREADS_MAX));<a name="line.1805"></a>
+<span class="sourceLineNo">1806</span>    return getOpenAndCloseThreadPool(maxThreads, threadNamePrefix);<a name="line.1806"></a>
+<span class="sourceLineNo">1807</span>  }<a name="line.1807"></a>
+<span class="sourceLineNo">1808</span><a name="line.1808"></a>
+<span class="sourceLineNo">1809</span>  protected ThreadPoolExecutor getStoreFileOpenAndCloseThreadPool(<a name="line.1809"></a>
+<span class="sourceLineNo">1810</span>      final String threadNamePrefix) {<a name="line.1810"></a>
+<span class="sourceLineNo">1811</span>    int numStores = Math.max(1, this.htableDescriptor.getFamilies().size());<a name="line.1811"></a>
+<span class="sourceLineNo">1812</span>    int maxThreads = Math.max(1,<a name="line.1812"></a>
+<span class="sourceLineNo">1813</span>        conf.getInt(HConstants.HSTORE_OPEN_AND_CLOSE_THREADS_MAX,<a name="line.1813"></a>
+<span class="sourceLineNo">1814</span>            HConstants.DEFAULT_HSTORE_OPEN_AND_CLOSE_THREADS_MAX)<a name="line.1814"></a>
+<span class="sourceLineNo">1815</span>            / numStores);<a name="line.1815"></a>
+<span class="sourceLineNo">1816</span>    return getOpenAndCloseThreadPool(maxThreads, threadNamePrefix);<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>  static ThreadPoolExecutor getOpenAndCloseThreadPool(int maxThreads,<a name="line.1819"></a>
+<span class="sourceLineNo">1820</span>      final String threadNamePrefix) {<a name="line.1820"></a>
+<span class="sourceLineNo">1821</span>    return Threads.getBoundedCachedThreadPool(maxThreads, 30L, TimeUnit.SECONDS,<a name="line.1821"></a>
+<span class="sourceLineNo">1822</span>      new ThreadFactory() {<a name="line.1822"></a>
+<span class="sourceLineNo">1823</span>        private int count = 1;<a name="line.1823"></a>
+<span class="sourceLineNo">1824</span><a name="line.1824"></a>
+<span class="sourceLineNo">1825</span>        @Override<a name="line.1825"></a>
+<span class="sourceLineNo">1826</span>        public Thread newThread(Runnable r) {<a name="line.1826"></a>
+<span class="sourceLineNo">1827</span>          return new Thread(r, threadNamePrefix + "-" + count++);<a name="line.1827"></a>
+<span class="sourceLineNo">1828</span>        }<a name="line.1828"></a>
+<span class="sourceLineNo">1829</span>      });<a name="line.1829"></a>
+<span class="sourceLineNo">1830</span>  }<a name="line.1830"></a>
+<span class="sourceLineNo">1831</span><a name="line.1831"></a>
+<span class="sourceLineNo">1832</span>   /**<a name="line.1832"></a>
+<span class="sourceLineNo">1833</span>    * @return True if its worth doing a flush before we put up the close flag.<a name="line.1833"></a>
+<span class="sourceLineNo">1834</span>    */<a name="line.1834"></a>
+<span class="sourceLineNo">1835</span>  private boolean worthPreFlushing() {<a name="line.1835"></a>
+<span class="sourceLineNo">1836</span>    return this.memstoreDataSize.get() &gt;<a name="line.1836"></a>
+<span class="sourceLineNo">1837</span>      this.conf.getLong("hbase.hregion.preclose.flush.size", 1024 * 1024 * 5);<a name="line.1837"></a>
 <span class="sourceLineNo">1838</span>  }<a name="line.1838"></a>
 <span class="sourceLineNo">1839</span><a name="line.1839"></a>
-<span class="sourceLin

<TRUNCATED>

Mime
View raw message