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