Skip to content

Commit

Permalink
Cache more efficiently getAll() and get() in FSTableDescriptors
Browse files Browse the repository at this point in the history
Signed-off-by: stack <stack@apache.org>
  • Loading branch information
Esteban Gutierrez authored and saintstack committed Nov 4, 2014
1 parent c66a6b0 commit 431b8a5
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,14 @@ void add(final HTableDescriptor htd)
*/
HTableDescriptor remove(final TableName tablename)
throws IOException;

/**
* Enables the tabledescriptor cache
*/
void setCacheOn() throws IOException;

/**
* Disables the tabledescriptor cache
*/
void setCacheOff() throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ public class HMaster extends HRegionServer implements MasterServices, Server {

MasterCoprocessorHost cpHost;

private final boolean preLoadTableDescriptors;

// Time stamps for when a hmaster became active
private long masterActiveTime;

Expand Down Expand Up @@ -285,8 +287,11 @@ public HMaster(final Configuration conf, CoordinatedStateManager csm)

this.metricsMaster = new MetricsMaster( new MetricsMasterWrapperImpl(this));

// preload table descriptor at startup
this.preLoadTableDescriptors = conf.getBoolean("hbase.master.preload.tabledescriptors", true);

// Do we publish the status?

boolean shouldPublish = conf.getBoolean(HConstants.STATUS_PUBLISHED,
HConstants.STATUS_PUBLISHED_DEFAULT);
Class<? extends ClusterStatusPublisher.Publisher> publisherClass =
Expand Down Expand Up @@ -505,6 +510,15 @@ private void finishActiveMasterInitialization(MonitoredTask status)
// TODO: Do this using Dependency Injection, using PicoContainer, Guice or Spring.
this.fileSystemManager = new MasterFileSystem(this, this);

// enable table descriptors cache
this.tableDescriptors.setCacheOn();

// warm-up HTDs cache on master initialization
if (preLoadTableDescriptors) {
status.setStatus("Pre-loading table descriptors");
this.tableDescriptors.getAll();
}

// publish cluster ID
status.setStatus("Publishing Cluster ID in ZooKeeper");
ZKClusterId.setClusterId(this.zooKeeper, fileSystemManager.getClusterId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,17 @@ private void handleCreateTable(TableName tableName)
ModifyRegionUtils.assignRegions(assignmentManager, regionInfos);
}

// 6. Set table enabled flag up in zk.
// 7. Set table enabled flag up in zk.
try {
assignmentManager.getTableStateManager().setTableState(tableName,
ZooKeeperProtos.Table.State.ENABLED);
} catch (CoordinatedStateException e) {
throw new IOException("Unable to ensure that " + tableName + " will be" +
" enabled because of a ZooKeeper issue", e);
}

// 8. Update the tabledescriptor cache.
((HMaster) this.server).getTableDescriptors().get(tableName);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ private void recreateTable(final List<HRegionInfo> regions) throws IOException {
CreateTableHandler.checkAndSetEnablingTable(assignmentManager, tableName);
try {
// 1. Create Table Descriptor
new FSTableDescriptors(server.getConfiguration())
.createTableDescriptorForTableDirectory(tempdir, this.hTableDescriptor, false);
Path tempTableDir = FSUtils.getTableDir(tempdir, this.tableName);
new FSTableDescriptors(server.getConfiguration())
.createTableDescriptorForTableDirectory(tempTableDir, this.hTableDescriptor, false);
Path tableDir = FSUtils.getTableDir(mfs.getRootDir(), this.tableName);

HRegionInfo[] newRegions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ public void uncaughtException(Thread t, Throwable e) {
this.fs = new HFileSystem(this.conf, useHBaseChecksum);
this.rootDir = FSUtils.getRootDir(this.conf);
this.tableDescriptors = new FSTableDescriptors(
this.fs, this.rootDir, !canUpdateTableDescriptor());
this.fs, this.rootDir, !canUpdateTableDescriptor(), false);

service = new ExecutorService(getServerName().toShortString());
spanReceiverHost = SpanReceiverHost.getInstance(getConfiguration());
Expand Down Expand Up @@ -608,7 +608,7 @@ protected HConnection createShortCircuitConnection() throws IOException {
return ConnectionUtils.createShortCircuitHConnection(
HConnectionManager.getConnection(conf), serverName, rpcServices, rpcServices);
}

/**
* Run test on configured codecs to make sure supporting libs are in place.
* @param c
Expand Down Expand Up @@ -3011,7 +3011,7 @@ private String getLastFailedRSFromZK(String encodedRegionName) throws KeeperExce
}
return result;
}

public CoprocessorServiceResponse execRegionServerService(final RpcController controller,
final CoprocessorServiceRequest serviceRequest) throws ServiceException {
try {
Expand Down Expand Up @@ -3058,7 +3058,7 @@ public void run(Message message) {
throw new ServiceException(ie);
}
}

/**
* @return The cache config instance used by the regionserver.
*/
Expand All @@ -3072,14 +3072,14 @@ public CacheConfig getCacheConfig() {
protected ConfigurationManager getConfigurationManager() {
return configurationManager;
}

/**
* Reload the configuration from disk.
*/
public void updateConfiguration() {
LOG.info("Reloading the configuration from disk.");
// Reload the configuration from disk.
conf.reloadConfiguration();
configurationManager.notifyAllObservers(conf);
configurationManager.notifyAllObservers(conf);
}
}

0 comments on commit 431b8a5

Please sign in to comment.