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     * @param namespace could be null, and will use default namespace if null
58     * @return a WAL for writing entries for the given region.
59     */
60    WAL getWAL(final byte[] identifier, byte[] namespace) throws IOException;
61  
62    /** @return the List of WALs that are used by this server
63     */
64    List<WAL> getWALs() throws IOException;
65  
66    /**
67     * persist outstanding WALs to storage and stop accepting new appends.
68     * This method serves as shorthand for sending a sync to every WAL provided by a given
69     * implementation. Those WALs will also stop accepting new writes.
70     */
71    void shutdown() throws IOException;
72  
73    /**
74     * shutdown utstanding WALs and clean up any persisted state.
75     * Call this method only when you will not need to replay any of the edits to the WALs from
76     * this provider. After this call completes, the underlying resources should have been reclaimed.
77     */
78    void close() throws IOException;
79  
80    // Writers are used internally. Users outside of the WAL should be relying on the
81    // interface provided by WAL.
82    interface Writer extends Closeable {
83      /**
84       * @param forceSync Flag to force sync rather than flushing to the buffer. Example - Hadoop
85       *          hflush vs hsync.
86       * @throws IOException
87       */
88      void sync(boolean forceSync) throws IOException;
89      void append(WAL.Entry entry) throws IOException;
90      long getLength() throws IOException;
91    }
92  
93    /**
94     * Get number of the log files this provider is managing
95     */
96    long getNumLogFiles();
97  
98    /**
99     * Get size of the log files this provider is managing
100    */
101   long getLogFileSize();
102 
103 }