HBASE-3 rest server: configure number of threads for jetty
HBASE-416 Add apache-style logging to REST server and add setting log level, etc. git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@619694 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
655065bcca
commit
ea98b03b76
|
@ -27,6 +27,10 @@ Hbase Change Log
|
||||||
(Edward Yoon & Bryan Duxbury via Stack)
|
(Edward Yoon & Bryan Duxbury via Stack)
|
||||||
HBASE-56 Unnecessary HQLClient Object creation in a shell loop
|
HBASE-56 Unnecessary HQLClient Object creation in a shell loop
|
||||||
(Edward Yoon via Stack)
|
(Edward Yoon via Stack)
|
||||||
|
HBASE-3 rest server: configure number of threads for jetty
|
||||||
|
(Bryan Duxbury via Stack)
|
||||||
|
HBASE-416 Add apache-style logging to REST server and add setting log
|
||||||
|
level, etc.
|
||||||
|
|
||||||
|
|
||||||
Branch 0.1
|
Branch 0.1
|
||||||
|
|
|
@ -381,7 +381,7 @@ public class HConnectionManager implements HConstants {
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
} else{
|
} else {
|
||||||
deleteCachedLocation(tableName, row);
|
deleteCachedLocation(tableName, row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,7 +509,14 @@ public class HConnectionManager implements HConstants {
|
||||||
// if there's something in the cache for this table.
|
// if there's something in the cache for this table.
|
||||||
if (!tableLocations.isEmpty()) {
|
if (!tableLocations.isEmpty()) {
|
||||||
if (tableLocations.containsKey(row)) {
|
if (tableLocations.containsKey(row)) {
|
||||||
return tableLocations.get(row);
|
HRegionLocation rl = tableLocations.get(row);
|
||||||
|
if (rl != null && LOG.isDebugEnabled()) {
|
||||||
|
LOG.debug("Cache hit in table locations for row <" +
|
||||||
|
row + "> and tableName " + tableName +
|
||||||
|
": location server " + rl.getServerAddress() +
|
||||||
|
", location region name " + rl.getRegionInfo().getRegionName());
|
||||||
|
}
|
||||||
|
return rl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// cut the cache so that we only get the part that could contain
|
// cut the cache so that we only get the part that could contain
|
||||||
|
@ -532,6 +539,10 @@ public class HConnectionManager implements HConstants {
|
||||||
// signifying that the region we're checking is actually the last
|
// signifying that the region we're checking is actually the last
|
||||||
// region in the table.
|
// region in the table.
|
||||||
if (endKey.equals(EMPTY_TEXT) || endKey.compareTo(row) > 0) {
|
if (endKey.equals(EMPTY_TEXT) || endKey.compareTo(row) > 0) {
|
||||||
|
if (LOG.isDebugEnabled()) {
|
||||||
|
LOG.debug("Found possible location for " + row + ", " +
|
||||||
|
possibleRegion);
|
||||||
|
}
|
||||||
return possibleRegion;
|
return possibleRegion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -541,7 +552,6 @@ public class HConnectionManager implements HConstants {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a cached location, if it satisfies the table name and row
|
* Delete a cached location, if it satisfies the table name and row
|
||||||
* requirements.
|
* requirements.
|
||||||
|
@ -578,13 +588,17 @@ public class HConnectionManager implements HConstants {
|
||||||
// otherwise it wouldn't be in the headMap.
|
// otherwise it wouldn't be in the headMap.
|
||||||
if (endKey.compareTo(row) <= 0) {
|
if (endKey.compareTo(row) <= 0) {
|
||||||
// delete any matching entry
|
// delete any matching entry
|
||||||
tableLocations.remove(matchingRegions.lastKey());
|
HRegionLocation rl =
|
||||||
|
tableLocations.remove(matchingRegions.lastKey());
|
||||||
|
if (rl != null && LOG.isDebugEnabled()) {
|
||||||
|
LOG.debug("Removed " + rl.getRegionInfo().getRegionName() +
|
||||||
|
" from cache because of " + row);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put a newly discovered HRegionLocation into the cache.
|
* Put a newly discovered HRegionLocation into the cache.
|
||||||
*/
|
*/
|
||||||
|
@ -729,6 +743,9 @@ public class HConnectionManager implements HConstants {
|
||||||
// if this works, then we're good, and we have an acceptable address,
|
// if this works, then we're good, and we have an acceptable address,
|
||||||
// so we can stop doing retries and return the result.
|
// so we can stop doing retries and return the result.
|
||||||
server.getRegionInfo(HRegionInfo.rootRegionInfo.getRegionName());
|
server.getRegionInfo(HRegionInfo.rootRegionInfo.getRegionName());
|
||||||
|
if (LOG.isDebugEnabled()) {
|
||||||
|
LOG.debug("Found ROOT " + HRegionInfo.rootRegionInfo);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (tries == numRetries - 1) {
|
if (tries == numRetries - 1) {
|
||||||
|
@ -757,7 +774,7 @@ public class HConnectionManager implements HConstants {
|
||||||
rootRegionAddress = null;
|
rootRegionAddress = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the adress is null by this point, then the retries have failed,
|
// if the address is null by this point, then the retries have failed,
|
||||||
// and we're sort of sunk
|
// and we're sort of sunk
|
||||||
if (rootRegionAddress == null) {
|
if (rootRegionAddress == null) {
|
||||||
throw new NoServerForRegionException(
|
throw new NoServerForRegionException(
|
||||||
|
|
|
@ -22,13 +22,19 @@ package org.apache.hadoop.hbase.rest;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.hbase.HBaseAdmin;
|
import org.apache.hadoop.hbase.HBaseAdmin;
|
||||||
import org.apache.hadoop.hbase.HBaseConfiguration;
|
import org.apache.hadoop.hbase.HBaseConfiguration;
|
||||||
import org.apache.hadoop.hbase.util.InfoServer;
|
import org.apache.hadoop.hbase.util.InfoServer;
|
||||||
|
import org.apache.hadoop.mapred.StatusHttpServer;
|
||||||
|
import org.mortbay.http.NCSARequestLog;
|
||||||
import org.mortbay.http.SocketListener;
|
import org.mortbay.http.SocketListener;
|
||||||
|
import org.mortbay.jetty.servlet.WebApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Servlet implementation class for hbase REST interface.
|
* Servlet implementation class for hbase REST interface.
|
||||||
|
@ -54,6 +60,7 @@ import org.mortbay.http.SocketListener;
|
||||||
*/
|
*/
|
||||||
public class Dispatcher extends javax.servlet.http.HttpServlet
|
public class Dispatcher extends javax.servlet.http.HttpServlet
|
||||||
implements javax.servlet.Servlet {
|
implements javax.servlet.Servlet {
|
||||||
|
private static final Log LOG = LogFactory.getLog(Dispatcher.class.getName());
|
||||||
private MetaHandler metaHandler;
|
private MetaHandler metaHandler;
|
||||||
private TableHandler tableHandler;
|
private TableHandler tableHandler;
|
||||||
private ScannerHandler scannerHandler;
|
private ScannerHandler scannerHandler;
|
||||||
|
@ -179,7 +186,9 @@ implements javax.servlet.Servlet {
|
||||||
System.out.println("Options:");
|
System.out.println("Options:");
|
||||||
System.out.println(" port Port to listen on. Default: 60050.");
|
System.out.println(" port Port to listen on. Default: 60050.");
|
||||||
System.out.println(" bind Address to bind on. Default: 0.0.0.0.");
|
System.out.println(" bind Address to bind on. Default: 0.0.0.0.");
|
||||||
|
System.out.println(" max-num-threads The maximum number of threads for Jetty to run. Defaults to 256.");
|
||||||
System.out.println(" help Print this message and exit.");
|
System.out.println(" help Print this message and exit.");
|
||||||
|
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,11 +203,13 @@ implements javax.servlet.Servlet {
|
||||||
|
|
||||||
int port = 60050;
|
int port = 60050;
|
||||||
String bindAddress = "0.0.0.0";
|
String bindAddress = "0.0.0.0";
|
||||||
|
int numThreads = 256;
|
||||||
|
|
||||||
// Process command-line args. TODO: Better cmd-line processing
|
// Process command-line args. TODO: Better cmd-line processing
|
||||||
// (but hopefully something not as painful as cli options).
|
// (but hopefully something not as painful as cli options).
|
||||||
final String addressArgKey = "--bind=";
|
final String addressArgKey = "--bind=";
|
||||||
final String portArgKey = "--port=";
|
final String portArgKey = "--port=";
|
||||||
|
final String numThreadsKey = "--max-num-threads=";
|
||||||
for (String cmd: args) {
|
for (String cmd: args) {
|
||||||
if (cmd.startsWith(addressArgKey)) {
|
if (cmd.startsWith(addressArgKey)) {
|
||||||
bindAddress = cmd.substring(addressArgKey.length());
|
bindAddress = cmd.substring(addressArgKey.length());
|
||||||
|
@ -214,18 +225,29 @@ implements javax.servlet.Servlet {
|
||||||
printUsageAndExit("To shutdown the REST server run " +
|
printUsageAndExit("To shutdown the REST server run " +
|
||||||
"bin/hbase-daemon.sh stop rest or send a kill signal to " +
|
"bin/hbase-daemon.sh stop rest or send a kill signal to " +
|
||||||
"the REST server pid");
|
"the REST server pid");
|
||||||
|
} else if (cmd.startsWith(numThreadsKey)) {
|
||||||
|
numThreads = Integer.parseInt(cmd.substring(numThreadsKey.length()));
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print out usage if we get to here.
|
// Print out usage if we get to here.
|
||||||
printUsageAndExit();
|
printUsageAndExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
org.mortbay.jetty.Server webServer = new org.mortbay.jetty.Server();
|
org.mortbay.jetty.Server webServer = new org.mortbay.jetty.Server();
|
||||||
SocketListener listener = new SocketListener();
|
SocketListener listener = new SocketListener();
|
||||||
listener.setPort(port);
|
listener.setPort(port);
|
||||||
listener.setHost(bindAddress);
|
listener.setHost(bindAddress);
|
||||||
|
listener.setMaxThreads(numThreads);
|
||||||
webServer.addListener(listener);
|
webServer.addListener(listener);
|
||||||
webServer.addWebApplication("/api", InfoServer.getWebAppDir("rest"));
|
NCSARequestLog ncsa = new NCSARequestLog();
|
||||||
|
ncsa.setLogLatency(true);
|
||||||
|
webServer.setRequestLog(ncsa);
|
||||||
|
WebApplicationContext context =
|
||||||
|
webServer.addWebApplication("/api", InfoServer.getWebAppDir("rest"));
|
||||||
|
context.addServlet("stacks", "/stacks",
|
||||||
|
StatusHttpServer.StackServlet.class.getName());
|
||||||
|
context.addServlet("logLevel", "/logLevel",
|
||||||
|
org.apache.hadoop.log.LogLevel.Servlet.class.getName());
|
||||||
webServer.start();
|
webServer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue