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  /**
036   * The WAL is going to be rolled. The oldPath can be null if this is
037   * the first log file from the regionserver.
038   * @param oldPath the path to the old wal
039   * @param newPath the path to the new wal
040   */
041  default void preLogRoll(Path oldPath, Path newPath) throws IOException {}
042
043  /**
044   * The WAL has been rolled. The oldPath can be null if this is
045   * the first log file from the regionserver.
046   * @param oldPath the path to the old wal
047   * @param newPath the path to the new wal
048   */
049  default void postLogRoll(Path oldPath, Path newPath) throws IOException {}
050
051  /**
052   * The WAL is going to be archived.
053   * @param oldPath the path to the old wal
054   * @param newPath the path to the new wal
055   */
056  default void preLogArchive(Path oldPath, Path newPath) throws IOException {}
057
058  /**
059   * The WAL has been archived.
060   * @param oldPath the path to the old wal
061   * @param newPath the path to the new wal
062   */
063  default void postLogArchive(Path oldPath, Path newPath) throws IOException {}
064
065  /**
066   * A request was made that the WAL be rolled.
067   */
068  default void logRollRequested(boolean tooFewReplicas) {}
069
070  /**
071   * The WAL is about to close.
072   */
073  default void logCloseRequested() {}
074
075  /**
076  * Called before each write.
077  */
078  default void visitLogEntryBeforeWrite(RegionInfo info, WALKey logKey, WALEdit logEdit) {}
079
080  /**
081   * @param logKey
082   * @param logEdit TODO: Retire this in favor of
083   *          {@link #visitLogEntryBeforeWrite(RegionInfo, WALKey, WALEdit)} It only exists to get
084   *          scope when replicating. Scope should be in the WALKey and not need us passing in a
085   *          <code>htd</code>.
086   * @throws IOException If failed to parse the WALEdit
087   */
088  default void visitLogEntryBeforeWrite(WALKey logKey, WALEdit logEdit) throws IOException {}
089
090  /**
091   * For notification post append to the writer.  Used by metrics system at least.
092   * TODO: Combine this with above.
093   * @param entryLen approx length of cells in this append.
094   * @param elapsedTimeMillis elapsed time in milliseconds.
095   * @param logKey A WAL key
096   * @param logEdit A WAL edit containing list of cells.
097   * @throws IOException if any network or I/O error occurred
098   */
099  default void postAppend(final long entryLen, final long elapsedTimeMillis, final WALKey logKey,
100      final WALEdit logEdit) throws IOException {}
101
102  /**
103   * For notification post writer sync.  Used by metrics system at least.
104   * @param timeInNanos How long the filesystem sync took in nanoseconds.
105   * @param handlerSyncs How many sync handler calls were released by this call to filesystem
106   * sync.
107   */
108  default void postSync(final long timeInNanos, final int handlerSyncs) {}
109}