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