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  /**
099   * @return Compression type setting for major compactions.
100   */
101  Compression.Algorithm getMajorCompactionCompressionType();
102
103  /**
104   * @return Compression type setting for minor compactions.
105   */
106  Compression.Algorithm getMinorCompactionCompressionType();
107
108  /**
109   * @return Compression type setting.
110   */
111  Compression.Algorithm getCompressionType();
112
113  /**
114   * @return an unmodifiable map.
115   */
116  Map<String, String> getConfiguration();
117  /**
118   * @param key the key whose associated value is to be returned
119   * @return accessing the configuration value by key.
120   */
121  String getConfigurationValue(String key);
122  /**
123   * @return replication factor set for this CF
124   */
125  short getDFSReplication();
126  /**
127   * @return the data block encoding algorithm used in block cache and
128   *         optionally on disk
129   */
130  DataBlockEncoding getDataBlockEncoding();
131  /**
132   * @return Return the raw crypto key attribute for the family, or null if not set
133   */
134  byte[] getEncryptionKey();
135
136  /**
137   * @return Return the encryption algorithm in use by this family
138   */
139  String getEncryptionType();
140  /**
141   * @return in-memory compaction policy if set for the cf. Returns null if no policy is set for
142   *          for this column family
143   */
144  MemoryCompactionPolicy getInMemoryCompaction();
145  /**
146   * @return return the KeepDeletedCells
147   */
148  KeepDeletedCells getKeepDeletedCells();
149  /**
150   * @return maximum number of versions
151   */
152  int getMaxVersions();
153  /**
154   * @return The minimum number of versions to keep.
155   */
156  int getMinVersions();
157  /**
158   * Get the mob compact partition policy for this family
159   * @return MobCompactPartitionPolicy
160   */
161  MobCompactPartitionPolicy getMobCompactPartitionPolicy();
162  /**
163   * Gets the mob threshold of the family.
164   * If the size of a cell value is larger than this threshold, it's regarded as a mob.
165   * The default threshold is 1024*100(100K)B.
166   * @return The mob threshold.
167   */
168  long getMobThreshold();
169  /**
170   * @return a copy of Name of this column family
171   */
172  byte[] getName();
173
174  /**
175   * @return Name of this column family
176   */
177  String getNameAsString();
178
179   /**
180    * @return the scope tag
181    */
182  int getScope();
183  /**
184   * Not using {@code enum} here because HDFS is not using {@code enum} for storage policy, see
185   * org.apache.hadoop.hdfs.server.blockmanagement.BlockStoragePolicySuite for more details.
186   * @return Return the storage policy in use by this family
187   */
188  String getStoragePolicy();
189 /**
190   * @return Time-to-live of cell contents, in seconds.
191   */
192  int getTimeToLive();
193  /**
194   * @param key The key.
195   * @return A clone value. Null if no mapping for the key
196   */
197  Bytes getValue(Bytes key);
198  /**
199   * @param key The key.
200   * @return A clone value. Null if no mapping for the key
201   */
202  byte[] getValue(byte[] key);
203  /**
204   * It clone all bytes of all elements.
205   * @return All values
206   */
207  Map<Bytes, Bytes> getValues();
208  /**
209   * @return True if hfile DATA type blocks should be cached (You cannot disable caching of INDEX
210   * and BLOOM type blocks).
211   */
212  boolean isBlockCacheEnabled();
213  /**
214   * @return true if we should cache bloomfilter blocks on write
215   */
216  boolean isCacheBloomsOnWrite();
217
218  /**
219   * @return true if we should cache data blocks on write
220   */
221  boolean isCacheDataOnWrite();
222  /**
223   * @return true if we should cache index blocks on write
224   */
225  boolean isCacheIndexesOnWrite();
226  /**
227   * @return Whether KV tags should be compressed along with DataBlockEncoding. When no
228   *         DataBlockEncoding is been used, this is having no effect.
229   */
230  boolean isCompressTags();
231  /**
232   * @return true if we should evict cached blocks from the blockcache on close
233   */
234  boolean isEvictBlocksOnClose();
235  /**
236   * @return True if we are to favor keeping all values for this column family in the
237   * HRegionServer cache.
238   */
239  boolean isInMemory();
240  /**
241   * Gets whether the mob is enabled for the family.
242   * @return True if the mob is enabled for the family.
243   */
244  boolean isMobEnabled();
245  /**
246   * @return true if we should prefetch blocks into the blockcache on open
247   */
248  boolean isPrefetchBlocksOnOpen();
249
250  /**
251   * @return Column family descriptor with only the customized attributes.
252   */
253  String toStringCustomizedValues();
254
255  /**
256   * By default, HBase only consider timestamp in versions. So a previous Delete with higher ts
257   * will mask a later Put with lower ts. Set this to true to enable new semantics of versions.
258   * We will also consider mvcc in versions. See HBASE-15968 for details.
259   */
260  boolean isNewVersionBehavior();
261}