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.HConstants;
21  import org.apache.hadoop.hbase.classification.InterfaceAudience;
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    private String hfileName = null;
57  
58    public HFileContextBuilder() {}
59  
60    /**
61     * Use this constructor if you want to change a few settings only in another context.
62     */
63    public HFileContextBuilder(final HFileContext hfc) {
64      this.usesHBaseChecksum = hfc.isUseHBaseChecksum();
65      this.includesMvcc = hfc.isIncludesMvcc();
66      this.includesTags = hfc.isIncludesTags();
67      this.compression = hfc.getCompression();
68      this.compressTags = hfc.isCompressTags();
69      this.checksumType = hfc.getChecksumType();
70      this.bytesPerChecksum = hfc.getBytesPerChecksum();
71      this.blocksize = hfc.getBlocksize();
72      this.encoding = hfc.getDataBlockEncoding();
73      this.cryptoContext = hfc.getEncryptionContext();
74      this.fileCreateTime = hfc.getFileCreateTime();
75      this.hfileName = hfc.getHFileName();
76    }
77  
78    public HFileContextBuilder withHBaseCheckSum(boolean useHBaseCheckSum) {
79      this.usesHBaseChecksum = useHBaseCheckSum;
80      return this;
81    }
82  
83    public HFileContextBuilder withIncludesMvcc(boolean includesMvcc) {
84      this.includesMvcc = includesMvcc;
85      return this;
86    }
87  
88    public HFileContextBuilder withIncludesTags(boolean includesTags) {
89      this.includesTags = includesTags;
90      return this;
91    }
92  
93    public HFileContextBuilder withCompression(Algorithm compression) {
94      this.compression = compression;
95      return this;
96    }
97  
98    public HFileContextBuilder withCompressTags(boolean compressTags) {
99      this.compressTags = compressTags;
100     return this;
101   }
102 
103   public HFileContextBuilder withChecksumType(ChecksumType checkSumType) {
104     this.checksumType = checkSumType;
105     return this;
106   }
107 
108   public HFileContextBuilder withBytesPerCheckSum(int bytesPerChecksum) {
109     this.bytesPerChecksum = bytesPerChecksum;
110     return this;
111   }
112 
113   public HFileContextBuilder withBlockSize(int blockSize) {
114     this.blocksize = blockSize;
115     return this;
116   }
117 
118   public HFileContextBuilder withDataBlockEncoding(DataBlockEncoding encoding) {
119     this.encoding = encoding;
120     return this;
121   }
122 
123   public HFileContextBuilder withEncryptionContext(Encryption.Context cryptoContext) {
124     this.cryptoContext = cryptoContext;
125     return this;
126   }
127 
128   public HFileContextBuilder withCreateTime(long fileCreateTime) {
129     this.fileCreateTime = fileCreateTime;
130     return this;
131   }
132 
133   public HFileContextBuilder withHFileName(String name) {
134     this.hfileName = name;
135     return this;
136   }
137 
138   public HFileContext build() {
139     return new HFileContext(usesHBaseChecksum, includesMvcc, includesTags, compression,
140         compressTags, checksumType, bytesPerChecksum, blocksize, encoding, cryptoContext,
141         fileCreateTime, hfileName);
142   }
143 }