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