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