001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.io.hfile; 019 020import org.apache.hadoop.hbase.CellComparator; 021import org.apache.hadoop.hbase.HConstants; 022import org.apache.hadoop.hbase.io.compress.Compression.Algorithm; 023import org.apache.hadoop.hbase.io.crypto.Encryption; 024import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding; 025import org.apache.hadoop.hbase.util.ChecksumType; 026import org.apache.yetus.audience.InterfaceAudience; 027 028/** 029 * A builder that helps in building up the HFileContext 030 */ 031@InterfaceAudience.Private 032public class HFileContextBuilder { 033 034 public static final int DEFAULT_BYTES_PER_CHECKSUM = 16 * 1024; 035 036 /** Whether checksum is enabled or not **/ 037 private boolean usesHBaseChecksum = true; 038 /** Whether mvcc is to be included in the Read/Write **/ 039 private boolean includesMvcc = true; 040 /** Whether tags are to be included in the Read/Write **/ 041 private boolean includesTags = false; 042 /** Compression algorithm used **/ 043 private Algorithm compression = Algorithm.NONE; 044 /** Whether tags to be compressed or not **/ 045 private boolean compressTags = false; 046 /** the checksum type **/ 047 private ChecksumType checksumType = ChecksumType.getDefaultChecksumType(); 048 /** the number of bytes per checksum value **/ 049 private int bytesPerChecksum = DEFAULT_BYTES_PER_CHECKSUM; 050 /** Number of uncompressed bytes we allow per block. */ 051 private int blocksize = HConstants.DEFAULT_BLOCKSIZE; 052 private DataBlockEncoding encoding = DataBlockEncoding.NONE; 053 /** Crypto context */ 054 private Encryption.Context cryptoContext = Encryption.Context.NONE; 055 private long fileCreateTime = 0; 056 057 private String hfileName = null; 058 private byte[] columnFamily = null; 059 private byte[] tableName = null; 060 private CellComparator cellComparator; 061 062 public HFileContextBuilder() {} 063 064 /** 065 * Use this constructor if you want to change a few settings only in another context. 066 */ 067 public HFileContextBuilder(final HFileContext hfc) { 068 this.usesHBaseChecksum = hfc.isUseHBaseChecksum(); 069 this.includesMvcc = hfc.isIncludesMvcc(); 070 this.includesTags = hfc.isIncludesTags(); 071 this.compression = hfc.getCompression(); 072 this.compressTags = hfc.isCompressTags(); 073 this.checksumType = hfc.getChecksumType(); 074 this.bytesPerChecksum = hfc.getBytesPerChecksum(); 075 this.blocksize = hfc.getBlocksize(); 076 this.encoding = hfc.getDataBlockEncoding(); 077 this.cryptoContext = hfc.getEncryptionContext(); 078 this.fileCreateTime = hfc.getFileCreateTime(); 079 this.hfileName = hfc.getHFileName(); 080 this.columnFamily = hfc.getColumnFamily(); 081 this.tableName = hfc.getTableName(); 082 this.cellComparator = hfc.getCellComparator(); 083 } 084 085 public HFileContextBuilder withHBaseCheckSum(boolean useHBaseCheckSum) { 086 this.usesHBaseChecksum = useHBaseCheckSum; 087 return this; 088 } 089 090 public HFileContextBuilder withIncludesMvcc(boolean includesMvcc) { 091 this.includesMvcc = includesMvcc; 092 return this; 093 } 094 095 public HFileContextBuilder withIncludesTags(boolean includesTags) { 096 this.includesTags = includesTags; 097 return this; 098 } 099 100 public HFileContextBuilder withCompression(Algorithm compression) { 101 this.compression = compression; 102 return this; 103 } 104 105 public HFileContextBuilder withCompressTags(boolean compressTags) { 106 this.compressTags = compressTags; 107 return this; 108 } 109 110 public HFileContextBuilder withChecksumType(ChecksumType checkSumType) { 111 this.checksumType = checkSumType; 112 return this; 113 } 114 115 public HFileContextBuilder withBytesPerCheckSum(int bytesPerChecksum) { 116 this.bytesPerChecksum = bytesPerChecksum; 117 return this; 118 } 119 120 public HFileContextBuilder withBlockSize(int blockSize) { 121 this.blocksize = blockSize; 122 return this; 123 } 124 125 public HFileContextBuilder withDataBlockEncoding(DataBlockEncoding encoding) { 126 this.encoding = encoding; 127 return this; 128 } 129 130 public HFileContextBuilder withEncryptionContext(Encryption.Context cryptoContext) { 131 this.cryptoContext = cryptoContext; 132 return this; 133 } 134 135 public HFileContextBuilder withCreateTime(long fileCreateTime) { 136 this.fileCreateTime = fileCreateTime; 137 return this; 138 } 139 140 public HFileContextBuilder withHFileName(String name) { 141 this.hfileName = name; 142 return this; 143 } 144 145 public HFileContextBuilder withColumnFamily(byte[] columnFamily){ 146 this.columnFamily = columnFamily; 147 return this; 148 } 149 150 public HFileContextBuilder withTableName(byte[] tableName){ 151 this.tableName = tableName; 152 return this; 153 } 154 155 public HFileContextBuilder withCellComparator(CellComparator cellComparator) { 156 this.cellComparator = cellComparator; 157 return this; 158 } 159 160 public HFileContext build() { 161 return new HFileContext(usesHBaseChecksum, includesMvcc, includesTags, compression, 162 compressTags, checksumType, bytesPerChecksum, blocksize, encoding, cryptoContext, 163 fileCreateTime, hfileName, columnFamily, tableName, cellComparator); 164 } 165}