You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by la...@apache.org on 2013/08/06 18:19:51 UTC
svn commit: r1511018 -
/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java
Author: larsh
Date: Tue Aug 6 16:19:51 2013
New Revision: 1511018
URL: http://svn.apache.org/r1511018
Log:
HBASE-9123 Use table dir modtime to avoid scanning table dir to check cached table descriptor in 0.94 (Dave Latham)
Modified:
hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java
Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java?rev=1511018&r1=1511017&r2=1511018&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java Tue Aug 6 16:19:51 2013
@@ -80,20 +80,27 @@ public class FSTableDescriptors implemen
new ConcurrentHashMap<String, TableDescriptorModtime>();
/**
- * Data structure to hold modification time and table descriptor.
+ * Data structure to cache a table descriptor, the time it was modified,
+ * and the time the table directory was modified.
*/
static class TableDescriptorModtime {
private final HTableDescriptor descriptor;
private final long modtime;
+ private final long dirmodtime;
- TableDescriptorModtime(final long modtime, final HTableDescriptor htd) {
+ TableDescriptorModtime(final long modtime, final long dirmodtime, final HTableDescriptor htd) {
this.descriptor = htd;
this.modtime = modtime;
+ this.dirmodtime = dirmodtime;
}
long getModtime() {
return this.modtime;
}
+
+ long getDirModtime() {
+ return this.dirmodtime;
+ }
HTableDescriptor getTableDescriptor() {
return this.descriptor;
@@ -153,15 +160,28 @@ public class FSTableDescriptors implemen
if (cachedtdm != null) {
// Check mod time has not changed (this is trip to NN).
- if (getTableInfoModtime(this.fs, this.rootdir, tablename) <= cachedtdm.getModtime()) {
+ // First check directory modtime as it doesn't require a scan of the full table directory
+ long tableDirModtime = getTableDirModtime(fs, this.rootdir, tablename);
+ boolean cachehit = false;
+ if (tableDirModtime <= cachedtdm.getDirModtime()) {
+ // table dir not changed since our cached entry
+ cachehit = true;
+ } else if (getTableInfoModtime(this.fs, this.rootdir, tablename) <= cachedtdm.getModtime()) {
+ // the table dir has changed (perhaps a region split) but the info file itself has not
+ // so the cached descriptor is good, we just need to update the entry
+ this.cache.put(tablename, new TableDescriptorModtime(cachedtdm.getModtime(),
+ tableDirModtime, cachedtdm.getTableDescriptor()));
+ cachehit = true;
+ } // else table info file has been changed, need to read it
+ if (cachehit) {
cachehits++;
return cachedtdm.getTableDescriptor();
}
- }
+ }
TableDescriptorModtime tdmt = null;
try {
- tdmt = getTableDescriptorModtime(this.fs, this.rootdir, tablename);
+ tdmt = getTableDescriptorModtime(this.fs, this.rootdir, tablename, true);
} catch (NullPointerException e) {
LOG.debug("Exception during readTableDecriptor. Current table name = "
+ tablename, e);
@@ -215,8 +235,10 @@ public class FSTableDescriptors implemen
throw new NotImplementedException();
}
if (!this.fsreadonly) updateHTableDescriptor(this.fs, this.rootdir, htd);
- long modtime = getTableInfoModtime(this.fs, this.rootdir, htd.getNameAsString());
- this.cache.put(htd.getNameAsString(), new TableDescriptorModtime(modtime, htd));
+ String tableName = htd.getNameAsString();
+ long modtime = getTableInfoModtime(this.fs, this.rootdir, tableName);
+ long dirmodtime = getTableDirModtime(this.fs, this.rootdir, tableName);
+ this.cache.put(tableName, new TableDescriptorModtime(modtime, dirmodtime, htd));
}
@Override
@@ -355,6 +377,14 @@ public class FSTableDescriptors implemen
TABLEINFO_NAME + "." + formatTableInfoSequenceId(sequenceid));
}
+ static long getTableDirModtime(final FileSystem fs, final Path rootdir,
+ final String tableName)
+ throws IOException {
+ Path tabledir = FSUtils.getTablePath(rootdir, tableName);
+ FileStatus status = fs.getFileStatus(tabledir);
+ return status == null? 0: status.getModificationTime();
+ }
+
/**
* @param fs
* @param rootdir
@@ -384,7 +414,7 @@ public class FSTableDescriptors implemen
HTableDescriptor htd = null;
try {
TableDescriptorModtime tdmt =
- getTableDescriptorModtime(fs, hbaseRootDir, Bytes.toString(tableName));
+ getTableDescriptorModtime(fs, hbaseRootDir, Bytes.toString(tableName), false);
htd = tdmt == null ? null : tdmt.getTableDescriptor();
} catch (NullPointerException e) {
LOG.debug("Exception during readTableDecriptor. Current table name = "
@@ -395,21 +425,22 @@ public class FSTableDescriptors implemen
static HTableDescriptor getTableDescriptor(FileSystem fs,
Path hbaseRootDir, String tableName) throws NullPointerException, IOException {
- TableDescriptorModtime tdmt = getTableDescriptorModtime(fs, hbaseRootDir, tableName);
+ TableDescriptorModtime tdmt = getTableDescriptorModtime(fs, hbaseRootDir, tableName, false);
return tdmt == null ? null : tdmt.getTableDescriptor();
}
static TableDescriptorModtime getTableDescriptorModtime(FileSystem fs,
- Path hbaseRootDir, String tableName) throws NullPointerException, IOException{
+ Path hbaseRootDir, String tableName, boolean readDirModtime)
+ throws NullPointerException, IOException{
// ignore both -ROOT- and .META. tables
if (Bytes.compareTo(Bytes.toBytes(tableName), HConstants.ROOT_TABLE_NAME) == 0
|| Bytes.compareTo(Bytes.toBytes(tableName), HConstants.META_TABLE_NAME) == 0) {
return null;
}
- return getTableDescriptorModtime(fs, FSUtils.getTablePath(hbaseRootDir, tableName));
+ return getTableDescriptorModtime(fs, FSUtils.getTablePath(hbaseRootDir, tableName), readDirModtime);
}
- static TableDescriptorModtime getTableDescriptorModtime(FileSystem fs, Path tableDir)
+ static TableDescriptorModtime getTableDescriptorModtime(FileSystem fs, Path tableDir, boolean readDirModtime)
throws NullPointerException, IOException {
if (tableDir == null) throw new NullPointerException();
FileStatus status = getTableInfoPath(fs, tableDir);
@@ -425,12 +456,16 @@ public class FSTableDescriptors implemen
} finally {
fsDataInputStream.close();
}
- return new TableDescriptorModtime(status.getModificationTime(), hTableDescriptor);
+ long dirModtime = 0;
+ if (readDirModtime) {
+ dirModtime = fs.getFileStatus(tableDir).getModificationTime();
+ }
+ return new TableDescriptorModtime(status.getModificationTime(), dirModtime, hTableDescriptor);
}
-
+
public static HTableDescriptor getTableDescriptor(FileSystem fs, Path tableDir)
throws IOException, NullPointerException {
- TableDescriptorModtime tdmt = getTableDescriptorModtime(fs, tableDir);
+ TableDescriptorModtime tdmt = getTableDescriptorModtime(fs, tableDir, false);
return tdmt == null? null: tdmt.getTableDescriptor();
}