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 /**
38 * The WAL is going to be rolled. The oldPath can be null if this is
39 * the first log file from the regionserver.
40 * @param oldPath the path to the old wal
41 * @param newPath the path to the new wal
42 */
43 void preLogRoll(Path oldPath, Path newPath) throws IOException;
44
45 /**
46 * The WAL has been rolled. The oldPath can be null if this is
47 * the first log file from the regionserver.
48 * @param oldPath the path to the old wal
49 * @param newPath the path to the new wal
50 */
51 void postLogRoll(Path oldPath, Path newPath) throws IOException;
52
53 /**
54 * The WAL is going to be archived.
55 * @param oldPath the path to the old wal
56 * @param newPath the path to the new wal
57 */
58 void preLogArchive(Path oldPath, Path newPath) throws IOException;
59
60 /**
61 * The WAL has been archived.
62 * @param oldPath the path to the old wal
63 * @param newPath the path to the new wal
64 */
65 void postLogArchive(Path oldPath, Path newPath) throws IOException;
66
67 /**
68 * A request was made that the WAL be rolled.
69 */
70 void logRollRequested(boolean tooFewReplicas);
71
72 /**
73 * The WAL is about to close.
74 */
75 void logCloseRequested();
76
77 /**
78 * Called before each write.
79 * @param info
80 * @param logKey
81 * @param logEdit
82 */
83 void visitLogEntryBeforeWrite(
84 HRegionInfo info, WALKey logKey, WALEdit logEdit
85 );
86
87 /**
88 * @param htd
89 * @param logKey
90 * @param logEdit TODO: Retire this in favor of
91 * {@link #visitLogEntryBeforeWrite(HRegionInfo, WALKey, WALEdit)} It only exists to get
92 * scope when replicating. Scope should be in the WALKey and not need us passing in a
93 * <code>htd</code>.
94 * @throws IOException If failed to parse the WALEdit
95 */
96 void visitLogEntryBeforeWrite(HTableDescriptor htd, WALKey logKey, WALEdit logEdit)
97 throws IOException;
98
99 /**
100 * For notification post append to the writer. Used by metrics system at least.
101 * TODO: Combine this with above.
102 * @param entryLen approx length of cells in this append.
103 * @param elapsedTimeMillis elapsed time in milliseconds.
104 * @param logKey A WAL key
105 * @param logEdit A WAL edit containing list of cells.
106 * @throws IOException if any network or I/O occurred
107 */
108 void postAppend(final long entryLen, final long elapsedTimeMillis, final WALKey logKey,
109 final WALEdit logEdit) throws IOException;
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
115 * sync.
116 */
117 void postSync(final long timeInNanos, final int handlerSyncs);
118
119 static class Base implements WALActionsListener {
120 @Override
121 public void preLogRoll(Path oldPath, Path newPath) throws IOException {}
122
123 @Override
124 public void postLogRoll(Path oldPath, Path newPath) throws IOException {}
125
126 @Override
127 public void preLogArchive(Path oldPath, Path newPath) throws IOException {}
128
129 @Override
130 public void postLogArchive(Path oldPath, Path newPath) throws IOException {}
131
132 @Override
133 public void logRollRequested(boolean tooFewReplicas) {}
134
135 @Override
136 public void logCloseRequested() {}
137
138 @Override
139 public void visitLogEntryBeforeWrite(HRegionInfo info, WALKey logKey, WALEdit logEdit) {}
140
141 @Override
142 public void visitLogEntryBeforeWrite(HTableDescriptor htd, WALKey logKey, WALEdit logEdit)
143 throws IOException {
144 }
145
146 @Override
147 public void postAppend(final long entryLen, final long elapsedTimeMillis, final WALKey logKey,
148 final WALEdit logEdit) throws IOException {
149 }
150
151 @Override
152 public void postSync(final long timeInNanos, final int handlerSyncs) {}
153 }
154 }