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.hbase.classification.InterfaceAudience;
24 import org.apache.hadoop.fs.Path;
25 import org.apache.hadoop.hbase.HRegionInfo;
26 import org.apache.hadoop.hbase.HTableDescriptor;
27
28 import org.apache.hadoop.hbase.wal.WALKey;
29
30 /**
31 * Get notification of WAL events. The invocations are inline
32 * so make sure your implementation is fast else you'll slow hbase.
33 */
34 @InterfaceAudience.Private
35 public interface WALActionsListener {
36
37 /** The reason for the log roll request. */
38 static enum RollRequestReason {
39 /** The length of the log exceeds the roll size threshold. */
40 SIZE,
41 /** Too few replicas in the writer pipeline. */
42 LOW_REPLICATION,
43 /** Too much time spent waiting for sync. */
44 SLOW_SYNC,
45 /** I/O or other error. */
46 ERROR
47 };
48
49 /**
50 * The WAL is going to be rolled. The oldPath can be null if this is
51 * the first log file from the regionserver.
52 * @param oldPath the path to the old wal
53 * @param newPath the path to the new wal
54 */
55 void preLogRoll(Path oldPath, Path newPath) throws IOException;
56
57 /**
58 * The WAL has been rolled. The oldPath can be null if this is
59 * the first log file from the regionserver.
60 * @param oldPath the path to the old wal
61 * @param newPath the path to the new wal
62 */
63 void postLogRoll(Path oldPath, Path newPath) throws IOException;
64
65 /**
66 * The WAL is going to be archived.
67 * @param oldPath the path to the old wal
68 * @param newPath the path to the new wal
69 */
70 void preLogArchive(Path oldPath, Path newPath) throws IOException;
71
72 /**
73 * The WAL has been archived.
74 * @param oldPath the path to the old wal
75 * @param newPath the path to the new wal
76 */
77 void postLogArchive(Path oldPath, Path newPath) throws IOException;
78
79 /**
80 * A request was made that the WAL be rolled.
81 */
82 void logRollRequested(RollRequestReason reason);
83
84 /**
85 * The WAL is about to close.
86 */
87 void logCloseRequested();
88
89 /**
90 * Called before each write.
91 * @param info
92 * @param logKey
93 * @param logEdit
94 */
95 void visitLogEntryBeforeWrite(
96 HRegionInfo info, WALKey logKey, WALEdit logEdit
97 );
98
99 /**
100 * @param htd
101 * @param logKey
102 * @param logEdit TODO: Retire this in favor of
103 * {@link #visitLogEntryBeforeWrite(HRegionInfo, WALKey, WALEdit)} It only exists to get
104 * scope when replicating. Scope should be in the WALKey and not need us passing in a
105 * <code>htd</code>.
106 * @throws IOException If failed to parse the WALEdit
107 */
108 void visitLogEntryBeforeWrite(HTableDescriptor htd, WALKey logKey, WALEdit logEdit)
109 throws IOException;
110
111 /**
112 * For notification post append to the writer. Used by metrics system at least.
113 * TODO: Combine this with above.
114 * @param entryLen approx length of cells in this append.
115 * @param elapsedTimeMillis elapsed time in milliseconds.
116 * @param logKey A WAL key
117 * @param logEdit A WAL edit containing list of cells.
118 * @throws IOException if any network or I/O occurred
119 */
120 void postAppend(final long entryLen, final long elapsedTimeMillis, final WALKey logKey,
121 final WALEdit logEdit) throws IOException;
122
123 /**
124 * For notification post writer sync. Used by metrics system at least.
125 * @param timeInNanos How long the filesystem sync took in nanoseconds.
126 * @param handlerSyncs How many sync handler calls were released by this call to filesystem
127 * sync.
128 */
129 void postSync(final long timeInNanos, final int handlerSyncs);
130
131 static class Base implements WALActionsListener {
132 @Override
133 public void preLogRoll(Path oldPath, Path newPath) throws IOException {}
134
135 @Override
136 public void postLogRoll(Path oldPath, Path newPath) throws IOException {}
137
138 @Override
139 public void preLogArchive(Path oldPath, Path newPath) throws IOException {}
140
141 @Override
142 public void postLogArchive(Path oldPath, Path newPath) throws IOException {}
143
144 @Override
145 public void logRollRequested(RollRequestReason reason) {}
146
147 @Override
148 public void logCloseRequested() {}
149
150 @Override
151 public void visitLogEntryBeforeWrite(HRegionInfo info, WALKey logKey, WALEdit logEdit) {}
152
153 @Override
154 public void visitLogEntryBeforeWrite(HTableDescriptor htd, WALKey logKey, WALEdit logEdit)
155 throws IOException {
156 }
157
158 @Override
159 public void postAppend(final long entryLen, final long elapsedTimeMillis, final WALKey logKey,
160 final WALEdit logEdit) throws IOException {
161 }
162
163 @Override
164 public void postSync(final long timeInNanos, final int handlerSyncs) {}
165 }
166 }