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 */
019package org.apache.hadoop.hbase.regionserver.wal;
020
021import java.io.IOException;
022import org.apache.hadoop.fs.Path;
023import org.apache.hadoop.hbase.client.RegionInfo;
024import org.apache.hadoop.hbase.wal.WALEdit;
025import org.apache.hadoop.hbase.wal.WALKey;
026import org.apache.yetus.audience.InterfaceAudience;
027
028/**
029 * Get notification of WAL events. The invocations are inline
030 * so make sure your implementation is fast else you'll slow hbase.
031 */
032@InterfaceAudience.Private
033public interface WALActionsListener {
034
035  /** The reason for the log roll request. */
036  static enum RollRequestReason {
037    /** The length of the log exceeds the roll size threshold. */
038    SIZE,
039    /** Too few replicas in the writer pipeline. */
040    LOW_REPLICATION,
041    /** Too much time spent waiting for sync. */
042    SLOW_SYNC,
043    /** I/O or other error. */
044    ERROR
045  };
046
047  /**
048   * The WAL is going to be rolled. The oldPath can be null if this is
049   * the first log file from the regionserver.
050   * @param oldPath the path to the old wal
051   * @param newPath the path to the new wal
052   */
053  default void preLogRoll(Path oldPath, Path newPath) throws IOException {}
054
055  /**
056   * The WAL has been rolled. The oldPath can be null if this is
057   * the first log file from the regionserver.
058   * @param oldPath the path to the old wal
059   * @param newPath the path to the new wal
060   */
061  default void postLogRoll(Path oldPath, Path newPath) throws IOException {}
062
063  /**
064   * The WAL is going to be archived.
065   * @param oldPath the path to the old wal
066   * @param newPath the path to the new wal
067   */
068  default void preLogArchive(Path oldPath, Path newPath) throws IOException {}
069
070  /**
071   * The WAL has been archived.
072   * @param oldPath the path to the old wal
073   * @param newPath the path to the new wal
074   */
075  default void postLogArchive(Path oldPath, Path newPath) throws IOException {}
076
077  /**
078   * A request was made that the WAL be rolled.
079   */
080  default void logRollRequested(RollRequestReason reason) {}
081
082  /**
083   * The WAL is about to close.
084   */
085  default void logCloseRequested() {}
086
087  /**
088  * Called before each write.
089  */
090  default void visitLogEntryBeforeWrite(RegionInfo info, WALKey logKey, WALEdit logEdit) {}
091
092  /**
093   * @param logKey
094   * @param logEdit TODO: Retire this in favor of
095   *          {@link #visitLogEntryBeforeWrite(RegionInfo, WALKey, WALEdit)} It only exists to get
096   *          scope when replicating. Scope should be in the WALKey and not need us passing in a
097   *          <code>htd</code>.
098   * @throws IOException If failed to parse the WALEdit
099   */
100  default void visitLogEntryBeforeWrite(WALKey logKey, WALEdit logEdit) throws IOException {}
101
102  /**
103   * For notification post append to the writer.  Used by metrics system at least.
104   * TODO: Combine this with above.
105   * @param entryLen approx length of cells in this append.
106   * @param elapsedTimeMillis elapsed time in milliseconds.
107   * @param logKey A WAL key
108   * @param logEdit A WAL edit containing list of cells.
109   * @throws IOException if any network or I/O error occurred
110   */
111  default void postAppend(final long entryLen, final long elapsedTimeMillis, final WALKey logKey,
112      final WALEdit logEdit) throws IOException {}
113
114  /**
115   * For notification post writer sync.  Used by metrics system at least.
116   * @param timeInNanos How long the filesystem sync took in nanoseconds.
117   * @param handlerSyncs How many sync handler calls were released by this call to filesystem
118   * sync.
119   */
120  default void postSync(final long timeInNanos, final int handlerSyncs) {}
121}