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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 package org
.apache
.hadoop
.hbase
.wal
;
21 import java
.io
.Closeable
;
22 import java
.io
.IOException
;
23 import java
.util
.List
;
24 import java
.util
.OptionalLong
;
25 import java
.util
.concurrent
.CompletableFuture
;
26 import org
.apache
.hadoop
.conf
.Configuration
;
27 import org
.apache
.hadoop
.hbase
.client
.RegionInfo
;
28 import org
.apache
.hadoop
.hbase
.regionserver
.wal
.WALActionsListener
;
29 import org
.apache
.hadoop
.hbase
.replication
.regionserver
.WALFileLengthProvider
;
30 import org
.apache
.yetus
.audience
.InterfaceAudience
;
33 * The Write Ahead Log (WAL) stores all durable edits to the HRegion. This interface provides the
34 * entry point for all WAL implementors.
36 * See {@link FSHLogProvider} for an example implementation. A single WALProvider will be used for
37 * retrieving multiple WALs in a particular region server and must be threadsafe.
39 @InterfaceAudience.Private
40 public interface WALProvider
{
43 * Set up the provider to create wals. will only be called once per instance.
44 * @param factory factory that made us may not be null
45 * @param conf may not be null
46 * @param providerId differentiate between providers from one factory. may be null
48 void init(WALFactory factory
, Configuration conf
, String providerId
) throws IOException
;
51 * @param region the region which we want to get a WAL for it. Could be null.
52 * @return a WAL for writing entries for the given region.
54 WAL
getWAL(RegionInfo region
) throws IOException
;
57 * @return the List of WALs that are used by this server
62 * persist outstanding WALs to storage and stop accepting new appends. This method serves as
63 * shorthand for sending a sync to every WAL provided by a given implementation. Those WALs will
64 * also stop accepting new writes.
66 void shutdown() throws IOException
;
69 * shutdown utstanding WALs and clean up any persisted state. Call this method only when you will
70 * not need to replay any of the edits to the WALs from this provider. After this call completes,
71 * the underlying resources should have been reclaimed.
73 void close() throws IOException
;
75 interface WriterBase
extends Closeable
{
79 // Writers are used internally. Users outside of the WAL should be relying on the
80 // interface provided by WAL.
81 interface Writer
extends WriterBase
{
82 void sync(boolean forceSync
) throws IOException
;
84 void append(WAL
.Entry entry
) throws IOException
;
87 interface AsyncWriter
extends WriterBase
{
88 CompletableFuture
<Long
> sync();
90 void append(WAL
.Entry entry
);
94 * Get number of the log files this provider is managing
96 long getNumLogFiles();
99 * Get size of the log files this provider is managing
101 long getLogFileSize();
104 * Add a {@link WALActionsListener}.
106 * Notice that you must call this method before calling {@link #getWAL(RegionInfo)} as this method
107 * will not effect the {@link WAL} which has already been created. And as long as we can only it
108 * when initialization, it is not thread safe.
110 void addWALActionsListener(WALActionsListener listener
);
112 default WALFileLengthProvider
getWALFileLengthProvider() {
113 return path
-> getWALs().stream().map(w
-> w
.getLogFileSizeIfBeingWritten(path
))
114 .filter(o
-> o
.isPresent()).findAny().orElse(OptionalLong
.empty());