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 the encryption key namespace for this family */
118  String getEncryptionKeyNamespace();
119
120  /** Returns Return the encryption algorithm in use by this family */
121  String getEncryptionType();
122
123  /**
124   * Returns in-memory compaction policy if set for the cf. Returns null if no policy is set for for
125   * this column family
126   */
127  MemoryCompactionPolicy getInMemoryCompaction();
128
129  /** Returns return the KeepDeletedCells */
130  KeepDeletedCells getKeepDeletedCells();
131
132  /** Returns maximum number of versions */
133  int getMaxVersions();
134
135  /** Returns The minimum number of versions to keep. */
136  int getMinVersions();
137
138  /**
139   * Get the mob compact partition policy for this family
140   */
141  MobCompactPartitionPolicy getMobCompactPartitionPolicy();
142
143  /**
144   * Gets the mob threshold of the family. If the size of a cell value is larger than this
145   * threshold, it's regarded as a mob. The default threshold is 1024*100(100K)B.
146   * @return The mob threshold.
147   */
148  long getMobThreshold();
149
150  /** Returns a copy of Name of this column family */
151  byte[] getName();
152
153  /** Returns Name of this column family */
154  String getNameAsString();
155
156  /** Returns the scope tag */
157  int getScope();
158
159  /**
160   * Not using {@code enum} here because HDFS is not using {@code enum} for storage policy, see
161   * org.apache.hadoop.hdfs.server.blockmanagement.BlockStoragePolicySuite for more details.
162   * @return Return the storage policy in use by this family
163   */
164  String getStoragePolicy();
165
166  /** Returns Time-to-live of cell contents, in seconds. */
167  int getTimeToLive();
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  Bytes getValue(Bytes 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  String getValue(String key);
182
183  /**
184   * Get a configuration value.
185   * @param key The key.
186   * @return A clone value. Null if no mapping for the key
187   */
188  byte[] getValue(byte[] key);
189
190  /**
191   * Get all configuration values. It clone all bytes of all elements.
192   * @return All values
193   */
194  Map<Bytes, Bytes> getValues();
195
196  /**
197   * Returns 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  /** Returns true if we should cache bloomfilter blocks on write */
203  boolean isCacheBloomsOnWrite();
204
205  /** Returns true if we should cache data blocks on write */
206  boolean isCacheDataOnWrite();
207
208  /** Returns true if we should cache index blocks on write */
209  boolean isCacheIndexesOnWrite();
210
211  /**
212   * Returns Whether KV tags should be compressed along with DataBlockEncoding. When no
213   * DataBlockEncoding is been used, this is having no effect.
214   */
215  boolean isCompressTags();
216
217  /** Returns true if we should evict cached blocks from the blockcache on close */
218  boolean isEvictBlocksOnClose();
219
220  /**
221   * Returns True if we are to favor keeping all values for this column family in the HRegionServer
222   * cache.
223   */
224  boolean isInMemory();
225
226  /**
227   * Gets whether the mob is enabled for the family.
228   * @return True if the mob is enabled for the family.
229   */
230  boolean isMobEnabled();
231
232  /** Returns true if we should prefetch blocks into the blockcache on open */
233  boolean isPrefetchBlocksOnOpen();
234
235  /** Returns Column family descriptor with only the customized attributes. */
236  String toStringCustomizedValues();
237
238  /**
239   * By default, HBase only consider timestamp in versions. So a previous Delete with higher ts will
240   * mask a later Put with lower ts. Set this to true to enable new semantics of versions. We will
241   * also consider mvcc in versions. See HBASE-15968 for details.
242   */
243  boolean isNewVersionBehavior();
244}