hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [06/51] [partial] hbase-site git commit: Published site at .
Date Tue, 26 Sep 2017 15:14:03 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/8e4e1542/devapidocs/src-html/org/apache/hadoop/hbase/thrift2/ThriftServer.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/thrift2/ThriftServer.html b/devapidocs/src-html/org/apache/hadoop/hbase/thrift2/ThriftServer.html
index 4f406f8..11d4572 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/thrift2/ThriftServer.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/thrift2/ThriftServer.html
@@ -164,454 +164,464 @@
 <span class="sourceLineNo">156</span>      "Amount of time in milliseconds before a server thread will timeout " +<a name="line.156"></a>
 <span class="sourceLineNo">157</span>      "waiting for client to send data on a connected socket. Currently, " +<a name="line.157"></a>
 <span class="sourceLineNo">158</span>      "only applies to TBoundedThreadPoolServer");<a name="line.158"></a>
-<span class="sourceLineNo">159</span>    OptionGroup servers = new OptionGroup();<a name="line.159"></a>
-<span class="sourceLineNo">160</span>    servers.addOption(<a name="line.160"></a>
-<span class="sourceLineNo">161</span>        new Option("nonblocking", false, "Use the TNonblockingServer. This implies the framed transport."));<a name="line.161"></a>
-<span class="sourceLineNo">162</span>    servers.addOption(new Option("hsha", false, "Use the THsHaServer. This implies the framed transport."));<a name="line.162"></a>
-<span class="sourceLineNo">163</span>    servers.addOption(new Option("selector", false, "Use the TThreadedSelectorServer. This implies the framed transport."));<a name="line.163"></a>
-<span class="sourceLineNo">164</span>    servers.addOption(new Option("threadpool", false, "Use the TThreadPoolServer. This is the default."));<a name="line.164"></a>
-<span class="sourceLineNo">165</span>    options.addOptionGroup(servers);<a name="line.165"></a>
-<span class="sourceLineNo">166</span>    return options;<a name="line.166"></a>
-<span class="sourceLineNo">167</span>  }<a name="line.167"></a>
-<span class="sourceLineNo">168</span><a name="line.168"></a>
-<span class="sourceLineNo">169</span>  private static CommandLine parseArguments(Configuration conf, Options options, String[] args)<a name="line.169"></a>
-<span class="sourceLineNo">170</span>      throws ParseException, IOException {<a name="line.170"></a>
-<span class="sourceLineNo">171</span>    CommandLineParser parser = new PosixParser();<a name="line.171"></a>
-<span class="sourceLineNo">172</span>    return parser.parse(options, args);<a name="line.172"></a>
-<span class="sourceLineNo">173</span>  }<a name="line.173"></a>
-<span class="sourceLineNo">174</span><a name="line.174"></a>
-<span class="sourceLineNo">175</span>  private static TProtocolFactory getTProtocolFactory(boolean isCompact) {<a name="line.175"></a>
-<span class="sourceLineNo">176</span>    if (isCompact) {<a name="line.176"></a>
-<span class="sourceLineNo">177</span>      log.debug("Using compact protocol");<a name="line.177"></a>
-<span class="sourceLineNo">178</span>      return new TCompactProtocol.Factory();<a name="line.178"></a>
-<span class="sourceLineNo">179</span>    } else {<a name="line.179"></a>
-<span class="sourceLineNo">180</span>      log.debug("Using binary protocol");<a name="line.180"></a>
-<span class="sourceLineNo">181</span>      return new TBinaryProtocol.Factory();<a name="line.181"></a>
-<span class="sourceLineNo">182</span>    }<a name="line.182"></a>
-<span class="sourceLineNo">183</span>  }<a name="line.183"></a>
-<span class="sourceLineNo">184</span><a name="line.184"></a>
-<span class="sourceLineNo">185</span>  private static TTransportFactory getTTransportFactory(<a name="line.185"></a>
-<span class="sourceLineNo">186</span>      SaslUtil.QualityOfProtection qop, String name, String host,<a name="line.186"></a>
-<span class="sourceLineNo">187</span>      boolean framed, int frameSize) {<a name="line.187"></a>
-<span class="sourceLineNo">188</span>    if (framed) {<a name="line.188"></a>
-<span class="sourceLineNo">189</span>      if (qop != null) {<a name="line.189"></a>
-<span class="sourceLineNo">190</span>        throw new RuntimeException("Thrift server authentication"<a name="line.190"></a>
-<span class="sourceLineNo">191</span>          + " doesn't work with framed transport yet");<a name="line.191"></a>
-<span class="sourceLineNo">192</span>      }<a name="line.192"></a>
-<span class="sourceLineNo">193</span>      log.debug("Using framed transport");<a name="line.193"></a>
-<span class="sourceLineNo">194</span>      return new TFramedTransport.Factory(frameSize);<a name="line.194"></a>
-<span class="sourceLineNo">195</span>    } else if (qop == null) {<a name="line.195"></a>
-<span class="sourceLineNo">196</span>      return new TTransportFactory();<a name="line.196"></a>
-<span class="sourceLineNo">197</span>    } else {<a name="line.197"></a>
-<span class="sourceLineNo">198</span>      Map&lt;String, String&gt; saslProperties = new HashMap&lt;&gt;();<a name="line.198"></a>
-<span class="sourceLineNo">199</span>      saslProperties.put(Sasl.QOP, qop.getSaslQop());<a name="line.199"></a>
-<span class="sourceLineNo">200</span>      TSaslServerTransport.Factory saslFactory = new TSaslServerTransport.Factory();<a name="line.200"></a>
-<span class="sourceLineNo">201</span>      saslFactory.addServerDefinition("GSSAPI", name, host, saslProperties,<a name="line.201"></a>
-<span class="sourceLineNo">202</span>        new SaslGssCallbackHandler() {<a name="line.202"></a>
-<span class="sourceLineNo">203</span>          @Override<a name="line.203"></a>
-<span class="sourceLineNo">204</span>          public void handle(Callback[] callbacks)<a name="line.204"></a>
-<span class="sourceLineNo">205</span>              throws UnsupportedCallbackException {<a name="line.205"></a>
-<span class="sourceLineNo">206</span>            AuthorizeCallback ac = null;<a name="line.206"></a>
-<span class="sourceLineNo">207</span>            for (Callback callback : callbacks) {<a name="line.207"></a>
-<span class="sourceLineNo">208</span>              if (callback instanceof AuthorizeCallback) {<a name="line.208"></a>
-<span class="sourceLineNo">209</span>                ac = (AuthorizeCallback) callback;<a name="line.209"></a>
-<span class="sourceLineNo">210</span>              } else {<a name="line.210"></a>
-<span class="sourceLineNo">211</span>                throw new UnsupportedCallbackException(callback,<a name="line.211"></a>
-<span class="sourceLineNo">212</span>                    "Unrecognized SASL GSSAPI Callback");<a name="line.212"></a>
-<span class="sourceLineNo">213</span>              }<a name="line.213"></a>
-<span class="sourceLineNo">214</span>            }<a name="line.214"></a>
-<span class="sourceLineNo">215</span>            if (ac != null) {<a name="line.215"></a>
-<span class="sourceLineNo">216</span>              String authid = ac.getAuthenticationID();<a name="line.216"></a>
-<span class="sourceLineNo">217</span>              String authzid = ac.getAuthorizationID();<a name="line.217"></a>
-<span class="sourceLineNo">218</span>              if (!authid.equals(authzid)) {<a name="line.218"></a>
-<span class="sourceLineNo">219</span>                ac.setAuthorized(false);<a name="line.219"></a>
-<span class="sourceLineNo">220</span>              } else {<a name="line.220"></a>
-<span class="sourceLineNo">221</span>                ac.setAuthorized(true);<a name="line.221"></a>
-<span class="sourceLineNo">222</span>                String userName = SecurityUtil.getUserFromPrincipal(authzid);<a name="line.222"></a>
-<span class="sourceLineNo">223</span>                log.info("Effective user: " + userName);<a name="line.223"></a>
-<span class="sourceLineNo">224</span>                ac.setAuthorizedID(userName);<a name="line.224"></a>
-<span class="sourceLineNo">225</span>              }<a name="line.225"></a>
-<span class="sourceLineNo">226</span>            }<a name="line.226"></a>
-<span class="sourceLineNo">227</span>          }<a name="line.227"></a>
-<span class="sourceLineNo">228</span>        });<a name="line.228"></a>
-<span class="sourceLineNo">229</span>      return saslFactory;<a name="line.229"></a>
-<span class="sourceLineNo">230</span>    }<a name="line.230"></a>
-<span class="sourceLineNo">231</span>  }<a name="line.231"></a>
-<span class="sourceLineNo">232</span><a name="line.232"></a>
-<span class="sourceLineNo">233</span>  /*<a name="line.233"></a>
-<span class="sourceLineNo">234</span>   * If bindValue is null, we don't bind.<a name="line.234"></a>
-<span class="sourceLineNo">235</span>   */<a name="line.235"></a>
-<span class="sourceLineNo">236</span>  private static InetSocketAddress bindToPort(String bindValue, int listenPort)<a name="line.236"></a>
-<span class="sourceLineNo">237</span>      throws UnknownHostException {<a name="line.237"></a>
-<span class="sourceLineNo">238</span>    try {<a name="line.238"></a>
-<span class="sourceLineNo">239</span>      if (bindValue == null) {<a name="line.239"></a>
-<span class="sourceLineNo">240</span>        return new InetSocketAddress(listenPort);<a name="line.240"></a>
-<span class="sourceLineNo">241</span>      } else {<a name="line.241"></a>
-<span class="sourceLineNo">242</span>        return new InetSocketAddress(InetAddress.getByName(bindValue), listenPort);<a name="line.242"></a>
-<span class="sourceLineNo">243</span>      }<a name="line.243"></a>
-<span class="sourceLineNo">244</span>    } catch (UnknownHostException e) {<a name="line.244"></a>
-<span class="sourceLineNo">245</span>      throw new RuntimeException("Could not bind to provided ip address", e);<a name="line.245"></a>
-<span class="sourceLineNo">246</span>    }<a name="line.246"></a>
-<span class="sourceLineNo">247</span>  }<a name="line.247"></a>
-<span class="sourceLineNo">248</span><a name="line.248"></a>
-<span class="sourceLineNo">249</span>  private static TServer getTNonBlockingServer(TProtocolFactory protocolFactory, TProcessor processor,<a name="line.249"></a>
-<span class="sourceLineNo">250</span>      TTransportFactory transportFactory, InetSocketAddress inetSocketAddress) throws TTransportException {<a name="line.250"></a>
-<span class="sourceLineNo">251</span>    TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(inetSocketAddress);<a name="line.251"></a>
-<span class="sourceLineNo">252</span>    log.info("starting HBase Nonblocking Thrift server on " + inetSocketAddress.toString());<a name="line.252"></a>
-<span class="sourceLineNo">253</span>    TNonblockingServer.Args serverArgs = new TNonblockingServer.Args(serverTransport);<a name="line.253"></a>
-<span class="sourceLineNo">254</span>    serverArgs.processor(processor);<a name="line.254"></a>
-<span class="sourceLineNo">255</span>    serverArgs.transportFactory(transportFactory);<a name="line.255"></a>
-<span class="sourceLineNo">256</span>    serverArgs.protocolFactory(protocolFactory);<a name="line.256"></a>
-<span class="sourceLineNo">257</span>    return new TNonblockingServer(serverArgs);<a name="line.257"></a>
-<span class="sourceLineNo">258</span>  }<a name="line.258"></a>
-<span class="sourceLineNo">259</span><a name="line.259"></a>
-<span class="sourceLineNo">260</span>  private static TServer getTHsHaServer(TProtocolFactory protocolFactory,<a name="line.260"></a>
-<span class="sourceLineNo">261</span>      TProcessor processor, TTransportFactory transportFactory,<a name="line.261"></a>
-<span class="sourceLineNo">262</span>      int workerThreads, int maxCallQueueSize,<a name="line.262"></a>
-<span class="sourceLineNo">263</span>      InetSocketAddress inetSocketAddress, ThriftMetrics metrics)<a name="line.263"></a>
-<span class="sourceLineNo">264</span>      throws TTransportException {<a name="line.264"></a>
-<span class="sourceLineNo">265</span>    TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(inetSocketAddress);<a name="line.265"></a>
-<span class="sourceLineNo">266</span>    log.info("starting HBase HsHA Thrift server on " + inetSocketAddress.toString());<a name="line.266"></a>
-<span class="sourceLineNo">267</span>    THsHaServer.Args serverArgs = new THsHaServer.Args(serverTransport);<a name="line.267"></a>
-<span class="sourceLineNo">268</span>    if (workerThreads &gt; 0) {<a name="line.268"></a>
-<span class="sourceLineNo">269</span>      // Could support the min &amp; max threads, avoiding to preserve existing functionality.<a name="line.269"></a>
-<span class="sourceLineNo">270</span>      serverArgs.minWorkerThreads(workerThreads).maxWorkerThreads(workerThreads);<a name="line.270"></a>
-<span class="sourceLineNo">271</span>    }<a name="line.271"></a>
-<span class="sourceLineNo">272</span>    ExecutorService executorService = createExecutor(<a name="line.272"></a>
-<span class="sourceLineNo">273</span>        workerThreads, maxCallQueueSize, metrics);<a name="line.273"></a>
-<span class="sourceLineNo">274</span>    serverArgs.executorService(executorService);<a name="line.274"></a>
-<span class="sourceLineNo">275</span>    serverArgs.processor(processor);<a name="line.275"></a>
-<span class="sourceLineNo">276</span>    serverArgs.transportFactory(transportFactory);<a name="line.276"></a>
-<span class="sourceLineNo">277</span>    serverArgs.protocolFactory(protocolFactory);<a name="line.277"></a>
-<span class="sourceLineNo">278</span>    return new THsHaServer(serverArgs);<a name="line.278"></a>
-<span class="sourceLineNo">279</span>  }<a name="line.279"></a>
-<span class="sourceLineNo">280</span><a name="line.280"></a>
-<span class="sourceLineNo">281</span>  private static TServer getTThreadedSelectorServer(TProtocolFactory protocolFactory,<a name="line.281"></a>
-<span class="sourceLineNo">282</span>      TProcessor processor, TTransportFactory transportFactory,<a name="line.282"></a>
-<span class="sourceLineNo">283</span>      int workerThreads, int selectorThreads, int maxCallQueueSize,<a name="line.283"></a>
-<span class="sourceLineNo">284</span>      InetSocketAddress inetSocketAddress, ThriftMetrics metrics)<a name="line.284"></a>
-<span class="sourceLineNo">285</span>      throws TTransportException {<a name="line.285"></a>
-<span class="sourceLineNo">286</span>    TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(inetSocketAddress);<a name="line.286"></a>
-<span class="sourceLineNo">287</span>    log.info("starting HBase ThreadedSelector Thrift server on " + inetSocketAddress.toString());<a name="line.287"></a>
-<span class="sourceLineNo">288</span>    TThreadedSelectorServer.Args serverArgs = new TThreadedSelectorServer.Args(serverTransport);<a name="line.288"></a>
-<span class="sourceLineNo">289</span>    if (workerThreads &gt; 0) {<a name="line.289"></a>
-<span class="sourceLineNo">290</span>        serverArgs.workerThreads(workerThreads);<a name="line.290"></a>
-<span class="sourceLineNo">291</span>    }<a name="line.291"></a>
-<span class="sourceLineNo">292</span>    if (selectorThreads &gt; 0) {<a name="line.292"></a>
-<span class="sourceLineNo">293</span>        serverArgs.selectorThreads(selectorThreads);<a name="line.293"></a>
-<span class="sourceLineNo">294</span>    }<a name="line.294"></a>
-<span class="sourceLineNo">295</span><a name="line.295"></a>
-<span class="sourceLineNo">296</span>    ExecutorService executorService = createExecutor(<a name="line.296"></a>
-<span class="sourceLineNo">297</span>        workerThreads, maxCallQueueSize, metrics);<a name="line.297"></a>
-<span class="sourceLineNo">298</span>    serverArgs.executorService(executorService);<a name="line.298"></a>
-<span class="sourceLineNo">299</span>    serverArgs.processor(processor);<a name="line.299"></a>
-<span class="sourceLineNo">300</span>    serverArgs.transportFactory(transportFactory);<a name="line.300"></a>
-<span class="sourceLineNo">301</span>    serverArgs.protocolFactory(protocolFactory);<a name="line.301"></a>
-<span class="sourceLineNo">302</span>    return new TThreadedSelectorServer(serverArgs);<a name="line.302"></a>
-<span class="sourceLineNo">303</span>  }<a name="line.303"></a>
-<span class="sourceLineNo">304</span><a name="line.304"></a>
-<span class="sourceLineNo">305</span>  private static ExecutorService createExecutor(<a name="line.305"></a>
-<span class="sourceLineNo">306</span>      int workerThreads, int maxCallQueueSize, ThriftMetrics metrics) {<a name="line.306"></a>
-<span class="sourceLineNo">307</span>    CallQueue callQueue;<a name="line.307"></a>
-<span class="sourceLineNo">308</span>    if (maxCallQueueSize &gt; 0) {<a name="line.308"></a>
-<span class="sourceLineNo">309</span>      callQueue = new CallQueue(new LinkedBlockingQueue&lt;&gt;(maxCallQueueSize), metrics);<a name="line.309"></a>
-<span class="sourceLineNo">310</span>    } else {<a name="line.310"></a>
-<span class="sourceLineNo">311</span>      callQueue = new CallQueue(new LinkedBlockingQueue&lt;&gt;(), metrics);<a name="line.311"></a>
-<span class="sourceLineNo">312</span>    }<a name="line.312"></a>
-<span class="sourceLineNo">313</span><a name="line.313"></a>
-<span class="sourceLineNo">314</span>    ThreadFactoryBuilder tfb = new ThreadFactoryBuilder();<a name="line.314"></a>
-<span class="sourceLineNo">315</span>    tfb.setDaemon(true);<a name="line.315"></a>
-<span class="sourceLineNo">316</span>    tfb.setNameFormat("thrift2-worker-%d");<a name="line.316"></a>
-<span class="sourceLineNo">317</span>    ThreadPoolExecutor pool = new THBaseThreadPoolExecutor(workerThreads, workerThreads,<a name="line.317"></a>
-<span class="sourceLineNo">318</span>            Long.MAX_VALUE, TimeUnit.SECONDS, callQueue, tfb.build(), metrics);<a name="line.318"></a>
-<span class="sourceLineNo">319</span>    pool.prestartAllCoreThreads();<a name="line.319"></a>
-<span class="sourceLineNo">320</span>    return pool;<a name="line.320"></a>
-<span class="sourceLineNo">321</span>  }<a name="line.321"></a>
-<span class="sourceLineNo">322</span><a name="line.322"></a>
-<span class="sourceLineNo">323</span>  private static TServer getTThreadPoolServer(TProtocolFactory protocolFactory,<a name="line.323"></a>
-<span class="sourceLineNo">324</span>                                              TProcessor processor,<a name="line.324"></a>
-<span class="sourceLineNo">325</span>                                              TTransportFactory transportFactory,<a name="line.325"></a>
-<span class="sourceLineNo">326</span>                                              int workerThreads,<a name="line.326"></a>
-<span class="sourceLineNo">327</span>                                              InetSocketAddress inetSocketAddress,<a name="line.327"></a>
-<span class="sourceLineNo">328</span>                                              int backlog,<a name="line.328"></a>
-<span class="sourceLineNo">329</span>                                              int clientTimeout,<a name="line.329"></a>
-<span class="sourceLineNo">330</span>                                              ThriftMetrics metrics)<a name="line.330"></a>
-<span class="sourceLineNo">331</span>      throws TTransportException {<a name="line.331"></a>
-<span class="sourceLineNo">332</span>    TServerTransport serverTransport = new TServerSocket(<a name="line.332"></a>
-<span class="sourceLineNo">333</span>                                           new TServerSocket.ServerSocketTransportArgs().<a name="line.333"></a>
-<span class="sourceLineNo">334</span>                                               bindAddr(inetSocketAddress).backlog(backlog).<a name="line.334"></a>
-<span class="sourceLineNo">335</span>                                               clientTimeout(clientTimeout));<a name="line.335"></a>
-<span class="sourceLineNo">336</span>    log.info("starting HBase ThreadPool Thrift server on " + inetSocketAddress.toString());<a name="line.336"></a>
-<span class="sourceLineNo">337</span>    TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport);<a name="line.337"></a>
-<span class="sourceLineNo">338</span>    serverArgs.processor(processor);<a name="line.338"></a>
-<span class="sourceLineNo">339</span>    serverArgs.transportFactory(transportFactory);<a name="line.339"></a>
-<span class="sourceLineNo">340</span>    serverArgs.protocolFactory(protocolFactory);<a name="line.340"></a>
-<span class="sourceLineNo">341</span>    if (workerThreads &gt; 0) {<a name="line.341"></a>
-<span class="sourceLineNo">342</span>      serverArgs.maxWorkerThreads(workerThreads);<a name="line.342"></a>
-<span class="sourceLineNo">343</span>    }<a name="line.343"></a>
-<span class="sourceLineNo">344</span>    ThreadPoolExecutor executor = new THBaseThreadPoolExecutor(serverArgs.minWorkerThreads,<a name="line.344"></a>
-<span class="sourceLineNo">345</span>        serverArgs.maxWorkerThreads, serverArgs.stopTimeoutVal, TimeUnit.SECONDS,<a name="line.345"></a>
-<span class="sourceLineNo">346</span>        new SynchronousQueue&lt;&gt;(), metrics);<a name="line.346"></a>
-<span class="sourceLineNo">347</span>    serverArgs.executorService(executor);<a name="line.347"></a>
-<span class="sourceLineNo">348</span><a name="line.348"></a>
-<span class="sourceLineNo">349</span>    return new TThreadPoolServer(serverArgs);<a name="line.349"></a>
-<span class="sourceLineNo">350</span>  }<a name="line.350"></a>
-<span class="sourceLineNo">351</span><a name="line.351"></a>
-<span class="sourceLineNo">352</span>  /**<a name="line.352"></a>
-<span class="sourceLineNo">353</span>   * Adds the option to pre-load filters at startup.<a name="line.353"></a>
-<span class="sourceLineNo">354</span>   *<a name="line.354"></a>
-<span class="sourceLineNo">355</span>   * @param conf  The current configuration instance.<a name="line.355"></a>
-<span class="sourceLineNo">356</span>   */<a name="line.356"></a>
-<span class="sourceLineNo">357</span>  protected static void registerFilters(Configuration conf) {<a name="line.357"></a>
-<span class="sourceLineNo">358</span>    String[] filters = conf.getStrings("hbase.thrift.filters");<a name="line.358"></a>
-<span class="sourceLineNo">359</span>    if(filters != null) {<a name="line.359"></a>
-<span class="sourceLineNo">360</span>      for(String filterClass: filters) {<a name="line.360"></a>
-<span class="sourceLineNo">361</span>        String[] filterPart = filterClass.split(":");<a name="line.361"></a>
-<span class="sourceLineNo">362</span>        if(filterPart.length != 2) {<a name="line.362"></a>
-<span class="sourceLineNo">363</span>          log.warn("Invalid filter specification " + filterClass + " - skipping");<a name="line.363"></a>
-<span class="sourceLineNo">364</span>        } else {<a name="line.364"></a>
-<span class="sourceLineNo">365</span>          ParseFilter.registerFilter(filterPart[0], filterPart[1]);<a name="line.365"></a>
-<span class="sourceLineNo">366</span>        }<a name="line.366"></a>
-<span class="sourceLineNo">367</span>      }<a name="line.367"></a>
-<span class="sourceLineNo">368</span>    }<a name="line.368"></a>
-<span class="sourceLineNo">369</span>  }<a name="line.369"></a>
-<span class="sourceLineNo">370</span><a name="line.370"></a>
-<span class="sourceLineNo">371</span>  /**<a name="line.371"></a>
-<span class="sourceLineNo">372</span>   * Start up the Thrift2 server.<a name="line.372"></a>
-<span class="sourceLineNo">373</span>   */<a name="line.373"></a>
-<span class="sourceLineNo">374</span>  public static void main(String[] args) throws Exception {<a name="line.374"></a>
-<span class="sourceLineNo">375</span>    final Configuration conf = HBaseConfiguration.create();<a name="line.375"></a>
-<span class="sourceLineNo">376</span>    // for now, only time we return is on an argument error.<a name="line.376"></a>
-<span class="sourceLineNo">377</span>    final int status = ToolRunner.run(conf, new ThriftServer(), args);<a name="line.377"></a>
-<span class="sourceLineNo">378</span>    System.exit(status);<a name="line.378"></a>
-<span class="sourceLineNo">379</span>  }<a name="line.379"></a>
-<span class="sourceLineNo">380</span><a name="line.380"></a>
-<span class="sourceLineNo">381</span>  @Override<a name="line.381"></a>
-<span class="sourceLineNo">382</span>  public int run(String[] args) throws Exception {<a name="line.382"></a>
-<span class="sourceLineNo">383</span>    final Configuration conf = getConf();<a name="line.383"></a>
-<span class="sourceLineNo">384</span>    TServer server = null;<a name="line.384"></a>
-<span class="sourceLineNo">385</span>    Options options = getOptions();<a name="line.385"></a>
-<span class="sourceLineNo">386</span>    CommandLine cmd = parseArguments(conf, options, args);<a name="line.386"></a>
-<span class="sourceLineNo">387</span>    int workerThreads = 0;<a name="line.387"></a>
-<span class="sourceLineNo">388</span>    int selectorThreads = 0;<a name="line.388"></a>
-<span class="sourceLineNo">389</span>    int maxCallQueueSize = -1; // use unbounded queue by default<a name="line.389"></a>
-<span class="sourceLineNo">390</span><a name="line.390"></a>
-<span class="sourceLineNo">391</span>    /**<a name="line.391"></a>
-<span class="sourceLineNo">392</span>     * This is to please both bin/hbase and bin/hbase-daemon. hbase-daemon provides "start" and "stop" arguments hbase<a name="line.392"></a>
-<span class="sourceLineNo">393</span>     * should print the help if no argument is provided<a name="line.393"></a>
-<span class="sourceLineNo">394</span>     */<a name="line.394"></a>
-<span class="sourceLineNo">395</span>    List&lt;?&gt; argList = cmd.getArgList();<a name="line.395"></a>
-<span class="sourceLineNo">396</span>    if (cmd.hasOption("help") || !argList.contains("start") || argList.contains("stop")) {<a name="line.396"></a>
-<span class="sourceLineNo">397</span>      printUsage();<a name="line.397"></a>
-<span class="sourceLineNo">398</span>      return 1;<a name="line.398"></a>
-<span class="sourceLineNo">399</span>    }<a name="line.399"></a>
-<span class="sourceLineNo">400</span><a name="line.400"></a>
-<span class="sourceLineNo">401</span>    // Get address to bind<a name="line.401"></a>
-<span class="sourceLineNo">402</span>    String bindAddress;<a name="line.402"></a>
-<span class="sourceLineNo">403</span>    if (cmd.hasOption("bind")) {<a name="line.403"></a>
-<span class="sourceLineNo">404</span>      bindAddress = cmd.getOptionValue("bind");<a name="line.404"></a>
-<span class="sourceLineNo">405</span>      conf.set("hbase.thrift.info.bindAddress", bindAddress);<a name="line.405"></a>
-<span class="sourceLineNo">406</span>    } else {<a name="line.406"></a>
-<span class="sourceLineNo">407</span>      bindAddress = conf.get("hbase.thrift.info.bindAddress");<a name="line.407"></a>
-<span class="sourceLineNo">408</span>    }<a name="line.408"></a>
-<span class="sourceLineNo">409</span><a name="line.409"></a>
-<span class="sourceLineNo">410</span>    // Get read timeout<a name="line.410"></a>
-<span class="sourceLineNo">411</span>    int readTimeout = THRIFT_SERVER_SOCKET_READ_TIMEOUT_DEFAULT;<a name="line.411"></a>
-<span class="sourceLineNo">412</span>    if (cmd.hasOption(READ_TIMEOUT_OPTION)) {<a name="line.412"></a>
-<span class="sourceLineNo">413</span>      try {<a name="line.413"></a>
-<span class="sourceLineNo">414</span>        readTimeout = Integer.parseInt(cmd.getOptionValue(READ_TIMEOUT_OPTION));<a name="line.414"></a>
-<span class="sourceLineNo">415</span>      } catch (NumberFormatException e) {<a name="line.415"></a>
-<span class="sourceLineNo">416</span>        throw new RuntimeException("Could not parse the value provided for the timeout option", e);<a name="line.416"></a>
+<span class="sourceLineNo">159</span>    options.addOption("ro", "readonly", false,<a name="line.159"></a>
+<span class="sourceLineNo">160</span>      "Respond only to read method requests [default: false]");<a name="line.160"></a>
+<span class="sourceLineNo">161</span>    OptionGroup servers = new OptionGroup();<a name="line.161"></a>
+<span class="sourceLineNo">162</span>    servers.addOption(<a name="line.162"></a>
+<span class="sourceLineNo">163</span>        new Option("nonblocking", false, "Use the TNonblockingServer. This implies the framed transport."));<a name="line.163"></a>
+<span class="sourceLineNo">164</span>    servers.addOption(new Option("hsha", false, "Use the THsHaServer. This implies the framed transport."));<a name="line.164"></a>
+<span class="sourceLineNo">165</span>    servers.addOption(new Option("selector", false, "Use the TThreadedSelectorServer. This implies the framed transport."));<a name="line.165"></a>
+<span class="sourceLineNo">166</span>    servers.addOption(new Option("threadpool", false, "Use the TThreadPoolServer. This is the default."));<a name="line.166"></a>
+<span class="sourceLineNo">167</span>    options.addOptionGroup(servers);<a name="line.167"></a>
+<span class="sourceLineNo">168</span>    return options;<a name="line.168"></a>
+<span class="sourceLineNo">169</span>  }<a name="line.169"></a>
+<span class="sourceLineNo">170</span><a name="line.170"></a>
+<span class="sourceLineNo">171</span>  private static CommandLine parseArguments(Configuration conf, Options options, String[] args)<a name="line.171"></a>
+<span class="sourceLineNo">172</span>      throws ParseException, IOException {<a name="line.172"></a>
+<span class="sourceLineNo">173</span>    CommandLineParser parser = new PosixParser();<a name="line.173"></a>
+<span class="sourceLineNo">174</span>    return parser.parse(options, args);<a name="line.174"></a>
+<span class="sourceLineNo">175</span>  }<a name="line.175"></a>
+<span class="sourceLineNo">176</span><a name="line.176"></a>
+<span class="sourceLineNo">177</span>  private static TProtocolFactory getTProtocolFactory(boolean isCompact) {<a name="line.177"></a>
+<span class="sourceLineNo">178</span>    if (isCompact) {<a name="line.178"></a>
+<span class="sourceLineNo">179</span>      log.debug("Using compact protocol");<a name="line.179"></a>
+<span class="sourceLineNo">180</span>      return new TCompactProtocol.Factory();<a name="line.180"></a>
+<span class="sourceLineNo">181</span>    } else {<a name="line.181"></a>
+<span class="sourceLineNo">182</span>      log.debug("Using binary protocol");<a name="line.182"></a>
+<span class="sourceLineNo">183</span>      return new TBinaryProtocol.Factory();<a name="line.183"></a>
+<span class="sourceLineNo">184</span>    }<a name="line.184"></a>
+<span class="sourceLineNo">185</span>  }<a name="line.185"></a>
+<span class="sourceLineNo">186</span><a name="line.186"></a>
+<span class="sourceLineNo">187</span>  private static TTransportFactory getTTransportFactory(<a name="line.187"></a>
+<span class="sourceLineNo">188</span>      SaslUtil.QualityOfProtection qop, String name, String host,<a name="line.188"></a>
+<span class="sourceLineNo">189</span>      boolean framed, int frameSize) {<a name="line.189"></a>
+<span class="sourceLineNo">190</span>    if (framed) {<a name="line.190"></a>
+<span class="sourceLineNo">191</span>      if (qop != null) {<a name="line.191"></a>
+<span class="sourceLineNo">192</span>        throw new RuntimeException("Thrift server authentication"<a name="line.192"></a>
+<span class="sourceLineNo">193</span>          + " doesn't work with framed transport yet");<a name="line.193"></a>
+<span class="sourceLineNo">194</span>      }<a name="line.194"></a>
+<span class="sourceLineNo">195</span>      log.debug("Using framed transport");<a name="line.195"></a>
+<span class="sourceLineNo">196</span>      return new TFramedTransport.Factory(frameSize);<a name="line.196"></a>
+<span class="sourceLineNo">197</span>    } else if (qop == null) {<a name="line.197"></a>
+<span class="sourceLineNo">198</span>      return new TTransportFactory();<a name="line.198"></a>
+<span class="sourceLineNo">199</span>    } else {<a name="line.199"></a>
+<span class="sourceLineNo">200</span>      Map&lt;String, String&gt; saslProperties = new HashMap&lt;&gt;();<a name="line.200"></a>
+<span class="sourceLineNo">201</span>      saslProperties.put(Sasl.QOP, qop.getSaslQop());<a name="line.201"></a>
+<span class="sourceLineNo">202</span>      TSaslServerTransport.Factory saslFactory = new TSaslServerTransport.Factory();<a name="line.202"></a>
+<span class="sourceLineNo">203</span>      saslFactory.addServerDefinition("GSSAPI", name, host, saslProperties,<a name="line.203"></a>
+<span class="sourceLineNo">204</span>        new SaslGssCallbackHandler() {<a name="line.204"></a>
+<span class="sourceLineNo">205</span>          @Override<a name="line.205"></a>
+<span class="sourceLineNo">206</span>          public void handle(Callback[] callbacks)<a name="line.206"></a>
+<span class="sourceLineNo">207</span>              throws UnsupportedCallbackException {<a name="line.207"></a>
+<span class="sourceLineNo">208</span>            AuthorizeCallback ac = null;<a name="line.208"></a>
+<span class="sourceLineNo">209</span>            for (Callback callback : callbacks) {<a name="line.209"></a>
+<span class="sourceLineNo">210</span>              if (callback instanceof AuthorizeCallback) {<a name="line.210"></a>
+<span class="sourceLineNo">211</span>                ac = (AuthorizeCallback) callback;<a name="line.211"></a>
+<span class="sourceLineNo">212</span>              } else {<a name="line.212"></a>
+<span class="sourceLineNo">213</span>                throw new UnsupportedCallbackException(callback,<a name="line.213"></a>
+<span class="sourceLineNo">214</span>                    "Unrecognized SASL GSSAPI Callback");<a name="line.214"></a>
+<span class="sourceLineNo">215</span>              }<a name="line.215"></a>
+<span class="sourceLineNo">216</span>            }<a name="line.216"></a>
+<span class="sourceLineNo">217</span>            if (ac != null) {<a name="line.217"></a>
+<span class="sourceLineNo">218</span>              String authid = ac.getAuthenticationID();<a name="line.218"></a>
+<span class="sourceLineNo">219</span>              String authzid = ac.getAuthorizationID();<a name="line.219"></a>
+<span class="sourceLineNo">220</span>              if (!authid.equals(authzid)) {<a name="line.220"></a>
+<span class="sourceLineNo">221</span>                ac.setAuthorized(false);<a name="line.221"></a>
+<span class="sourceLineNo">222</span>              } else {<a name="line.222"></a>
+<span class="sourceLineNo">223</span>                ac.setAuthorized(true);<a name="line.223"></a>
+<span class="sourceLineNo">224</span>                String userName = SecurityUtil.getUserFromPrincipal(authzid);<a name="line.224"></a>
+<span class="sourceLineNo">225</span>                log.info("Effective user: " + userName);<a name="line.225"></a>
+<span class="sourceLineNo">226</span>                ac.setAuthorizedID(userName);<a name="line.226"></a>
+<span class="sourceLineNo">227</span>              }<a name="line.227"></a>
+<span class="sourceLineNo">228</span>            }<a name="line.228"></a>
+<span class="sourceLineNo">229</span>          }<a name="line.229"></a>
+<span class="sourceLineNo">230</span>        });<a name="line.230"></a>
+<span class="sourceLineNo">231</span>      return saslFactory;<a name="line.231"></a>
+<span class="sourceLineNo">232</span>    }<a name="line.232"></a>
+<span class="sourceLineNo">233</span>  }<a name="line.233"></a>
+<span class="sourceLineNo">234</span><a name="line.234"></a>
+<span class="sourceLineNo">235</span>  /*<a name="line.235"></a>
+<span class="sourceLineNo">236</span>   * If bindValue is null, we don't bind.<a name="line.236"></a>
+<span class="sourceLineNo">237</span>   */<a name="line.237"></a>
+<span class="sourceLineNo">238</span>  private static InetSocketAddress bindToPort(String bindValue, int listenPort)<a name="line.238"></a>
+<span class="sourceLineNo">239</span>      throws UnknownHostException {<a name="line.239"></a>
+<span class="sourceLineNo">240</span>    try {<a name="line.240"></a>
+<span class="sourceLineNo">241</span>      if (bindValue == null) {<a name="line.241"></a>
+<span class="sourceLineNo">242</span>        return new InetSocketAddress(listenPort);<a name="line.242"></a>
+<span class="sourceLineNo">243</span>      } else {<a name="line.243"></a>
+<span class="sourceLineNo">244</span>        return new InetSocketAddress(InetAddress.getByName(bindValue), listenPort);<a name="line.244"></a>
+<span class="sourceLineNo">245</span>      }<a name="line.245"></a>
+<span class="sourceLineNo">246</span>    } catch (UnknownHostException e) {<a name="line.246"></a>
+<span class="sourceLineNo">247</span>      throw new RuntimeException("Could not bind to provided ip address", e);<a name="line.247"></a>
+<span class="sourceLineNo">248</span>    }<a name="line.248"></a>
+<span class="sourceLineNo">249</span>  }<a name="line.249"></a>
+<span class="sourceLineNo">250</span><a name="line.250"></a>
+<span class="sourceLineNo">251</span>  private static TServer getTNonBlockingServer(TProtocolFactory protocolFactory, TProcessor processor,<a name="line.251"></a>
+<span class="sourceLineNo">252</span>      TTransportFactory transportFactory, InetSocketAddress inetSocketAddress) throws TTransportException {<a name="line.252"></a>
+<span class="sourceLineNo">253</span>    TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(inetSocketAddress);<a name="line.253"></a>
+<span class="sourceLineNo">254</span>    log.info("starting HBase Nonblocking Thrift server on " + inetSocketAddress.toString());<a name="line.254"></a>
+<span class="sourceLineNo">255</span>    TNonblockingServer.Args serverArgs = new TNonblockingServer.Args(serverTransport);<a name="line.255"></a>
+<span class="sourceLineNo">256</span>    serverArgs.processor(processor);<a name="line.256"></a>
+<span class="sourceLineNo">257</span>    serverArgs.transportFactory(transportFactory);<a name="line.257"></a>
+<span class="sourceLineNo">258</span>    serverArgs.protocolFactory(protocolFactory);<a name="line.258"></a>
+<span class="sourceLineNo">259</span>    return new TNonblockingServer(serverArgs);<a name="line.259"></a>
+<span class="sourceLineNo">260</span>  }<a name="line.260"></a>
+<span class="sourceLineNo">261</span><a name="line.261"></a>
+<span class="sourceLineNo">262</span>  private static TServer getTHsHaServer(TProtocolFactory protocolFactory,<a name="line.262"></a>
+<span class="sourceLineNo">263</span>      TProcessor processor, TTransportFactory transportFactory,<a name="line.263"></a>
+<span class="sourceLineNo">264</span>      int workerThreads, int maxCallQueueSize,<a name="line.264"></a>
+<span class="sourceLineNo">265</span>      InetSocketAddress inetSocketAddress, ThriftMetrics metrics)<a name="line.265"></a>
+<span class="sourceLineNo">266</span>      throws TTransportException {<a name="line.266"></a>
+<span class="sourceLineNo">267</span>    TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(inetSocketAddress);<a name="line.267"></a>
+<span class="sourceLineNo">268</span>    log.info("starting HBase HsHA Thrift server on " + inetSocketAddress.toString());<a name="line.268"></a>
+<span class="sourceLineNo">269</span>    THsHaServer.Args serverArgs = new THsHaServer.Args(serverTransport);<a name="line.269"></a>
+<span class="sourceLineNo">270</span>    if (workerThreads &gt; 0) {<a name="line.270"></a>
+<span class="sourceLineNo">271</span>      // Could support the min &amp; max threads, avoiding to preserve existing functionality.<a name="line.271"></a>
+<span class="sourceLineNo">272</span>      serverArgs.minWorkerThreads(workerThreads).maxWorkerThreads(workerThreads);<a name="line.272"></a>
+<span class="sourceLineNo">273</span>    }<a name="line.273"></a>
+<span class="sourceLineNo">274</span>    ExecutorService executorService = createExecutor(<a name="line.274"></a>
+<span class="sourceLineNo">275</span>        workerThreads, maxCallQueueSize, metrics);<a name="line.275"></a>
+<span class="sourceLineNo">276</span>    serverArgs.executorService(executorService);<a name="line.276"></a>
+<span class="sourceLineNo">277</span>    serverArgs.processor(processor);<a name="line.277"></a>
+<span class="sourceLineNo">278</span>    serverArgs.transportFactory(transportFactory);<a name="line.278"></a>
+<span class="sourceLineNo">279</span>    serverArgs.protocolFactory(protocolFactory);<a name="line.279"></a>
+<span class="sourceLineNo">280</span>    return new THsHaServer(serverArgs);<a name="line.280"></a>
+<span class="sourceLineNo">281</span>  }<a name="line.281"></a>
+<span class="sourceLineNo">282</span><a name="line.282"></a>
+<span class="sourceLineNo">283</span>  private static TServer getTThreadedSelectorServer(TProtocolFactory protocolFactory,<a name="line.283"></a>
+<span class="sourceLineNo">284</span>      TProcessor processor, TTransportFactory transportFactory,<a name="line.284"></a>
+<span class="sourceLineNo">285</span>      int workerThreads, int selectorThreads, int maxCallQueueSize,<a name="line.285"></a>
+<span class="sourceLineNo">286</span>      InetSocketAddress inetSocketAddress, ThriftMetrics metrics)<a name="line.286"></a>
+<span class="sourceLineNo">287</span>      throws TTransportException {<a name="line.287"></a>
+<span class="sourceLineNo">288</span>    TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(inetSocketAddress);<a name="line.288"></a>
+<span class="sourceLineNo">289</span>    log.info("starting HBase ThreadedSelector Thrift server on " + inetSocketAddress.toString());<a name="line.289"></a>
+<span class="sourceLineNo">290</span>    TThreadedSelectorServer.Args serverArgs = new TThreadedSelectorServer.Args(serverTransport);<a name="line.290"></a>
+<span class="sourceLineNo">291</span>    if (workerThreads &gt; 0) {<a name="line.291"></a>
+<span class="sourceLineNo">292</span>        serverArgs.workerThreads(workerThreads);<a name="line.292"></a>
+<span class="sourceLineNo">293</span>    }<a name="line.293"></a>
+<span class="sourceLineNo">294</span>    if (selectorThreads &gt; 0) {<a name="line.294"></a>
+<span class="sourceLineNo">295</span>        serverArgs.selectorThreads(selectorThreads);<a name="line.295"></a>
+<span class="sourceLineNo">296</span>    }<a name="line.296"></a>
+<span class="sourceLineNo">297</span><a name="line.297"></a>
+<span class="sourceLineNo">298</span>    ExecutorService executorService = createExecutor(<a name="line.298"></a>
+<span class="sourceLineNo">299</span>        workerThreads, maxCallQueueSize, metrics);<a name="line.299"></a>
+<span class="sourceLineNo">300</span>    serverArgs.executorService(executorService);<a name="line.300"></a>
+<span class="sourceLineNo">301</span>    serverArgs.processor(processor);<a name="line.301"></a>
+<span class="sourceLineNo">302</span>    serverArgs.transportFactory(transportFactory);<a name="line.302"></a>
+<span class="sourceLineNo">303</span>    serverArgs.protocolFactory(protocolFactory);<a name="line.303"></a>
+<span class="sourceLineNo">304</span>    return new TThreadedSelectorServer(serverArgs);<a name="line.304"></a>
+<span class="sourceLineNo">305</span>  }<a name="line.305"></a>
+<span class="sourceLineNo">306</span><a name="line.306"></a>
+<span class="sourceLineNo">307</span>  private static ExecutorService createExecutor(<a name="line.307"></a>
+<span class="sourceLineNo">308</span>      int workerThreads, int maxCallQueueSize, ThriftMetrics metrics) {<a name="line.308"></a>
+<span class="sourceLineNo">309</span>    CallQueue callQueue;<a name="line.309"></a>
+<span class="sourceLineNo">310</span>    if (maxCallQueueSize &gt; 0) {<a name="line.310"></a>
+<span class="sourceLineNo">311</span>      callQueue = new CallQueue(new LinkedBlockingQueue&lt;&gt;(maxCallQueueSize), metrics);<a name="line.311"></a>
+<span class="sourceLineNo">312</span>    } else {<a name="line.312"></a>
+<span class="sourceLineNo">313</span>      callQueue = new CallQueue(new LinkedBlockingQueue&lt;&gt;(), metrics);<a name="line.313"></a>
+<span class="sourceLineNo">314</span>    }<a name="line.314"></a>
+<span class="sourceLineNo">315</span><a name="line.315"></a>
+<span class="sourceLineNo">316</span>    ThreadFactoryBuilder tfb = new ThreadFactoryBuilder();<a name="line.316"></a>
+<span class="sourceLineNo">317</span>    tfb.setDaemon(true);<a name="line.317"></a>
+<span class="sourceLineNo">318</span>    tfb.setNameFormat("thrift2-worker-%d");<a name="line.318"></a>
+<span class="sourceLineNo">319</span>    ThreadPoolExecutor pool = new THBaseThreadPoolExecutor(workerThreads, workerThreads,<a name="line.319"></a>
+<span class="sourceLineNo">320</span>            Long.MAX_VALUE, TimeUnit.SECONDS, callQueue, tfb.build(), metrics);<a name="line.320"></a>
+<span class="sourceLineNo">321</span>    pool.prestartAllCoreThreads();<a name="line.321"></a>
+<span class="sourceLineNo">322</span>    return pool;<a name="line.322"></a>
+<span class="sourceLineNo">323</span>  }<a name="line.323"></a>
+<span class="sourceLineNo">324</span><a name="line.324"></a>
+<span class="sourceLineNo">325</span>  private static TServer getTThreadPoolServer(TProtocolFactory protocolFactory,<a name="line.325"></a>
+<span class="sourceLineNo">326</span>                                              TProcessor processor,<a name="line.326"></a>
+<span class="sourceLineNo">327</span>                                              TTransportFactory transportFactory,<a name="line.327"></a>
+<span class="sourceLineNo">328</span>                                              int workerThreads,<a name="line.328"></a>
+<span class="sourceLineNo">329</span>                                              InetSocketAddress inetSocketAddress,<a name="line.329"></a>
+<span class="sourceLineNo">330</span>                                              int backlog,<a name="line.330"></a>
+<span class="sourceLineNo">331</span>                                              int clientTimeout,<a name="line.331"></a>
+<span class="sourceLineNo">332</span>                                              ThriftMetrics metrics)<a name="line.332"></a>
+<span class="sourceLineNo">333</span>      throws TTransportException {<a name="line.333"></a>
+<span class="sourceLineNo">334</span>    TServerTransport serverTransport = new TServerSocket(<a name="line.334"></a>
+<span class="sourceLineNo">335</span>                                           new TServerSocket.ServerSocketTransportArgs().<a name="line.335"></a>
+<span class="sourceLineNo">336</span>                                               bindAddr(inetSocketAddress).backlog(backlog).<a name="line.336"></a>
+<span class="sourceLineNo">337</span>                                               clientTimeout(clientTimeout));<a name="line.337"></a>
+<span class="sourceLineNo">338</span>    log.info("starting HBase ThreadPool Thrift server on " + inetSocketAddress.toString());<a name="line.338"></a>
+<span class="sourceLineNo">339</span>    TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport);<a name="line.339"></a>
+<span class="sourceLineNo">340</span>    serverArgs.processor(processor);<a name="line.340"></a>
+<span class="sourceLineNo">341</span>    serverArgs.transportFactory(transportFactory);<a name="line.341"></a>
+<span class="sourceLineNo">342</span>    serverArgs.protocolFactory(protocolFactory);<a name="line.342"></a>
+<span class="sourceLineNo">343</span>    if (workerThreads &gt; 0) {<a name="line.343"></a>
+<span class="sourceLineNo">344</span>      serverArgs.maxWorkerThreads(workerThreads);<a name="line.344"></a>
+<span class="sourceLineNo">345</span>    }<a name="line.345"></a>
+<span class="sourceLineNo">346</span>    ThreadPoolExecutor executor = new THBaseThreadPoolExecutor(serverArgs.minWorkerThreads,<a name="line.346"></a>
+<span class="sourceLineNo">347</span>        serverArgs.maxWorkerThreads, serverArgs.stopTimeoutVal, TimeUnit.SECONDS,<a name="line.347"></a>
+<span class="sourceLineNo">348</span>        new SynchronousQueue&lt;&gt;(), metrics);<a name="line.348"></a>
+<span class="sourceLineNo">349</span>    serverArgs.executorService(executor);<a name="line.349"></a>
+<span class="sourceLineNo">350</span><a name="line.350"></a>
+<span class="sourceLineNo">351</span>    return new TThreadPoolServer(serverArgs);<a name="line.351"></a>
+<span class="sourceLineNo">352</span>  }<a name="line.352"></a>
+<span class="sourceLineNo">353</span><a name="line.353"></a>
+<span class="sourceLineNo">354</span>  /**<a name="line.354"></a>
+<span class="sourceLineNo">355</span>   * Adds the option to pre-load filters at startup.<a name="line.355"></a>
+<span class="sourceLineNo">356</span>   *<a name="line.356"></a>
+<span class="sourceLineNo">357</span>   * @param conf  The current configuration instance.<a name="line.357"></a>
+<span class="sourceLineNo">358</span>   */<a name="line.358"></a>
+<span class="sourceLineNo">359</span>  protected static void registerFilters(Configuration conf) {<a name="line.359"></a>
+<span class="sourceLineNo">360</span>    String[] filters = conf.getStrings("hbase.thrift.filters");<a name="line.360"></a>
+<span class="sourceLineNo">361</span>    if(filters != null) {<a name="line.361"></a>
+<span class="sourceLineNo">362</span>      for(String filterClass: filters) {<a name="line.362"></a>
+<span class="sourceLineNo">363</span>        String[] filterPart = filterClass.split(":");<a name="line.363"></a>
+<span class="sourceLineNo">364</span>        if(filterPart.length != 2) {<a name="line.364"></a>
+<span class="sourceLineNo">365</span>          log.warn("Invalid filter specification " + filterClass + " - skipping");<a name="line.365"></a>
+<span class="sourceLineNo">366</span>        } else {<a name="line.366"></a>
+<span class="sourceLineNo">367</span>          ParseFilter.registerFilter(filterPart[0], filterPart[1]);<a name="line.367"></a>
+<span class="sourceLineNo">368</span>        }<a name="line.368"></a>
+<span class="sourceLineNo">369</span>      }<a name="line.369"></a>
+<span class="sourceLineNo">370</span>    }<a name="line.370"></a>
+<span class="sourceLineNo">371</span>  }<a name="line.371"></a>
+<span class="sourceLineNo">372</span><a name="line.372"></a>
+<span class="sourceLineNo">373</span>  /**<a name="line.373"></a>
+<span class="sourceLineNo">374</span>   * Start up the Thrift2 server.<a name="line.374"></a>
+<span class="sourceLineNo">375</span>   */<a name="line.375"></a>
+<span class="sourceLineNo">376</span>  public static void main(String[] args) throws Exception {<a name="line.376"></a>
+<span class="sourceLineNo">377</span>    final Configuration conf = HBaseConfiguration.create();<a name="line.377"></a>
+<span class="sourceLineNo">378</span>    // for now, only time we return is on an argument error.<a name="line.378"></a>
+<span class="sourceLineNo">379</span>    final int status = ToolRunner.run(conf, new ThriftServer(), args);<a name="line.379"></a>
+<span class="sourceLineNo">380</span>    System.exit(status);<a name="line.380"></a>
+<span class="sourceLineNo">381</span>  }<a name="line.381"></a>
+<span class="sourceLineNo">382</span><a name="line.382"></a>
+<span class="sourceLineNo">383</span>  @Override<a name="line.383"></a>
+<span class="sourceLineNo">384</span>  public int run(String[] args) throws Exception {<a name="line.384"></a>
+<span class="sourceLineNo">385</span>    final Configuration conf = getConf();<a name="line.385"></a>
+<span class="sourceLineNo">386</span>    TServer server = null;<a name="line.386"></a>
+<span class="sourceLineNo">387</span>    Options options = getOptions();<a name="line.387"></a>
+<span class="sourceLineNo">388</span>    CommandLine cmd = parseArguments(conf, options, args);<a name="line.388"></a>
+<span class="sourceLineNo">389</span>    int workerThreads = 0;<a name="line.389"></a>
+<span class="sourceLineNo">390</span>    int selectorThreads = 0;<a name="line.390"></a>
+<span class="sourceLineNo">391</span>    int maxCallQueueSize = -1; // use unbounded queue by default<a name="line.391"></a>
+<span class="sourceLineNo">392</span><a name="line.392"></a>
+<span class="sourceLineNo">393</span>    /**<a name="line.393"></a>
+<span class="sourceLineNo">394</span>     * This is to please both bin/hbase and bin/hbase-daemon. hbase-daemon provides "start" and "stop" arguments hbase<a name="line.394"></a>
+<span class="sourceLineNo">395</span>     * should print the help if no argument is provided<a name="line.395"></a>
+<span class="sourceLineNo">396</span>     */<a name="line.396"></a>
+<span class="sourceLineNo">397</span>    List&lt;?&gt; argList = cmd.getArgList();<a name="line.397"></a>
+<span class="sourceLineNo">398</span>    if (cmd.hasOption("help") || !argList.contains("start") || argList.contains("stop")) {<a name="line.398"></a>
+<span class="sourceLineNo">399</span>      printUsage();<a name="line.399"></a>
+<span class="sourceLineNo">400</span>      return 1;<a name="line.400"></a>
+<span class="sourceLineNo">401</span>    }<a name="line.401"></a>
+<span class="sourceLineNo">402</span><a name="line.402"></a>
+<span class="sourceLineNo">403</span>    // Get address to bind<a name="line.403"></a>
+<span class="sourceLineNo">404</span>    String bindAddress;<a name="line.404"></a>
+<span class="sourceLineNo">405</span>    if (cmd.hasOption("bind")) {<a name="line.405"></a>
+<span class="sourceLineNo">406</span>      bindAddress = cmd.getOptionValue("bind");<a name="line.406"></a>
+<span class="sourceLineNo">407</span>      conf.set("hbase.thrift.info.bindAddress", bindAddress);<a name="line.407"></a>
+<span class="sourceLineNo">408</span>    } else {<a name="line.408"></a>
+<span class="sourceLineNo">409</span>      bindAddress = conf.get("hbase.thrift.info.bindAddress");<a name="line.409"></a>
+<span class="sourceLineNo">410</span>    }<a name="line.410"></a>
+<span class="sourceLineNo">411</span><a name="line.411"></a>
+<span class="sourceLineNo">412</span>    // check if server should only process read requests, if so override the conf<a name="line.412"></a>
+<span class="sourceLineNo">413</span>    if (cmd.hasOption("readonly")) {<a name="line.413"></a>
+<span class="sourceLineNo">414</span>      conf.setBoolean("hbase.thrift.readonly", true);<a name="line.414"></a>
+<span class="sourceLineNo">415</span>      if (log.isDebugEnabled()) {<a name="line.415"></a>
+<span class="sourceLineNo">416</span>        log.debug("readonly set to true");<a name="line.416"></a>
 <span class="sourceLineNo">417</span>      }<a name="line.417"></a>
-<span class="sourceLineNo">418</span>    } else {<a name="line.418"></a>
-<span class="sourceLineNo">419</span>      readTimeout = conf.getInt(THRIFT_SERVER_SOCKET_READ_TIMEOUT_KEY,<a name="line.419"></a>
-<span class="sourceLineNo">420</span>        THRIFT_SERVER_SOCKET_READ_TIMEOUT_DEFAULT);<a name="line.420"></a>
-<span class="sourceLineNo">421</span>    }<a name="line.421"></a>
-<span class="sourceLineNo">422</span><a name="line.422"></a>
-<span class="sourceLineNo">423</span>    // Get port to bind to<a name="line.423"></a>
-<span class="sourceLineNo">424</span>    int listenPort = 0;<a name="line.424"></a>
-<span class="sourceLineNo">425</span>    try {<a name="line.425"></a>
-<span class="sourceLineNo">426</span>      if (cmd.hasOption("port")) {<a name="line.426"></a>
-<span class="sourceLineNo">427</span>        listenPort = Integer.parseInt(cmd.getOptionValue("port"));<a name="line.427"></a>
-<span class="sourceLineNo">428</span>      } else {<a name="line.428"></a>
-<span class="sourceLineNo">429</span>        listenPort = conf.getInt("hbase.regionserver.thrift.port", DEFAULT_LISTEN_PORT);<a name="line.429"></a>
-<span class="sourceLineNo">430</span>      }<a name="line.430"></a>
-<span class="sourceLineNo">431</span>    } catch (NumberFormatException e) {<a name="line.431"></a>
-<span class="sourceLineNo">432</span>      throw new RuntimeException("Could not parse the value provided for the port option", e);<a name="line.432"></a>
-<span class="sourceLineNo">433</span>    }<a name="line.433"></a>
-<span class="sourceLineNo">434</span><a name="line.434"></a>
-<span class="sourceLineNo">435</span>    // Thrift's implementation uses '0' as a placeholder for 'use the default.'<a name="line.435"></a>
-<span class="sourceLineNo">436</span>    int backlog = conf.getInt(BACKLOG_CONF_KEY, 0);<a name="line.436"></a>
-<span class="sourceLineNo">437</span><a name="line.437"></a>
-<span class="sourceLineNo">438</span>    // Local hostname and user name,<a name="line.438"></a>
-<span class="sourceLineNo">439</span>    // used only if QOP is configured.<a name="line.439"></a>
-<span class="sourceLineNo">440</span>    String host = null;<a name="line.440"></a>
-<span class="sourceLineNo">441</span>    String name = null;<a name="line.441"></a>
-<span class="sourceLineNo">442</span><a name="line.442"></a>
-<span class="sourceLineNo">443</span>    UserProvider userProvider = UserProvider.instantiate(conf);<a name="line.443"></a>
-<span class="sourceLineNo">444</span>    // login the server principal (if using secure Hadoop)<a name="line.444"></a>
-<span class="sourceLineNo">445</span>    boolean securityEnabled = userProvider.isHadoopSecurityEnabled()<a name="line.445"></a>
-<span class="sourceLineNo">446</span>      &amp;&amp; userProvider.isHBaseSecurityEnabled();<a name="line.446"></a>
-<span class="sourceLineNo">447</span>    if (securityEnabled) {<a name="line.447"></a>
-<span class="sourceLineNo">448</span>      host = Strings.domainNamePointerToHostName(DNS.getDefaultHost(<a name="line.448"></a>
-<span class="sourceLineNo">449</span>        conf.get("hbase.thrift.dns.interface", "default"),<a name="line.449"></a>
-<span class="sourceLineNo">450</span>        conf.get("hbase.thrift.dns.nameserver", "default")));<a name="line.450"></a>
-<span class="sourceLineNo">451</span>      userProvider.login("hbase.thrift.keytab.file",<a name="line.451"></a>
-<span class="sourceLineNo">452</span>        "hbase.thrift.kerberos.principal", host);<a name="line.452"></a>
-<span class="sourceLineNo">453</span>    }<a name="line.453"></a>
-<span class="sourceLineNo">454</span><a name="line.454"></a>
-<span class="sourceLineNo">455</span>    UserGroupInformation realUser = userProvider.getCurrent().getUGI();<a name="line.455"></a>
-<span class="sourceLineNo">456</span>    String stringQop = conf.get(THRIFT_QOP_KEY);<a name="line.456"></a>
-<span class="sourceLineNo">457</span>    SaslUtil.QualityOfProtection qop = null;<a name="line.457"></a>
-<span class="sourceLineNo">458</span>    if (stringQop != null) {<a name="line.458"></a>
-<span class="sourceLineNo">459</span>      qop = SaslUtil.getQop(stringQop);<a name="line.459"></a>
-<span class="sourceLineNo">460</span>      if (!securityEnabled) {<a name="line.460"></a>
-<span class="sourceLineNo">461</span>        throw new IOException("Thrift server must"<a name="line.461"></a>
-<span class="sourceLineNo">462</span>          + " run in secure mode to support authentication");<a name="line.462"></a>
-<span class="sourceLineNo">463</span>      }<a name="line.463"></a>
-<span class="sourceLineNo">464</span>      // Extract the name from the principal<a name="line.464"></a>
-<span class="sourceLineNo">465</span>      name = SecurityUtil.getUserFromPrincipal(<a name="line.465"></a>
-<span class="sourceLineNo">466</span>        conf.get("hbase.thrift.kerberos.principal"));<a name="line.466"></a>
-<span class="sourceLineNo">467</span>    }<a name="line.467"></a>
-<span class="sourceLineNo">468</span><a name="line.468"></a>
-<span class="sourceLineNo">469</span>    boolean nonblocking = cmd.hasOption("nonblocking");<a name="line.469"></a>
-<span class="sourceLineNo">470</span>    boolean hsha = cmd.hasOption("hsha");<a name="line.470"></a>
-<span class="sourceLineNo">471</span>    boolean selector = cmd.hasOption("selector");<a name="line.471"></a>
-<span class="sourceLineNo">472</span><a name="line.472"></a>
-<span class="sourceLineNo">473</span>    ThriftMetrics metrics = new ThriftMetrics(conf, ThriftMetrics.ThriftServerType.TWO);<a name="line.473"></a>
-<span class="sourceLineNo">474</span>    final JvmPauseMonitor pauseMonitor = new JvmPauseMonitor(conf, metrics.getSource());<a name="line.474"></a>
-<span class="sourceLineNo">475</span><a name="line.475"></a>
-<span class="sourceLineNo">476</span>    String implType = "threadpool";<a name="line.476"></a>
-<span class="sourceLineNo">477</span>    if (nonblocking) {<a name="line.477"></a>
-<span class="sourceLineNo">478</span>      implType = "nonblocking";<a name="line.478"></a>
-<span class="sourceLineNo">479</span>    } else if (hsha) {<a name="line.479"></a>
-<span class="sourceLineNo">480</span>      implType = "hsha";<a name="line.480"></a>
-<span class="sourceLineNo">481</span>    } else if (selector) {<a name="line.481"></a>
-<span class="sourceLineNo">482</span>      implType = "selector";<a name="line.482"></a>
-<span class="sourceLineNo">483</span>    }<a name="line.483"></a>
-<span class="sourceLineNo">484</span><a name="line.484"></a>
-<span class="sourceLineNo">485</span>    conf.set("hbase.regionserver.thrift.server.type", implType);<a name="line.485"></a>
-<span class="sourceLineNo">486</span>    conf.setInt("hbase.regionserver.thrift.port", listenPort);<a name="line.486"></a>
-<span class="sourceLineNo">487</span>    registerFilters(conf);<a name="line.487"></a>
-<span class="sourceLineNo">488</span><a name="line.488"></a>
-<span class="sourceLineNo">489</span>    // Construct correct ProtocolFactory<a name="line.489"></a>
-<span class="sourceLineNo">490</span>    boolean compact = cmd.hasOption("compact") ||<a name="line.490"></a>
-<span class="sourceLineNo">491</span>        conf.getBoolean("hbase.regionserver.thrift.compact", false);<a name="line.491"></a>
-<span class="sourceLineNo">492</span>    TProtocolFactory protocolFactory = getTProtocolFactory(compact);<a name="line.492"></a>
-<span class="sourceLineNo">493</span>    final ThriftHBaseServiceHandler hbaseHandler =<a name="line.493"></a>
-<span class="sourceLineNo">494</span>      new ThriftHBaseServiceHandler(conf, userProvider);<a name="line.494"></a>
-<span class="sourceLineNo">495</span>    THBaseService.Iface handler =<a name="line.495"></a>
-<span class="sourceLineNo">496</span>      ThriftHBaseServiceHandler.newInstance(hbaseHandler, metrics);<a name="line.496"></a>
-<span class="sourceLineNo">497</span>    final THBaseService.Processor p = new THBaseService.Processor(handler);<a name="line.497"></a>
-<span class="sourceLineNo">498</span>    conf.setBoolean("hbase.regionserver.thrift.compact", compact);<a name="line.498"></a>
-<span class="sourceLineNo">499</span>    TProcessor processor = p;<a name="line.499"></a>
-<span class="sourceLineNo">500</span><a name="line.500"></a>
-<span class="sourceLineNo">501</span>    boolean framed = cmd.hasOption("framed") ||<a name="line.501"></a>
-<span class="sourceLineNo">502</span>        conf.getBoolean("hbase.regionserver.thrift.framed", false) || nonblocking || hsha;<a name="line.502"></a>
-<span class="sourceLineNo">503</span>    TTransportFactory transportFactory = getTTransportFactory(qop, name, host, framed,<a name="line.503"></a>
-<span class="sourceLineNo">504</span>        conf.getInt("hbase.regionserver.thrift.framed.max_frame_size_in_mb", 2) * 1024 * 1024);<a name="line.504"></a>
-<span class="sourceLineNo">505</span>    InetSocketAddress inetSocketAddress = bindToPort(bindAddress, listenPort);<a name="line.505"></a>
-<span class="sourceLineNo">506</span>    conf.setBoolean("hbase.regionserver.thrift.framed", framed);<a name="line.506"></a>
-<span class="sourceLineNo">507</span>    if (qop != null) {<a name="line.507"></a>
-<span class="sourceLineNo">508</span>      // Create a processor wrapper, to get the caller<a name="line.508"></a>
-<span class="sourceLineNo">509</span>      processor = new TProcessor() {<a name="line.509"></a>
-<span class="sourceLineNo">510</span>        @Override<a name="line.510"></a>
-<span class="sourceLineNo">511</span>        public boolean process(TProtocol inProt,<a name="line.511"></a>
-<span class="sourceLineNo">512</span>            TProtocol outProt) throws TException {<a name="line.512"></a>
-<span class="sourceLineNo">513</span>          TSaslServerTransport saslServerTransport =<a name="line.513"></a>
-<span class="sourceLineNo">514</span>            (TSaslServerTransport)inProt.getTransport();<a name="line.514"></a>
-<span class="sourceLineNo">515</span>          SaslServer saslServer = saslServerTransport.getSaslServer();<a name="line.515"></a>
-<span class="sourceLineNo">516</span>          String principal = saslServer.getAuthorizationID();<a name="line.516"></a>
-<span class="sourceLineNo">517</span>          hbaseHandler.setEffectiveUser(principal);<a name="line.517"></a>
-<span class="sourceLineNo">518</span>          return p.process(inProt, outProt);<a name="line.518"></a>
-<span class="sourceLineNo">519</span>        }<a name="line.519"></a>
-<span class="sourceLineNo">520</span>      };<a name="line.520"></a>
-<span class="sourceLineNo">521</span>    }<a name="line.521"></a>
-<span class="sourceLineNo">522</span><a name="line.522"></a>
-<span class="sourceLineNo">523</span>    if (cmd.hasOption("w")) {<a name="line.523"></a>
-<span class="sourceLineNo">524</span>      workerThreads = Integer.parseInt(cmd.getOptionValue("w"));<a name="line.524"></a>
-<span class="sourceLineNo">525</span>    }<a name="line.525"></a>
-<span class="sourceLineNo">526</span>    if (cmd.hasOption("s")) {<a name="line.526"></a>
-<span class="sourceLineNo">527</span>      selectorThreads = Integer.parseInt(cmd.getOptionValue("s"));<a name="line.527"></a>
-<span class="sourceLineNo">528</span>    }<a name="line.528"></a>
-<span class="sourceLineNo">529</span>    if (cmd.hasOption("q")) {<a name="line.529"></a>
-<span class="sourceLineNo">530</span>      maxCallQueueSize = Integer.parseInt(cmd.getOptionValue("q"));<a name="line.530"></a>
+<span class="sourceLineNo">418</span>    }<a name="line.418"></a>
+<span class="sourceLineNo">419</span><a name="line.419"></a>
+<span class="sourceLineNo">420</span>    // Get read timeout<a name="line.420"></a>
+<span class="sourceLineNo">421</span>    int readTimeout = THRIFT_SERVER_SOCKET_READ_TIMEOUT_DEFAULT;<a name="line.421"></a>
+<span class="sourceLineNo">422</span>    if (cmd.hasOption(READ_TIMEOUT_OPTION)) {<a name="line.422"></a>
+<span class="sourceLineNo">423</span>      try {<a name="line.423"></a>
+<span class="sourceLineNo">424</span>        readTimeout = Integer.parseInt(cmd.getOptionValue(READ_TIMEOUT_OPTION));<a name="line.424"></a>
+<span class="sourceLineNo">425</span>      } catch (NumberFormatException e) {<a name="line.425"></a>
+<span class="sourceLineNo">426</span>        throw new RuntimeException("Could not parse the value provided for the timeout option", e);<a name="line.426"></a>
+<span class="sourceLineNo">427</span>      }<a name="line.427"></a>
+<span class="sourceLineNo">428</span>    } else {<a name="line.428"></a>
+<span class="sourceLineNo">429</span>      readTimeout = conf.getInt(THRIFT_SERVER_SOCKET_READ_TIMEOUT_KEY,<a name="line.429"></a>
+<span class="sourceLineNo">430</span>        THRIFT_SERVER_SOCKET_READ_TIMEOUT_DEFAULT);<a name="line.430"></a>
+<span class="sourceLineNo">431</span>    }<a name="line.431"></a>
+<span class="sourceLineNo">432</span><a name="line.432"></a>
+<span class="sourceLineNo">433</span>    // Get port to bind to<a name="line.433"></a>
+<span class="sourceLineNo">434</span>    int listenPort = 0;<a name="line.434"></a>
+<span class="sourceLineNo">435</span>    try {<a name="line.435"></a>
+<span class="sourceLineNo">436</span>      if (cmd.hasOption("port")) {<a name="line.436"></a>
+<span class="sourceLineNo">437</span>        listenPort = Integer.parseInt(cmd.getOptionValue("port"));<a name="line.437"></a>
+<span class="sourceLineNo">438</span>      } else {<a name="line.438"></a>
+<span class="sourceLineNo">439</span>        listenPort = conf.getInt("hbase.regionserver.thrift.port", DEFAULT_LISTEN_PORT);<a name="line.439"></a>
+<span class="sourceLineNo">440</span>      }<a name="line.440"></a>
+<span class="sourceLineNo">441</span>    } catch (NumberFormatException e) {<a name="line.441"></a>
+<span class="sourceLineNo">442</span>      throw new RuntimeException("Could not parse the value provided for the port option", e);<a name="line.442"></a>
+<span class="sourceLineNo">443</span>    }<a name="line.443"></a>
+<span class="sourceLineNo">444</span><a name="line.444"></a>
+<span class="sourceLineNo">445</span>    // Thrift's implementation uses '0' as a placeholder for 'use the default.'<a name="line.445"></a>
+<span class="sourceLineNo">446</span>    int backlog = conf.getInt(BACKLOG_CONF_KEY, 0);<a name="line.446"></a>
+<span class="sourceLineNo">447</span><a name="line.447"></a>
+<span class="sourceLineNo">448</span>    // Local hostname and user name,<a name="line.448"></a>
+<span class="sourceLineNo">449</span>    // used only if QOP is configured.<a name="line.449"></a>
+<span class="sourceLineNo">450</span>    String host = null;<a name="line.450"></a>
+<span class="sourceLineNo">451</span>    String name = null;<a name="line.451"></a>
+<span class="sourceLineNo">452</span><a name="line.452"></a>
+<span class="sourceLineNo">453</span>    UserProvider userProvider = UserProvider.instantiate(conf);<a name="line.453"></a>
+<span class="sourceLineNo">454</span>    // login the server principal (if using secure Hadoop)<a name="line.454"></a>
+<span class="sourceLineNo">455</span>    boolean securityEnabled = userProvider.isHadoopSecurityEnabled()<a name="line.455"></a>
+<span class="sourceLineNo">456</span>      &amp;&amp; userProvider.isHBaseSecurityEnabled();<a name="line.456"></a>
+<span class="sourceLineNo">457</span>    if (securityEnabled) {<a name="line.457"></a>
+<span class="sourceLineNo">458</span>      host = Strings.domainNamePointerToHostName(DNS.getDefaultHost(<a name="line.458"></a>
+<span class="sourceLineNo">459</span>        conf.get("hbase.thrift.dns.interface", "default"),<a name="line.459"></a>
+<span class="sourceLineNo">460</span>        conf.get("hbase.thrift.dns.nameserver", "default")));<a name="line.460"></a>
+<span class="sourceLineNo">461</span>      userProvider.login("hbase.thrift.keytab.file",<a name="line.461"></a>
+<span class="sourceLineNo">462</span>        "hbase.thrift.kerberos.principal", host);<a name="line.462"></a>
+<span class="sourceLineNo">463</span>    }<a name="line.463"></a>
+<span class="sourceLineNo">464</span><a name="line.464"></a>
+<span class="sourceLineNo">465</span>    UserGroupInformation realUser = userProvider.getCurrent().getUGI();<a name="line.465"></a>
+<span class="sourceLineNo">466</span>    String stringQop = conf.get(THRIFT_QOP_KEY);<a name="line.466"></a>
+<span class="sourceLineNo">467</span>    SaslUtil.QualityOfProtection qop = null;<a name="line.467"></a>
+<span class="sourceLineNo">468</span>    if (stringQop != null) {<a name="line.468"></a>
+<span class="sourceLineNo">469</span>      qop = SaslUtil.getQop(stringQop);<a name="line.469"></a>
+<span class="sourceLineNo">470</span>      if (!securityEnabled) {<a name="line.470"></a>
+<span class="sourceLineNo">471</span>        throw new IOException("Thrift server must"<a name="line.471"></a>
+<span class="sourceLineNo">472</span>          + " run in secure mode to support authentication");<a name="line.472"></a>
+<span class="sourceLineNo">473</span>      }<a name="line.473"></a>
+<span class="sourceLineNo">474</span>      // Extract the name from the principal<a name="line.474"></a>
+<span class="sourceLineNo">475</span>      name = SecurityUtil.getUserFromPrincipal(<a name="line.475"></a>
+<span class="sourceLineNo">476</span>        conf.get("hbase.thrift.kerberos.principal"));<a name="line.476"></a>
+<span class="sourceLineNo">477</span>    }<a name="line.477"></a>
+<span class="sourceLineNo">478</span><a name="line.478"></a>
+<span class="sourceLineNo">479</span>    boolean nonblocking = cmd.hasOption("nonblocking");<a name="line.479"></a>
+<span class="sourceLineNo">480</span>    boolean hsha = cmd.hasOption("hsha");<a name="line.480"></a>
+<span class="sourceLineNo">481</span>    boolean selector = cmd.hasOption("selector");<a name="line.481"></a>
+<span class="sourceLineNo">482</span><a name="line.482"></a>
+<span class="sourceLineNo">483</span>    ThriftMetrics metrics = new ThriftMetrics(conf, ThriftMetrics.ThriftServerType.TWO);<a name="line.483"></a>
+<span class="sourceLineNo">484</span>    final JvmPauseMonitor pauseMonitor = new JvmPauseMonitor(conf, metrics.getSource());<a name="line.484"></a>
+<span class="sourceLineNo">485</span><a name="line.485"></a>
+<span class="sourceLineNo">486</span>    String implType = "threadpool";<a name="line.486"></a>
+<span class="sourceLineNo">487</span>    if (nonblocking) {<a name="line.487"></a>
+<span class="sourceLineNo">488</span>      implType = "nonblocking";<a name="line.488"></a>
+<span class="sourceLineNo">489</span>    } else if (hsha) {<a name="line.489"></a>
+<span class="sourceLineNo">490</span>      implType = "hsha";<a name="line.490"></a>
+<span class="sourceLineNo">491</span>    } else if (selector) {<a name="line.491"></a>
+<span class="sourceLineNo">492</span>      implType = "selector";<a name="line.492"></a>
+<span class="sourceLineNo">493</span>    }<a name="line.493"></a>
+<span class="sourceLineNo">494</span><a name="line.494"></a>
+<span class="sourceLineNo">495</span>    conf.set("hbase.regionserver.thrift.server.type", implType);<a name="line.495"></a>
+<span class="sourceLineNo">496</span>    conf.setInt("hbase.regionserver.thrift.port", listenPort);<a name="line.496"></a>
+<span class="sourceLineNo">497</span>    registerFilters(conf);<a name="line.497"></a>
+<span class="sourceLineNo">498</span><a name="line.498"></a>
+<span class="sourceLineNo">499</span>    // Construct correct ProtocolFactory<a name="line.499"></a>
+<span class="sourceLineNo">500</span>    boolean compact = cmd.hasOption("compact") ||<a name="line.500"></a>
+<span class="sourceLineNo">501</span>        conf.getBoolean("hbase.regionserver.thrift.compact", false);<a name="line.501"></a>
+<span class="sourceLineNo">502</span>    TProtocolFactory protocolFactory = getTProtocolFactory(compact);<a name="line.502"></a>
+<span class="sourceLineNo">503</span>    final ThriftHBaseServiceHandler hbaseHandler =<a name="line.503"></a>
+<span class="sourceLineNo">504</span>      new ThriftHBaseServiceHandler(conf, userProvider);<a name="line.504"></a>
+<span class="sourceLineNo">505</span>    THBaseService.Iface handler =<a name="line.505"></a>
+<span class="sourceLineNo">506</span>      ThriftHBaseServiceHandler.newInstance(hbaseHandler, metrics);<a name="line.506"></a>
+<span class="sourceLineNo">507</span>    final THBaseService.Processor p = new THBaseService.Processor(handler);<a name="line.507"></a>
+<span class="sourceLineNo">508</span>    conf.setBoolean("hbase.regionserver.thrift.compact", compact);<a name="line.508"></a>
+<span class="sourceLineNo">509</span>    TProcessor processor = p;<a name="line.509"></a>
+<span class="sourceLineNo">510</span><a name="line.510"></a>
+<span class="sourceLineNo">511</span>    boolean framed = cmd.hasOption("framed") ||<a name="line.511"></a>
+<span class="sourceLineNo">512</span>        conf.getBoolean("hbase.regionserver.thrift.framed", false) || nonblocking || hsha;<a name="line.512"></a>
+<span class="sourceLineNo">513</span>    TTransportFactory transportFactory = getTTransportFactory(qop, name, host, framed,<a name="line.513"></a>
+<span class="sourceLineNo">514</span>        conf.getInt("hbase.regionserver.thrift.framed.max_frame_size_in_mb", 2) * 1024 * 1024);<a name="line.514"></a>
+<span class="sourceLineNo">515</span>    InetSocketAddress inetSocketAddress = bindToPort(bindAddress, listenPort);<a name="line.515"></a>
+<span class="sourceLineNo">516</span>    conf.setBoolean("hbase.regionserver.thrift.framed", framed);<a name="line.516"></a>
+<span class="sourceLineNo">517</span>    if (qop != null) {<a name="line.517"></a>
+<span class="sourceLineNo">518</span>      // Create a processor wrapper, to get the caller<a name="line.518"></a>
+<span class="sourceLineNo">519</span>      processor = new TProcessor() {<a name="line.519"></a>
+<span class="sourceLineNo">520</span>        @Override<a name="line.520"></a>
+<span class="sourceLineNo">521</span>        public boolean process(TProtocol inProt,<a name="line.521"></a>
+<span class="sourceLineNo">522</span>            TProtocol outProt) throws TException {<a name="line.522"></a>
+<span class="sourceLineNo">523</span>          TSaslServerTransport saslServerTransport =<a name="line.523"></a>
+<span class="sourceLineNo">524</span>            (TSaslServerTransport)inProt.getTransport();<a name="line.524"></a>
+<span class="sourceLineNo">525</span>          SaslServer saslServer = saslServerTransport.getSaslServer();<a name="line.525"></a>
+<span class="sourceLineNo">526</span>          String principal = saslServer.getAuthorizationID();<a name="line.526"></a>
+<span class="sourceLineNo">527</span>          hbaseHandler.setEffectiveUser(principal);<a name="line.527"></a>
+<span class="sourceLineNo">528</span>          return p.process(inProt, outProt);<a name="line.528"></a>
+<span class="sourceLineNo">529</span>        }<a name="line.529"></a>
+<span class="sourceLineNo">530</span>      };<a name="line.530"></a>
 <span class="sourceLineNo">531</span>    }<a name="line.531"></a>
 <span class="sourceLineNo">532</span><a name="line.532"></a>
-<span class="sourceLineNo">533</span>    // check for user-defined info server port setting, if so override the conf<a name="line.533"></a>
-<span class="sourceLineNo">534</span>    try {<a name="line.534"></a>
-<span class="sourceLineNo">535</span>      if (cmd.hasOption("infoport")) {<a name="line.535"></a>
-<span class="sourceLineNo">536</span>        String val = cmd.getOptionValue("infoport");<a name="line.536"></a>
-<span class="sourceLineNo">537</span>        conf.setInt("hbase.thrift.info.port", Integer.parseInt(val));<a name="line.537"></a>
-<span class="sourceLineNo">538</span>        log.debug("Web UI port set to " + val);<a name="line.538"></a>
-<span class="sourceLineNo">539</span>      }<a name="line.539"></a>
-<span class="sourceLineNo">540</span>    } catch (NumberFormatException e) {<a name="line.540"></a>
-<span class="sourceLineNo">541</span>      log.error("Could not parse the value provided for the infoport option", e);<a name="line.541"></a>
-<span class="sourceLineNo">542</span>      printUsage();<a name="line.542"></a>
-<span class="sourceLineNo">543</span>      System.exit(1);<a name="line.543"></a>
-<span class="sourceLineNo">544</span>    }<a name="line.544"></a>
-<span class="sourceLineNo">545</span><a name="line.545"></a>
-<span class="sourceLineNo">546</span>    // Put up info server.<a name="line.546"></a>
-<span class="sourceLineNo">547</span>    int port = conf.getInt("hbase.thrift.info.port", 9095);<a name="line.547"></a>
-<span class="sourceLineNo">548</span>    if (port &gt;= 0) {<a name="line.548"></a>
-<span class="sourceLineNo">549</span>      conf.setLong("startcode", System.currentTimeMillis());<a name="line.549"></a>
-<span class="sourceLineNo">550</span>      String a = conf.get("hbase.thrift.info.bindAddress", "0.0.0.0");<a name="line.550"></a>
-<span class="sourceLineNo">551</span>      InfoServer infoServer = new InfoServer("thrift", a, port, false, conf);<a name="line.551"></a>
-<span class="sourceLineNo">552</span>      infoServer.setAttribute("hbase.conf", conf);<a name="line.552"></a>
-<span class="sourceLineNo">553</span>      infoServer.start();<a name="line.553"></a>
+<span class="sourceLineNo">533</span>    if (cmd.hasOption("w")) {<a name="line.533"></a>
+<span class="sourceLineNo">534</span>      workerThreads = Integer.parseInt(cmd.getOptionValue("w"));<a name="line.534"></a>
+<span class="sourceLineNo">535</span>    }<a name="line.535"></a>
+<span class="sourceLineNo">536</span>    if (cmd.hasOption("s")) {<a name="line.536"></a>
+<span class="sourceLineNo">537</span>      selectorThreads = Integer.parseInt(cmd.getOptionValue("s"));<a name="line.537"></a>
+<span class="sourceLineNo">538</span>    }<a name="line.538"></a>
+<span class="sourceLineNo">539</span>    if (cmd.hasOption("q")) {<a name="line.539"></a>
+<span class="sourceLineNo">540</span>      maxCallQueueSize = Integer.parseInt(cmd.getOptionValue("q"));<a name="line.540"></a>
+<span class="sourceLineNo">541</span>    }<a name="line.541"></a>
+<span class="sourceLineNo">542</span><a name="line.542"></a>
+<span class="sourceLineNo">543</span>    // check for user-defined info server port setting, if so override the conf<a name="line.543"></a>
+<span class="sourceLineNo">544</span>    try {<a name="line.544"></a>
+<span class="sourceLineNo">545</span>      if (cmd.hasOption("infoport")) {<a name="line.545"></a>
+<span class="sourceLineNo">546</span>        String val = cmd.getOptionValue("infoport");<a name="line.546"></a>
+<span class="sourceLineNo">547</span>        conf.setInt("hbase.thrift.info.port", Integer.parseInt(val));<a name="line.547"></a>
+<span class="sourceLineNo">548</span>        log.debug("Web UI port set to " + val);<a name="line.548"></a>
+<span class="sourceLineNo">549</span>      }<a name="line.549"></a>
+<span class="sourceLineNo">550</span>    } catch (NumberFormatException e) {<a name="line.550"></a>
+<span class="sourceLineNo">551</span>      log.error("Could not parse the value provided for the infoport option", e);<a name="line.551"></a>
+<span class="sourceLineNo">552</span>      printUsage();<a name="line.552"></a>
+<span class="sourceLineNo">553</span>      System.exit(1);<a name="line.553"></a>
 <span class="sourceLineNo">554</span>    }<a name="line.554"></a>
 <span class="sourceLineNo">555</span><a name="line.555"></a>
-<span class="sourceLineNo">556</span>    if (nonblocking) {<a name="line.556"></a>
-<span class="sourceLineNo">557</span>      server = getTNonBlockingServer(protocolFactory,<a name="line.557"></a>
-<span class="sourceLineNo">558</span>          processor,<a name="line.558"></a>
-<span class="sourceLineNo">559</span>          transportFactory,<a name="line.559"></a>
-<span class="sourceLineNo">560</span>          inetSocketAddress);<a name="line.560"></a>
-<span class="sourceLineNo">561</span>    } else if (hsha) {<a name="line.561"></a>
-<span class="sourceLineNo">562</span>      server = getTHsHaServer(protocolFactory,<a name="line.562"></a>
-<span class="sourceLineNo">563</span>          processor,<a name="line.563"></a>
-<span class="sourceLineNo">564</span>          transportFactory,<a name="line.564"></a>
-<span class="sourceLineNo">565</span>          workerThreads,<a name="line.565"></a>
-<span class="sourceLineNo">566</span>          maxCallQueueSize,<a name="line.566"></a>
-<span class="sourceLineNo">567</span>          inetSocketAddress,<a name="line.567"></a>
-<span class="sourceLineNo">568</span>          metrics);<a name="line.568"></a>
-<span class="sourceLineNo">569</span>    } else if (selector) {<a name="line.569"></a>
-<span class="sourceLineNo">570</span>      server = getTThreadedSelectorServer(protocolFactory,<a name="line.570"></a>
-<span class="sourceLineNo">571</span>          processor,<a name="line.571"></a>
-<span class="sourceLineNo">572</span>          transportFactory,<a name="line.572"></a>
-<span class="sourceLineNo">573</span>          workerThreads,<a name="line.573"></a>
-<span class="sourceLineNo">574</span>          selectorThreads,<a name="line.574"></a>
-<span class="sourceLineNo">575</span>          maxCallQueueSize,<a name="line.575"></a>
-<span class="sourceLineNo">576</span>          inetSocketAddress,<a name="line.576"></a>
-<span class="sourceLineNo">577</span>          metrics);<a name="line.577"></a>
-<span class="sourceLineNo">578</span>    } else {<a name="line.578"></a>
-<span class="sourceLineNo">579</span>      server = getTThreadPoolServer(protocolFactory,<a name="line.579"></a>
-<span class="sourceLineNo">580</span>          processor,<a name="line.580"></a>
-<span class="sourceLineNo">581</span>          transportFactory,<a name="line.581"></a>
-<span class="sourceLineNo">582</span>          workerThreads,<a name="line.582"></a>
-<span class="sourceLineNo">583</span>          inetSocketAddress,<a name="line.583"></a>
-<span class="sourceLineNo">584</span>          backlog,<a name="line.584"></a>
-<span class="sourceLineNo">585</span>          readTimeout,<a name="line.585"></a>
-<span class="sourceLineNo">586</span>          metrics);<a name="line.586"></a>
-<span class="sourceLineNo">587</span>    }<a name="line.587"></a>
-<span class="sourceLineNo">588</span><a name="line.588"></a>
-<span class="sourceLineNo">589</span>    final TServer tserver = server;<a name="line.589"></a>
-<span class="sourceLineNo">590</span>    realUser.doAs(<a name="line.590"></a>
-<span class="sourceLineNo">591</span>      new PrivilegedAction&lt;Object&gt;() {<a name="line.591"></a>
-<span class="sourceLineNo">592</span>        @Override<a name="line.592"></a>
-<span class="sourceLineNo">593</span>        public Object run() {<a name="line.593"></a>
-<span class="sourceLineNo">594</span>          pauseMonitor.start();<a name="line.594"></a>
-<span class="sourceLineNo">595</span>          try {<a name="line.595"></a>
-<span class="sourceLineNo">596</span>            tserver.serve();<a name="line.596"></a>
-<span class="sourceLineNo">597</span>            return null;<a name="line.597"></a>
-<span class="sourceLineNo">598</span>          } finally {<a name="line.598"></a>
-<span class="sourceLineNo">599</span>            pauseMonitor.stop();<a name="line.599"></a>
-<span class="sourceLineNo">600</span>          }<a name="line.600"></a>
-<span class="sourceLineNo">601</span>        }<a name="line.601"></a>
-<span class="sourceLineNo">602</span>      });<a name="line.602"></a>
-<span class="sourceLineNo">603</span>    // when tserver.stop eventually happens we'll get here.<a name="line.603"></a>
-<span class="sourceLineNo">604</span>    return 0;<a name="line.604"></a>
-<span class="sourceLineNo">605</span>  }<a name="line.605"></a>
-<span class="sourceLineNo">606</span>}<a name="line.606"></a>
+<span class="sourceLineNo">556</span>    // Put up info server.<a name="line.556"></a>
+<span class="sourceLineNo">557</span>    int port = conf.getInt("hbase.thrift.info.port", 9095);<a name="line.557"></a>
+<span class="sourceLineNo">558</span>    if (port &gt;= 0) {<a name="line.558"></a>
+<span class="sourceLineNo">559</span>      conf.setLong("startcode", System.currentTimeMillis());<a name="line.559"></a>
+<span class="sourceLineNo">560</span>      String a = conf.get("hbase.thrift.info.bindAddress", "0.0.0.0");<a name="line.560"></a>
+<span class="sourceLineNo">561</span>      InfoServer infoServer = new InfoServer("thrift", a, port, false, conf);<a name="line.561"></a>
+<span class="sourceLineNo">562</span>      infoServer.setAttribute("hbase.conf", conf);<a name="line.562"></a>
+<span class="sourceLineNo">563</span>      infoServer.start();<a name="line.563"></a>
+<span class="sourceLineNo">564</span>    }<a name="line.564"></a>
+<span class="sourceLineNo">565</span><a name="line.565"></a>
+<span class="sourceLineNo">566</span>    if (nonblocking) {<a name="line.566"></a>
+<span class="sourceLineNo">567</span>      server = getTNonBlockingServer(protocolFactory,<a name="line.567"></a>
+<span class="sourceLineNo">568</span>          processor,<a name="line.568"></a>
+<span class="sourceLineNo">569</span>          transportFactory,<a name="line.569"></a>
+<span class="sourceLineNo">570</span>          inetSocketAddress);<a name="line.570"></a>
+<span class="sourceLineNo">571</span>    } else if (hsha) {<a name="line.571"></a>
+<span class="sourceLineNo">572</span>      server = getTHsHaServer(protocolFactory,<a name="line.572"></a>
+<span class="sourceLineNo">573</span>          processor,<a name="line.573"></a>
+<span class="sourceLineNo">574</span>          transportFactory,<a name="line.574"></a>
+<span class="sourceLineNo">575</span>          workerThreads,<a name="line.575"></a>
+<span class="sourceLineNo">576</span>          maxCallQueueSize,<a name="line.576"></a>
+<span class="sourceLineNo">577</span>          inetSocketAddress,<a name="line.577"></a>
+<span class="sourceLineNo">578</span>          metrics);<a name="line.578"></a>
+<span class="sourceLineNo">579</span>    } else if (selector) {<a name="line.579"></a>
+<span class="sourceLineNo">580</span>      server = getTThreadedSelectorServer(protocolFactory,<a name="line.580"></a>
+<span class="sourceLineNo">581</span>          processor,<a name="line.581"></a>
+<span class="sourceLineNo">582</span>          transportFactory,<a name="line.582"></a>
+<span class="sourceLineNo">583</span>          workerThreads,<a name="line.583"></a>
+<span class="sourceLineNo">584</span>          selectorThreads,<a name="line.584"></a>
+<span class="sourceLineNo">585</span>          maxCallQueueSize,<a name="line.585"></a>
+<span class="sourceLineNo">586</span>     

<TRUNCATED>

Mime
View raw message