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.hbase.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  
35    /** Whether checksum is enabled or not **/
36    private boolean usesHBaseChecksum = true;
37    /** Whether mvcc is to be included in the Read/Write **/
38    private boolean includesMvcc = true;
39    /** Whether tags are to be included in the Read/Write **/
40    private boolean includesTags = false;
41    /** Compression algorithm used **/
42    private Algorithm compression = Algorithm.NONE;
43    /** Whether tags to be compressed or not **/
44    private boolean compressTags = false;
45    /** the checksum type **/
46    private ChecksumType checksumType = ChecksumType.getDefaultChecksumType();
47    /** the number of bytes per checksum value **/
48    private int bytesPerChecksum = DEFAULT_BYTES_PER_CHECKSUM;
49    /** Number of uncompressed bytes we allow per block. */
50    private int blocksize = HConstants.DEFAULT_BLOCKSIZE;
51    private DataBlockEncoding encoding = DataBlockEncoding.NONE;
52    /** Crypto context */
53    private Encryption.Context cryptoContext = Encryption.Context.NONE;
54    private long fileCreateTime = 0;
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 HFileContextBuilder withCreateTime(long fileCreateTime) {
107     this.fileCreateTime = fileCreateTime;
108     return this;
109   }
110 
111   public HFileContext build() {
112     return new HFileContext(usesHBaseChecksum, includesMvcc, includesTags, compression,
113         compressTags, checksumType, bytesPerChecksum, blocksize, encoding, cryptoContext,
114         fileCreateTime);
115   }
116 }