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.regionserver.storefiletracker; 019 020import java.io.IOException; 021import java.util.Collection; 022import java.util.List; 023import org.apache.hadoop.fs.FileStatus; 024import org.apache.hadoop.fs.Path; 025import org.apache.hadoop.hbase.TableName; 026import org.apache.hadoop.hbase.client.TableDescriptorBuilder; 027import org.apache.hadoop.hbase.io.Reference; 028import org.apache.hadoop.hbase.regionserver.CreateStoreFileWriterParams; 029import org.apache.hadoop.hbase.regionserver.StoreFileInfo; 030import org.apache.hadoop.hbase.regionserver.StoreFileWriter; 031import org.apache.yetus.audience.InterfaceAudience; 032 033/** 034 * An interface to define how we track the store files for a give store. 035 * <p/> 036 * In the old time, we will write store to a tmp directory first, and then rename it to the actual 037 * data file. And once a store file is under data directory, we will consider it as 'committed'. And 038 * we need to do listing when loading store files. 039 * <p/> 040 * When cloud age is coming, now we want to store the store files on object storage, where rename 041 * and list are not as cheap as on HDFS, especially rename. Although introducing a metadata 042 * management layer for object storage could solve the problem, but we still want HBase to run on 043 * pure object storage, so here we introduce this interface to abstract how we track the store 044 * files. For the old implementation, we just persist nothing here, and do listing to load store 045 * files. When running on object storage, we could persist the store file list in a system region, 046 * or in a file on the object storage, to make it possible to write directly into the data directory 047 * to avoid renaming, and also avoid listing when loading store files. 048 * <p/> 049 * The implementation requires to be thread safe as flush and compaction may occur as the same time, 050 * and we could also do multiple compactions at the same time. As the implementation may choose to 051 * persist the store file list to external storage, which could be slow, it is the duty for the 052 * callers to not call it inside a lock which may block normal read/write requests. 053 */ 054@InterfaceAudience.Private 055public interface StoreFileTracker { 056 /** 057 * Load the store files list when opening a region. 058 */ 059 List<StoreFileInfo> load() throws IOException; 060 061 /** 062 * Add new store files. 063 * <p/> 064 * Used for flush and bulk load. 065 */ 066 void add(Collection<StoreFileInfo> newFiles) throws IOException; 067 068 /** 069 * Add new store files and remove compacted store files after compaction. 070 */ 071 void replace(Collection<StoreFileInfo> compactedFiles, Collection<StoreFileInfo> newFiles) 072 throws IOException; 073 074 /** 075 * Set the store files. 076 */ 077 void set(List<StoreFileInfo> files) throws IOException; 078 079 /** 080 * Create a writer for writing new store files. 081 * @return Writer for a new StoreFile 082 */ 083 StoreFileWriter createWriter(CreateStoreFileWriterParams params) throws IOException; 084 085 /** 086 * Adds StoreFileTracker implementations specific configurations into the table descriptor. 087 * <p/> 088 * This is used to avoid accidentally data loss when changing the cluster level store file tracker 089 * implementation, and also possible misconfiguration between master and region servers. 090 * <p/> 091 * See HBASE-26246 for more details. 092 * @param builder The table descriptor builder for the given table. 093 */ 094 TableDescriptorBuilder updateWithTrackerConfigs(TableDescriptorBuilder builder); 095 096 /** 097 * Whether the implementation of this tracker requires you to write to temp directory first, i.e, 098 * does not allow broken store files under the actual data directory. 099 */ 100 boolean requireWritingToTmpDirFirst(); 101 102 Reference createReference(Reference reference, Path path) throws IOException; 103 104 /** 105 * Reads the reference file from the given path. 106 * @param path the {@link Path} to the reference file in the file system. 107 * @return a {@link Reference} that points at top/bottom half of a an hfile 108 */ 109 Reference readReference(Path path) throws IOException; 110 111 /** 112 * Returns true if the specified family has reference files 113 * @return true if family contains reference files 114 */ 115 boolean hasReferences() throws IOException; 116 117 StoreFileInfo getStoreFileInfo(final FileStatus fileStatus, final Path initialPath, 118 final boolean primaryReplica) throws IOException; 119 120 StoreFileInfo getStoreFileInfo(final Path initialPath, final boolean primaryReplica) 121 throws IOException; 122 123 /** 124 * Create a new HFileLink 125 * <p> 126 * It also adds a back-reference to the hfile back-reference directory to simplify the 127 * reference-count and the cleaning process. 128 * @param hfileLinkName - HFileLink name (it contains hfile-region-table) 129 * @param createBackRef - Whether back reference should be created. Defaults to true. 130 * @return the file link name. 131 * @throws IOException on file or parent directory creation failure. 132 */ 133 String createHFileLink(final TableName linkedTable, final String linkedRegion, 134 final String hfileName, final boolean createBackRef) throws IOException; 135 136 /** 137 * Create a new HFileLink starting from a hfileLink name 138 * <p> 139 * It also adds a back-reference to the hfile back-reference directory to simplify the 140 * reference-count and the cleaning process. 141 * @param hfileLinkName - HFileLink name (it contains hfile-region-table) 142 * @param createBackRef - Whether back reference should be created. Defaults to true. 143 * @return the file link name. 144 * @throws IOException on file or parent directory creation failure. 145 */ 146 String createFromHFileLink(final String hfileName, final boolean createBackRef) 147 throws IOException; 148 149}