1 /*
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 package org.apache.hadoop.hbase.regionserver.wal;
20
21 import java.io.IOException;
22
23 import org.apache.hadoop.fs.Path;
24 import org.apache.hadoop.hbase.HRegionInfo;
25 import org.apache.hadoop.hbase.HTableDescriptor;
26 import org.apache.hadoop.hbase.classification.InterfaceAudience;
27 import org.apache.hadoop.hbase.wal.WALKey;
28
29 /**
30 * Get notification of WAL events. The invocations are inline
31 * so make sure your implementation is fast else you'll slow hbase.
32 */
33 @InterfaceAudience.Private
34 public interface WALActionsListener {
35
36 /**
37 * The WAL is going to be rolled. The oldPath can be null if this is
38 * the first log file from the regionserver.
39 * @param oldPath the path to the old wal
40 * @param newPath the path to the new wal
41 */
42 void preLogRoll(Path oldPath, Path newPath) throws IOException;
43
44 /**
45 * The WAL has been rolled. The oldPath can be null if this is
46 * the first log file from the regionserver.
47 * @param oldPath the path to the old wal
48 * @param newPath the path to the new wal
49 */
50 void postLogRoll(Path oldPath, Path newPath) throws IOException;
51
52 /**
53 * The WAL is going to be archived.
54 * @param oldPath the path to the old wal
55 * @param newPath the path to the new wal
56 */
57 void preLogArchive(Path oldPath, Path newPath) throws IOException;
58
59 /**
60 * The WAL has been archived.
61 * @param oldPath the path to the old wal
62 * @param newPath the path to the new wal
63 */
64 void postLogArchive(Path oldPath, Path newPath) throws IOException;
65
66 /**
67 * A request was made that the WAL be rolled.
68 */
69 void logRollRequested(boolean tooFewReplicas);
70
71 /**
72 * The WAL is about to close.
73 */
74 void logCloseRequested();
75
76 /**
77 * Called before each write.
78 * @param info
79 * @param logKey
80 * @param logEdit
81 */
82 void visitLogEntryBeforeWrite(
83 HRegionInfo info, WALKey logKey, WALEdit logEdit
84 ) throws IOException;
85
86 /**
87 * @param htd
88 * @param logKey
89 * @param logEdit TODO: Retire this in favor of
90 * {@link #visitLogEntryBeforeWrite(HRegionInfo, WALKey, WALEdit)} It only exists to get
91 * scope when replicating. Scope should be in the WALKey and not need us passing in a
92 * <code>htd</code>.
93 * @throws IOException If failed to parse the WALEdit
94 */
95 void visitLogEntryBeforeWrite(HTableDescriptor htd, WALKey logKey, WALEdit logEdit)
96 throws IOException;
97
98 /**
99 * For notification post append to the writer. Used by metrics system at least.
100 * TODO: Combine this 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 occurred
106 */
107 void postAppend(final long entryLen, final long elapsedTimeMillis, final WALKey logKey,
108 final WALEdit logEdit) throws IOException;
109
110 /**
111 * For notification post writer sync. Used by metrics system at least.
112 * @param timeInNanos How long the filesystem sync took in nanoseconds.
113 * @param handlerSyncs How many sync handler calls were released by this call to filesystem
114 * sync.
115 */
116 void postSync(final long timeInNanos, final int handlerSyncs);
117
118 static class Base implements WALActionsListener {
119 @Override
120 public void preLogRoll(Path oldPath, Path newPath) throws IOException {}
121
122 @Override
123 public void postLogRoll(Path oldPath, Path newPath) throws IOException {}
124
125 @Override
126 public void preLogArchive(Path oldPath, Path newPath) throws IOException {}
127
128 @Override
129 public void postLogArchive(Path oldPath, Path newPath) throws IOException {}
130
131 @Override
132 public void logRollRequested(boolean tooFewReplicas) {}
133
134 @Override
135 public void logCloseRequested() {}
136
137 @Override
138 public void visitLogEntryBeforeWrite(HRegionInfo info, WALKey logKey, WALEdit logEdit) throws IOException {}
139
140 @Override
141 public void visitLogEntryBeforeWrite(HTableDescriptor htd, WALKey logKey, WALEdit logEdit)
142 throws IOException {
143 }
144
145 @Override
146 public void postAppend(final long entryLen, final long elapsedTimeMillis, final WALKey logKey,
147 final WALEdit logEdit) throws IOException {
148 }
149
150 @Override
151 public void postSync(final long timeInNanos, final int handlerSyncs) {}
152 }
153 }