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