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    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 = false;
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    private long fileCreateTime = 0;
56  
57    public HFileContextBuilder withHBaseCheckSum(boolean useHBaseCheckSum) {
58      this.usesHBaseChecksum = useHBaseCheckSum;
59      return this;
60    }
61  
62    public HFileContextBuilder withIncludesMvcc(boolean includesMvcc) {
63      this.includesMvcc = includesMvcc;
64      return this;
65    }
66  
67    public HFileContextBuilder withIncludesTags(boolean includesTags) {
68      this.includesTags = includesTags;
69      return this;
70    }
71  
72    public HFileContextBuilder withCompression(Algorithm compression) {
73      this.compression = compression;
74      return this;
75    }
76  
77    public HFileContextBuilder withCompressTags(boolean compressTags) {
78      this.compressTags = compressTags;
79      return this;
80    }
81  
82    public HFileContextBuilder withChecksumType(ChecksumType checkSumType) {
83      this.checksumType = checkSumType;
84      return this;
85    }
86  
87    public HFileContextBuilder withBytesPerCheckSum(int bytesPerChecksum) {
88      this.bytesPerChecksum = bytesPerChecksum;
89      return this;
90    }
91  
92    public HFileContextBuilder withBlockSize(int blockSize) {
93      this.blocksize = blockSize;
94      return this;
95    }
96  
97    public HFileContextBuilder withDataBlockEncoding(DataBlockEncoding encoding) {
98      this.encoding = encoding;
99      return this;
100   }
101 
102   public HFileContextBuilder withEncryptionContext(Encryption.Context cryptoContext) {
103     this.cryptoContext = cryptoContext;
104     return this;
105   }
106 
107   public HFileContextBuilder withCreateTime(long fileCreateTime) {
108     this.fileCreateTime = fileCreateTime;
109     return this;
110   }
111 
112   public HFileContext build() {
113     return new HFileContext(usesHBaseChecksum, includesMvcc, includesTags, compression,
114         compressTags, checksumType, bytesPerChecksum, blocksize, encoding, cryptoContext,
115         fileCreateTime);
116   }
117 }