HBASE-7018 Fix and Improve TableDescriptor caching for bulk assignment
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1401525 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
65a7c12942
commit
af295f5605
|
@ -17,7 +17,6 @@
|
|||
*/
|
||||
package org.apache.hadoop.hbase;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -34,22 +33,18 @@ public interface TableDescriptors {
|
|||
/**
|
||||
* @param tablename
|
||||
* @return HTableDescriptor for tablename
|
||||
* @throws TableExistsException
|
||||
* @throws FileNotFoundException
|
||||
* @throws IOException
|
||||
*/
|
||||
public HTableDescriptor get(final String tablename)
|
||||
throws FileNotFoundException, IOException;
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* @param tablename
|
||||
* @return HTableDescriptor for tablename
|
||||
* @throws TableExistsException
|
||||
* @throws FileNotFoundException
|
||||
* @throws IOException
|
||||
*/
|
||||
public HTableDescriptor get(final byte[] tablename)
|
||||
throws FileNotFoundException, IOException;
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Get Map of all HTableDescriptors. Populates the descriptor cache as a
|
||||
|
|
|
@ -128,7 +128,7 @@ public class FSTableDescriptors implements TableDescriptors {
|
|||
*/
|
||||
@Override
|
||||
public HTableDescriptor get(final byte [] tablename)
|
||||
throws FileNotFoundException, IOException {
|
||||
throws IOException {
|
||||
return get(Bytes.toString(tablename));
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ public class FSTableDescriptors implements TableDescriptors {
|
|||
*/
|
||||
@Override
|
||||
public HTableDescriptor get(final String tablename)
|
||||
throws FileNotFoundException, IOException {
|
||||
throws IOException {
|
||||
invocations++;
|
||||
if (HTableDescriptor.ROOT_TABLEDESC.getNameAsString().equals(tablename)) {
|
||||
cachehits++;
|
||||
|
@ -154,20 +154,19 @@ public class FSTableDescriptors implements TableDescriptors {
|
|||
}
|
||||
|
||||
// Look in cache of descriptors.
|
||||
TableDescriptorModtime tdm = this.cache.get(tablename);
|
||||
TableDescriptorModtime cachedtdm = this.cache.get(tablename);
|
||||
|
||||
// Check mod time has not changed (this is trip to NN).
|
||||
long modtime = getTableInfoModtime(this.fs, this.rootdir, tablename);
|
||||
if (tdm != null) {
|
||||
if (modtime <= tdm.getModtime()) {
|
||||
if (cachedtdm != null) {
|
||||
// Check mod time has not changed (this is trip to NN).
|
||||
if (getTableInfoModtime(this.fs, this.rootdir, tablename) <= cachedtdm.getModtime()) {
|
||||
cachehits++;
|
||||
return tdm.getTableDescriptor();
|
||||
return cachedtdm.getTableDescriptor();
|
||||
}
|
||||
}
|
||||
|
||||
HTableDescriptor htd = null;
|
||||
TableDescriptorModtime tdmt = null;
|
||||
try {
|
||||
htd = getTableDescriptor(this.fs, this.rootdir, tablename);
|
||||
tdmt = getTableDescriptorModtime(this.fs, this.rootdir, tablename);
|
||||
} catch (NullPointerException e) {
|
||||
LOG.debug("Exception during readTableDecriptor. Current table name = "
|
||||
+ tablename, e);
|
||||
|
@ -176,14 +175,14 @@ public class FSTableDescriptors implements TableDescriptors {
|
|||
+ tablename, ioe);
|
||||
}
|
||||
|
||||
if (htd == null) {
|
||||
if (tdmt == null) {
|
||||
LOG.warn("The following folder is in HBase's root directory and " +
|
||||
"doesn't contain a table descriptor, " +
|
||||
"do consider deleting it: " + tablename);
|
||||
} else {
|
||||
this.cache.put(tablename, new TableDescriptorModtime(modtime, htd));
|
||||
this.cache.put(tablename, tdmt);
|
||||
}
|
||||
return htd;
|
||||
return tdmt == null ? null : tdmt.getTableDescriptor();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -237,7 +236,7 @@ public class FSTableDescriptors implements TableDescriptors {
|
|||
}
|
||||
}
|
||||
TableDescriptorModtime tdm = this.cache.remove(tablename);
|
||||
return tdm == null? null: tdm.getTableDescriptor();
|
||||
return tdm == null ? null : tdm.getTableDescriptor();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -389,7 +388,9 @@ public class FSTableDescriptors implements TableDescriptors {
|
|||
throws IOException {
|
||||
HTableDescriptor htd = null;
|
||||
try {
|
||||
htd = getTableDescriptor(fs, hbaseRootDir, Bytes.toString(tableName));
|
||||
TableDescriptorModtime tdmt =
|
||||
getTableDescriptorModtime(fs, hbaseRootDir, Bytes.toString(tableName));
|
||||
htd = tdmt == null ? null : tdmt.getTableDescriptor();
|
||||
} catch (NullPointerException e) {
|
||||
LOG.debug("Exception during readTableDecriptor. Current table name = "
|
||||
+ Bytes.toString(tableName), e);
|
||||
|
@ -398,19 +399,23 @@ public class FSTableDescriptors implements TableDescriptors {
|
|||
}
|
||||
|
||||
static HTableDescriptor getTableDescriptor(FileSystem fs,
|
||||
Path hbaseRootDir, String tableName) throws NullPointerException, IOException {
|
||||
TableDescriptorModtime tdmt = getTableDescriptorModtime(fs, hbaseRootDir, tableName);
|
||||
return tdmt == null ? null : tdmt.getTableDescriptor();
|
||||
}
|
||||
|
||||
static TableDescriptorModtime getTableDescriptorModtime(FileSystem fs,
|
||||
Path hbaseRootDir, String tableName) throws NullPointerException, IOException{
|
||||
HTableDescriptor htd = null;
|
||||
// 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;
|
||||
}
|
||||
htd = getTableDescriptor(fs, FSUtils.getTablePath(hbaseRootDir, tableName));
|
||||
return htd;
|
||||
return getTableDescriptorModtime(fs, FSUtils.getTablePath(hbaseRootDir, tableName));
|
||||
}
|
||||
|
||||
public static HTableDescriptor getTableDescriptor(FileSystem fs, Path tableDir)
|
||||
throws IOException, NullPointerException {
|
||||
static TableDescriptorModtime getTableDescriptorModtime(FileSystem fs, Path tableDir)
|
||||
throws NullPointerException, IOException {
|
||||
if (tableDir == null) throw new NullPointerException();
|
||||
FileStatus status = getTableInfoPath(fs, tableDir);
|
||||
if (status == null) {
|
||||
|
@ -435,7 +440,13 @@ public class FSTableDescriptors implements TableDescriptors {
|
|||
// Convert the file over to be pb before leaving here.
|
||||
createTableDescriptor(fs, tableDir.getParent(), htd, true);
|
||||
}
|
||||
return htd;
|
||||
return new TableDescriptorModtime(status.getModificationTime(), htd);
|
||||
}
|
||||
|
||||
public static HTableDescriptor getTableDescriptor(FileSystem fs, Path tableDir)
|
||||
throws IOException, NullPointerException {
|
||||
TableDescriptorModtime tdmt = getTableDescriptorModtime(fs, tableDir);
|
||||
return tdmt == null ? null : tdmt.getTableDescriptor();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,7 +25,6 @@ import static org.junit.Assert.assertTrue;
|
|||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
|
@ -267,13 +266,13 @@ public class TestCatalogJanitor {
|
|||
|
||||
@Override
|
||||
public HTableDescriptor get(byte[] tablename)
|
||||
throws FileNotFoundException, IOException {
|
||||
throws IOException {
|
||||
return get(Bytes.toString(tablename));
|
||||
}
|
||||
|
||||
@Override
|
||||
public HTableDescriptor get(String tablename)
|
||||
throws FileNotFoundException, IOException {
|
||||
throws IOException {
|
||||
return createHTableDescriptor();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue