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.client; 019 020import java.util.Comparator; 021import java.util.HashMap; 022import java.util.Map; 023import org.apache.hadoop.hbase.KeepDeletedCells; 024import org.apache.hadoop.hbase.MemoryCompactionPolicy; 025import org.apache.hadoop.hbase.io.compress.Compression; 026import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding; 027import org.apache.hadoop.hbase.regionserver.BloomType; 028import org.apache.hadoop.hbase.util.Bytes; 029import org.apache.yetus.audience.InterfaceAudience; 030 031/** 032 * An ColumnFamilyDescriptor contains information about a column family such as the number of 033 * versions, compression settings, etc. It is used as input when creating a table or adding a 034 * column. To construct a new instance, use the {@link ColumnFamilyDescriptorBuilder} methods 035 * @since 2.0.0 036 */ 037@InterfaceAudience.Public 038public interface ColumnFamilyDescriptor { 039 040 @InterfaceAudience.Private 041 static final Comparator<ColumnFamilyDescriptor> COMPARATOR = 042 (ColumnFamilyDescriptor lhs, ColumnFamilyDescriptor rhs) -> { 043 int result = Bytes.compareTo(lhs.getName(), rhs.getName()); 044 if (result != 0) { 045 return result; 046 } 047 // punt on comparison for ordering, just calculate difference. 048 result = lhs.getValues().hashCode() - rhs.getValues().hashCode(); 049 if (result != 0) { 050 return result; 051 } 052 return lhs.getConfiguration().hashCode() - rhs.getConfiguration().hashCode(); 053 }; 054 055 static final Bytes REPLICATION_SCOPE_BYTES = 056 new Bytes(Bytes.toBytes(ColumnFamilyDescriptorBuilder.REPLICATION_SCOPE)); 057 058 @InterfaceAudience.Private 059 static final Comparator<ColumnFamilyDescriptor> COMPARATOR_IGNORE_REPLICATION = 060 (ColumnFamilyDescriptor lcf, ColumnFamilyDescriptor rcf) -> { 061 int result = Bytes.compareTo(lcf.getName(), rcf.getName()); 062 if (result != 0) { 063 return result; 064 } 065 // ColumnFamilyDescriptor.getValues is a immutable map, so copy it and remove 066 // REPLICATION_SCOPE_BYTES 067 Map<Bytes, Bytes> lValues = new HashMap<>(); 068 lValues.putAll(lcf.getValues()); 069 lValues.remove(REPLICATION_SCOPE_BYTES); 070 Map<Bytes, Bytes> rValues = new HashMap<>(); 071 rValues.putAll(rcf.getValues()); 072 rValues.remove(REPLICATION_SCOPE_BYTES); 073 result = lValues.hashCode() - rValues.hashCode(); 074 if (result != 0) { 075 return result; 076 } 077 return lcf.getConfiguration().hashCode() - rcf.getConfiguration().hashCode(); 078 }; 079 080 /** Returns The storefile/hfile blocksize for this column family. */ 081 int getBlocksize(); 082 083 /** Returns bloom filter type used for new StoreFiles in ColumnFamily */ 084 BloomType getBloomFilterType(); 085 086 /** Returns Compression type setting. */ 087 Compression.Algorithm getCompactionCompressionType(); 088 089 /** Returns Compression type setting for major compactions. */ 090 Compression.Algorithm getMajorCompactionCompressionType(); 091 092 /** Returns Compression type setting for minor compactions. */ 093 Compression.Algorithm getMinorCompactionCompressionType(); 094 095 /** Returns Compression type setting. */ 096 Compression.Algorithm getCompressionType(); 097 098 /** Returns an unmodifiable map. */ 099 Map<String, String> getConfiguration(); 100 101 /** Returns accessing the configuration value by key. */ 102 String getConfigurationValue(String key); 103 104 /** Returns replication factor set for this CF */ 105 short getDFSReplication(); 106 107 /** Returns the data block encoding algorithm used in block cache and optionally on disk */ 108 DataBlockEncoding getDataBlockEncoding(); 109 110 /** Returns Return the raw crypto key attribute for the family, or null if not set */ 111 byte[] getEncryptionKey(); 112 113 /** Returns Return the encryption algorithm in use by this family */ 114 String getEncryptionType(); 115 116 /** 117 * Returns in-memory compaction policy if set for the cf. Returns null if no policy is set for for 118 * this column family 119 */ 120 MemoryCompactionPolicy getInMemoryCompaction(); 121 122 /** Returns return the KeepDeletedCells */ 123 KeepDeletedCells getKeepDeletedCells(); 124 125 /** Returns maximum number of versions */ 126 int getMaxVersions(); 127 128 /** Returns The minimum number of versions to keep. */ 129 int getMinVersions(); 130 131 /** 132 * Get the mob compact partition policy for this family n 133 */ 134 MobCompactPartitionPolicy getMobCompactPartitionPolicy(); 135 136 /** 137 * Gets the mob threshold of the family. If the size of a cell value is larger than this 138 * threshold, it's regarded as a mob. The default threshold is 1024*100(100K)B. 139 * @return The mob threshold. 140 */ 141 long getMobThreshold(); 142 143 /** Returns a copy of Name of this column family */ 144 byte[] getName(); 145 146 /** Returns Name of this column family */ 147 String getNameAsString(); 148 149 /** Returns the scope tag */ 150 int getScope(); 151 152 /** 153 * Not using {@code enum} here because HDFS is not using {@code enum} for storage policy, see 154 * org.apache.hadoop.hdfs.server.blockmanagement.BlockStoragePolicySuite for more details. 155 * @return Return the storage policy in use by this family 156 */ 157 String getStoragePolicy(); 158 159 /** Returns Time-to-live of cell contents, in seconds. */ 160 int getTimeToLive(); 161 162 /** 163 * Get a configuration value. 164 * @param key The key. 165 * @return A clone value. Null if no mapping for the key 166 */ 167 Bytes getValue(Bytes key); 168 169 /** 170 * Get a configuration value. 171 * @param key The key. 172 * @return A clone value. Null if no mapping for the key 173 */ 174 String getValue(String key); 175 176 /** 177 * Get a configuration value. 178 * @param key The key. 179 * @return A clone value. Null if no mapping for the key 180 */ 181 byte[] getValue(byte[] key); 182 183 /** 184 * Get all configuration values. It clone all bytes of all elements. 185 * @return All values 186 */ 187 Map<Bytes, Bytes> getValues(); 188 189 /** 190 * Returns True if hfile DATA type blocks should be cached (You cannot disable caching of INDEX 191 * and BLOOM type blocks). 192 */ 193 boolean isBlockCacheEnabled(); 194 195 /** Returns true if we should cache bloomfilter blocks on write */ 196 boolean isCacheBloomsOnWrite(); 197 198 /** Returns true if we should cache data blocks on write */ 199 boolean isCacheDataOnWrite(); 200 201 /** Returns true if we should cache index blocks on write */ 202 boolean isCacheIndexesOnWrite(); 203 204 /** 205 * Returns Whether KV tags should be compressed along with DataBlockEncoding. When no 206 * DataBlockEncoding is been used, this is having no effect. 207 */ 208 boolean isCompressTags(); 209 210 /** Returns true if we should evict cached blocks from the blockcache on close */ 211 boolean isEvictBlocksOnClose(); 212 213 /** 214 * Returns True if we are to favor keeping all values for this column family in the HRegionServer 215 * cache. 216 */ 217 boolean isInMemory(); 218 219 /** 220 * Gets whether the mob is enabled for the family. 221 * @return True if the mob is enabled for the family. 222 */ 223 boolean isMobEnabled(); 224 225 /** Returns true if we should prefetch blocks into the blockcache on open */ 226 boolean isPrefetchBlocksOnOpen(); 227 228 /** Returns Column family descriptor with only the customized attributes. */ 229 String toStringCustomizedValues(); 230 231 /** 232 * By default, HBase only consider timestamp in versions. So a previous Delete with higher ts will 233 * mask a later Put with lower ts. Set this to true to enable new semantics of versions. We will 234 * also consider mvcc in versions. See HBASE-15968 for details. 235 */ 236 boolean isNewVersionBehavior(); 237}