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