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  /** Returns the current value of exitWorker */
068  boolean isStop();
069
070  /**
071   * Wait for the new tasks and grab one
072   * @throws InterruptedException if the SplitLogWorker was stopped
073   */
074  void taskLoop() throws InterruptedException;
075
076  /**
077   * marks log file as corrupted
078   * @param rootDir where to find the log
079   * @param name    of the log
080   * @param fs      file system
081   */
082  void markCorrupted(Path rootDir, String name, FileSystem fs);
083
084  /**
085   * Check whether the log splitter is ready to supply tasks
086   * @return false if there is no tasks
087   * @throws InterruptedException if the SplitLogWorker was stopped
088   */
089  boolean isReady() throws InterruptedException;
090
091  /**
092   * Used by unit tests to check how many tasks were processed
093   * @return number of tasks
094   */
095  int getTaskReadySeq();
096
097  /**
098   * set the listener for task changes. Implementation specific
099   */
100  void registerListener();
101
102  /**
103   * remove the listener for task changes. Implementation specific
104   */
105  void removeListener();
106
107  /* WALSplitterHandler part */
108
109  /**
110   * Notify coordination engine that splitting task has completed.
111   * @param slt              See {@link SplitLogTask}
112   * @param ctr              counter to be updated
113   * @param splitTaskDetails details about log split task (specific to coordination engine being
114   *                         used).
115   */
116  void endTask(SplitLogTask slt, LongAdder ctr, SplitTaskDetails splitTaskDetails);
117
118  /**
119   * Interface for log-split tasks Used to carry implementation details in encapsulated way through
120   * Handlers to the coordination API.
121   */
122  interface SplitTaskDetails {
123
124    /** Returns full file path in HDFS for the WAL file to be split. */
125    String getWALFile();
126  }
127}