Class FSTableDescriptors
- All Implemented Interfaces:
TableDescriptors
TableDescriptors
that reads descriptors from the passed filesystem. It
expects descriptors to be in a file in the TABLEINFO_DIR
subdir of the table's directory
in FS. Can be read-only -- i.e. does not modify the filesystem or can be read and write.
Also has utility for keeping up the table descriptors tableinfo file. The table schema file is
kept in the TABLEINFO_DIR
subdir of the table directory in the filesystem. It has a
TABLEINFO_FILE_PREFIX
and then a suffix that is the edit sequenceid: e.g.
.tableinfo.0000000003
. This sequenceid is always increasing. It starts at zero. The
table schema file with the highest sequenceid has the most recent schema edit. Usually there is
one file only, the most recent but there may be short periods where there are more than one file.
Old files are eventually cleaned. Presumption is that there will not be lots of concurrent
clients making table schema edits. If so, the below needs a bit of a reworking and perhaps some
supporting api in hdfs.
-
Nested Class Summary
Modifier and TypeClassDescription(package private) static final class
-
Field Summary
Modifier and TypeFieldDescriptionprivate final Map<TableName,
TableDescriptor> (package private) long
private final org.apache.hadoop.fs.FileSystem
private final boolean
private boolean
(package private) long
private static final org.slf4j.Logger
private final org.apache.hadoop.fs.Path
static final String
static final String
The file name prefix used to store HTD in HDFS(package private) static final Comparator<org.apache.hadoop.fs.FileStatus>
CompareFileStatus
instances byPath.getName()
.private static final org.apache.hadoop.fs.PathFilter
private final boolean
(package private) static final int
Width of the sequenceid that is a suffix on a tableinfo file. -
Constructor Summary
ConstructorDescriptionFSTableDescriptors
(org.apache.hadoop.conf.Configuration conf) Construct a FSTableDescriptors instance using the hbase root dir of the given conf and the filesystem where that root dir lives.FSTableDescriptors
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootdir) FSTableDescriptors
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootdir, boolean fsreadonly, boolean usecache) -
Method Summary
Modifier and TypeMethodDescriptionstatic TableDescriptorBuilder
createMetaTableDescriptorBuilder
(org.apache.hadoop.conf.Configuration conf) boolean
Create new TableDescriptor in HDFS.boolean
createTableDescriptor
(TableDescriptor htd, boolean forceCreation) Create new TableDescriptor in HDFS.static boolean
createTableDescriptorForTableDirectory
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path tableDir, TableDescriptor htd, boolean forceCreation) Create a new TableDescriptor in HDFS in the specified table directory.boolean
createTableDescriptorForTableDirectory
(org.apache.hadoop.fs.Path tableDir, TableDescriptor htd, boolean forceCreation) Create a new TableDescriptor in HDFS in the specified table directory.private static void
deleteMalformedFile
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path file) private static void
deleteTableDescriptorFiles
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dir, int maxSequenceId) Deletes files matching the table info file pattern within the given directory whose sequenceId is at most the given max sequenceId.static void
deleteTableDescriptors
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path tableDir) private static String
formatTableInfoSequenceId
(int number) Get the current table descriptor for the given table, or null if none exists.getAll()
Returns a map from table name to table descriptor for all tables.getByNamespace
(String name) Find descriptors by namespace.static ColumnFamilyDescriptor
static TableDescriptor
getTableDescriptorFromFs
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path tableDir) Returns the latest table descriptor for the table located at the given directory directly from the file system if it exists.private static Optional<Pair<org.apache.hadoop.fs.FileStatus,
TableDescriptor>> getTableDescriptorFromFs
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path tableDir, boolean readonly) static TableDescriptor
getTableDescriptorFromFs
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path hbaseRootDir, TableName tableName) Returns the latest table descriptor for the given table directly from the file system if it exists, bypassing the local cache.private org.apache.hadoop.fs.Path
getTableDir
(TableName tableName) Return the table directory in HDFSstatic ColumnFamilyDescriptor
getTableFamilyDescForMeta
(org.apache.hadoop.conf.Configuration conf) (package private) static String
getTableInfoFileName
(int sequenceId, byte[] content) Returns Name of tableinfo file.(package private) static FSTableDescriptors.SequenceIdAndFileLength
getTableInfoSequenceIdAndFileLength
(org.apache.hadoop.fs.Path p) Returns the current sequence id and file length or 0 if none found.static boolean
isTableDir
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path tableDir) Check whether we have a valid TableDescriptor.protected boolean
Removes the table descriptor from the local cache and returns it.static TableDescriptor
tryUpdateAndGetMetaTableDescriptor
(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootdir) static void
tryUpdateMetaTableDescriptor
(org.apache.hadoop.conf.Configuration conf) void
update
(TableDescriptor td, boolean cacheOnly) Add or update descriptor(package private) org.apache.hadoop.fs.Path
private static org.apache.hadoop.fs.Path
writeTableDescriptor
(org.apache.hadoop.fs.FileSystem fs, TableDescriptor td, org.apache.hadoop.fs.Path tableDir, org.apache.hadoop.fs.FileStatus currentDescriptorFile) Attempts to write a new table descriptor to the given table's directory.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.hadoop.hbase.TableDescriptors
exists, update
-
Field Details
-
LOG
-
fs
-
rootdir
-
fsreadonly
-
usecache
-
fsvisited
-
cachehits
long cachehits -
invocations
long invocations -
TABLEINFO_FILE_PREFIX
The file name prefix used to store HTD in HDFS- See Also:
-
TABLEINFO_DIR
- See Also:
-
cache
-
TABLEINFO_FILESTATUS_COMPARATOR
CompareFileStatus
instances byPath.getName()
. Returns in reverse order. -
TABLEINFO_PATHFILTER
-
WIDTH_OF_SEQUENCE_ID
Width of the sequenceid that is a suffix on a tableinfo file.- See Also:
-
-
Constructor Details
-
FSTableDescriptors
Construct a FSTableDescriptors instance using the hbase root dir of the given conf and the filesystem where that root dir lives. This instance can do write operations (is not read only).- Throws:
IOException
-
FSTableDescriptors
-
FSTableDescriptors
public FSTableDescriptors(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootdir, boolean fsreadonly, boolean usecache)
-
-
Method Details
-
tryUpdateMetaTableDescriptor
public static void tryUpdateMetaTableDescriptor(org.apache.hadoop.conf.Configuration conf) throws IOException - Throws:
IOException
-
tryUpdateAndGetMetaTableDescriptor
public static TableDescriptor tryUpdateAndGetMetaTableDescriptor(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootdir) throws IOException - Throws:
IOException
-
getTableFamilyDescForMeta
public static ColumnFamilyDescriptor getTableFamilyDescForMeta(org.apache.hadoop.conf.Configuration conf) -
getReplBarrierFamilyDescForMeta
-
createMetaTableDescriptorBuilder
public static TableDescriptorBuilder createMetaTableDescriptorBuilder(org.apache.hadoop.conf.Configuration conf) throws IOException - Throws:
IOException
-
isUsecache
-
get
Get the current table descriptor for the given table, or null if none exists. Uses a local cache of the descriptor but still checks the filesystem on each call iffsvisited
is nottrue
, i.e, we haven't done a full scan yet, to see if a newer file has been created since the cached one was read.- Specified by:
get
in interfaceTableDescriptors
-
getAll
Returns a map from table name to table descriptor for all tables.- Specified by:
getAll
in interfaceTableDescriptors
- Returns:
- Map of all descriptors.
- Throws:
IOException
-
getByNamespace
Find descriptors by namespace.- Specified by:
getByNamespace
in interfaceTableDescriptors
- Returns:
- Map of all descriptors.
- Throws:
IOException
- See Also:
-
update
Description copied from interface:TableDescriptors
Add or update descriptor- Specified by:
update
in interfaceTableDescriptors
- Parameters:
td
- Descriptor to set into TableDescriptorscacheOnly
- only add the givenhtd
to cache, without updating the storage. For example, when creating table, we will write the descriptor to fs when creating the fs layout, so we do not need to update the fs again.- Throws:
IOException
-
updateTableDescriptor
- Throws:
IOException
-
remove
Removes the table descriptor from the local cache and returns it. If not in read only mode, it also deletes the entire table directory(!) from the FileSystem.- Specified by:
remove
in interfaceTableDescriptors
- Throws:
IOException
-
isTableDir
public static boolean isTableDir(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path tableDir) throws IOException Check whether we have a valid TableDescriptor.- Throws:
IOException
-
getTableDir
Return the table directory in HDFS -
formatTableInfoSequenceId
- Parameters:
number
- Number to use as suffix.- Returns:
- Returns zero-prefixed decimal version of passed number (Does absolute in case number is negative).
-
getTableInfoSequenceIdAndFileLength
static FSTableDescriptors.SequenceIdAndFileLength getTableInfoSequenceIdAndFileLength(org.apache.hadoop.fs.Path p) Returns the current sequence id and file length or 0 if none found.- Parameters:
p
- Path to a.tableinfo
file.
-
getTableInfoFileName
Returns Name of tableinfo file. -
getTableDescriptorFromFs
public static TableDescriptor getTableDescriptorFromFs(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path hbaseRootDir, TableName tableName) throws IOException Returns the latest table descriptor for the given table directly from the file system if it exists, bypassing the local cache. Returns null if it's not found.- Throws:
IOException
-
getTableDescriptorFromFs
public static TableDescriptor getTableDescriptorFromFs(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path tableDir) throws IOException Returns the latest table descriptor for the table located at the given directory directly from the file system if it exists.- Throws:
IOException
-
deleteMalformedFile
private static void deleteMalformedFile(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path file) throws IOException - Throws:
IOException
-
getTableDescriptorFromFs
private static Optional<Pair<org.apache.hadoop.fs.FileStatus,TableDescriptor>> getTableDescriptorFromFs(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path tableDir, boolean readonly) throws IOException - Throws:
IOException
-
deleteTableDescriptors
public static void deleteTableDescriptors(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path tableDir) throws IOException - Throws:
IOException
-
deleteTableDescriptorFiles
private static void deleteTableDescriptorFiles(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dir, int maxSequenceId) throws IOException Deletes files matching the table info file pattern within the given directory whose sequenceId is at most the given max sequenceId.- Throws:
IOException
-
writeTableDescriptor
private static org.apache.hadoop.fs.Path writeTableDescriptor(org.apache.hadoop.fs.FileSystem fs, TableDescriptor td, org.apache.hadoop.fs.Path tableDir, org.apache.hadoop.fs.FileStatus currentDescriptorFile) throws IOException Attempts to write a new table descriptor to the given table's directory. It begins at the currentSequenceId + 1 and tries 10 times to find a new sequence number not already in use. Removes the current descriptor file if passed in.- Returns:
- Descriptor file or null if we failed write.
- Throws:
IOException
-
createTableDescriptor
Create new TableDescriptor in HDFS. Happens when we are creating table. Used by tests.- Returns:
- True if we successfully created file.
- Throws:
IOException
-
createTableDescriptor
Create new TableDescriptor in HDFS. Happens when we are creating table. If forceCreation is true then even if previous table descriptor is present it will be overwritten- Returns:
- True if we successfully created file.
- Throws:
IOException
-
createTableDescriptorForTableDirectory
public boolean createTableDescriptorForTableDirectory(org.apache.hadoop.fs.Path tableDir, TableDescriptor htd, boolean forceCreation) throws IOException Create a new TableDescriptor in HDFS in the specified table directory. Happens when we create a new table during cluster start or in Clone and Create Table Procedures. Checks readOnly flag passed on construction.- Parameters:
tableDir
- table directory under which we should write the filehtd
- description of the table to writeforceCreation
- if true,then even if previous table descriptor is present it will be overwritten- Returns:
- true if the we successfully created the file, false if the file already exists and we weren't forcing the descriptor creation.
- Throws:
IOException
- if a filesystem error occurs
-
createTableDescriptorForTableDirectory
public static boolean createTableDescriptorForTableDirectory(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path tableDir, TableDescriptor htd, boolean forceCreation) throws IOException Create a new TableDescriptor in HDFS in the specified table directory. Happens when we create a new table snapshoting. Does not enforce read-only. That is for caller to determine.- Parameters:
fs
- Filesystem to use.tableDir
- table directory under which we should write the filehtd
- description of the table to writeforceCreation
- if true,then even if previous table descriptor is present it will be overwritten- Returns:
- true if the we successfully created the file, false if the file already exists and we weren't forcing the descriptor creation.
- Throws:
IOException
- if a filesystem error occurs
-