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;
019
020import java.io.IOException;
021import java.util.Map;
022
023import org.apache.yetus.audience.InterfaceAudience;
024import org.apache.hadoop.hbase.client.TableDescriptor;
025
026/**
027 * Get, remove and modify table descriptors.
028 */
029@InterfaceAudience.Private
030public interface TableDescriptors {
031
032  /**
033   * Test whether a given table exists, i.e, has a table descriptor.
034   */
035  default boolean exists(TableName tableName) throws IOException {
036    return get(tableName) != null;
037  }
038
039  /**
040   * @return TableDescriptor for tablename
041   */
042  TableDescriptor get(TableName tableName) throws IOException;
043
044  /**
045   * Get Map of all NamespaceDescriptors for a given namespace.
046   * @return Map of all descriptors.
047   */
048  Map<String, TableDescriptor> getByNamespace(String name) throws IOException;
049
050  /**
051   * Get Map of all TableDescriptors. Populates the descriptor cache as a side effect.
052   * </p>
053   * Notice: the key of map is the table name which contains namespace. It was generated by
054   * {@link TableName#getNameWithNamespaceInclAsString()}.
055   * @return Map of all descriptors.
056   */
057  Map<String, TableDescriptor> getAll() throws IOException;
058
059  /**
060   * Add or update descriptor. Just call {@link #update(TableDescriptor, boolean)} with
061   * {@code cacheOnly} as {@code false}.
062   */
063  default void update(TableDescriptor htd) throws IOException {
064    update(htd, false);
065  }
066
067  /**
068   * Add or update descriptor
069   * @param htd Descriptor to set into TableDescriptors
070   * @param cacheOnly only add the given {@code htd} to cache, without updating the storage. For
071   *          example, when creating table, we will write the descriptor to fs when creating the fs
072   *          layout, so we do not need to update the fs again.
073   */
074  void update(TableDescriptor htd, boolean cacheOnly) throws IOException;
075
076  /**
077   * @return Instance of table descriptor or null if none found.
078   */
079  TableDescriptor remove(TableName tablename) throws IOException;
080}