View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.io.hfile;
19  
20  import org.apache.hadoop.classification.InterfaceAudience;
21  import org.apache.hadoop.hbase.HConstants;
22  import org.apache.hadoop.hbase.io.compress.Compression.Algorithm;
23  import org.apache.hadoop.hbase.io.crypto.Encryption;
24  import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
25  import org.apache.hadoop.hbase.util.ChecksumType;
26  
27  /**
28   * A builder that helps in building up the HFileContext 
29   */
30  @InterfaceAudience.Private
31  public class HFileContextBuilder {
32  
33    public static final int DEFAULT_BYTES_PER_CHECKSUM = 16 * 1024;
34    public static final ChecksumType DEFAULT_CHECKSUM_TYPE = ChecksumType.CRC32;
35  
36    /** Whether checksum is enabled or not **/
37    private boolean usesHBaseChecksum = true;
38    /** Whether mvcc is to be included in the Read/Write **/
39    private boolean includesMvcc = true;
40    /** Whether tags are to be included in the Read/Write **/
41    private boolean includesTags;
42    /** Compression algorithm used **/
43    private Algorithm compression = Algorithm.NONE;
44    /** Whether tags to be compressed or not **/
45    private boolean compressTags = false;
46    /** the checksum type **/
47    private ChecksumType checksumType = DEFAULT_CHECKSUM_TYPE;
48    /** the number of bytes per checksum value **/
49    private int bytesPerChecksum = DEFAULT_BYTES_PER_CHECKSUM;
50    /** Number of uncompressed bytes we allow per block. */
51    private int blocksize = HConstants.DEFAULT_BLOCKSIZE;
52    private DataBlockEncoding encoding = DataBlockEncoding.NONE;
53    /** Crypto context */
54    private Encryption.Context cryptoContext = Encryption.Context.NONE;
55  
56    public HFileContextBuilder withHBaseCheckSum(boolean useHBaseCheckSum) {
57      this.usesHBaseChecksum = useHBaseCheckSum;
58      return this;
59    }
60  
61    public HFileContextBuilder withIncludesMvcc(boolean includesMvcc) {
62      this.includesMvcc = includesMvcc;
63      return this;
64    }
65  
66    public HFileContextBuilder withIncludesTags(boolean includesTags) {
67      this.includesTags = includesTags;
68      return this;
69    }
70  
71    public HFileContextBuilder withCompression(Algorithm compression) {
72      this.compression = compression;
73      return this;
74    }
75  
76    public HFileContextBuilder withCompressTags(boolean compressTags) {
77      this.compressTags = compressTags;
78      return this;
79    }
80  
81    public HFileContextBuilder withChecksumType(ChecksumType checkSumType) {
82      this.checksumType = checkSumType;
83      return this;
84    }
85  
86    public HFileContextBuilder withBytesPerCheckSum(int bytesPerChecksum) {
87      this.bytesPerChecksum = bytesPerChecksum;
88      return this;
89    }
90  
91    public HFileContextBuilder withBlockSize(int blockSize) {
92      this.blocksize = blockSize;
93      return this;
94    }
95  
96    public HFileContextBuilder withDataBlockEncoding(DataBlockEncoding encoding) {
97      this.encoding = encoding;
98      return this;
99    }
100 
101   public HFileContextBuilder withEncryptionContext(Encryption.Context cryptoContext) {
102     this.cryptoContext = cryptoContext;
103     return this;
104   }
105 
106   public HFileContext build() {
107     return new HFileContext(usesHBaseChecksum, includesMvcc, includesTags, compression,
108       compressTags, checksumType, bytesPerChecksum, blocksize, encoding, cryptoContext);
109   }
110 }