View Javadoc

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.wal;
20  
21  import java.io.Closeable;
22  import java.io.IOException;
23  import java.util.List;
24  
25  import org.apache.hadoop.hbase.classification.InterfaceAudience;
26  import org.apache.hadoop.hbase.classification.InterfaceStability;
27  import org.apache.hadoop.conf.Configuration;
28  
29  // imports for things that haven't moved from regionserver.wal yet.
30  import org.apache.hadoop.hbase.regionserver.wal.WALActionsListener;
31  
32  /**
33   * The Write Ahead Log (WAL) stores all durable edits to the HRegion.
34   * This interface provides the entry point for all WAL implementors.
35   * <p>
36   * See {@link DefaultWALProvider} for an example implementation.
37   *
38   * A single WALProvider will be used for retrieving multiple WALs in a particular region server
39   * and must be threadsafe.
40   */
41  @InterfaceAudience.Private
42  public interface WALProvider {
43  
44    /**
45     * Set up the provider to create wals.
46     * will only be called once per instance.
47     * @param factory factory that made us may not be null
48     * @param conf may not be null
49     * @param listeners may be null
50     * @param providerId differentiate between providers from one factory. may be null
51     */
52    void init(final WALFactory factory, final Configuration conf,
53        final List<WALActionsListener> listeners, final String providerId) throws IOException;
54  
55    /**
56     * @param identifier may not be null. contents will not be altered.
57     * @return a WAL for writing entries for the given region.
58     */
59    WAL getWAL(final byte[] identifier) throws IOException;
60  
61    /**
62     * persist outstanding WALs to storage and stop accepting new appends.
63     * This method serves as shorthand for sending a sync to every WAL provided by a given
64     * implementation. Those WALs will also stop accepting new writes.
65     */
66    void shutdown() throws IOException;
67  
68    /**
69     * shutdown utstanding WALs and clean up any persisted state.
70     * Call this method only when you will not need to replay any of the edits to the WALs from
71     * this provider. After this call completes, the underlying resources should have been reclaimed.
72     */
73    void close() throws IOException;
74  
75    // Writers are used internally. Users outside of the WAL should be relying on the
76    // interface provided by WAL.
77    interface Writer extends Closeable {
78      void sync() throws IOException;
79      void append(WAL.Entry entry) throws IOException;
80      long getLength() throws IOException;
81    }
82  
83  }