View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with this
4    * work for additional information regarding copyright ownership. The ASF
5    * licenses this file to you under the Apache License, Version 2.0 (the
6    * "License"); you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14   * License for the specific language governing permissions and limitations
15   * under the License.
16   */
17  package org.apache.hadoop.hbase.io.hfile;
18  
19  import java.nio.ByteBuffer;
20  
21  import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
22  import org.apache.hadoop.hbase.util.Pair;
23  
24  /**
25   * Does not perform any kind of encoding/decoding.
26   */
27  public class NoOpDataBlockEncoder implements HFileDataBlockEncoder {
28  
29    public static final NoOpDataBlockEncoder INSTANCE =
30        new NoOpDataBlockEncoder();
31  
32    /** Cannot be instantiated. Use {@link #INSTANCE} instead. */
33    private NoOpDataBlockEncoder() {
34    }
35  
36    @Override
37    public HFileBlock diskToCacheFormat(HFileBlock block, boolean isCompaction) {
38      if (block.getBlockType() == BlockType.ENCODED_DATA) {
39        throw new IllegalStateException("Unexpected encoded block");
40      }
41      return block;
42    }
43  
44    @Override
45    public Pair<ByteBuffer, BlockType> beforeWriteToDisk(
46        ByteBuffer in, boolean includesMemstoreTS, byte[] dummyHeader) {
47      return new Pair<ByteBuffer, BlockType>(in, BlockType.DATA);
48    }
49  
50    @Override
51    public boolean useEncodedScanner(boolean isCompaction) {
52      return false;
53    }
54  
55    @Override
56    public void saveMetadata(HFile.Writer writer) {
57    }
58  
59    @Override
60    public DataBlockEncoding getEncodingOnDisk() {
61      return DataBlockEncoding.NONE;
62    }
63  
64    @Override
65    public DataBlockEncoding getEncodingInCache() {
66      return DataBlockEncoding.NONE;
67    }
68  
69    @Override
70    public DataBlockEncoding getEffectiveEncodingInCache(boolean isCompaction) {
71      return DataBlockEncoding.NONE;
72    }
73  
74    @Override
75    public String toString() {
76      return getClass().getSimpleName();
77    }
78  
79  }