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.util.concurrent.atomic.LongAdder;
021import org.apache.hadoop.conf.Configuration;
022import org.apache.hadoop.fs.FileSystem;
023import org.apache.hadoop.fs.Path;
024import org.apache.hadoop.hbase.SplitLogTask;
025import org.apache.hadoop.hbase.regionserver.RegionServerServices;
026import org.apache.hadoop.hbase.regionserver.SplitLogWorker;
027import org.apache.hadoop.hbase.regionserver.SplitLogWorker.TaskExecutor;
028import org.apache.yetus.audience.InterfaceAudience;
029
030/**
031 * Coordinated operations for {@link SplitLogWorker} and
032 * {@link org.apache.hadoop.hbase.regionserver.handler.WALSplitterHandler} Important methods for
033 * SplitLogWorker: <BR>
034 * {@link #isReady()} called from {@link SplitLogWorker#run()} to check whether the coordination is
035 * ready to supply the tasks <BR>
036 * {@link #taskLoop()} loop for new tasks until the worker is stopped <BR>
037 * {@link #isStop()} a flag indicates whether worker should finish <BR>
038 * {@link #registerListener()} called from {@link SplitLogWorker#run()} and could register listener
039 * for external changes in coordination (if required) <BR>
040 * {@link #endTask(SplitLogTask, LongAdder, SplitTaskDetails)} notify coordination engine that
041 * <p>
042 * Important methods for WALSplitterHandler: <BR>
043 * splitting task has completed.
044 * @deprecated since 2.4.0 and in 3.0.0, to be removed in 4.0.0, replaced by procedure-based
045 *             distributed WAL splitter, see SplitWALManager
046 */
047@Deprecated
048@InterfaceAudience.Private
049public interface SplitLogWorkerCoordination {
050
051  /**
052   * Initialize internal values. This method should be used when corresponding SplitLogWorker
053   * instance is created
054   * @param server            instance of RegionServerServices to work with
055   * @param conf              is current configuration.
056   * @param splitTaskExecutor split executor from SplitLogWorker
057   * @param worker            instance of SplitLogWorker
058   */
059  void init(RegionServerServices server, Configuration conf, TaskExecutor splitTaskExecutor,
060    SplitLogWorker worker);
061
062  /**
063   * called when Coordination should stop processing tasks and exit
064   */
065  void stopProcessingTasks();
066
067  /**
068   * @return the current value of exitWorker
069   */
070  boolean isStop();
071
072  /**
073   * Wait for the new tasks and grab one
074   * @throws InterruptedException if the SplitLogWorker was stopped
075   */
076  void taskLoop() throws InterruptedException;
077
078  /**
079   * marks log file as corrupted
080   * @param rootDir where to find the log
081   * @param name    of the log
082   * @param fs      file system
083   */
084  void markCorrupted(Path rootDir, String name, FileSystem fs);
085
086  /**
087   * Check whether the log splitter is ready to supply tasks
088   * @return false if there is no tasks
089   * @throws InterruptedException if the SplitLogWorker was stopped
090   */
091  boolean isReady() throws InterruptedException;
092
093  /**
094   * Used by unit tests to check how many tasks were processed
095   * @return number of tasks
096   */
097  int getTaskReadySeq();
098
099  /**
100   * set the listener for task changes. Implementation specific
101   */
102  void registerListener();
103
104  /**
105   * remove the listener for task changes. Implementation specific
106   */
107  void removeListener();
108
109  /* WALSplitterHandler part */
110
111  /**
112   * Notify coordination engine that splitting task has completed.
113   * @param slt              See {@link SplitLogTask}
114   * @param ctr              counter to be updated
115   * @param splitTaskDetails details about log split task (specific to coordination engine being
116   *                         used).
117   */
118  void endTask(SplitLogTask slt, LongAdder ctr, SplitTaskDetails splitTaskDetails);
119
120  /**
121   * Interface for log-split tasks Used to carry implementation details in encapsulated way through
122   * Handlers to the coordination API.
123   */
124  interface SplitTaskDetails {
125
126    /**
127     * @return full file path in HDFS for the WAL file to be split.
128     */
129    String getWALFile();
130  }
131}