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