hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject [30/51] [partial] hbase git commit: Published site at 3bac31b2a49bca153df3b47a198667828b61f36e.
Date Sun, 29 Nov 2015 21:17:43 GMT
http://git-wip-us.apache.org/repos/asf/hbase/blob/ef7355e1/devapidocs/src-html/org/apache/hadoop/hbase/master/SplitLogManager.ResubmitDirective.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/master/SplitLogManager.ResubmitDirective.html b/devapidocs/src-html/org/apache/hadoop/hbase/master/SplitLogManager.ResubmitDirective.html
index fc37c91..9c149ef 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/master/SplitLogManager.ResubmitDirective.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/master/SplitLogManager.ResubmitDirective.html
@@ -407,441 +407,440 @@
 <span class="sourceLineNo">399</span>   * It removes recovering regions under /hbase/recovering-regions/[encoded region name] so that the<a name="line.399"></a>
 <span class="sourceLineNo">400</span>   * region server hosting the region can allow reads to the recovered region<a name="line.400"></a>
 <span class="sourceLineNo">401</span>   * @param serverNames servers which are just recovered<a name="line.401"></a>
-<span class="sourceLineNo">402</span>   * @param isMetaRecovery whether current recovery is for the meta region on<a name="line.402"></a>
-<span class="sourceLineNo">403</span>   *          &lt;code&gt;serverNames&lt;code&gt;<a name="line.403"></a>
-<span class="sourceLineNo">404</span>   */<a name="line.404"></a>
-<span class="sourceLineNo">405</span>  private void removeRecoveringRegions(final Set&lt;ServerName&gt; serverNames, Boolean isMetaRecovery) {<a name="line.405"></a>
-<span class="sourceLineNo">406</span>    if (!isLogReplaying()) {<a name="line.406"></a>
-<span class="sourceLineNo">407</span>      // the function is only used in WALEdit direct replay mode<a name="line.407"></a>
-<span class="sourceLineNo">408</span>      return;<a name="line.408"></a>
-<span class="sourceLineNo">409</span>    }<a name="line.409"></a>
-<span class="sourceLineNo">410</span>    if (serverNames == null || serverNames.isEmpty()) return;<a name="line.410"></a>
-<span class="sourceLineNo">411</span><a name="line.411"></a>
-<span class="sourceLineNo">412</span>    Set&lt;String&gt; recoveredServerNameSet = new HashSet&lt;String&gt;();<a name="line.412"></a>
-<span class="sourceLineNo">413</span>    for (ServerName tmpServerName : serverNames) {<a name="line.413"></a>
-<span class="sourceLineNo">414</span>      recoveredServerNameSet.add(tmpServerName.getServerName());<a name="line.414"></a>
-<span class="sourceLineNo">415</span>    }<a name="line.415"></a>
-<span class="sourceLineNo">416</span>   <a name="line.416"></a>
-<span class="sourceLineNo">417</span>    this.recoveringRegionLock.lock();<a name="line.417"></a>
-<span class="sourceLineNo">418</span>    try {<a name="line.418"></a>
-<span class="sourceLineNo">419</span>      ((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.419"></a>
-<span class="sourceLineNo">420</span>          .getSplitLogManagerCoordination().removeRecoveringRegions(recoveredServerNameSet,<a name="line.420"></a>
-<span class="sourceLineNo">421</span>            isMetaRecovery);<a name="line.421"></a>
-<span class="sourceLineNo">422</span>    } catch (IOException e) {<a name="line.422"></a>
-<span class="sourceLineNo">423</span>      LOG.warn("removeRecoveringRegions got exception. Will retry", e);<a name="line.423"></a>
-<span class="sourceLineNo">424</span>      if (serverNames != null &amp;&amp; !serverNames.isEmpty()) {<a name="line.424"></a>
-<span class="sourceLineNo">425</span>        this.failedRecoveringRegionDeletions.add(new Pair&lt;Set&lt;ServerName&gt;, Boolean&gt;(serverNames,<a name="line.425"></a>
-<span class="sourceLineNo">426</span>            isMetaRecovery));<a name="line.426"></a>
-<span class="sourceLineNo">427</span>      }<a name="line.427"></a>
-<span class="sourceLineNo">428</span>    } finally {<a name="line.428"></a>
-<span class="sourceLineNo">429</span>      this.recoveringRegionLock.unlock();<a name="line.429"></a>
-<span class="sourceLineNo">430</span>    }<a name="line.430"></a>
-<span class="sourceLineNo">431</span>  }<a name="line.431"></a>
-<span class="sourceLineNo">432</span><a name="line.432"></a>
-<span class="sourceLineNo">433</span>  /**<a name="line.433"></a>
-<span class="sourceLineNo">434</span>   * It removes stale recovering regions under /hbase/recovering-regions/[encoded region name]<a name="line.434"></a>
-<span class="sourceLineNo">435</span>   * during master initialization phase.<a name="line.435"></a>
-<span class="sourceLineNo">436</span>   * @param failedServers A set of known failed servers<a name="line.436"></a>
-<span class="sourceLineNo">437</span>   * @throws IOException<a name="line.437"></a>
-<span class="sourceLineNo">438</span>   */<a name="line.438"></a>
-<span class="sourceLineNo">439</span>  void removeStaleRecoveringRegions(final Set&lt;ServerName&gt; failedServers) throws IOException,<a name="line.439"></a>
-<span class="sourceLineNo">440</span>      InterruptedIOException {<a name="line.440"></a>
-<span class="sourceLineNo">441</span>    Set&lt;String&gt; knownFailedServers = new HashSet&lt;String&gt;();<a name="line.441"></a>
-<span class="sourceLineNo">442</span>    if (failedServers != null) {<a name="line.442"></a>
-<span class="sourceLineNo">443</span>      for (ServerName tmpServerName : failedServers) {<a name="line.443"></a>
-<span class="sourceLineNo">444</span>        knownFailedServers.add(tmpServerName.getServerName());<a name="line.444"></a>
-<span class="sourceLineNo">445</span>      }<a name="line.445"></a>
-<span class="sourceLineNo">446</span>    }<a name="line.446"></a>
-<span class="sourceLineNo">447</span><a name="line.447"></a>
-<span class="sourceLineNo">448</span>    this.recoveringRegionLock.lock();<a name="line.448"></a>
-<span class="sourceLineNo">449</span>    try {<a name="line.449"></a>
-<span class="sourceLineNo">450</span>      ((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.450"></a>
-<span class="sourceLineNo">451</span>          .getSplitLogManagerCoordination().removeStaleRecoveringRegions(knownFailedServers);<a name="line.451"></a>
-<span class="sourceLineNo">452</span>    } finally {<a name="line.452"></a>
-<span class="sourceLineNo">453</span>      this.recoveringRegionLock.unlock();<a name="line.453"></a>
-<span class="sourceLineNo">454</span>    }<a name="line.454"></a>
-<span class="sourceLineNo">455</span>  }<a name="line.455"></a>
-<span class="sourceLineNo">456</span><a name="line.456"></a>
-<span class="sourceLineNo">457</span>  /**<a name="line.457"></a>
-<span class="sourceLineNo">458</span>   * @param path<a name="line.458"></a>
-<span class="sourceLineNo">459</span>   * @param batch<a name="line.459"></a>
-<span class="sourceLineNo">460</span>   * @return null on success, existing task on error<a name="line.460"></a>
-<span class="sourceLineNo">461</span>   */<a name="line.461"></a>
-<span class="sourceLineNo">462</span>  private Task createTaskIfAbsent(String path, TaskBatch batch) {<a name="line.462"></a>
-<span class="sourceLineNo">463</span>    Task oldtask;<a name="line.463"></a>
-<span class="sourceLineNo">464</span>    // batch.installed is only changed via this function and<a name="line.464"></a>
-<span class="sourceLineNo">465</span>    // a single thread touches batch.installed.<a name="line.465"></a>
-<span class="sourceLineNo">466</span>    Task newtask = new Task();<a name="line.466"></a>
-<span class="sourceLineNo">467</span>    newtask.batch = batch;<a name="line.467"></a>
-<span class="sourceLineNo">468</span>    oldtask = tasks.putIfAbsent(path, newtask);<a name="line.468"></a>
-<span class="sourceLineNo">469</span>    if (oldtask == null) {<a name="line.469"></a>
-<span class="sourceLineNo">470</span>      batch.installed++;<a name="line.470"></a>
-<span class="sourceLineNo">471</span>      return null;<a name="line.471"></a>
-<span class="sourceLineNo">472</span>    }<a name="line.472"></a>
-<span class="sourceLineNo">473</span>    // new task was not used.<a name="line.473"></a>
-<span class="sourceLineNo">474</span>    synchronized (oldtask) {<a name="line.474"></a>
-<span class="sourceLineNo">475</span>      if (oldtask.isOrphan()) {<a name="line.475"></a>
-<span class="sourceLineNo">476</span>        if (oldtask.status == SUCCESS) {<a name="line.476"></a>
-<span class="sourceLineNo">477</span>          // The task is already done. Do not install the batch for this<a name="line.477"></a>
-<span class="sourceLineNo">478</span>          // task because it might be too late for setDone() to update<a name="line.478"></a>
-<span class="sourceLineNo">479</span>          // batch.done. There is no need for the batch creator to wait for<a name="line.479"></a>
-<span class="sourceLineNo">480</span>          // this task to complete.<a name="line.480"></a>
-<span class="sourceLineNo">481</span>          return (null);<a name="line.481"></a>
-<span class="sourceLineNo">482</span>        }<a name="line.482"></a>
-<span class="sourceLineNo">483</span>        if (oldtask.status == IN_PROGRESS) {<a name="line.483"></a>
-<span class="sourceLineNo">484</span>          oldtask.batch = batch;<a name="line.484"></a>
-<span class="sourceLineNo">485</span>          batch.installed++;<a name="line.485"></a>
-<span class="sourceLineNo">486</span>          LOG.debug("Previously orphan task " + path + " is now being waited upon");<a name="line.486"></a>
-<span class="sourceLineNo">487</span>          return null;<a name="line.487"></a>
-<span class="sourceLineNo">488</span>        }<a name="line.488"></a>
-<span class="sourceLineNo">489</span>        while (oldtask.status == FAILURE) {<a name="line.489"></a>
-<span class="sourceLineNo">490</span>          LOG.debug("wait for status of task " + path + " to change to DELETED");<a name="line.490"></a>
-<span class="sourceLineNo">491</span>          SplitLogCounters.tot_mgr_wait_for_zk_delete.incrementAndGet();<a name="line.491"></a>
-<span class="sourceLineNo">492</span>          try {<a name="line.492"></a>
-<span class="sourceLineNo">493</span>            oldtask.wait();<a name="line.493"></a>
-<span class="sourceLineNo">494</span>          } catch (InterruptedException e) {<a name="line.494"></a>
-<span class="sourceLineNo">495</span>            Thread.currentThread().interrupt();<a name="line.495"></a>
-<span class="sourceLineNo">496</span>            LOG.warn("Interrupted when waiting for znode delete callback");<a name="line.496"></a>
-<span class="sourceLineNo">497</span>            // fall through to return failure<a name="line.497"></a>
-<span class="sourceLineNo">498</span>            break;<a name="line.498"></a>
-<span class="sourceLineNo">499</span>          }<a name="line.499"></a>
-<span class="sourceLineNo">500</span>        }<a name="line.500"></a>
-<span class="sourceLineNo">501</span>        if (oldtask.status != DELETED) {<a name="line.501"></a>
-<span class="sourceLineNo">502</span>          LOG.warn("Failure because previously failed task"<a name="line.502"></a>
-<span class="sourceLineNo">503</span>              + " state still present. Waiting for znode delete callback" + " path=" + path);<a name="line.503"></a>
-<span class="sourceLineNo">504</span>          return oldtask;<a name="line.504"></a>
-<span class="sourceLineNo">505</span>        }<a name="line.505"></a>
-<span class="sourceLineNo">506</span>        // reinsert the newTask and it must succeed this time<a name="line.506"></a>
-<span class="sourceLineNo">507</span>        Task t = tasks.putIfAbsent(path, newtask);<a name="line.507"></a>
-<span class="sourceLineNo">508</span>        if (t == null) {<a name="line.508"></a>
-<span class="sourceLineNo">509</span>          batch.installed++;<a name="line.509"></a>
-<span class="sourceLineNo">510</span>          return null;<a name="line.510"></a>
-<span class="sourceLineNo">511</span>        }<a name="line.511"></a>
-<span class="sourceLineNo">512</span>        LOG.fatal("Logic error. Deleted task still present in tasks map");<a name="line.512"></a>
-<span class="sourceLineNo">513</span>        assert false : "Deleted task still present in tasks map";<a name="line.513"></a>
-<span class="sourceLineNo">514</span>        return t;<a name="line.514"></a>
-<span class="sourceLineNo">515</span>      }<a name="line.515"></a>
-<span class="sourceLineNo">516</span>      LOG.warn("Failure because two threads can't wait for the same task; path=" + path);<a name="line.516"></a>
-<span class="sourceLineNo">517</span>      return oldtask;<a name="line.517"></a>
-<span class="sourceLineNo">518</span>    }<a name="line.518"></a>
-<span class="sourceLineNo">519</span>  }<a name="line.519"></a>
-<span class="sourceLineNo">520</span><a name="line.520"></a>
-<span class="sourceLineNo">521</span>  Task findOrCreateOrphanTask(String path) {<a name="line.521"></a>
-<span class="sourceLineNo">522</span>    Task orphanTask = new Task();<a name="line.522"></a>
-<span class="sourceLineNo">523</span>    Task task;<a name="line.523"></a>
-<span class="sourceLineNo">524</span>    task = tasks.putIfAbsent(path, orphanTask);<a name="line.524"></a>
-<span class="sourceLineNo">525</span>    if (task == null) {<a name="line.525"></a>
-<span class="sourceLineNo">526</span>      LOG.info("creating orphan task " + path);<a name="line.526"></a>
-<span class="sourceLineNo">527</span>      SplitLogCounters.tot_mgr_orphan_task_acquired.incrementAndGet();<a name="line.527"></a>
-<span class="sourceLineNo">528</span>      task = orphanTask;<a name="line.528"></a>
-<span class="sourceLineNo">529</span>    }<a name="line.529"></a>
-<span class="sourceLineNo">530</span>    return task;<a name="line.530"></a>
-<span class="sourceLineNo">531</span>  }<a name="line.531"></a>
-<span class="sourceLineNo">532</span><a name="line.532"></a>
-<span class="sourceLineNo">533</span>  public void stop() {<a name="line.533"></a>
-<span class="sourceLineNo">534</span>    if (choreService != null) {<a name="line.534"></a>
-<span class="sourceLineNo">535</span>      choreService.shutdown();<a name="line.535"></a>
-<span class="sourceLineNo">536</span>    }<a name="line.536"></a>
-<span class="sourceLineNo">537</span>    if (timeoutMonitor != null) {<a name="line.537"></a>
-<span class="sourceLineNo">538</span>      timeoutMonitor.cancel(true);<a name="line.538"></a>
-<span class="sourceLineNo">539</span>    }<a name="line.539"></a>
-<span class="sourceLineNo">540</span>  }<a name="line.540"></a>
-<span class="sourceLineNo">541</span><a name="line.541"></a>
-<span class="sourceLineNo">542</span>  void handleDeadWorker(ServerName workerName) {<a name="line.542"></a>
-<span class="sourceLineNo">543</span>    // resubmit the tasks on the TimeoutMonitor thread. Makes it easier<a name="line.543"></a>
-<span class="sourceLineNo">544</span>    // to reason about concurrency. Makes it easier to retry.<a name="line.544"></a>
-<span class="sourceLineNo">545</span>    synchronized (deadWorkersLock) {<a name="line.545"></a>
-<span class="sourceLineNo">546</span>      if (deadWorkers == null) {<a name="line.546"></a>
-<span class="sourceLineNo">547</span>        deadWorkers = new HashSet&lt;ServerName&gt;(100);<a name="line.547"></a>
-<span class="sourceLineNo">548</span>      }<a name="line.548"></a>
-<span class="sourceLineNo">549</span>      deadWorkers.add(workerName);<a name="line.549"></a>
-<span class="sourceLineNo">550</span>    }<a name="line.550"></a>
-<span class="sourceLineNo">551</span>    LOG.info("dead splitlog worker " + workerName);<a name="line.551"></a>
-<span class="sourceLineNo">552</span>  }<a name="line.552"></a>
-<span class="sourceLineNo">553</span><a name="line.553"></a>
-<span class="sourceLineNo">554</span>  void handleDeadWorkers(Set&lt;ServerName&gt; serverNames) {<a name="line.554"></a>
-<span class="sourceLineNo">555</span>    synchronized (deadWorkersLock) {<a name="line.555"></a>
-<span class="sourceLineNo">556</span>      if (deadWorkers == null) {<a name="line.556"></a>
-<span class="sourceLineNo">557</span>        deadWorkers = new HashSet&lt;ServerName&gt;(100);<a name="line.557"></a>
-<span class="sourceLineNo">558</span>      }<a name="line.558"></a>
-<span class="sourceLineNo">559</span>      deadWorkers.addAll(serverNames);<a name="line.559"></a>
-<span class="sourceLineNo">560</span>    }<a name="line.560"></a>
-<span class="sourceLineNo">561</span>    LOG.info("dead splitlog workers " + serverNames);<a name="line.561"></a>
-<span class="sourceLineNo">562</span>  }<a name="line.562"></a>
-<span class="sourceLineNo">563</span><a name="line.563"></a>
-<span class="sourceLineNo">564</span>  /**<a name="line.564"></a>
-<span class="sourceLineNo">565</span>   * This function is to set recovery mode from outstanding split log tasks from before or current<a name="line.565"></a>
-<span class="sourceLineNo">566</span>   * configuration setting<a name="line.566"></a>
-<span class="sourceLineNo">567</span>   * @param isForInitialization<a name="line.567"></a>
-<span class="sourceLineNo">568</span>   * @throws IOException throws if it's impossible to set recovery mode<a name="line.568"></a>
-<span class="sourceLineNo">569</span>   */<a name="line.569"></a>
-<span class="sourceLineNo">570</span>  public void setRecoveryMode(boolean isForInitialization) throws IOException {<a name="line.570"></a>
-<span class="sourceLineNo">571</span>    ((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.571"></a>
-<span class="sourceLineNo">572</span>        .getSplitLogManagerCoordination().setRecoveryMode(isForInitialization);<a name="line.572"></a>
-<span class="sourceLineNo">573</span><a name="line.573"></a>
-<span class="sourceLineNo">574</span>  }<a name="line.574"></a>
-<span class="sourceLineNo">575</span><a name="line.575"></a>
-<span class="sourceLineNo">576</span>  public void markRegionsRecovering(ServerName server, Set&lt;HRegionInfo&gt; userRegions)<a name="line.576"></a>
-<span class="sourceLineNo">577</span>      throws InterruptedIOException, IOException {<a name="line.577"></a>
-<span class="sourceLineNo">578</span>    if (userRegions == null || (!isLogReplaying())) {<a name="line.578"></a>
-<span class="sourceLineNo">579</span>      return;<a name="line.579"></a>
-<span class="sourceLineNo">580</span>    }<a name="line.580"></a>
-<span class="sourceLineNo">581</span>    try {<a name="line.581"></a>
-<span class="sourceLineNo">582</span>      this.recoveringRegionLock.lock();<a name="line.582"></a>
-<span class="sourceLineNo">583</span>      // mark that we're creating recovering regions<a name="line.583"></a>
-<span class="sourceLineNo">584</span>      ((BaseCoordinatedStateManager) this.server.getCoordinatedStateManager())<a name="line.584"></a>
-<span class="sourceLineNo">585</span>          .getSplitLogManagerCoordination().markRegionsRecovering(server, userRegions);<a name="line.585"></a>
-<span class="sourceLineNo">586</span>    } finally {<a name="line.586"></a>
-<span class="sourceLineNo">587</span>      this.recoveringRegionLock.unlock();<a name="line.587"></a>
-<span class="sourceLineNo">588</span>    }<a name="line.588"></a>
-<span class="sourceLineNo">589</span><a name="line.589"></a>
-<span class="sourceLineNo">590</span>  }<a name="line.590"></a>
-<span class="sourceLineNo">591</span><a name="line.591"></a>
-<span class="sourceLineNo">592</span>  /**<a name="line.592"></a>
-<span class="sourceLineNo">593</span>   * @return whether log is replaying<a name="line.593"></a>
-<span class="sourceLineNo">594</span>   */<a name="line.594"></a>
-<span class="sourceLineNo">595</span>  public boolean isLogReplaying() {<a name="line.595"></a>
-<span class="sourceLineNo">596</span>    CoordinatedStateManager m = server.getCoordinatedStateManager();<a name="line.596"></a>
-<span class="sourceLineNo">597</span>    if (m == null) return false;<a name="line.597"></a>
-<span class="sourceLineNo">598</span>    return ((BaseCoordinatedStateManager)m).getSplitLogManagerCoordination().isReplaying();<a name="line.598"></a>
-<span class="sourceLineNo">599</span>  }<a name="line.599"></a>
-<span class="sourceLineNo">600</span><a name="line.600"></a>
-<span class="sourceLineNo">601</span>  /**<a name="line.601"></a>
-<span class="sourceLineNo">602</span>   * @return whether log is splitting<a name="line.602"></a>
-<span class="sourceLineNo">603</span>   */<a name="line.603"></a>
-<span class="sourceLineNo">604</span>  public boolean isLogSplitting() {<a name="line.604"></a>
-<span class="sourceLineNo">605</span>    if (server.getCoordinatedStateManager() == null) return false;<a name="line.605"></a>
-<span class="sourceLineNo">606</span>    return ((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.606"></a>
-<span class="sourceLineNo">607</span>        .getSplitLogManagerCoordination().isSplitting();<a name="line.607"></a>
-<span class="sourceLineNo">608</span>  }<a name="line.608"></a>
-<span class="sourceLineNo">609</span><a name="line.609"></a>
-<span class="sourceLineNo">610</span>  /**<a name="line.610"></a>
-<span class="sourceLineNo">611</span>   * @return the current log recovery mode<a name="line.611"></a>
-<span class="sourceLineNo">612</span>   */<a name="line.612"></a>
-<span class="sourceLineNo">613</span>  public RecoveryMode getRecoveryMode() {<a name="line.613"></a>
-<span class="sourceLineNo">614</span>    return ((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.614"></a>
-<span class="sourceLineNo">615</span>        .getSplitLogManagerCoordination().getRecoveryMode();<a name="line.615"></a>
-<span class="sourceLineNo">616</span>  }<a name="line.616"></a>
-<span class="sourceLineNo">617</span><a name="line.617"></a>
-<span class="sourceLineNo">618</span>  /**<a name="line.618"></a>
-<span class="sourceLineNo">619</span>   * Keeps track of the batch of tasks submitted together by a caller in splitLogDistributed().<a name="line.619"></a>
-<span class="sourceLineNo">620</span>   * Clients threads use this object to wait for all their tasks to be done.<a name="line.620"></a>
-<span class="sourceLineNo">621</span>   * &lt;p&gt;<a name="line.621"></a>
-<span class="sourceLineNo">622</span>   * All access is synchronized.<a name="line.622"></a>
-<span class="sourceLineNo">623</span>   */<a name="line.623"></a>
-<span class="sourceLineNo">624</span>  @InterfaceAudience.Private<a name="line.624"></a>
-<span class="sourceLineNo">625</span>  public static class TaskBatch {<a name="line.625"></a>
-<span class="sourceLineNo">626</span>    public int installed = 0;<a name="line.626"></a>
-<span class="sourceLineNo">627</span>    public int done = 0;<a name="line.627"></a>
-<span class="sourceLineNo">628</span>    public int error = 0;<a name="line.628"></a>
-<span class="sourceLineNo">629</span>    public volatile boolean isDead = false;<a name="line.629"></a>
-<span class="sourceLineNo">630</span><a name="line.630"></a>
-<span class="sourceLineNo">631</span>    @Override<a name="line.631"></a>
-<span class="sourceLineNo">632</span>    public String toString() {<a name="line.632"></a>
-<span class="sourceLineNo">633</span>      return ("installed = " + installed + " done = " + done + " error = " + error);<a name="line.633"></a>
-<span class="sourceLineNo">634</span>    }<a name="line.634"></a>
-<span class="sourceLineNo">635</span>  }<a name="line.635"></a>
-<span class="sourceLineNo">636</span><a name="line.636"></a>
-<span class="sourceLineNo">637</span>  /**<a name="line.637"></a>
-<span class="sourceLineNo">638</span>   * in memory state of an active task.<a name="line.638"></a>
-<span class="sourceLineNo">639</span>   */<a name="line.639"></a>
-<span class="sourceLineNo">640</span>  @InterfaceAudience.Private<a name="line.640"></a>
-<span class="sourceLineNo">641</span>  public static class Task {<a name="line.641"></a>
-<span class="sourceLineNo">642</span>    public volatile long last_update;<a name="line.642"></a>
-<span class="sourceLineNo">643</span>    public volatile int last_version;<a name="line.643"></a>
-<span class="sourceLineNo">644</span>    public volatile ServerName cur_worker_name;<a name="line.644"></a>
-<span class="sourceLineNo">645</span>    public volatile TaskBatch batch;<a name="line.645"></a>
-<span class="sourceLineNo">646</span>    public volatile TerminationStatus status;<a name="line.646"></a>
-<span class="sourceLineNo">647</span>    public volatile int incarnation;<a name="line.647"></a>
-<span class="sourceLineNo">648</span>    public final AtomicInteger unforcedResubmits = new AtomicInteger();<a name="line.648"></a>
-<span class="sourceLineNo">649</span>    public volatile boolean resubmitThresholdReached;<a name="line.649"></a>
-<span class="sourceLineNo">650</span><a name="line.650"></a>
-<span class="sourceLineNo">651</span>    @Override<a name="line.651"></a>
-<span class="sourceLineNo">652</span>    public String toString() {<a name="line.652"></a>
-<span class="sourceLineNo">653</span>      return ("last_update = " + last_update + " last_version = " + last_version<a name="line.653"></a>
-<span class="sourceLineNo">654</span>          + " cur_worker_name = " + cur_worker_name + " status = " + status + " incarnation = "<a name="line.654"></a>
-<span class="sourceLineNo">655</span>          + incarnation + " resubmits = " + unforcedResubmits.get() + " batch = " + batch);<a name="line.655"></a>
-<span class="sourceLineNo">656</span>    }<a name="line.656"></a>
-<span class="sourceLineNo">657</span><a name="line.657"></a>
-<span class="sourceLineNo">658</span>    public Task() {<a name="line.658"></a>
-<span class="sourceLineNo">659</span>      incarnation = 0;<a name="line.659"></a>
-<span class="sourceLineNo">660</span>      last_version = -1;<a name="line.660"></a>
-<span class="sourceLineNo">661</span>      status = IN_PROGRESS;<a name="line.661"></a>
-<span class="sourceLineNo">662</span>      setUnassigned();<a name="line.662"></a>
-<span class="sourceLineNo">663</span>    }<a name="line.663"></a>
-<span class="sourceLineNo">664</span><a name="line.664"></a>
-<span class="sourceLineNo">665</span>    public boolean isOrphan() {<a name="line.665"></a>
-<span class="sourceLineNo">666</span>      return (batch == null || batch.isDead);<a name="line.666"></a>
-<span class="sourceLineNo">667</span>    }<a name="line.667"></a>
-<span class="sourceLineNo">668</span><a name="line.668"></a>
-<span class="sourceLineNo">669</span>    public boolean isUnassigned() {<a name="line.669"></a>
-<span class="sourceLineNo">670</span>      return (cur_worker_name == null);<a name="line.670"></a>
-<span class="sourceLineNo">671</span>    }<a name="line.671"></a>
-<span class="sourceLineNo">672</span><a name="line.672"></a>
-<span class="sourceLineNo">673</span>    public void heartbeatNoDetails(long time) {<a name="line.673"></a>
-<span class="sourceLineNo">674</span>      last_update = time;<a name="line.674"></a>
-<span class="sourceLineNo">675</span>    }<a name="line.675"></a>
-<span class="sourceLineNo">676</span><a name="line.676"></a>
-<span class="sourceLineNo">677</span>    public void heartbeat(long time, int version, ServerName worker) {<a name="line.677"></a>
-<span class="sourceLineNo">678</span>      last_version = version;<a name="line.678"></a>
-<span class="sourceLineNo">679</span>      last_update = time;<a name="line.679"></a>
-<span class="sourceLineNo">680</span>      cur_worker_name = worker;<a name="line.680"></a>
-<span class="sourceLineNo">681</span>    }<a name="line.681"></a>
-<span class="sourceLineNo">682</span><a name="line.682"></a>
-<span class="sourceLineNo">683</span>    public void setUnassigned() {<a name="line.683"></a>
-<span class="sourceLineNo">684</span>      cur_worker_name = null;<a name="line.684"></a>
-<span class="sourceLineNo">685</span>      last_update = -1;<a name="line.685"></a>
-<span class="sourceLineNo">686</span>    }<a name="line.686"></a>
-<span class="sourceLineNo">687</span>  }<a name="line.687"></a>
-<span class="sourceLineNo">688</span><a name="line.688"></a>
-<span class="sourceLineNo">689</span>  /**<a name="line.689"></a>
-<span class="sourceLineNo">690</span>   * Periodically checks all active tasks and resubmits the ones that have timed out<a name="line.690"></a>
-<span class="sourceLineNo">691</span>   */<a name="line.691"></a>
-<span class="sourceLineNo">692</span>  private class TimeoutMonitor extends ScheduledChore {<a name="line.692"></a>
-<span class="sourceLineNo">693</span>    private long lastLog = 0;<a name="line.693"></a>
-<span class="sourceLineNo">694</span><a name="line.694"></a>
-<span class="sourceLineNo">695</span>    public TimeoutMonitor(final int period, Stoppable stopper) {<a name="line.695"></a>
-<span class="sourceLineNo">696</span>      super("SplitLogManager Timeout Monitor", stopper, period);<a name="line.696"></a>
-<span class="sourceLineNo">697</span>    }<a name="line.697"></a>
-<span class="sourceLineNo">698</span><a name="line.698"></a>
-<span class="sourceLineNo">699</span>    @Override<a name="line.699"></a>
-<span class="sourceLineNo">700</span>    protected void chore() {<a name="line.700"></a>
-<span class="sourceLineNo">701</span>      int resubmitted = 0;<a name="line.701"></a>
-<span class="sourceLineNo">702</span>      int unassigned = 0;<a name="line.702"></a>
-<span class="sourceLineNo">703</span>      int tot = 0;<a name="line.703"></a>
-<span class="sourceLineNo">704</span>      boolean found_assigned_task = false;<a name="line.704"></a>
-<span class="sourceLineNo">705</span>      Set&lt;ServerName&gt; localDeadWorkers;<a name="line.705"></a>
-<span class="sourceLineNo">706</span><a name="line.706"></a>
-<span class="sourceLineNo">707</span>      synchronized (deadWorkersLock) {<a name="line.707"></a>
-<span class="sourceLineNo">708</span>        localDeadWorkers = deadWorkers;<a name="line.708"></a>
-<span class="sourceLineNo">709</span>        deadWorkers = null;<a name="line.709"></a>
-<span class="sourceLineNo">710</span>      }<a name="line.710"></a>
-<span class="sourceLineNo">711</span><a name="line.711"></a>
-<span class="sourceLineNo">712</span>      for (Map.Entry&lt;String, Task&gt; e : tasks.entrySet()) {<a name="line.712"></a>
-<span class="sourceLineNo">713</span>        String path = e.getKey();<a name="line.713"></a>
-<span class="sourceLineNo">714</span>        Task task = e.getValue();<a name="line.714"></a>
-<span class="sourceLineNo">715</span>        ServerName cur_worker = task.cur_worker_name;<a name="line.715"></a>
-<span class="sourceLineNo">716</span>        tot++;<a name="line.716"></a>
-<span class="sourceLineNo">717</span>        // don't easily resubmit a task which hasn't been picked up yet. It<a name="line.717"></a>
-<span class="sourceLineNo">718</span>        // might be a long while before a SplitLogWorker is free to pick up a<a name="line.718"></a>
-<span class="sourceLineNo">719</span>        // task. This is because a SplitLogWorker picks up a task one at a<a name="line.719"></a>
-<span class="sourceLineNo">720</span>        // time. If we want progress when there are no region servers then we<a name="line.720"></a>
-<span class="sourceLineNo">721</span>        // will have to run a SplitLogWorker thread in the Master.<a name="line.721"></a>
-<span class="sourceLineNo">722</span>        if (task.isUnassigned()) {<a name="line.722"></a>
-<span class="sourceLineNo">723</span>          unassigned++;<a name="line.723"></a>
-<span class="sourceLineNo">724</span>          continue;<a name="line.724"></a>
-<span class="sourceLineNo">725</span>        }<a name="line.725"></a>
-<span class="sourceLineNo">726</span>        found_assigned_task = true;<a name="line.726"></a>
-<span class="sourceLineNo">727</span>        if (localDeadWorkers != null &amp;&amp; localDeadWorkers.contains(cur_worker)) {<a name="line.727"></a>
-<span class="sourceLineNo">728</span>          SplitLogCounters.tot_mgr_resubmit_dead_server_task.incrementAndGet();<a name="line.728"></a>
-<span class="sourceLineNo">729</span>          if (((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.729"></a>
-<span class="sourceLineNo">730</span>              .getSplitLogManagerCoordination().resubmitTask(path, task, FORCE)) {<a name="line.730"></a>
-<span class="sourceLineNo">731</span>            resubmitted++;<a name="line.731"></a>
-<span class="sourceLineNo">732</span>          } else {<a name="line.732"></a>
-<span class="sourceLineNo">733</span>            handleDeadWorker(cur_worker);<a name="line.733"></a>
-<span class="sourceLineNo">734</span>            LOG.warn("Failed to resubmit task " + path + " owned by dead " + cur_worker<a name="line.734"></a>
-<span class="sourceLineNo">735</span>                + ", will retry.");<a name="line.735"></a>
-<span class="sourceLineNo">736</span>          }<a name="line.736"></a>
-<span class="sourceLineNo">737</span>        } else if (((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.737"></a>
-<span class="sourceLineNo">738</span>            .getSplitLogManagerCoordination().resubmitTask(path, task, CHECK)) {<a name="line.738"></a>
-<span class="sourceLineNo">739</span>          resubmitted++;<a name="line.739"></a>
-<span class="sourceLineNo">740</span>        }<a name="line.740"></a>
-<span class="sourceLineNo">741</span>      }<a name="line.741"></a>
-<span class="sourceLineNo">742</span>      if (tot &gt; 0) {<a name="line.742"></a>
-<span class="sourceLineNo">743</span>        long now = EnvironmentEdgeManager.currentTime();<a name="line.743"></a>
-<span class="sourceLineNo">744</span>        if (now &gt; lastLog + 5000) {<a name="line.744"></a>
-<span class="sourceLineNo">745</span>          lastLog = now;<a name="line.745"></a>
-<span class="sourceLineNo">746</span>          LOG.info("total tasks = " + tot + " unassigned = " + unassigned + " tasks=" + tasks);<a name="line.746"></a>
-<span class="sourceLineNo">747</span>        }<a name="line.747"></a>
-<span class="sourceLineNo">748</span>      }<a name="line.748"></a>
-<span class="sourceLineNo">749</span>      if (resubmitted &gt; 0) {<a name="line.749"></a>
-<span class="sourceLineNo">750</span>        LOG.info("resubmitted " + resubmitted + " out of " + tot + " tasks");<a name="line.750"></a>
-<span class="sourceLineNo">751</span>      }<a name="line.751"></a>
-<span class="sourceLineNo">752</span>      // If there are pending tasks and all of them have been unassigned for<a name="line.752"></a>
-<span class="sourceLineNo">753</span>      // some time then put up a RESCAN node to ping the workers.<a name="line.753"></a>
-<span class="sourceLineNo">754</span>      // ZKSplitlog.DEFAULT_UNASSIGNED_TIMEOUT is of the order of minutes<a name="line.754"></a>
-<span class="sourceLineNo">755</span>      // because a. it is very unlikely that every worker had a<a name="line.755"></a>
-<span class="sourceLineNo">756</span>      // transient error when trying to grab the task b. if there are no<a name="line.756"></a>
-<span class="sourceLineNo">757</span>      // workers then all tasks wills stay unassigned indefinitely and the<a name="line.757"></a>
-<span class="sourceLineNo">758</span>      // manager will be indefinitely creating RESCAN nodes. TODO may be the<a name="line.758"></a>
-<span class="sourceLineNo">759</span>      // master should spawn both a manager and a worker thread to guarantee<a name="line.759"></a>
-<span class="sourceLineNo">760</span>      // that there is always one worker in the system<a name="line.760"></a>
-<span class="sourceLineNo">761</span>      if (tot &gt; 0<a name="line.761"></a>
-<span class="sourceLineNo">762</span>          &amp;&amp; !found_assigned_task<a name="line.762"></a>
-<span class="sourceLineNo">763</span>          &amp;&amp; ((EnvironmentEdgeManager.currentTime() - lastTaskCreateTime) &gt; unassignedTimeout)) {<a name="line.763"></a>
-<span class="sourceLineNo">764</span>        for (Map.Entry&lt;String, Task&gt; e : tasks.entrySet()) {<a name="line.764"></a>
-<span class="sourceLineNo">765</span>          String key = e.getKey();<a name="line.765"></a>
-<span class="sourceLineNo">766</span>          Task task = e.getValue();<a name="line.766"></a>
-<span class="sourceLineNo">767</span>          // we have to do task.isUnassigned() check again because tasks might<a name="line.767"></a>
-<span class="sourceLineNo">768</span>          // have been asynchronously assigned. There is no locking required<a name="line.768"></a>
-<span class="sourceLineNo">769</span>          // for these checks ... it is OK even if tryGetDataSetWatch() is<a name="line.769"></a>
-<span class="sourceLineNo">770</span>          // called unnecessarily for a taskpath<a name="line.770"></a>
-<span class="sourceLineNo">771</span>          if (task.isUnassigned() &amp;&amp; (task.status != FAILURE)) {<a name="line.771"></a>
-<span class="sourceLineNo">772</span>            // We just touch the znode to make sure its still there<a name="line.772"></a>
-<span class="sourceLineNo">773</span>            ((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.773"></a>
-<span class="sourceLineNo">774</span>                .getSplitLogManagerCoordination().checkTaskStillAvailable(key);<a name="line.774"></a>
-<span class="sourceLineNo">775</span>          }<a name="line.775"></a>
-<span class="sourceLineNo">776</span>        }<a name="line.776"></a>
-<span class="sourceLineNo">777</span>        ((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.777"></a>
-<span class="sourceLineNo">778</span>            .getSplitLogManagerCoordination().checkTasks();<a name="line.778"></a>
-<span class="sourceLineNo">779</span>        SplitLogCounters.tot_mgr_resubmit_unassigned.incrementAndGet();<a name="line.779"></a>
-<span class="sourceLineNo">780</span>        LOG.debug("resubmitting unassigned task(s) after timeout");<a name="line.780"></a>
-<span class="sourceLineNo">781</span>      }<a name="line.781"></a>
-<span class="sourceLineNo">782</span>      Set&lt;String&gt; failedDeletions =<a name="line.782"></a>
-<span class="sourceLineNo">783</span>          ((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.783"></a>
-<span class="sourceLineNo">784</span>              .getSplitLogManagerCoordination().getDetails().getFailedDeletions();<a name="line.784"></a>
-<span class="sourceLineNo">785</span>      // Retry previously failed deletes<a name="line.785"></a>
-<span class="sourceLineNo">786</span>      if (failedDeletions.size() &gt; 0) {<a name="line.786"></a>
-<span class="sourceLineNo">787</span>        List&lt;String&gt; tmpPaths = new ArrayList&lt;String&gt;(failedDeletions);<a name="line.787"></a>
-<span class="sourceLineNo">788</span>        for (String tmpPath : tmpPaths) {<a name="line.788"></a>
-<span class="sourceLineNo">789</span>          // deleteNode is an async call<a name="line.789"></a>
-<span class="sourceLineNo">790</span>          ((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.790"></a>
-<span class="sourceLineNo">791</span>              .getSplitLogManagerCoordination().deleteTask(tmpPath);<a name="line.791"></a>
-<span class="sourceLineNo">792</span>        }<a name="line.792"></a>
-<span class="sourceLineNo">793</span>        failedDeletions.removeAll(tmpPaths);<a name="line.793"></a>
-<span class="sourceLineNo">794</span>      }<a name="line.794"></a>
-<span class="sourceLineNo">795</span><a name="line.795"></a>
-<span class="sourceLineNo">796</span>      // Garbage collect left-over<a name="line.796"></a>
-<span class="sourceLineNo">797</span>      long timeInterval =<a name="line.797"></a>
-<span class="sourceLineNo">798</span>          EnvironmentEdgeManager.currentTime()<a name="line.798"></a>
-<span class="sourceLineNo">799</span>              - ((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.799"></a>
-<span class="sourceLineNo">800</span>                  .getSplitLogManagerCoordination().getLastRecoveryTime();<a name="line.800"></a>
-<span class="sourceLineNo">801</span>      if (!failedRecoveringRegionDeletions.isEmpty()<a name="line.801"></a>
-<span class="sourceLineNo">802</span>          || (tot == 0 &amp;&amp; tasks.size() == 0 &amp;&amp; (timeInterval &gt; checkRecoveringTimeThreshold))) {<a name="line.802"></a>
-<span class="sourceLineNo">803</span>        // inside the function there have more checks before GC anything<a name="line.803"></a>
-<span class="sourceLineNo">804</span>        if (!failedRecoveringRegionDeletions.isEmpty()) {<a name="line.804"></a>
-<span class="sourceLineNo">805</span>          List&lt;Pair&lt;Set&lt;ServerName&gt;, Boolean&gt;&gt; previouslyFailedDeletions =<a name="line.805"></a>
-<span class="sourceLineNo">806</span>              new ArrayList&lt;Pair&lt;Set&lt;ServerName&gt;, Boolean&gt;&gt;(failedRecoveringRegionDeletions);<a name="line.806"></a>
-<span class="sourceLineNo">807</span>          failedRecoveringRegionDeletions.removeAll(previouslyFailedDeletions);<a name="line.807"></a>
-<span class="sourceLineNo">808</span>          for (Pair&lt;Set&lt;ServerName&gt;, Boolean&gt; failedDeletion : previouslyFailedDeletions) {<a name="line.808"></a>
-<span class="sourceLineNo">809</span>            removeRecoveringRegions(failedDeletion.getFirst(), failedDeletion.getSecond());<a name="line.809"></a>
-<span class="sourceLineNo">810</span>          }<a name="line.810"></a>
-<span class="sourceLineNo">811</span>        } else {<a name="line.811"></a>
-<span class="sourceLineNo">812</span>          removeRecoveringRegions(null, null);<a name="line.812"></a>
-<span class="sourceLineNo">813</span>        }<a name="line.813"></a>
-<span class="sourceLineNo">814</span>      }<a name="line.814"></a>
-<span class="sourceLineNo">815</span>    }<a name="line.815"></a>
-<span class="sourceLineNo">816</span>  }<a name="line.816"></a>
-<span class="sourceLineNo">817</span><a name="line.817"></a>
-<span class="sourceLineNo">818</span>  public enum ResubmitDirective {<a name="line.818"></a>
-<span class="sourceLineNo">819</span>    CHECK(), FORCE();<a name="line.819"></a>
-<span class="sourceLineNo">820</span>  }<a name="line.820"></a>
-<span class="sourceLineNo">821</span><a name="line.821"></a>
-<span class="sourceLineNo">822</span>  public enum TerminationStatus {<a name="line.822"></a>
-<span class="sourceLineNo">823</span>    IN_PROGRESS("in_progress"), SUCCESS("success"), FAILURE("failure"), DELETED("deleted");<a name="line.823"></a>
-<span class="sourceLineNo">824</span><a name="line.824"></a>
-<span class="sourceLineNo">825</span>    String statusMsg;<a name="line.825"></a>
-<span class="sourceLineNo">826</span><a name="line.826"></a>
-<span class="sourceLineNo">827</span>    TerminationStatus(String msg) {<a name="line.827"></a>
-<span class="sourceLineNo">828</span>      statusMsg = msg;<a name="line.828"></a>
-<span class="sourceLineNo">829</span>    }<a name="line.829"></a>
-<span class="sourceLineNo">830</span><a name="line.830"></a>
-<span class="sourceLineNo">831</span>    @Override<a name="line.831"></a>
-<span class="sourceLineNo">832</span>    public String toString() {<a name="line.832"></a>
-<span class="sourceLineNo">833</span>      return statusMsg;<a name="line.833"></a>
-<span class="sourceLineNo">834</span>    }<a name="line.834"></a>
-<span class="sourceLineNo">835</span>  }<a name="line.835"></a>
-<span class="sourceLineNo">836</span>}<a name="line.836"></a>
+<span class="sourceLineNo">402</span>   * @param isMetaRecovery whether current recovery is for the meta region on {@code serverNames}<a name="line.402"></a>
+<span class="sourceLineNo">403</span>   */<a name="line.403"></a>
+<span class="sourceLineNo">404</span>  private void removeRecoveringRegions(final Set&lt;ServerName&gt; serverNames, Boolean isMetaRecovery) {<a name="line.404"></a>
+<span class="sourceLineNo">405</span>    if (!isLogReplaying()) {<a name="line.405"></a>
+<span class="sourceLineNo">406</span>      // the function is only used in WALEdit direct replay mode<a name="line.406"></a>
+<span class="sourceLineNo">407</span>      return;<a name="line.407"></a>
+<span class="sourceLineNo">408</span>    }<a name="line.408"></a>
+<span class="sourceLineNo">409</span>    if (serverNames == null || serverNames.isEmpty()) return;<a name="line.409"></a>
+<span class="sourceLineNo">410</span><a name="line.410"></a>
+<span class="sourceLineNo">411</span>    Set&lt;String&gt; recoveredServerNameSet = new HashSet&lt;String&gt;();<a name="line.411"></a>
+<span class="sourceLineNo">412</span>    for (ServerName tmpServerName : serverNames) {<a name="line.412"></a>
+<span class="sourceLineNo">413</span>      recoveredServerNameSet.add(tmpServerName.getServerName());<a name="line.413"></a>
+<span class="sourceLineNo">414</span>    }<a name="line.414"></a>
+<span class="sourceLineNo">415</span>   <a name="line.415"></a>
+<span class="sourceLineNo">416</span>    this.recoveringRegionLock.lock();<a name="line.416"></a>
+<span class="sourceLineNo">417</span>    try {<a name="line.417"></a>
+<span class="sourceLineNo">418</span>      ((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.418"></a>
+<span class="sourceLineNo">419</span>          .getSplitLogManagerCoordination().removeRecoveringRegions(recoveredServerNameSet,<a name="line.419"></a>
+<span class="sourceLineNo">420</span>            isMetaRecovery);<a name="line.420"></a>
+<span class="sourceLineNo">421</span>    } catch (IOException e) {<a name="line.421"></a>
+<span class="sourceLineNo">422</span>      LOG.warn("removeRecoveringRegions got exception. Will retry", e);<a name="line.422"></a>
+<span class="sourceLineNo">423</span>      if (serverNames != null &amp;&amp; !serverNames.isEmpty()) {<a name="line.423"></a>
+<span class="sourceLineNo">424</span>        this.failedRecoveringRegionDeletions.add(new Pair&lt;Set&lt;ServerName&gt;, Boolean&gt;(serverNames,<a name="line.424"></a>
+<span class="sourceLineNo">425</span>            isMetaRecovery));<a name="line.425"></a>
+<span class="sourceLineNo">426</span>      }<a name="line.426"></a>
+<span class="sourceLineNo">427</span>    } finally {<a name="line.427"></a>
+<span class="sourceLineNo">428</span>      this.recoveringRegionLock.unlock();<a name="line.428"></a>
+<span class="sourceLineNo">429</span>    }<a name="line.429"></a>
+<span class="sourceLineNo">430</span>  }<a name="line.430"></a>
+<span class="sourceLineNo">431</span><a name="line.431"></a>
+<span class="sourceLineNo">432</span>  /**<a name="line.432"></a>
+<span class="sourceLineNo">433</span>   * It removes stale recovering regions under /hbase/recovering-regions/[encoded region name]<a name="line.433"></a>
+<span class="sourceLineNo">434</span>   * during master initialization phase.<a name="line.434"></a>
+<span class="sourceLineNo">435</span>   * @param failedServers A set of known failed servers<a name="line.435"></a>
+<span class="sourceLineNo">436</span>   * @throws IOException<a name="line.436"></a>
+<span class="sourceLineNo">437</span>   */<a name="line.437"></a>
+<span class="sourceLineNo">438</span>  void removeStaleRecoveringRegions(final Set&lt;ServerName&gt; failedServers) throws IOException,<a name="line.438"></a>
+<span class="sourceLineNo">439</span>      InterruptedIOException {<a name="line.439"></a>
+<span class="sourceLineNo">440</span>    Set&lt;String&gt; knownFailedServers = new HashSet&lt;String&gt;();<a name="line.440"></a>
+<span class="sourceLineNo">441</span>    if (failedServers != null) {<a name="line.441"></a>
+<span class="sourceLineNo">442</span>      for (ServerName tmpServerName : failedServers) {<a name="line.442"></a>
+<span class="sourceLineNo">443</span>        knownFailedServers.add(tmpServerName.getServerName());<a name="line.443"></a>
+<span class="sourceLineNo">444</span>      }<a name="line.444"></a>
+<span class="sourceLineNo">445</span>    }<a name="line.445"></a>
+<span class="sourceLineNo">446</span><a name="line.446"></a>
+<span class="sourceLineNo">447</span>    this.recoveringRegionLock.lock();<a name="line.447"></a>
+<span class="sourceLineNo">448</span>    try {<a name="line.448"></a>
+<span class="sourceLineNo">449</span>      ((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.449"></a>
+<span class="sourceLineNo">450</span>          .getSplitLogManagerCoordination().removeStaleRecoveringRegions(knownFailedServers);<a name="line.450"></a>
+<span class="sourceLineNo">451</span>    } finally {<a name="line.451"></a>
+<span class="sourceLineNo">452</span>      this.recoveringRegionLock.unlock();<a name="line.452"></a>
+<span class="sourceLineNo">453</span>    }<a name="line.453"></a>
+<span class="sourceLineNo">454</span>  }<a name="line.454"></a>
+<span class="sourceLineNo">455</span><a name="line.455"></a>
+<span class="sourceLineNo">456</span>  /**<a name="line.456"></a>
+<span class="sourceLineNo">457</span>   * @param path<a name="line.457"></a>
+<span class="sourceLineNo">458</span>   * @param batch<a name="line.458"></a>
+<span class="sourceLineNo">459</span>   * @return null on success, existing task on error<a name="line.459"></a>
+<span class="sourceLineNo">460</span>   */<a name="line.460"></a>
+<span class="sourceLineNo">461</span>  private Task createTaskIfAbsent(String path, TaskBatch batch) {<a name="line.461"></a>
+<span class="sourceLineNo">462</span>    Task oldtask;<a name="line.462"></a>
+<span class="sourceLineNo">463</span>    // batch.installed is only changed via this function and<a name="line.463"></a>
+<span class="sourceLineNo">464</span>    // a single thread touches batch.installed.<a name="line.464"></a>
+<span class="sourceLineNo">465</span>    Task newtask = new Task();<a name="line.465"></a>
+<span class="sourceLineNo">466</span>    newtask.batch = batch;<a name="line.466"></a>
+<span class="sourceLineNo">467</span>    oldtask = tasks.putIfAbsent(path, newtask);<a name="line.467"></a>
+<span class="sourceLineNo">468</span>    if (oldtask == null) {<a name="line.468"></a>
+<span class="sourceLineNo">469</span>      batch.installed++;<a name="line.469"></a>
+<span class="sourceLineNo">470</span>      return null;<a name="line.470"></a>
+<span class="sourceLineNo">471</span>    }<a name="line.471"></a>
+<span class="sourceLineNo">472</span>    // new task was not used.<a name="line.472"></a>
+<span class="sourceLineNo">473</span>    synchronized (oldtask) {<a name="line.473"></a>
+<span class="sourceLineNo">474</span>      if (oldtask.isOrphan()) {<a name="line.474"></a>
+<span class="sourceLineNo">475</span>        if (oldtask.status == SUCCESS) {<a name="line.475"></a>
+<span class="sourceLineNo">476</span>          // The task is already done. Do not install the batch for this<a name="line.476"></a>
+<span class="sourceLineNo">477</span>          // task because it might be too late for setDone() to update<a name="line.477"></a>
+<span class="sourceLineNo">478</span>          // batch.done. There is no need for the batch creator to wait for<a name="line.478"></a>
+<span class="sourceLineNo">479</span>          // this task to complete.<a name="line.479"></a>
+<span class="sourceLineNo">480</span>          return (null);<a name="line.480"></a>
+<span class="sourceLineNo">481</span>        }<a name="line.481"></a>
+<span class="sourceLineNo">482</span>        if (oldtask.status == IN_PROGRESS) {<a name="line.482"></a>
+<span class="sourceLineNo">483</span>          oldtask.batch = batch;<a name="line.483"></a>
+<span class="sourceLineNo">484</span>          batch.installed++;<a name="line.484"></a>
+<span class="sourceLineNo">485</span>          LOG.debug("Previously orphan task " + path + " is now being waited upon");<a name="line.485"></a>
+<span class="sourceLineNo">486</span>          return null;<a name="line.486"></a>
+<span class="sourceLineNo">487</span>        }<a name="line.487"></a>
+<span class="sourceLineNo">488</span>        while (oldtask.status == FAILURE) {<a name="line.488"></a>
+<span class="sourceLineNo">489</span>          LOG.debug("wait for status of task " + path + " to change to DELETED");<a name="line.489"></a>
+<span class="sourceLineNo">490</span>          SplitLogCounters.tot_mgr_wait_for_zk_delete.incrementAndGet();<a name="line.490"></a>
+<span class="sourceLineNo">491</span>          try {<a name="line.491"></a>
+<span class="sourceLineNo">492</span>            oldtask.wait();<a name="line.492"></a>
+<span class="sourceLineNo">493</span>          } catch (InterruptedException e) {<a name="line.493"></a>
+<span class="sourceLineNo">494</span>            Thread.currentThread().interrupt();<a name="line.494"></a>
+<span class="sourceLineNo">495</span>            LOG.warn("Interrupted when waiting for znode delete callback");<a name="line.495"></a>
+<span class="sourceLineNo">496</span>            // fall through to return failure<a name="line.496"></a>
+<span class="sourceLineNo">497</span>            break;<a name="line.497"></a>
+<span class="sourceLineNo">498</span>          }<a name="line.498"></a>
+<span class="sourceLineNo">499</span>        }<a name="line.499"></a>
+<span class="sourceLineNo">500</span>        if (oldtask.status != DELETED) {<a name="line.500"></a>
+<span class="sourceLineNo">501</span>          LOG.warn("Failure because previously failed task"<a name="line.501"></a>
+<span class="sourceLineNo">502</span>              + " state still present. Waiting for znode delete callback" + " path=" + path);<a name="line.502"></a>
+<span class="sourceLineNo">503</span>          return oldtask;<a name="line.503"></a>
+<span class="sourceLineNo">504</span>        }<a name="line.504"></a>
+<span class="sourceLineNo">505</span>        // reinsert the newTask and it must succeed this time<a name="line.505"></a>
+<span class="sourceLineNo">506</span>        Task t = tasks.putIfAbsent(path, newtask);<a name="line.506"></a>
+<span class="sourceLineNo">507</span>        if (t == null) {<a name="line.507"></a>
+<span class="sourceLineNo">508</span>          batch.installed++;<a name="line.508"></a>
+<span class="sourceLineNo">509</span>          return null;<a name="line.509"></a>
+<span class="sourceLineNo">510</span>        }<a name="line.510"></a>
+<span class="sourceLineNo">511</span>        LOG.fatal("Logic error. Deleted task still present in tasks map");<a name="line.511"></a>
+<span class="sourceLineNo">512</span>        assert false : "Deleted task still present in tasks map";<a name="line.512"></a>
+<span class="sourceLineNo">513</span>        return t;<a name="line.513"></a>
+<span class="sourceLineNo">514</span>      }<a name="line.514"></a>
+<span class="sourceLineNo">515</span>      LOG.warn("Failure because two threads can't wait for the same task; path=" + path);<a name="line.515"></a>
+<span class="sourceLineNo">516</span>      return oldtask;<a name="line.516"></a>
+<span class="sourceLineNo">517</span>    }<a name="line.517"></a>
+<span class="sourceLineNo">518</span>  }<a name="line.518"></a>
+<span class="sourceLineNo">519</span><a name="line.519"></a>
+<span class="sourceLineNo">520</span>  Task findOrCreateOrphanTask(String path) {<a name="line.520"></a>
+<span class="sourceLineNo">521</span>    Task orphanTask = new Task();<a name="line.521"></a>
+<span class="sourceLineNo">522</span>    Task task;<a name="line.522"></a>
+<span class="sourceLineNo">523</span>    task = tasks.putIfAbsent(path, orphanTask);<a name="line.523"></a>
+<span class="sourceLineNo">524</span>    if (task == null) {<a name="line.524"></a>
+<span class="sourceLineNo">525</span>      LOG.info("creating orphan task " + path);<a name="line.525"></a>
+<span class="sourceLineNo">526</span>      SplitLogCounters.tot_mgr_orphan_task_acquired.incrementAndGet();<a name="line.526"></a>
+<span class="sourceLineNo">527</span>      task = orphanTask;<a name="line.527"></a>
+<span class="sourceLineNo">528</span>    }<a name="line.528"></a>
+<span class="sourceLineNo">529</span>    return task;<a name="line.529"></a>
+<span class="sourceLineNo">530</span>  }<a name="line.530"></a>
+<span class="sourceLineNo">531</span><a name="line.531"></a>
+<span class="sourceLineNo">532</span>  public void stop() {<a name="line.532"></a>
+<span class="sourceLineNo">533</span>    if (choreService != null) {<a name="line.533"></a>
+<span class="sourceLineNo">534</span>      choreService.shutdown();<a name="line.534"></a>
+<span class="sourceLineNo">535</span>    }<a name="line.535"></a>
+<span class="sourceLineNo">536</span>    if (timeoutMonitor != null) {<a name="line.536"></a>
+<span class="sourceLineNo">537</span>      timeoutMonitor.cancel(true);<a name="line.537"></a>
+<span class="sourceLineNo">538</span>    }<a name="line.538"></a>
+<span class="sourceLineNo">539</span>  }<a name="line.539"></a>
+<span class="sourceLineNo">540</span><a name="line.540"></a>
+<span class="sourceLineNo">541</span>  void handleDeadWorker(ServerName workerName) {<a name="line.541"></a>
+<span class="sourceLineNo">542</span>    // resubmit the tasks on the TimeoutMonitor thread. Makes it easier<a name="line.542"></a>
+<span class="sourceLineNo">543</span>    // to reason about concurrency. Makes it easier to retry.<a name="line.543"></a>
+<span class="sourceLineNo">544</span>    synchronized (deadWorkersLock) {<a name="line.544"></a>
+<span class="sourceLineNo">545</span>      if (deadWorkers == null) {<a name="line.545"></a>
+<span class="sourceLineNo">546</span>        deadWorkers = new HashSet&lt;ServerName&gt;(100);<a name="line.546"></a>
+<span class="sourceLineNo">547</span>      }<a name="line.547"></a>
+<span class="sourceLineNo">548</span>      deadWorkers.add(workerName);<a name="line.548"></a>
+<span class="sourceLineNo">549</span>    }<a name="line.549"></a>
+<span class="sourceLineNo">550</span>    LOG.info("dead splitlog worker " + workerName);<a name="line.550"></a>
+<span class="sourceLineNo">551</span>  }<a name="line.551"></a>
+<span class="sourceLineNo">552</span><a name="line.552"></a>
+<span class="sourceLineNo">553</span>  void handleDeadWorkers(Set&lt;ServerName&gt; serverNames) {<a name="line.553"></a>
+<span class="sourceLineNo">554</span>    synchronized (deadWorkersLock) {<a name="line.554"></a>
+<span class="sourceLineNo">555</span>      if (deadWorkers == null) {<a name="line.555"></a>
+<span class="sourceLineNo">556</span>        deadWorkers = new HashSet&lt;ServerName&gt;(100);<a name="line.556"></a>
+<span class="sourceLineNo">557</span>      }<a name="line.557"></a>
+<span class="sourceLineNo">558</span>      deadWorkers.addAll(serverNames);<a name="line.558"></a>
+<span class="sourceLineNo">559</span>    }<a name="line.559"></a>
+<span class="sourceLineNo">560</span>    LOG.info("dead splitlog workers " + serverNames);<a name="line.560"></a>
+<span class="sourceLineNo">561</span>  }<a name="line.561"></a>
+<span class="sourceLineNo">562</span><a name="line.562"></a>
+<span class="sourceLineNo">563</span>  /**<a name="line.563"></a>
+<span class="sourceLineNo">564</span>   * This function is to set recovery mode from outstanding split log tasks from before or current<a name="line.564"></a>
+<span class="sourceLineNo">565</span>   * configuration setting<a name="line.565"></a>
+<span class="sourceLineNo">566</span>   * @param isForInitialization<a name="line.566"></a>
+<span class="sourceLineNo">567</span>   * @throws IOException throws if it's impossible to set recovery mode<a name="line.567"></a>
+<span class="sourceLineNo">568</span>   */<a name="line.568"></a>
+<span class="sourceLineNo">569</span>  public void setRecoveryMode(boolean isForInitialization) throws IOException {<a name="line.569"></a>
+<span class="sourceLineNo">570</span>    ((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.570"></a>
+<span class="sourceLineNo">571</span>        .getSplitLogManagerCoordination().setRecoveryMode(isForInitialization);<a name="line.571"></a>
+<span class="sourceLineNo">572</span><a name="line.572"></a>
+<span class="sourceLineNo">573</span>  }<a name="line.573"></a>
+<span class="sourceLineNo">574</span><a name="line.574"></a>
+<span class="sourceLineNo">575</span>  public void markRegionsRecovering(ServerName server, Set&lt;HRegionInfo&gt; userRegions)<a name="line.575"></a>
+<span class="sourceLineNo">576</span>      throws InterruptedIOException, IOException {<a name="line.576"></a>
+<span class="sourceLineNo">577</span>    if (userRegions == null || (!isLogReplaying())) {<a name="line.577"></a>
+<span class="sourceLineNo">578</span>      return;<a name="line.578"></a>
+<span class="sourceLineNo">579</span>    }<a name="line.579"></a>
+<span class="sourceLineNo">580</span>    try {<a name="line.580"></a>
+<span class="sourceLineNo">581</span>      this.recoveringRegionLock.lock();<a name="line.581"></a>
+<span class="sourceLineNo">582</span>      // mark that we're creating recovering regions<a name="line.582"></a>
+<span class="sourceLineNo">583</span>      ((BaseCoordinatedStateManager) this.server.getCoordinatedStateManager())<a name="line.583"></a>
+<span class="sourceLineNo">584</span>          .getSplitLogManagerCoordination().markRegionsRecovering(server, userRegions);<a name="line.584"></a>
+<span class="sourceLineNo">585</span>    } finally {<a name="line.585"></a>
+<span class="sourceLineNo">586</span>      this.recoveringRegionLock.unlock();<a name="line.586"></a>
+<span class="sourceLineNo">587</span>    }<a name="line.587"></a>
+<span class="sourceLineNo">588</span><a name="line.588"></a>
+<span class="sourceLineNo">589</span>  }<a name="line.589"></a>
+<span class="sourceLineNo">590</span><a name="line.590"></a>
+<span class="sourceLineNo">591</span>  /**<a name="line.591"></a>
+<span class="sourceLineNo">592</span>   * @return whether log is replaying<a name="line.592"></a>
+<span class="sourceLineNo">593</span>   */<a name="line.593"></a>
+<span class="sourceLineNo">594</span>  public boolean isLogReplaying() {<a name="line.594"></a>
+<span class="sourceLineNo">595</span>    CoordinatedStateManager m = server.getCoordinatedStateManager();<a name="line.595"></a>
+<span class="sourceLineNo">596</span>    if (m == null) return false;<a name="line.596"></a>
+<span class="sourceLineNo">597</span>    return ((BaseCoordinatedStateManager)m).getSplitLogManagerCoordination().isReplaying();<a name="line.597"></a>
+<span class="sourceLineNo">598</span>  }<a name="line.598"></a>
+<span class="sourceLineNo">599</span><a name="line.599"></a>
+<span class="sourceLineNo">600</span>  /**<a name="line.600"></a>
+<span class="sourceLineNo">601</span>   * @return whether log is splitting<a name="line.601"></a>
+<span class="sourceLineNo">602</span>   */<a name="line.602"></a>
+<span class="sourceLineNo">603</span>  public boolean isLogSplitting() {<a name="line.603"></a>
+<span class="sourceLineNo">604</span>    if (server.getCoordinatedStateManager() == null) return false;<a name="line.604"></a>
+<span class="sourceLineNo">605</span>    return ((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.605"></a>
+<span class="sourceLineNo">606</span>        .getSplitLogManagerCoordination().isSplitting();<a name="line.606"></a>
+<span class="sourceLineNo">607</span>  }<a name="line.607"></a>
+<span class="sourceLineNo">608</span><a name="line.608"></a>
+<span class="sourceLineNo">609</span>  /**<a name="line.609"></a>
+<span class="sourceLineNo">610</span>   * @return the current log recovery mode<a name="line.610"></a>
+<span class="sourceLineNo">611</span>   */<a name="line.611"></a>
+<span class="sourceLineNo">612</span>  public RecoveryMode getRecoveryMode() {<a name="line.612"></a>
+<span class="sourceLineNo">613</span>    return ((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.613"></a>
+<span class="sourceLineNo">614</span>        .getSplitLogManagerCoordination().getRecoveryMode();<a name="line.614"></a>
+<span class="sourceLineNo">615</span>  }<a name="line.615"></a>
+<span class="sourceLineNo">616</span><a name="line.616"></a>
+<span class="sourceLineNo">617</span>  /**<a name="line.617"></a>
+<span class="sourceLineNo">618</span>   * Keeps track of the batch of tasks submitted together by a caller in splitLogDistributed().<a name="line.618"></a>
+<span class="sourceLineNo">619</span>   * Clients threads use this object to wait for all their tasks to be done.<a name="line.619"></a>
+<span class="sourceLineNo">620</span>   * &lt;p&gt;<a name="line.620"></a>
+<span class="sourceLineNo">621</span>   * All access is synchronized.<a name="line.621"></a>
+<span class="sourceLineNo">622</span>   */<a name="line.622"></a>
+<span class="sourceLineNo">623</span>  @InterfaceAudience.Private<a name="line.623"></a>
+<span class="sourceLineNo">624</span>  public static class TaskBatch {<a name="line.624"></a>
+<span class="sourceLineNo">625</span>    public int installed = 0;<a name="line.625"></a>
+<span class="sourceLineNo">626</span>    public int done = 0;<a name="line.626"></a>
+<span class="sourceLineNo">627</span>    public int error = 0;<a name="line.627"></a>
+<span class="sourceLineNo">628</span>    public volatile boolean isDead = false;<a name="line.628"></a>
+<span class="sourceLineNo">629</span><a name="line.629"></a>
+<span class="sourceLineNo">630</span>    @Override<a name="line.630"></a>
+<span class="sourceLineNo">631</span>    public String toString() {<a name="line.631"></a>
+<span class="sourceLineNo">632</span>      return ("installed = " + installed + " done = " + done + " error = " + error);<a name="line.632"></a>
+<span class="sourceLineNo">633</span>    }<a name="line.633"></a>
+<span class="sourceLineNo">634</span>  }<a name="line.634"></a>
+<span class="sourceLineNo">635</span><a name="line.635"></a>
+<span class="sourceLineNo">636</span>  /**<a name="line.636"></a>
+<span class="sourceLineNo">637</span>   * in memory state of an active task.<a name="line.637"></a>
+<span class="sourceLineNo">638</span>   */<a name="line.638"></a>
+<span class="sourceLineNo">639</span>  @InterfaceAudience.Private<a name="line.639"></a>
+<span class="sourceLineNo">640</span>  public static class Task {<a name="line.640"></a>
+<span class="sourceLineNo">641</span>    public volatile long last_update;<a name="line.641"></a>
+<span class="sourceLineNo">642</span>    public volatile int last_version;<a name="line.642"></a>
+<span class="sourceLineNo">643</span>    public volatile ServerName cur_worker_name;<a name="line.643"></a>
+<span class="sourceLineNo">644</span>    public volatile TaskBatch batch;<a name="line.644"></a>
+<span class="sourceLineNo">645</span>    public volatile TerminationStatus status;<a name="line.645"></a>
+<span class="sourceLineNo">646</span>    public volatile int incarnation;<a name="line.646"></a>
+<span class="sourceLineNo">647</span>    public final AtomicInteger unforcedResubmits = new AtomicInteger();<a name="line.647"></a>
+<span class="sourceLineNo">648</span>    public volatile boolean resubmitThresholdReached;<a name="line.648"></a>
+<span class="sourceLineNo">649</span><a name="line.649"></a>
+<span class="sourceLineNo">650</span>    @Override<a name="line.650"></a>
+<span class="sourceLineNo">651</span>    public String toString() {<a name="line.651"></a>
+<span class="sourceLineNo">652</span>      return ("last_update = " + last_update + " last_version = " + last_version<a name="line.652"></a>
+<span class="sourceLineNo">653</span>          + " cur_worker_name = " + cur_worker_name + " status = " + status + " incarnation = "<a name="line.653"></a>
+<span class="sourceLineNo">654</span>          + incarnation + " resubmits = " + unforcedResubmits.get() + " batch = " + batch);<a name="line.654"></a>
+<span class="sourceLineNo">655</span>    }<a name="line.655"></a>
+<span class="sourceLineNo">656</span><a name="line.656"></a>
+<span class="sourceLineNo">657</span>    public Task() {<a name="line.657"></a>
+<span class="sourceLineNo">658</span>      incarnation = 0;<a name="line.658"></a>
+<span class="sourceLineNo">659</span>      last_version = -1;<a name="line.659"></a>
+<span class="sourceLineNo">660</span>      status = IN_PROGRESS;<a name="line.660"></a>
+<span class="sourceLineNo">661</span>      setUnassigned();<a name="line.661"></a>
+<span class="sourceLineNo">662</span>    }<a name="line.662"></a>
+<span class="sourceLineNo">663</span><a name="line.663"></a>
+<span class="sourceLineNo">664</span>    public boolean isOrphan() {<a name="line.664"></a>
+<span class="sourceLineNo">665</span>      return (batch == null || batch.isDead);<a name="line.665"></a>
+<span class="sourceLineNo">666</span>    }<a name="line.666"></a>
+<span class="sourceLineNo">667</span><a name="line.667"></a>
+<span class="sourceLineNo">668</span>    public boolean isUnassigned() {<a name="line.668"></a>
+<span class="sourceLineNo">669</span>      return (cur_worker_name == null);<a name="line.669"></a>
+<span class="sourceLineNo">670</span>    }<a name="line.670"></a>
+<span class="sourceLineNo">671</span><a name="line.671"></a>
+<span class="sourceLineNo">672</span>    public void heartbeatNoDetails(long time) {<a name="line.672"></a>
+<span class="sourceLineNo">673</span>      last_update = time;<a name="line.673"></a>
+<span class="sourceLineNo">674</span>    }<a name="line.674"></a>
+<span class="sourceLineNo">675</span><a name="line.675"></a>
+<span class="sourceLineNo">676</span>    public void heartbeat(long time, int version, ServerName worker) {<a name="line.676"></a>
+<span class="sourceLineNo">677</span>      last_version = version;<a name="line.677"></a>
+<span class="sourceLineNo">678</span>      last_update = time;<a name="line.678"></a>
+<span class="sourceLineNo">679</span>      cur_worker_name = worker;<a name="line.679"></a>
+<span class="sourceLineNo">680</span>    }<a name="line.680"></a>
+<span class="sourceLineNo">681</span><a name="line.681"></a>
+<span class="sourceLineNo">682</span>    public void setUnassigned() {<a name="line.682"></a>
+<span class="sourceLineNo">683</span>      cur_worker_name = null;<a name="line.683"></a>
+<span class="sourceLineNo">684</span>      last_update = -1;<a name="line.684"></a>
+<span class="sourceLineNo">685</span>    }<a name="line.685"></a>
+<span class="sourceLineNo">686</span>  }<a name="line.686"></a>
+<span class="sourceLineNo">687</span><a name="line.687"></a>
+<span class="sourceLineNo">688</span>  /**<a name="line.688"></a>
+<span class="sourceLineNo">689</span>   * Periodically checks all active tasks and resubmits the ones that have timed out<a name="line.689"></a>
+<span class="sourceLineNo">690</span>   */<a name="line.690"></a>
+<span class="sourceLineNo">691</span>  private class TimeoutMonitor extends ScheduledChore {<a name="line.691"></a>
+<span class="sourceLineNo">692</span>    private long lastLog = 0;<a name="line.692"></a>
+<span class="sourceLineNo">693</span><a name="line.693"></a>
+<span class="sourceLineNo">694</span>    public TimeoutMonitor(final int period, Stoppable stopper) {<a name="line.694"></a>
+<span class="sourceLineNo">695</span>      super("SplitLogManager Timeout Monitor", stopper, period);<a name="line.695"></a>
+<span class="sourceLineNo">696</span>    }<a name="line.696"></a>
+<span class="sourceLineNo">697</span><a name="line.697"></a>
+<span class="sourceLineNo">698</span>    @Override<a name="line.698"></a>
+<span class="sourceLineNo">699</span>    protected void chore() {<a name="line.699"></a>
+<span class="sourceLineNo">700</span>      int resubmitted = 0;<a name="line.700"></a>
+<span class="sourceLineNo">701</span>      int unassigned = 0;<a name="line.701"></a>
+<span class="sourceLineNo">702</span>      int tot = 0;<a name="line.702"></a>
+<span class="sourceLineNo">703</span>      boolean found_assigned_task = false;<a name="line.703"></a>
+<span class="sourceLineNo">704</span>      Set&lt;ServerName&gt; localDeadWorkers;<a name="line.704"></a>
+<span class="sourceLineNo">705</span><a name="line.705"></a>
+<span class="sourceLineNo">706</span>      synchronized (deadWorkersLock) {<a name="line.706"></a>
+<span class="sourceLineNo">707</span>        localDeadWorkers = deadWorkers;<a name="line.707"></a>
+<span class="sourceLineNo">708</span>        deadWorkers = null;<a name="line.708"></a>
+<span class="sourceLineNo">709</span>      }<a name="line.709"></a>
+<span class="sourceLineNo">710</span><a name="line.710"></a>
+<span class="sourceLineNo">711</span>      for (Map.Entry&lt;String, Task&gt; e : tasks.entrySet()) {<a name="line.711"></a>
+<span class="sourceLineNo">712</span>        String path = e.getKey();<a name="line.712"></a>
+<span class="sourceLineNo">713</span>        Task task = e.getValue();<a name="line.713"></a>
+<span class="sourceLineNo">714</span>        ServerName cur_worker = task.cur_worker_name;<a name="line.714"></a>
+<span class="sourceLineNo">715</span>        tot++;<a name="line.715"></a>
+<span class="sourceLineNo">716</span>        // don't easily resubmit a task which hasn't been picked up yet. It<a name="line.716"></a>
+<span class="sourceLineNo">717</span>        // might be a long while before a SplitLogWorker is free to pick up a<a name="line.717"></a>
+<span class="sourceLineNo">718</span>        // task. This is because a SplitLogWorker picks up a task one at a<a name="line.718"></a>
+<span class="sourceLineNo">719</span>        // time. If we want progress when there are no region servers then we<a name="line.719"></a>
+<span class="sourceLineNo">720</span>        // will have to run a SplitLogWorker thread in the Master.<a name="line.720"></a>
+<span class="sourceLineNo">721</span>        if (task.isUnassigned()) {<a name="line.721"></a>
+<span class="sourceLineNo">722</span>          unassigned++;<a name="line.722"></a>
+<span class="sourceLineNo">723</span>          continue;<a name="line.723"></a>
+<span class="sourceLineNo">724</span>        }<a name="line.724"></a>
+<span class="sourceLineNo">725</span>        found_assigned_task = true;<a name="line.725"></a>
+<span class="sourceLineNo">726</span>        if (localDeadWorkers != null &amp;&amp; localDeadWorkers.contains(cur_worker)) {<a name="line.726"></a>
+<span class="sourceLineNo">727</span>          SplitLogCounters.tot_mgr_resubmit_dead_server_task.incrementAndGet();<a name="line.727"></a>
+<span class="sourceLineNo">728</span>          if (((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.728"></a>
+<span class="sourceLineNo">729</span>              .getSplitLogManagerCoordination().resubmitTask(path, task, FORCE)) {<a name="line.729"></a>
+<span class="sourceLineNo">730</span>            resubmitted++;<a name="line.730"></a>
+<span class="sourceLineNo">731</span>          } else {<a name="line.731"></a>
+<span class="sourceLineNo">732</span>            handleDeadWorker(cur_worker);<a name="line.732"></a>
+<span class="sourceLineNo">733</span>            LOG.warn("Failed to resubmit task " + path + " owned by dead " + cur_worker<a name="line.733"></a>
+<span class="sourceLineNo">734</span>                + ", will retry.");<a name="line.734"></a>
+<span class="sourceLineNo">735</span>          }<a name="line.735"></a>
+<span class="sourceLineNo">736</span>        } else if (((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.736"></a>
+<span class="sourceLineNo">737</span>            .getSplitLogManagerCoordination().resubmitTask(path, task, CHECK)) {<a name="line.737"></a>
+<span class="sourceLineNo">738</span>          resubmitted++;<a name="line.738"></a>
+<span class="sourceLineNo">739</span>        }<a name="line.739"></a>
+<span class="sourceLineNo">740</span>      }<a name="line.740"></a>
+<span class="sourceLineNo">741</span>      if (tot &gt; 0) {<a name="line.741"></a>
+<span class="sourceLineNo">742</span>        long now = EnvironmentEdgeManager.currentTime();<a name="line.742"></a>
+<span class="sourceLineNo">743</span>        if (now &gt; lastLog + 5000) {<a name="line.743"></a>
+<span class="sourceLineNo">744</span>          lastLog = now;<a name="line.744"></a>
+<span class="sourceLineNo">745</span>          LOG.info("total tasks = " + tot + " unassigned = " + unassigned + " tasks=" + tasks);<a name="line.745"></a>
+<span class="sourceLineNo">746</span>        }<a name="line.746"></a>
+<span class="sourceLineNo">747</span>      }<a name="line.747"></a>
+<span class="sourceLineNo">748</span>      if (resubmitted &gt; 0) {<a name="line.748"></a>
+<span class="sourceLineNo">749</span>        LOG.info("resubmitted " + resubmitted + " out of " + tot + " tasks");<a name="line.749"></a>
+<span class="sourceLineNo">750</span>      }<a name="line.750"></a>
+<span class="sourceLineNo">751</span>      // If there are pending tasks and all of them have been unassigned for<a name="line.751"></a>
+<span class="sourceLineNo">752</span>      // some time then put up a RESCAN node to ping the workers.<a name="line.752"></a>
+<span class="sourceLineNo">753</span>      // ZKSplitlog.DEFAULT_UNASSIGNED_TIMEOUT is of the order of minutes<a name="line.753"></a>
+<span class="sourceLineNo">754</span>      // because a. it is very unlikely that every worker had a<a name="line.754"></a>
+<span class="sourceLineNo">755</span>      // transient error when trying to grab the task b. if there are no<a name="line.755"></a>
+<span class="sourceLineNo">756</span>      // workers then all tasks wills stay unassigned indefinitely and the<a name="line.756"></a>
+<span class="sourceLineNo">757</span>      // manager will be indefinitely creating RESCAN nodes. TODO may be the<a name="line.757"></a>
+<span class="sourceLineNo">758</span>      // master should spawn both a manager and a worker thread to guarantee<a name="line.758"></a>
+<span class="sourceLineNo">759</span>      // that there is always one worker in the system<a name="line.759"></a>
+<span class="sourceLineNo">760</span>      if (tot &gt; 0<a name="line.760"></a>
+<span class="sourceLineNo">761</span>          &amp;&amp; !found_assigned_task<a name="line.761"></a>
+<span class="sourceLineNo">762</span>          &amp;&amp; ((EnvironmentEdgeManager.currentTime() - lastTaskCreateTime) &gt; unassignedTimeout)) {<a name="line.762"></a>
+<span class="sourceLineNo">763</span>        for (Map.Entry&lt;String, Task&gt; e : tasks.entrySet()) {<a name="line.763"></a>
+<span class="sourceLineNo">764</span>          String key = e.getKey();<a name="line.764"></a>
+<span class="sourceLineNo">765</span>          Task task = e.getValue();<a name="line.765"></a>
+<span class="sourceLineNo">766</span>          // we have to do task.isUnassigned() check again because tasks might<a name="line.766"></a>
+<span class="sourceLineNo">767</span>          // have been asynchronously assigned. There is no locking required<a name="line.767"></a>
+<span class="sourceLineNo">768</span>          // for these checks ... it is OK even if tryGetDataSetWatch() is<a name="line.768"></a>
+<span class="sourceLineNo">769</span>          // called unnecessarily for a taskpath<a name="line.769"></a>
+<span class="sourceLineNo">770</span>          if (task.isUnassigned() &amp;&amp; (task.status != FAILURE)) {<a name="line.770"></a>
+<span class="sourceLineNo">771</span>            // We just touch the znode to make sure its still there<a name="line.771"></a>
+<span class="sourceLineNo">772</span>            ((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.772"></a>
+<span class="sourceLineNo">773</span>                .getSplitLogManagerCoordination().checkTaskStillAvailable(key);<a name="line.773"></a>
+<span class="sourceLineNo">774</span>          }<a name="line.774"></a>
+<span class="sourceLineNo">775</span>        }<a name="line.775"></a>
+<span class="sourceLineNo">776</span>        ((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.776"></a>
+<span class="sourceLineNo">777</span>            .getSplitLogManagerCoordination().checkTasks();<a name="line.777"></a>
+<span class="sourceLineNo">778</span>        SplitLogCounters.tot_mgr_resubmit_unassigned.incrementAndGet();<a name="line.778"></a>
+<span class="sourceLineNo">779</span>        LOG.debug("resubmitting unassigned task(s) after timeout");<a name="line.779"></a>
+<span class="sourceLineNo">780</span>      }<a name="line.780"></a>
+<span class="sourceLineNo">781</span>      Set&lt;String&gt; failedDeletions =<a name="line.781"></a>
+<span class="sourceLineNo">782</span>          ((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.782"></a>
+<span class="sourceLineNo">783</span>              .getSplitLogManagerCoordination().getDetails().getFailedDeletions();<a name="line.783"></a>
+<span class="sourceLineNo">784</span>      // Retry previously failed deletes<a name="line.784"></a>
+<span class="sourceLineNo">785</span>      if (failedDeletions.size() &gt; 0) {<a name="line.785"></a>
+<span class="sourceLineNo">786</span>        List&lt;String&gt; tmpPaths = new ArrayList&lt;String&gt;(failedDeletions);<a name="line.786"></a>
+<span class="sourceLineNo">787</span>        for (String tmpPath : tmpPaths) {<a name="line.787"></a>
+<span class="sourceLineNo">788</span>          // deleteNode is an async call<a name="line.788"></a>
+<span class="sourceLineNo">789</span>          ((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.789"></a>
+<span class="sourceLineNo">790</span>              .getSplitLogManagerCoordination().deleteTask(tmpPath);<a name="line.790"></a>
+<span class="sourceLineNo">791</span>        }<a name="line.791"></a>
+<span class="sourceLineNo">792</span>        failedDeletions.removeAll(tmpPaths);<a name="line.792"></a>
+<span class="sourceLineNo">793</span>      }<a name="line.793"></a>
+<span class="sourceLineNo">794</span><a name="line.794"></a>
+<span class="sourceLineNo">795</span>      // Garbage collect left-over<a name="line.795"></a>
+<span class="sourceLineNo">796</span>      long timeInterval =<a name="line.796"></a>
+<span class="sourceLineNo">797</span>          EnvironmentEdgeManager.currentTime()<a name="line.797"></a>
+<span class="sourceLineNo">798</span>              - ((BaseCoordinatedStateManager) server.getCoordinatedStateManager())<a name="line.798"></a>
+<span class="sourceLineNo">799</span>                  .getSplitLogManagerCoordination().getLastRecoveryTime();<a name="line.799"></a>
+<span class="sourceLineNo">800</span>      if (!failedRecoveringRegionDeletions.isEmpty()<a name="line.800"></a>
+<span class="sourceLineNo">801</span>          || (tot == 0 &amp;&amp; tasks.size() == 0 &amp;&amp; (timeInterval &gt; checkRecoveringTimeThreshold))) {<a name="line.801"></a>
+<span class="sourceLineNo">802</span>        // inside the function there have more checks before GC anything<a name="line.802"></a>
+<span class="sourceLineNo">803</span>        if (!failedRecoveringRegionDeletions.isEmpty()) {<a name="line.803"></a>
+<span class="sourceLineNo">804</span>          List&lt;Pair&lt;Set&lt;ServerName&gt;, Boolean&gt;&gt; previouslyFailedDeletions =<a name="line.804"></a>
+<span class="sourceLineNo">805</span>              new ArrayList&lt;Pair&lt;Set&lt;ServerName&gt;, Boolean&gt;&gt;(failedRecoveringRegionDeletions);<a name="line.805"></a>
+<span class="sourceLineNo">806</span>          failedRecoveringRegionDeletions.removeAll(previouslyFailedDeletions);<a name="line.806"></a>
+<span class="sourceLineNo">807</span>          for (Pair&lt;Set&lt;ServerName&gt;, Boolean&gt; failedDeletion : previouslyFailedDeletions) {<a name="line.807"></a>
+<span class="sourceLineNo">808</span>            removeRecoveringRegions(failedDeletion.getFirst(), failedDeletion.getSecond());<a name="line.808"></a>
+<span class="sourceLineNo">809</span>          }<a name="line.809"></a>
+<span class="sourceLineNo">810</span>        } else {<a name="line.810"></a>
+<span class="sourceLineNo">811</span>          removeRecoveringRegions(null, null);<a name="line.811"></a>
+<span class="sourceLineNo">812</span>        }<a name="line.812"></a>
+<span class="sourceLineNo">813</span>      }<a name="line.813"></a>
+<span class="sourceLineNo">814</span>    }<a name="line.814"></a>
+<span class="sourceLineNo">815</span>  }<a name="line.815"></a>
+<span class="sourceLineNo">816</span><a name="line.816"></a>
+<span class="sourceLineNo">817</span>  public enum ResubmitDirective {<a name="line.817"></a>
+<span class="sourceLineNo">818</span>    CHECK(), FORCE();<a name="line.818"></a>
+<span class="sourceLineNo">819</span>  }<a name="line.819"></a>
+<span class="sourceLineNo">820</span><a name="line.820"></a>
+<span class="sourceLineNo">821</span>  public enum TerminationStatus {<a name="line.821"></a>
+<span class="sourceLineNo">822</span>    IN_PROGRESS("in_progress"), SUCCESS("success"), FAILURE("failure"), DELETED("deleted");<a name="line.822"></a>
+<span class="sourceLineNo">823</span><a name="line.823"></a>
+<span class="sourceLineNo">824</span>    String statusMsg;<a name="line.824"></a>
+<span class="sourceLineNo">825</span><a name="line.825"></a>
+<span class="sourceLineNo">826</span>    TerminationStatus(String msg) {<a name="line.826"></a>
+<span class="sourceLineNo">827</span>      statusMsg = msg;<a name="line.827"></a>
+<span class="sourceLineNo">828</span>    }<a name="line.828"></a>
+<span class="sourceLineNo">829</span><a name="line.829"></a>
+<span class="sourceLineNo">830</span>    @Override<a name="line.830"></a>
+<span class="sourceLineNo">831</span>    public String toString() {<a name="line.831"></a>
+<span class="sourceLineNo">832</span>      return statusMsg;<a name="line.832"></a>
+<span class="sourceLineNo">833</span>    }<a name="line.833"></a>
+<span class="sourceLineNo">834</span>  }<a name="line.834"></a>
+<span class="sourceLineNo">835</span>}<a name="line.835"></a>
 
 
 


Mime
View raw message