001/**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *     http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019
020package org.apache.hadoop.hbase.coordination;
021
022import java.io.IOException;
023import java.util.Set;
024import java.util.concurrent.ConcurrentMap;
025
026import org.apache.hadoop.hbase.ServerName;
027import org.apache.hadoop.hbase.master.MasterServices;
028import org.apache.hadoop.hbase.master.SplitLogManager.ResubmitDirective;
029import org.apache.hadoop.hbase.master.SplitLogManager.Task;
030import org.apache.yetus.audience.InterfaceAudience;
031
032import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;
033
034/**
035 * Coordination for SplitLogManager. It creates and works with tasks for split log operations<BR>
036 * Manager prepares task by calling {@link #prepareTask} and submit it by
037 * {@link #submitTask(String)}. After that it periodically check the number of remaining tasks by
038 * {@link #remainingTasksInCoordination()} and waits until it become zero.
039 * <P>
040 * Methods required for task life circle: <BR>
041 * {@link #checkTaskStillAvailable(String)} Check that task is still there <BR>
042 * {@link #checkTasks()} check for unassigned tasks and resubmit them
043 */
044@InterfaceAudience.Private
045public interface SplitLogManagerCoordination {
046  /**
047   * Detail class that shares data between coordination and split log manager
048   */
049  class SplitLogManagerDetails {
050    final private ConcurrentMap<String, Task> tasks;
051    final private MasterServices master;
052    final private Set<String> failedDeletions;
053
054    public SplitLogManagerDetails(ConcurrentMap<String, Task> tasks, MasterServices master,
055        Set<String> failedDeletions) {
056      this.tasks = tasks;
057      this.master = master;
058      this.failedDeletions = failedDeletions;
059    }
060
061    /**
062     * @return the master value
063     */
064    public MasterServices getMaster() {
065      return master;
066    }
067
068    /**
069     * @return map of tasks
070     */
071    public ConcurrentMap<String, Task> getTasks() {
072      return tasks;
073    }
074
075    /**
076     * @return a set of failed deletions
077     */
078    public Set<String> getFailedDeletions() {
079      return failedDeletions;
080    }
081
082    /**
083     * @return server name
084     */
085    public ServerName getServerName() {
086      return master.getServerName();
087    }
088  }
089
090  /**
091   * Provide the configuration from the SplitLogManager
092   */
093  void setDetails(SplitLogManagerDetails details);
094
095  /**
096   * Returns the configuration that was provided previously
097   */
098  SplitLogManagerDetails getDetails();
099
100  /**
101   * Prepare the new task
102   * @param taskName name of the task
103   * @return the task id
104   */
105  String prepareTask(String taskName);
106
107  /**
108   * tells Coordination that it should check for new tasks
109   */
110  void checkTasks();
111
112  /**
113   * Return the number of remaining tasks
114   */
115  int remainingTasksInCoordination();
116
117  /**
118   * Check that the task is still there
119   * @param task node to check
120   */
121  void checkTaskStillAvailable(String task);
122
123  /**
124   * Resubmit the task in case if found unassigned or failed
125   * @param taskName path related to task
126   * @param task to resubmit
127   * @param force whether it should be forced
128   * @return whether it was successful
129   */
130
131  boolean resubmitTask(String taskName, Task task, ResubmitDirective force);
132
133  /**
134   * @param taskName to be submitted
135   */
136  void submitTask(String taskName);
137
138  /**
139   * @param taskName to be removed
140   */
141  void deleteTask(String taskName);
142
143  /**
144   * Support method to init constants such as timeout. Mostly required for UTs.
145   * @throws IOException
146   */
147  @VisibleForTesting
148  void init() throws IOException;
149}