View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.hbase.thrift;
20  
21  import static org.apache.hadoop.hbase.util.Bytes.getBytes;
22  
23  import java.io.IOException;
24  import java.net.InetAddress;
25  import java.net.InetSocketAddress;
26  import java.net.UnknownHostException;
27  import java.nio.ByteBuffer;
28  import java.security.PrivilegedAction;
29  import java.util.ArrayList;
30  import java.util.Arrays;
31  import java.util.Collections;
32  import java.util.HashMap;
33  import java.util.List;
34  import java.util.Map;
35  import java.util.TreeMap;
36  import java.util.concurrent.BlockingQueue;
37  import java.util.concurrent.ExecutorService;
38  import java.util.concurrent.LinkedBlockingQueue;
39  import java.util.concurrent.ThreadPoolExecutor;
40  import java.util.concurrent.TimeUnit;
41  
42  import javax.security.auth.callback.Callback;
43  import javax.security.auth.callback.UnsupportedCallbackException;
44  import javax.security.sasl.AuthorizeCallback;
45  import javax.security.sasl.Sasl;
46  import javax.security.sasl.SaslServer;
47  
48  import org.apache.commons.cli.CommandLine;
49  import org.apache.commons.cli.Option;
50  import org.apache.commons.cli.OptionGroup;
51  import org.apache.commons.logging.Log;
52  import org.apache.commons.logging.LogFactory;
53  import org.apache.hadoop.conf.Configuration;
54  import org.apache.hadoop.hbase.HBaseConfiguration;
55  import org.apache.hadoop.hbase.HColumnDescriptor;
56  import org.apache.hadoop.hbase.HConstants;
57  import org.apache.hadoop.hbase.HRegionInfo;
58  import org.apache.hadoop.hbase.HRegionLocation;
59  import org.apache.hadoop.hbase.HTableDescriptor;
60  import org.apache.hadoop.hbase.KeyValue;
61  import org.apache.hadoop.hbase.ServerName;
62  import org.apache.hadoop.hbase.TableName;
63  import org.apache.hadoop.hbase.TableNotFoundException;
64  import org.apache.hadoop.hbase.classification.InterfaceAudience;
65  import org.apache.hadoop.hbase.client.Admin;
66  import org.apache.hadoop.hbase.client.Append;
67  import org.apache.hadoop.hbase.client.Delete;
68  import org.apache.hadoop.hbase.client.Durability;
69  import org.apache.hadoop.hbase.client.Get;
70  import org.apache.hadoop.hbase.client.HBaseAdmin;
71  import org.apache.hadoop.hbase.client.Increment;
72  import org.apache.hadoop.hbase.client.OperationWithAttributes;
73  import org.apache.hadoop.hbase.client.Put;
74  import org.apache.hadoop.hbase.client.RegionLocator;
75  import org.apache.hadoop.hbase.client.Result;
76  import org.apache.hadoop.hbase.client.ResultScanner;
77  import org.apache.hadoop.hbase.client.Scan;
78  import org.apache.hadoop.hbase.client.Table;
79  import org.apache.hadoop.hbase.filter.Filter;
80  import org.apache.hadoop.hbase.filter.ParseFilter;
81  import org.apache.hadoop.hbase.filter.PrefixFilter;
82  import org.apache.hadoop.hbase.filter.WhileMatchFilter;
83  import org.apache.hadoop.hbase.security.SecurityUtil;
84  import org.apache.hadoop.hbase.security.UserProvider;
85  import org.apache.hadoop.hbase.thrift.CallQueue.Call;
86  import org.apache.hadoop.hbase.thrift.generated.AlreadyExists;
87  import org.apache.hadoop.hbase.thrift.generated.BatchMutation;
88  import org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor;
89  import org.apache.hadoop.hbase.thrift.generated.Hbase;
90  import org.apache.hadoop.hbase.thrift.generated.IOError;
91  import org.apache.hadoop.hbase.thrift.generated.IllegalArgument;
92  import org.apache.hadoop.hbase.thrift.generated.Mutation;
93  import org.apache.hadoop.hbase.thrift.generated.TAppend;
94  import org.apache.hadoop.hbase.thrift.generated.TCell;
95  import org.apache.hadoop.hbase.thrift.generated.TIncrement;
96  import org.apache.hadoop.hbase.thrift.generated.TRegionInfo;
97  import org.apache.hadoop.hbase.thrift.generated.TRowResult;
98  import org.apache.hadoop.hbase.thrift.generated.TScan;
99  import org.apache.hadoop.hbase.util.Bytes;
100 import org.apache.hadoop.hbase.util.ConnectionCache;
101 import org.apache.hadoop.hbase.util.Strings;
102 import org.apache.hadoop.net.DNS;
103 import org.apache.hadoop.security.SaslRpcServer.SaslGssCallbackHandler;
104 import org.apache.hadoop.security.UserGroupInformation;
105 import org.apache.hadoop.security.authorize.ProxyUsers;
106 import org.apache.thrift.TException;
107 import org.apache.thrift.TProcessor;
108 import org.apache.thrift.protocol.TBinaryProtocol;
109 import org.apache.thrift.protocol.TCompactProtocol;
110 import org.apache.thrift.protocol.TProtocol;
111 import org.apache.thrift.protocol.TProtocolFactory;
112 import org.apache.thrift.server.THsHaServer;
113 import org.apache.thrift.server.TNonblockingServer;
114 import org.apache.thrift.server.TServer;
115 import org.apache.thrift.server.TServlet;
116 import org.apache.thrift.server.TThreadedSelectorServer;
117 import org.apache.thrift.transport.TFramedTransport;
118 import org.apache.thrift.transport.TNonblockingServerSocket;
119 import org.apache.thrift.transport.TNonblockingServerTransport;
120 import org.apache.thrift.transport.TSaslServerTransport;
121 import org.apache.thrift.transport.TServerSocket;
122 import org.apache.thrift.transport.TServerTransport;
123 import org.apache.thrift.transport.TTransportFactory;
124 import org.mortbay.jetty.Connector;
125 import org.mortbay.jetty.Server;
126 import org.mortbay.jetty.nio.SelectChannelConnector;
127 import org.mortbay.jetty.security.SslSelectChannelConnector;
128 import org.mortbay.jetty.servlet.Context;
129 import org.mortbay.jetty.servlet.ServletHolder;
130 import org.mortbay.thread.QueuedThreadPool;
131 
132 import com.google.common.base.Joiner;
133 import com.google.common.base.Throwables;
134 import com.google.common.util.concurrent.ThreadFactoryBuilder;
135 
136 /**
137  * ThriftServerRunner - this class starts up a Thrift server which implements
138  * the Hbase API specified in the Hbase.thrift IDL file.
139  */
140 @InterfaceAudience.Private
141 @SuppressWarnings("deprecation")
142 public class ThriftServerRunner implements Runnable {
143 
144   private static final Log LOG = LogFactory.getLog(ThriftServerRunner.class);
145 
146   static final String SERVER_TYPE_CONF_KEY =
147       "hbase.regionserver.thrift.server.type";
148 
149   static final String BIND_CONF_KEY = "hbase.regionserver.thrift.ipaddress";
150   static final String COMPACT_CONF_KEY = "hbase.regionserver.thrift.compact";
151   static final String FRAMED_CONF_KEY = "hbase.regionserver.thrift.framed";
152   static final String MAX_FRAME_SIZE_CONF_KEY = "hbase.regionserver.thrift.framed.max_frame_size_in_mb";
153   static final String PORT_CONF_KEY = "hbase.regionserver.thrift.port";
154   static final String COALESCE_INC_KEY = "hbase.regionserver.thrift.coalesceIncrement";
155   static final String USE_HTTP_CONF_KEY = "hbase.regionserver.thrift.http";
156   static final String HTTP_MIN_THREADS = "hbase.thrift.http_threads.min";
157   static final String HTTP_MAX_THREADS = "hbase.thrift.http_threads.max";
158 
159   static final String THRIFT_SSL_ENABLED = "hbase.thrift.ssl.enabled";
160   static final String THRIFT_SSL_KEYSTORE_STORE = "hbase.thrift.ssl.keystore.store";
161   static final String THRIFT_SSL_KEYSTORE_PASSWORD = "hbase.thrift.ssl.keystore.password";
162   static final String THRIFT_SSL_KEYSTORE_KEYPASSWORD = "hbase.thrift.ssl.keystore.keypassword";
163 
164 
165   /**
166    * Thrift quality of protection configuration key. Valid values can be:
167    * auth-conf: authentication, integrity and confidentiality checking
168    * auth-int: authentication and integrity checking
169    * auth: authentication only
170    *
171    * This is used to authenticate the callers and support impersonation.
172    * The thrift server and the HBase cluster must run in secure mode.
173    */
174   static final String THRIFT_QOP_KEY = "hbase.thrift.security.qop";
175 
176   private static final String DEFAULT_BIND_ADDR = "0.0.0.0";
177   public static final int DEFAULT_LISTEN_PORT = 9090;
178   public static final int HREGION_VERSION = 1;
179   static final String THRIFT_SUPPORT_PROXYUSER = "hbase.thrift.support.proxyuser";
180   private final int listenPort;
181 
182   private Configuration conf;
183   volatile TServer tserver;
184   volatile Server httpServer;
185   private final Hbase.Iface handler;
186   private final ThriftMetrics metrics;
187   private final HBaseHandler hbaseHandler;
188   private final UserGroupInformation realUser;
189 
190   private final String qop;
191   private String host;
192 
193   private final boolean securityEnabled;
194   private final boolean doAsEnabled;
195 
196   /** An enum of server implementation selections */
197   enum ImplType {
198     HS_HA("hsha", true, THsHaServer.class, true),
199     NONBLOCKING("nonblocking", true, TNonblockingServer.class, true),
200     THREAD_POOL("threadpool", false, TBoundedThreadPoolServer.class, true),
201     THREADED_SELECTOR(
202         "threadedselector", true, TThreadedSelectorServer.class, true);
203 
204     public static final ImplType DEFAULT = THREAD_POOL;
205 
206     final String option;
207     final boolean isAlwaysFramed;
208     final Class<? extends TServer> serverClass;
209     final boolean canSpecifyBindIP;
210 
211     ImplType(String option, boolean isAlwaysFramed,
212         Class<? extends TServer> serverClass, boolean canSpecifyBindIP) {
213       this.option = option;
214       this.isAlwaysFramed = isAlwaysFramed;
215       this.serverClass = serverClass;
216       this.canSpecifyBindIP = canSpecifyBindIP;
217     }
218 
219     /**
220      * @return <code>-option</code> so we can get the list of options from
221      *         {@link #values()}
222      */
223     @Override
224     public String toString() {
225       return "-" + option;
226     }
227 
228     String getDescription() {
229       StringBuilder sb = new StringBuilder("Use the " +
230           serverClass.getSimpleName());
231       if (isAlwaysFramed) {
232         sb.append(" This implies the framed transport.");
233       }
234       if (this == DEFAULT) {
235         sb.append("This is the default.");
236       }
237       return sb.toString();
238     }
239 
240     static OptionGroup createOptionGroup() {
241       OptionGroup group = new OptionGroup();
242       for (ImplType t : values()) {
243         group.addOption(new Option(t.option, t.getDescription()));
244       }
245       return group;
246     }
247 
248     static ImplType getServerImpl(Configuration conf) {
249       String confType = conf.get(SERVER_TYPE_CONF_KEY, THREAD_POOL.option);
250       for (ImplType t : values()) {
251         if (confType.equals(t.option)) {
252           return t;
253         }
254       }
255       throw new AssertionError("Unknown server ImplType.option:" + confType);
256     }
257 
258     static void setServerImpl(CommandLine cmd, Configuration conf) {
259       ImplType chosenType = null;
260       int numChosen = 0;
261       for (ImplType t : values()) {
262         if (cmd.hasOption(t.option)) {
263           chosenType = t;
264           ++numChosen;
265         }
266       }
267       if (numChosen < 1) {
268         LOG.info("Using default thrift server type");
269         chosenType = DEFAULT;
270       } else if (numChosen > 1) {
271         throw new AssertionError("Exactly one option out of " +
272           Arrays.toString(values()) + " has to be specified");
273       }
274       LOG.info("Using thrift server type " + chosenType.option);
275       conf.set(SERVER_TYPE_CONF_KEY, chosenType.option);
276     }
277 
278     public String simpleClassName() {
279       return serverClass.getSimpleName();
280     }
281 
282     public static List<String> serversThatCannotSpecifyBindIP() {
283       List<String> l = new ArrayList<String>();
284       for (ImplType t : values()) {
285         if (!t.canSpecifyBindIP) {
286           l.add(t.simpleClassName());
287         }
288       }
289       return l;
290     }
291 
292   }
293 
294   public ThriftServerRunner(Configuration conf) throws IOException {
295     UserProvider userProvider = UserProvider.instantiate(conf);
296     // login the server principal (if using secure Hadoop)
297     securityEnabled = userProvider.isHadoopSecurityEnabled()
298       && userProvider.isHBaseSecurityEnabled();
299     if (securityEnabled) {
300       host = Strings.domainNamePointerToHostName(DNS.getDefaultHost(
301         conf.get("hbase.thrift.dns.interface", "default"),
302         conf.get("hbase.thrift.dns.nameserver", "default")));
303       userProvider.login("hbase.thrift.keytab.file",
304         "hbase.thrift.kerberos.principal", host);
305     }
306     this.conf = HBaseConfiguration.create(conf);
307     this.listenPort = conf.getInt(PORT_CONF_KEY, DEFAULT_LISTEN_PORT);
308     this.metrics = new ThriftMetrics(conf, ThriftMetrics.ThriftServerType.ONE);
309     this.hbaseHandler = new HBaseHandler(conf, userProvider);
310     this.hbaseHandler.initMetrics(metrics);
311     this.handler = HbaseHandlerMetricsProxy.newInstance(
312       hbaseHandler, metrics, conf);
313     this.realUser = userProvider.getCurrent().getUGI();
314     qop = conf.get(THRIFT_QOP_KEY);
315     doAsEnabled = conf.getBoolean(THRIFT_SUPPORT_PROXYUSER, false);
316     if (qop != null) {
317       if (!qop.equals("auth") && !qop.equals("auth-int")
318           && !qop.equals("auth-conf")) {
319         throw new IOException("Invalid " + THRIFT_QOP_KEY + ": " + qop
320           + ", it must be 'auth', 'auth-int', or 'auth-conf'");
321       }
322       if (!securityEnabled) {
323         throw new IOException("Thrift server must"
324           + " run in secure mode to support authentication");
325       }
326     }
327   }
328 
329   /*
330    * Runs the Thrift server
331    */
332   @Override
333   public void run() {
334     realUser.doAs(new PrivilegedAction<Object>() {
335       @Override
336       public Object run() {
337         try {
338           if (conf.getBoolean(USE_HTTP_CONF_KEY, false)) {
339             setupHTTPServer();
340             httpServer.start();
341             httpServer.join();
342           } else {
343             setupServer();
344             tserver.serve();
345           }
346         } catch (Exception e) {
347           LOG.fatal("Cannot run ThriftServer", e);
348           // Crash the process if the ThriftServer is not running
349           System.exit(-1);
350         }
351         return null;
352       }
353     });
354 
355   }
356 
357   public void shutdown() {
358     if (tserver != null) {
359       tserver.stop();
360       tserver = null;
361     }
362     if (httpServer != null) {
363       try {
364         httpServer.stop();
365         httpServer = null;
366       } catch (Exception e) {
367         LOG.error("Problem encountered in shutting down HTTP server " + e.getCause());
368       }
369       httpServer = null;
370     }
371   }
372 
373   private void setupHTTPServer() throws IOException {
374     TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
375     TProcessor processor = new Hbase.Processor<Hbase.Iface>(handler);
376     TServlet thriftHttpServlet = new ThriftHttpServlet(processor, protocolFactory, realUser,
377         conf, hbaseHandler, securityEnabled, doAsEnabled);
378 
379     httpServer = new Server();
380     // Context handler
381     Context context = new Context(httpServer, "/", Context.SESSIONS);
382     context.setContextPath("/");
383     String httpPath = "/*";
384     httpServer.setHandler(context);
385     context.addServlet(new ServletHolder(thriftHttpServlet), httpPath);
386 
387     // set up Jetty and run the embedded server
388     Connector connector = new SelectChannelConnector();
389     if(conf.getBoolean(THRIFT_SSL_ENABLED, false)) {
390       SslSelectChannelConnector sslConnector = new SslSelectChannelConnector();
391       String keystore = conf.get(THRIFT_SSL_KEYSTORE_STORE);
392       String password = HBaseConfiguration.getPassword(conf,
393           THRIFT_SSL_KEYSTORE_PASSWORD, null);
394       String keyPassword = HBaseConfiguration.getPassword(conf,
395           THRIFT_SSL_KEYSTORE_KEYPASSWORD, password);
396       sslConnector.setKeystore(keystore);
397       sslConnector.setPassword(password);
398       sslConnector.setKeyPassword(keyPassword);
399       connector = sslConnector;
400     }
401     String host = getBindAddress(conf).getHostAddress();
402     connector.setPort(listenPort);
403     connector.setHost(host);
404     httpServer.addConnector(connector);
405 
406     if (doAsEnabled) {
407       ProxyUsers.refreshSuperUserGroupsConfiguration(conf);
408     }
409 
410     // Set the default max thread number to 100 to limit
411     // the number of concurrent requests so that Thrfit HTTP server doesn't OOM easily.
412     // Jetty set the default max thread number to 250, if we don't set it.
413     //
414     // Our default min thread number 2 is the same as that used by Jetty.
415     int minThreads = conf.getInt(HTTP_MIN_THREADS, 2);
416     int maxThreads = conf.getInt(HTTP_MAX_THREADS, 100);
417     QueuedThreadPool threadPool = new QueuedThreadPool(maxThreads);
418     threadPool.setMinThreads(minThreads);
419     httpServer.setThreadPool(threadPool);
420 
421     httpServer.setSendServerVersion(false);
422     httpServer.setSendDateHeader(false);
423     httpServer.setStopAtShutdown(true);
424 
425     LOG.info("Starting Thrift HTTP Server on " + Integer.toString(listenPort));
426   }
427 
428   /**
429    * Setting up the thrift TServer
430    */
431   private void setupServer() throws Exception {
432     // Construct correct ProtocolFactory
433     TProtocolFactory protocolFactory;
434     if (conf.getBoolean(COMPACT_CONF_KEY, false)) {
435       LOG.debug("Using compact protocol");
436       protocolFactory = new TCompactProtocol.Factory();
437     } else {
438       LOG.debug("Using binary protocol");
439       protocolFactory = new TBinaryProtocol.Factory();
440     }
441 
442     final TProcessor p = new Hbase.Processor<Hbase.Iface>(handler);
443     ImplType implType = ImplType.getServerImpl(conf);
444     TProcessor processor = p;
445 
446     // Construct correct TransportFactory
447     TTransportFactory transportFactory;
448     if (conf.getBoolean(FRAMED_CONF_KEY, false) || implType.isAlwaysFramed) {
449       if (qop != null) {
450         throw new RuntimeException("Thrift server authentication"
451           + " doesn't work with framed transport yet");
452       }
453       transportFactory = new TFramedTransport.Factory(
454           conf.getInt(MAX_FRAME_SIZE_CONF_KEY, 2)  * 1024 * 1024);
455       LOG.debug("Using framed transport");
456     } else if (qop == null) {
457       transportFactory = new TTransportFactory();
458     } else {
459       // Extract the name from the principal
460       String name = SecurityUtil.getUserFromPrincipal(
461         conf.get("hbase.thrift.kerberos.principal"));
462       Map<String, String> saslProperties = new HashMap<String, String>();
463       saslProperties.put(Sasl.QOP, qop);
464       TSaslServerTransport.Factory saslFactory = new TSaslServerTransport.Factory();
465       saslFactory.addServerDefinition("GSSAPI", name, host, saslProperties,
466         new SaslGssCallbackHandler() {
467           @Override
468           public void handle(Callback[] callbacks)
469               throws UnsupportedCallbackException {
470             AuthorizeCallback ac = null;
471             for (Callback callback : callbacks) {
472               if (callback instanceof AuthorizeCallback) {
473                 ac = (AuthorizeCallback) callback;
474               } else {
475                 throw new UnsupportedCallbackException(callback,
476                     "Unrecognized SASL GSSAPI Callback");
477               }
478             }
479             if (ac != null) {
480               String authid = ac.getAuthenticationID();
481               String authzid = ac.getAuthorizationID();
482               if (!authid.equals(authzid)) {
483                 ac.setAuthorized(false);
484               } else {
485                 ac.setAuthorized(true);
486                 String userName = SecurityUtil.getUserFromPrincipal(authzid);
487                 LOG.info("Effective user: " + userName);
488                 ac.setAuthorizedID(userName);
489               }
490             }
491           }
492         });
493       transportFactory = saslFactory;
494 
495       // Create a processor wrapper, to get the caller
496       processor = new TProcessor() {
497         @Override
498         public boolean process(TProtocol inProt,
499             TProtocol outProt) throws TException {
500           TSaslServerTransport saslServerTransport =
501             (TSaslServerTransport)inProt.getTransport();
502           SaslServer saslServer = saslServerTransport.getSaslServer();
503           String principal = saslServer.getAuthorizationID();
504           hbaseHandler.setEffectiveUser(principal);
505           return p.process(inProt, outProt);
506         }
507       };
508     }
509 
510     if (conf.get(BIND_CONF_KEY) != null && !implType.canSpecifyBindIP) {
511       LOG.error("Server types " + Joiner.on(", ").join(
512           ImplType.serversThatCannotSpecifyBindIP()) + " don't support IP " +
513           "address binding at the moment. See " +
514           "https://issues.apache.org/jira/browse/HBASE-2155 for details.");
515       throw new RuntimeException(
516           "-" + BIND_CONF_KEY + " not supported with " + implType);
517     }
518 
519     if (implType == ImplType.HS_HA || implType == ImplType.NONBLOCKING ||
520         implType == ImplType.THREADED_SELECTOR) {
521 
522       InetAddress listenAddress = getBindAddress(conf);
523       TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(
524           new InetSocketAddress(listenAddress, listenPort));
525 
526       if (implType == ImplType.NONBLOCKING) {
527         TNonblockingServer.Args serverArgs =
528             new TNonblockingServer.Args(serverTransport);
529         serverArgs.processor(processor)
530                   .transportFactory(transportFactory)
531                   .protocolFactory(protocolFactory);
532         tserver = new TNonblockingServer(serverArgs);
533       } else if (implType == ImplType.HS_HA) {
534         THsHaServer.Args serverArgs = new THsHaServer.Args(serverTransport);
535         CallQueue callQueue =
536             new CallQueue(new LinkedBlockingQueue<Call>(), metrics);
537         ExecutorService executorService = createExecutor(
538             callQueue, serverArgs.getWorkerThreads());
539         serverArgs.executorService(executorService)
540                   .processor(processor)
541                   .transportFactory(transportFactory)
542                   .protocolFactory(protocolFactory);
543         tserver = new THsHaServer(serverArgs);
544       } else { // THREADED_SELECTOR
545         TThreadedSelectorServer.Args serverArgs =
546             new HThreadedSelectorServerArgs(serverTransport, conf);
547         CallQueue callQueue =
548             new CallQueue(new LinkedBlockingQueue<Call>(), metrics);
549         ExecutorService executorService = createExecutor(
550             callQueue, serverArgs.getWorkerThreads());
551         serverArgs.executorService(executorService)
552                   .processor(processor)
553                   .transportFactory(transportFactory)
554                   .protocolFactory(protocolFactory);
555         tserver = new TThreadedSelectorServer(serverArgs);
556       }
557       LOG.info("starting HBase " + implType.simpleClassName() +
558           " server on " + Integer.toString(listenPort));
559     } else if (implType == ImplType.THREAD_POOL) {
560       // Thread pool server. Get the IP address to bind to.
561       InetAddress listenAddress = getBindAddress(conf);
562 
563       TServerTransport serverTransport = new TServerSocket(
564           new InetSocketAddress(listenAddress, listenPort));
565 
566       TBoundedThreadPoolServer.Args serverArgs =
567           new TBoundedThreadPoolServer.Args(serverTransport, conf);
568       serverArgs.processor(processor)
569                 .transportFactory(transportFactory)
570                 .protocolFactory(protocolFactory);
571       LOG.info("starting " + ImplType.THREAD_POOL.simpleClassName() + " on "
572           + listenAddress + ":" + Integer.toString(listenPort)
573           + "; " + serverArgs);
574       TBoundedThreadPoolServer tserver =
575           new TBoundedThreadPoolServer(serverArgs, metrics);
576       this.tserver = tserver;
577     } else {
578       throw new AssertionError("Unsupported Thrift server implementation: " +
579           implType.simpleClassName());
580     }
581 
582     // A sanity check that we instantiated the right type of server.
583     if (tserver.getClass() != implType.serverClass) {
584       throw new AssertionError("Expected to create Thrift server class " +
585           implType.serverClass.getName() + " but got " +
586           tserver.getClass().getName());
587     }
588 
589 
590 
591     registerFilters(conf);
592   }
593 
594   ExecutorService createExecutor(BlockingQueue<Runnable> callQueue,
595                                  int workerThreads) {
596     ThreadFactoryBuilder tfb = new ThreadFactoryBuilder();
597     tfb.setDaemon(true);
598     tfb.setNameFormat("thrift-worker-%d");
599     return new ThreadPoolExecutor(workerThreads, workerThreads,
600             Long.MAX_VALUE, TimeUnit.SECONDS, callQueue, tfb.build());
601   }
602 
603   private InetAddress getBindAddress(Configuration conf)
604       throws UnknownHostException {
605     String bindAddressStr = conf.get(BIND_CONF_KEY, DEFAULT_BIND_ADDR);
606     return InetAddress.getByName(bindAddressStr);
607   }
608 
609   protected static class ResultScannerWrapper {
610 
611     private final ResultScanner scanner;
612     private final boolean sortColumns;
613     public ResultScannerWrapper(ResultScanner resultScanner,
614                                 boolean sortResultColumns) {
615       scanner = resultScanner;
616       sortColumns = sortResultColumns;
617    }
618 
619     public ResultScanner getScanner() {
620       return scanner;
621     }
622 
623     public boolean isColumnSorted() {
624       return sortColumns;
625     }
626   }
627 
628   /**
629    * The HBaseHandler is a glue object that connects Thrift RPC calls to the
630    * HBase client API primarily defined in the Admin and Table objects.
631    */
632   public static class HBaseHandler implements Hbase.Iface {
633     protected Configuration conf;
634     protected static final Log LOG = LogFactory.getLog(HBaseHandler.class);
635 
636     // nextScannerId and scannerMap are used to manage scanner state
637     protected int nextScannerId = 0;
638     protected HashMap<Integer, ResultScannerWrapper> scannerMap = null;
639     private ThriftMetrics metrics = null;
640 
641     private final ConnectionCache connectionCache;
642 
643     private static ThreadLocal<Map<String, Table>> threadLocalTables =
644         new ThreadLocal<Map<String, Table>>() {
645       @Override
646       protected Map<String, Table> initialValue() {
647         return new TreeMap<String, Table>();
648       }
649     };
650 
651     IncrementCoalescer coalescer = null;
652 
653     static final String CLEANUP_INTERVAL = "hbase.thrift.connection.cleanup-interval";
654     static final String MAX_IDLETIME = "hbase.thrift.connection.max-idletime";
655 
656     /**
657      * Returns a list of all the column families for a given Table.
658      *
659      * @param table
660      * @throws IOException
661      */
662     byte[][] getAllColumns(Table table) throws IOException {
663       HColumnDescriptor[] cds = table.getTableDescriptor().getColumnFamilies();
664       byte[][] columns = new byte[cds.length][];
665       for (int i = 0; i < cds.length; i++) {
666         columns[i] = Bytes.add(cds[i].getName(),
667             KeyValue.COLUMN_FAMILY_DELIM_ARRAY);
668       }
669       return columns;
670     }
671 
672     /**
673      * Creates and returns a Table instance from a given table name.
674      *
675      * @param tableName
676      *          name of table
677      * @return Table object
678      * @throws IOException
679      */
680     public Table getTable(final byte[] tableName) throws
681         IOException {
682       String table = Bytes.toString(tableName);
683       Map<String, Table> tables = threadLocalTables.get();
684       if (!tables.containsKey(table)) {
685         tables.put(table, (Table)connectionCache.getTable(table));
686       }
687       return tables.get(table);
688     }
689 
690     public Table getTable(final ByteBuffer tableName) throws IOException {
691       return getTable(getBytes(tableName));
692     }
693 
694     /**
695      * Assigns a unique ID to the scanner and adds the mapping to an internal
696      * hash-map.
697      *
698      * @param scanner
699      * @return integer scanner id
700      */
701     protected synchronized int addScanner(ResultScanner scanner,boolean sortColumns) {
702       int id = nextScannerId++;
703       ResultScannerWrapper resultScannerWrapper = new ResultScannerWrapper(scanner, sortColumns);
704       scannerMap.put(id, resultScannerWrapper);
705       return id;
706     }
707 
708     /**
709      * Returns the scanner associated with the specified ID.
710      *
711      * @param id
712      * @return a Scanner, or null if ID was invalid.
713      */
714     protected synchronized ResultScannerWrapper getScanner(int id) {
715       return scannerMap.get(id);
716     }
717 
718     /**
719      * Removes the scanner associated with the specified ID from the internal
720      * id-&gt;scanner hash-map.
721      *
722      * @param id
723      * @return a Scanner, or null if ID was invalid.
724      */
725     protected synchronized ResultScannerWrapper removeScanner(int id) {
726       return scannerMap.remove(id);
727     }
728 
729     protected HBaseHandler(final Configuration c,
730         final UserProvider userProvider) throws IOException {
731       this.conf = c;
732       scannerMap = new HashMap<Integer, ResultScannerWrapper>();
733       this.coalescer = new IncrementCoalescer(this);
734 
735       int cleanInterval = conf.getInt(CLEANUP_INTERVAL, 10 * 1000);
736       int maxIdleTime = conf.getInt(MAX_IDLETIME, 10 * 60 * 1000);
737       connectionCache = new ConnectionCache(
738         conf, userProvider, cleanInterval, maxIdleTime);
739     }
740 
741     /**
742      * Obtain HBaseAdmin. Creates the instance if it is not already created.
743      */
744     private Admin getAdmin() throws IOException {
745       return connectionCache.getAdmin();
746     }
747 
748     void setEffectiveUser(String effectiveUser) {
749       connectionCache.setEffectiveUser(effectiveUser);
750     }
751 
752     @Override
753     public void enableTable(ByteBuffer tableName) throws IOError {
754       try{
755         getAdmin().enableTable(getTableName(tableName));
756       } catch (IOException e) {
757         LOG.warn(e.getMessage(), e);
758         throw new IOError(Throwables.getStackTraceAsString(e));
759       }
760     }
761 
762     @Override
763     public void disableTable(ByteBuffer tableName) throws IOError{
764       try{
765         getAdmin().disableTable(getTableName(tableName));
766       } catch (IOException e) {
767         LOG.warn(e.getMessage(), e);
768         throw new IOError(Throwables.getStackTraceAsString(e));
769       }
770     }
771 
772     @Override
773     public boolean isTableEnabled(ByteBuffer tableName) throws IOError {
774       try {
775         return this.connectionCache.getAdmin().isTableEnabled(getTableName(tableName));
776       } catch (IOException e) {
777         LOG.warn(e.getMessage(), e);
778         throw new IOError(Throwables.getStackTraceAsString(e));
779       }
780     }
781 
782     @Override
783     public void compact(ByteBuffer tableNameOrRegionName) throws IOError {
784       try {
785         // TODO: HBaseAdmin.compact(byte[]) deprecated and not trivial to replace here.
786         // ThriftServerRunner.compact should be deprecated and replaced with methods specific to
787         // table and region.
788         ((HBaseAdmin) getAdmin()).compact(getBytes(tableNameOrRegionName));
789       } catch (IOException e) {
790         LOG.warn(e.getMessage(), e);
791         throw new IOError(Throwables.getStackTraceAsString(e));
792       }
793     }
794 
795     @Override
796     public void majorCompact(ByteBuffer tableNameOrRegionName) throws IOError {
797       try {
798         // TODO: HBaseAdmin.majorCompact(byte[]) deprecated and not trivial to replace here.
799         // ThriftServerRunner.majorCompact should be deprecated and replaced with methods specific
800         // to table and region.
801         ((HBaseAdmin) getAdmin()).majorCompact(getBytes(tableNameOrRegionName));
802       } catch (IOException e) {
803         LOG.warn(e.getMessage(), e);
804         throw new IOError(Throwables.getStackTraceAsString(e));
805       }
806     }
807 
808     @Override
809     public List<ByteBuffer> getTableNames() throws IOError {
810       try {
811         TableName[] tableNames = this.getAdmin().listTableNames();
812         ArrayList<ByteBuffer> list = new ArrayList<ByteBuffer>(tableNames.length);
813         for (int i = 0; i < tableNames.length; i++) {
814           list.add(ByteBuffer.wrap(tableNames[i].getName()));
815         }
816         return list;
817       } catch (IOException e) {
818         LOG.warn(e.getMessage(), e);
819         throw new IOError(Throwables.getStackTraceAsString(e));
820       }
821     }
822 
823     /**
824      * @return the list of regions in the given table, or an empty list if the table does not exist
825      */
826     @Override
827     public List<TRegionInfo> getTableRegions(ByteBuffer tableName)
828     throws IOError {
829       try (RegionLocator locator = connectionCache.getRegionLocator(getBytes(tableName))) {
830         List<HRegionLocation> regionLocations = locator.getAllRegionLocations();
831         List<TRegionInfo> results = new ArrayList<TRegionInfo>();
832         for (HRegionLocation regionLocation : regionLocations) {
833           HRegionInfo info = regionLocation.getRegionInfo();
834           ServerName serverName = regionLocation.getServerName();
835           TRegionInfo region = new TRegionInfo();
836           region.serverName = ByteBuffer.wrap(
837               Bytes.toBytes(serverName.getHostname()));
838           region.port = serverName.getPort();
839           region.startKey = ByteBuffer.wrap(info.getStartKey());
840           region.endKey = ByteBuffer.wrap(info.getEndKey());
841           region.id = info.getRegionId();
842           region.name = ByteBuffer.wrap(info.getRegionName());
843           region.version = HREGION_VERSION; // HRegion now not versioned, PB encoding used
844           results.add(region);
845         }
846         return results;
847       } catch (TableNotFoundException e) {
848         // Return empty list for non-existing table
849         return Collections.emptyList();
850       } catch (IOException e){
851         LOG.warn(e.getMessage(), e);
852         throw new IOError(Throwables.getStackTraceAsString(e));
853       }
854     }
855 
856     @Deprecated
857     @Override
858     public List<TCell> get(
859         ByteBuffer tableName, ByteBuffer row, ByteBuffer column,
860         Map<ByteBuffer, ByteBuffer> attributes)
861         throws IOError {
862       byte [][] famAndQf = KeyValue.parseColumn(getBytes(column));
863       if (famAndQf.length == 1) {
864         return get(tableName, row, famAndQf[0], null, attributes);
865       }
866       if (famAndQf.length == 2) {
867         return get(tableName, row, famAndQf[0], famAndQf[1], attributes);
868       }
869       throw new IllegalArgumentException("Invalid familyAndQualifier provided.");
870     }
871 
872     /**
873      * Note: this internal interface is slightly different from public APIs in regard to handling
874      * of the qualifier. Here we differ from the public Java API in that null != byte[0]. Rather,
875      * we respect qual == null as a request for the entire column family. The caller (
876      * {@link #get(ByteBuffer, ByteBuffer, ByteBuffer, Map)}) interface IS consistent in that the
877      * column is parse like normal.
878      */
879     protected List<TCell> get(ByteBuffer tableName,
880                               ByteBuffer row,
881                               byte[] family,
882                               byte[] qualifier,
883                               Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
884       try {
885         Table table = getTable(tableName);
886         Get get = new Get(getBytes(row));
887         addAttributes(get, attributes);
888         if (qualifier == null) {
889           get.addFamily(family);
890         } else {
891           get.addColumn(family, qualifier);
892         }
893         Result result = table.get(get);
894         return ThriftUtilities.cellFromHBase(result.rawCells());
895       } catch (IOException e) {
896         LOG.warn(e.getMessage(), e);
897         throw new IOError(Throwables.getStackTraceAsString(e));
898       }
899     }
900 
901     @Deprecated
902     @Override
903     public List<TCell> getVer(ByteBuffer tableName, ByteBuffer row, ByteBuffer column,
904         int numVersions, Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
905       byte [][] famAndQf = KeyValue.parseColumn(getBytes(column));
906       if(famAndQf.length == 1) {
907         return getVer(tableName, row, famAndQf[0], null, numVersions, attributes);
908       }
909       if (famAndQf.length == 2) {
910         return getVer(tableName, row, famAndQf[0], famAndQf[1], numVersions, attributes);
911       }
912       throw new IllegalArgumentException("Invalid familyAndQualifier provided.");
913 
914     }
915 
916     /**
917      * Note: this public interface is slightly different from public Java APIs in regard to
918      * handling of the qualifier. Here we differ from the public Java API in that null != byte[0].
919      * Rather, we respect qual == null as a request for the entire column family. If you want to
920      * access the entire column family, use
921      * {@link #getVer(ByteBuffer, ByteBuffer, ByteBuffer, int, Map)} with a {@code column} value
922      * that lacks a {@code ':'}.
923      */
924     public List<TCell> getVer(ByteBuffer tableName, ByteBuffer row, byte[] family,
925         byte[] qualifier, int numVersions, Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
926       try {
927         Table table = getTable(tableName);
928         Get get = new Get(getBytes(row));
929         addAttributes(get, attributes);
930         if (null == qualifier) {
931           get.addFamily(family);
932         } else {
933           get.addColumn(family, qualifier);
934         }
935         get.setMaxVersions(numVersions);
936         Result result = table.get(get);
937         return ThriftUtilities.cellFromHBase(result.rawCells());
938       } catch (IOException e) {
939         LOG.warn(e.getMessage(), e);
940         throw new IOError(Throwables.getStackTraceAsString(e));
941       }
942     }
943 
944     @Deprecated
945     @Override
946     public List<TCell> getVerTs(ByteBuffer tableName, ByteBuffer row, ByteBuffer column,
947         long timestamp, int numVersions, Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
948       byte [][] famAndQf = KeyValue.parseColumn(getBytes(column));
949       if (famAndQf.length == 1) {
950         return getVerTs(tableName, row, famAndQf[0], null, timestamp, numVersions, attributes);
951       }
952       if (famAndQf.length == 2) {
953         return getVerTs(tableName, row, famAndQf[0], famAndQf[1], timestamp, numVersions,
954           attributes);
955       }
956       throw new IllegalArgumentException("Invalid familyAndQualifier provided.");
957     }
958 
959     /**
960      * Note: this internal interface is slightly different from public APIs in regard to handling
961      * of the qualifier. Here we differ from the public Java API in that null != byte[0]. Rather,
962      * we respect qual == null as a request for the entire column family. The caller (
963      * {@link #getVerTs(ByteBuffer, ByteBuffer, ByteBuffer, long, int, Map)}) interface IS
964      * consistent in that the column is parse like normal.
965      */
966     protected List<TCell> getVerTs(ByteBuffer tableName, ByteBuffer row, byte[] family,
967         byte[] qualifier, long timestamp, int numVersions, Map<ByteBuffer, ByteBuffer> attributes)
968         throws IOError {
969       try {
970         Table table = getTable(tableName);
971         Get get = new Get(getBytes(row));
972         addAttributes(get, attributes);
973         if (null == qualifier) {
974           get.addFamily(family);
975         } else {
976           get.addColumn(family, qualifier);
977         }
978         get.setTimeRange(0, timestamp);
979         get.setMaxVersions(numVersions);
980         Result result = table.get(get);
981         return ThriftUtilities.cellFromHBase(result.rawCells());
982       } catch (IOException e) {
983         LOG.warn(e.getMessage(), e);
984         throw new IOError(Throwables.getStackTraceAsString(e));
985       }
986     }
987 
988     @Override
989     public List<TRowResult> getRow(ByteBuffer tableName, ByteBuffer row,
990         Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
991       return getRowWithColumnsTs(tableName, row, null,
992                                  HConstants.LATEST_TIMESTAMP,
993                                  attributes);
994     }
995 
996     @Override
997     public List<TRowResult> getRowWithColumns(ByteBuffer tableName,
998                                               ByteBuffer row,
999         List<ByteBuffer> columns,
1000         Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
1001       return getRowWithColumnsTs(tableName, row, columns,
1002                                  HConstants.LATEST_TIMESTAMP,
1003                                  attributes);
1004     }
1005 
1006     @Override
1007     public List<TRowResult> getRowTs(ByteBuffer tableName, ByteBuffer row,
1008         long timestamp, Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
1009       return getRowWithColumnsTs(tableName, row, null,
1010                                  timestamp, attributes);
1011     }
1012 
1013     @Override
1014     public List<TRowResult> getRowWithColumnsTs(
1015         ByteBuffer tableName, ByteBuffer row, List<ByteBuffer> columns,
1016         long timestamp, Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
1017       try {
1018         Table table = getTable(tableName);
1019         if (columns == null) {
1020           Get get = new Get(getBytes(row));
1021           addAttributes(get, attributes);
1022           get.setTimeRange(0, timestamp);
1023           Result result = table.get(get);
1024           return ThriftUtilities.rowResultFromHBase(result);
1025         }
1026         Get get = new Get(getBytes(row));
1027         addAttributes(get, attributes);
1028         for(ByteBuffer column : columns) {
1029           byte [][] famAndQf = KeyValue.parseColumn(getBytes(column));
1030           if (famAndQf.length == 1) {
1031               get.addFamily(famAndQf[0]);
1032           } else {
1033               get.addColumn(famAndQf[0], famAndQf[1]);
1034           }
1035         }
1036         get.setTimeRange(0, timestamp);
1037         Result result = table.get(get);
1038         return ThriftUtilities.rowResultFromHBase(result);
1039       } catch (IOException e) {
1040         LOG.warn(e.getMessage(), e);
1041         throw new IOError(Throwables.getStackTraceAsString(e));
1042       }
1043     }
1044 
1045     @Override
1046     public List<TRowResult> getRows(ByteBuffer tableName,
1047                                     List<ByteBuffer> rows,
1048         Map<ByteBuffer, ByteBuffer> attributes)
1049         throws IOError {
1050       return getRowsWithColumnsTs(tableName, rows, null,
1051                                   HConstants.LATEST_TIMESTAMP,
1052                                   attributes);
1053     }
1054 
1055     @Override
1056     public List<TRowResult> getRowsWithColumns(ByteBuffer tableName,
1057                                                List<ByteBuffer> rows,
1058         List<ByteBuffer> columns,
1059         Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
1060       return getRowsWithColumnsTs(tableName, rows, columns,
1061                                   HConstants.LATEST_TIMESTAMP,
1062                                   attributes);
1063     }
1064 
1065     @Override
1066     public List<TRowResult> getRowsTs(ByteBuffer tableName,
1067                                       List<ByteBuffer> rows,
1068         long timestamp,
1069         Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
1070       return getRowsWithColumnsTs(tableName, rows, null,
1071                                   timestamp, attributes);
1072     }
1073 
1074     @Override
1075     public List<TRowResult> getRowsWithColumnsTs(ByteBuffer tableName,
1076                                                  List<ByteBuffer> rows,
1077         List<ByteBuffer> columns, long timestamp,
1078         Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
1079       try {
1080         List<Get> gets = new ArrayList<Get>(rows.size());
1081         Table table = getTable(tableName);
1082         if (metrics != null) {
1083           metrics.incNumRowKeysInBatchGet(rows.size());
1084         }
1085         for (ByteBuffer row : rows) {
1086           Get get = new Get(getBytes(row));
1087           addAttributes(get, attributes);
1088           if (columns != null) {
1089 
1090             for(ByteBuffer column : columns) {
1091               byte [][] famAndQf = KeyValue.parseColumn(getBytes(column));
1092               if (famAndQf.length == 1) {
1093                 get.addFamily(famAndQf[0]);
1094               } else {
1095                 get.addColumn(famAndQf[0], famAndQf[1]);
1096               }
1097             }
1098           }
1099           get.setTimeRange(0, timestamp);
1100           gets.add(get);
1101         }
1102         Result[] result = table.get(gets);
1103         return ThriftUtilities.rowResultFromHBase(result);
1104       } catch (IOException e) {
1105         LOG.warn(e.getMessage(), e);
1106         throw new IOError(Throwables.getStackTraceAsString(e));
1107       }
1108     }
1109 
1110     @Override
1111     public void deleteAll(
1112         ByteBuffer tableName, ByteBuffer row, ByteBuffer column,
1113         Map<ByteBuffer, ByteBuffer> attributes)
1114         throws IOError {
1115       deleteAllTs(tableName, row, column, HConstants.LATEST_TIMESTAMP,
1116                   attributes);
1117     }
1118 
1119     @Override
1120     public void deleteAllTs(ByteBuffer tableName,
1121                             ByteBuffer row,
1122                             ByteBuffer column,
1123         long timestamp, Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
1124       try {
1125         Table table = getTable(tableName);
1126         Delete delete  = new Delete(getBytes(row));
1127         addAttributes(delete, attributes);
1128         byte [][] famAndQf = KeyValue.parseColumn(getBytes(column));
1129         if (famAndQf.length == 1) {
1130           delete.deleteFamily(famAndQf[0], timestamp);
1131         } else {
1132           delete.deleteColumns(famAndQf[0], famAndQf[1], timestamp);
1133         }
1134         table.delete(delete);
1135 
1136       } catch (IOException e) {
1137         LOG.warn(e.getMessage(), e);
1138         throw new IOError(Throwables.getStackTraceAsString(e));
1139       }
1140     }
1141 
1142     @Override
1143     public void deleteAllRow(
1144         ByteBuffer tableName, ByteBuffer row,
1145         Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
1146       deleteAllRowTs(tableName, row, HConstants.LATEST_TIMESTAMP, attributes);
1147     }
1148 
1149     @Override
1150     public void deleteAllRowTs(
1151         ByteBuffer tableName, ByteBuffer row, long timestamp,
1152         Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
1153       try {
1154         Table table = getTable(tableName);
1155         Delete delete  = new Delete(getBytes(row), timestamp);
1156         addAttributes(delete, attributes);
1157         table.delete(delete);
1158       } catch (IOException e) {
1159         LOG.warn(e.getMessage(), e);
1160         throw new IOError(Throwables.getStackTraceAsString(e));
1161       }
1162     }
1163 
1164     @Override
1165     public void createTable(ByteBuffer in_tableName,
1166         List<ColumnDescriptor> columnFamilies) throws IOError,
1167         IllegalArgument, AlreadyExists {
1168       TableName tableName = getTableName(in_tableName);
1169       try {
1170         if (getAdmin().tableExists(tableName)) {
1171           throw new AlreadyExists("table name already in use");
1172         }
1173         HTableDescriptor desc = new HTableDescriptor(tableName);
1174         for (ColumnDescriptor col : columnFamilies) {
1175           HColumnDescriptor colDesc = ThriftUtilities.colDescFromThrift(col);
1176           desc.addFamily(colDesc);
1177         }
1178         getAdmin().createTable(desc);
1179       } catch (IOException e) {
1180         LOG.warn(e.getMessage(), e);
1181         throw new IOError(Throwables.getStackTraceAsString(e));
1182       } catch (IllegalArgumentException e) {
1183         LOG.warn(e.getMessage(), e);
1184         throw new IllegalArgument(Throwables.getStackTraceAsString(e));
1185       }
1186     }
1187 
1188     private static TableName getTableName(ByteBuffer buffer) {
1189       return TableName.valueOf(getBytes(buffer));
1190     }
1191 
1192     @Override
1193     public void deleteTable(ByteBuffer in_tableName) throws IOError {
1194       TableName tableName = getTableName(in_tableName);
1195       if (LOG.isDebugEnabled()) {
1196         LOG.debug("deleteTable: table=" + tableName);
1197       }
1198       try {
1199         if (!getAdmin().tableExists(tableName)) {
1200           throw new IOException("table does not exist");
1201         }
1202         getAdmin().deleteTable(tableName);
1203       } catch (IOException e) {
1204         LOG.warn(e.getMessage(), e);
1205         throw new IOError(Throwables.getStackTraceAsString(e));
1206       }
1207     }
1208 
1209     @Override
1210     public void mutateRow(ByteBuffer tableName, ByteBuffer row,
1211         List<Mutation> mutations, Map<ByteBuffer, ByteBuffer> attributes)
1212         throws IOError, IllegalArgument {
1213       mutateRowTs(tableName, row, mutations, HConstants.LATEST_TIMESTAMP,
1214                   attributes);
1215     }
1216 
1217     @Override
1218     public void mutateRowTs(ByteBuffer tableName, ByteBuffer row,
1219         List<Mutation> mutations, long timestamp,
1220         Map<ByteBuffer, ByteBuffer> attributes)
1221         throws IOError, IllegalArgument {
1222       Table table = null;
1223       try {
1224         table = getTable(tableName);
1225         Put put = new Put(getBytes(row), timestamp);
1226         addAttributes(put, attributes);
1227 
1228         Delete delete = new Delete(getBytes(row));
1229         addAttributes(delete, attributes);
1230         if (metrics != null) {
1231           metrics.incNumRowKeysInBatchMutate(mutations.size());
1232         }
1233 
1234         // I apologize for all this mess :)
1235         for (Mutation m : mutations) {
1236           byte[][] famAndQf = KeyValue.parseColumn(getBytes(m.column));
1237           if (m.isDelete) {
1238             if (famAndQf.length == 1) {
1239               delete.deleteFamily(famAndQf[0], timestamp);
1240             } else {
1241               delete.deleteColumns(famAndQf[0], famAndQf[1], timestamp);
1242             }
1243             delete.setDurability(m.writeToWAL ? Durability.SYNC_WAL
1244                 : Durability.SKIP_WAL);
1245           } else {
1246             if(famAndQf.length == 1) {
1247               LOG.warn("No column qualifier specified. Delete is the only mutation supported "
1248                   + "over the whole column family.");
1249             } else {
1250               put.addImmutable(famAndQf[0], famAndQf[1],
1251                   m.value != null ? getBytes(m.value)
1252                       : HConstants.EMPTY_BYTE_ARRAY);
1253             }
1254             put.setDurability(m.writeToWAL ? Durability.SYNC_WAL : Durability.SKIP_WAL);
1255           }
1256         }
1257         if (!delete.isEmpty())
1258           table.delete(delete);
1259         if (!put.isEmpty())
1260           table.put(put);
1261       } catch (IOException e) {
1262         LOG.warn(e.getMessage(), e);
1263         throw new IOError(Throwables.getStackTraceAsString(e));
1264       } catch (IllegalArgumentException e) {
1265         LOG.warn(e.getMessage(), e);
1266         throw new IllegalArgument(Throwables.getStackTraceAsString(e));
1267       }
1268     }
1269 
1270     @Override
1271     public void mutateRows(ByteBuffer tableName, List<BatchMutation> rowBatches,
1272         Map<ByteBuffer, ByteBuffer> attributes)
1273         throws IOError, IllegalArgument, TException {
1274       mutateRowsTs(tableName, rowBatches, HConstants.LATEST_TIMESTAMP, attributes);
1275     }
1276 
1277     @Override
1278     public void mutateRowsTs(
1279         ByteBuffer tableName, List<BatchMutation> rowBatches, long timestamp,
1280         Map<ByteBuffer, ByteBuffer> attributes)
1281         throws IOError, IllegalArgument, TException {
1282       List<Put> puts = new ArrayList<Put>();
1283       List<Delete> deletes = new ArrayList<Delete>();
1284 
1285       for (BatchMutation batch : rowBatches) {
1286         byte[] row = getBytes(batch.row);
1287         List<Mutation> mutations = batch.mutations;
1288         Delete delete = new Delete(row);
1289         addAttributes(delete, attributes);
1290         Put put = new Put(row, timestamp);
1291         addAttributes(put, attributes);
1292         for (Mutation m : mutations) {
1293           byte[][] famAndQf = KeyValue.parseColumn(getBytes(m.column));
1294           if (m.isDelete) {
1295             // no qualifier, family only.
1296             if (famAndQf.length == 1) {
1297               delete.deleteFamily(famAndQf[0], timestamp);
1298             } else {
1299               delete.deleteColumns(famAndQf[0], famAndQf[1], timestamp);
1300             }
1301             delete.setDurability(m.writeToWAL ? Durability.SYNC_WAL
1302                 : Durability.SKIP_WAL);
1303           } else {
1304             if (famAndQf.length == 1) {
1305               LOG.warn("No column qualifier specified. Delete is the only mutation supported "
1306                   + "over the whole column family.");
1307             }
1308             if (famAndQf.length == 2) {
1309               put.addImmutable(famAndQf[0], famAndQf[1],
1310                   m.value != null ? getBytes(m.value)
1311                       : HConstants.EMPTY_BYTE_ARRAY);
1312             } else {
1313               throw new IllegalArgumentException("Invalid famAndQf provided.");
1314             }
1315             put.setDurability(m.writeToWAL ? Durability.SYNC_WAL : Durability.SKIP_WAL);
1316           }
1317         }
1318         if (!delete.isEmpty())
1319           deletes.add(delete);
1320         if (!put.isEmpty())
1321           puts.add(put);
1322       }
1323 
1324       Table table = null;
1325       try {
1326         table = getTable(tableName);
1327         if (!puts.isEmpty())
1328           table.put(puts);
1329         if (!deletes.isEmpty())
1330           table.delete(deletes);
1331 
1332       } catch (IOException e) {
1333         LOG.warn(e.getMessage(), e);
1334         throw new IOError(Throwables.getStackTraceAsString(e));
1335       } catch (IllegalArgumentException e) {
1336         LOG.warn(e.getMessage(), e);
1337         throw new IllegalArgument(Throwables.getStackTraceAsString(e));
1338       }
1339     }
1340 
1341     @Deprecated
1342     @Override
1343     public long atomicIncrement(
1344         ByteBuffer tableName, ByteBuffer row, ByteBuffer column, long amount)
1345             throws IOError, IllegalArgument, TException {
1346       byte [][] famAndQf = KeyValue.parseColumn(getBytes(column));
1347       if(famAndQf.length == 1) {
1348         return atomicIncrement(tableName, row, famAndQf[0], HConstants.EMPTY_BYTE_ARRAY, amount);
1349       }
1350       return atomicIncrement(tableName, row, famAndQf[0], famAndQf[1], amount);
1351     }
1352 
1353     protected long atomicIncrement(ByteBuffer tableName, ByteBuffer row,
1354         byte [] family, byte [] qualifier, long amount)
1355         throws IOError, IllegalArgument, TException {
1356       Table table;
1357       try {
1358         table = getTable(tableName);
1359         return table.incrementColumnValue(
1360             getBytes(row), family, qualifier, amount);
1361       } catch (IOException e) {
1362         LOG.warn(e.getMessage(), e);
1363         throw new IOError(Throwables.getStackTraceAsString(e));
1364       }
1365     }
1366 
1367     @Override
1368     public void scannerClose(int id) throws IOError, IllegalArgument {
1369       LOG.debug("scannerClose: id=" + id);
1370       ResultScannerWrapper resultScannerWrapper = getScanner(id);
1371       if (resultScannerWrapper == null) {
1372         String message = "scanner ID is invalid";
1373         LOG.warn(message);
1374         throw new IllegalArgument("scanner ID is invalid");
1375       }
1376       resultScannerWrapper.getScanner().close();
1377       removeScanner(id);
1378     }
1379 
1380     @Override
1381     public List<TRowResult> scannerGetList(int id,int nbRows)
1382         throws IllegalArgument, IOError {
1383       LOG.debug("scannerGetList: id=" + id);
1384       ResultScannerWrapper resultScannerWrapper = getScanner(id);
1385       if (null == resultScannerWrapper) {
1386         String message = "scanner ID is invalid";
1387         LOG.warn(message);
1388         throw new IllegalArgument("scanner ID is invalid");
1389       }
1390 
1391       Result [] results = null;
1392       try {
1393         results = resultScannerWrapper.getScanner().next(nbRows);
1394         if (null == results) {
1395           return new ArrayList<TRowResult>();
1396         }
1397       } catch (IOException e) {
1398         LOG.warn(e.getMessage(), e);
1399         throw new IOError(Throwables.getStackTraceAsString(e));
1400       }
1401       return ThriftUtilities.rowResultFromHBase(results, resultScannerWrapper.isColumnSorted());
1402     }
1403 
1404     @Override
1405     public List<TRowResult> scannerGet(int id) throws IllegalArgument, IOError {
1406       return scannerGetList(id,1);
1407     }
1408 
1409     @Override
1410     public int scannerOpenWithScan(ByteBuffer tableName, TScan tScan,
1411         Map<ByteBuffer, ByteBuffer> attributes)
1412         throws IOError {
1413       try {
1414         Table table = getTable(tableName);
1415         Scan scan = new Scan();
1416         addAttributes(scan, attributes);
1417         if (tScan.isSetStartRow()) {
1418           scan.setStartRow(tScan.getStartRow());
1419         }
1420         if (tScan.isSetStopRow()) {
1421           scan.setStopRow(tScan.getStopRow());
1422         }
1423         if (tScan.isSetTimestamp()) {
1424           scan.setTimeRange(0, tScan.getTimestamp());
1425         }
1426         if (tScan.isSetCaching()) {
1427           scan.setCaching(tScan.getCaching());
1428         }
1429         if (tScan.isSetBatchSize()) {
1430           scan.setBatch(tScan.getBatchSize());
1431         }
1432         if (tScan.isSetColumns() && tScan.getColumns().size() != 0) {
1433           for(ByteBuffer column : tScan.getColumns()) {
1434             byte [][] famQf = KeyValue.parseColumn(getBytes(column));
1435             if(famQf.length == 1) {
1436               scan.addFamily(famQf[0]);
1437             } else {
1438               scan.addColumn(famQf[0], famQf[1]);
1439             }
1440           }
1441         }
1442         if (tScan.isSetFilterString()) {
1443           ParseFilter parseFilter = new ParseFilter();
1444           scan.setFilter(
1445               parseFilter.parseFilterString(tScan.getFilterString()));
1446         }
1447         if (tScan.isSetReversed()) {
1448           scan.setReversed(tScan.isReversed());
1449         }
1450         return addScanner(table.getScanner(scan), tScan.sortColumns);
1451       } catch (IOException e) {
1452         LOG.warn(e.getMessage(), e);
1453         throw new IOError(Throwables.getStackTraceAsString(e));
1454       }
1455     }
1456 
1457     @Override
1458     public int scannerOpen(ByteBuffer tableName, ByteBuffer startRow,
1459         List<ByteBuffer> columns,
1460         Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
1461       try {
1462         Table table = getTable(tableName);
1463         Scan scan = new Scan(getBytes(startRow));
1464         addAttributes(scan, attributes);
1465         if(columns != null && columns.size() != 0) {
1466           for(ByteBuffer column : columns) {
1467             byte [][] famQf = KeyValue.parseColumn(getBytes(column));
1468             if(famQf.length == 1) {
1469               scan.addFamily(famQf[0]);
1470             } else {
1471               scan.addColumn(famQf[0], famQf[1]);
1472             }
1473           }
1474         }
1475         return addScanner(table.getScanner(scan), false);
1476       } catch (IOException e) {
1477         LOG.warn(e.getMessage(), e);
1478         throw new IOError(Throwables.getStackTraceAsString(e));
1479       }
1480     }
1481 
1482     @Override
1483     public int scannerOpenWithStop(ByteBuffer tableName, ByteBuffer startRow,
1484         ByteBuffer stopRow, List<ByteBuffer> columns,
1485         Map<ByteBuffer, ByteBuffer> attributes)
1486         throws IOError, TException {
1487       try {
1488         Table table = getTable(tableName);
1489         Scan scan = new Scan(getBytes(startRow), getBytes(stopRow));
1490         addAttributes(scan, attributes);
1491         if(columns != null && columns.size() != 0) {
1492           for(ByteBuffer column : columns) {
1493             byte [][] famQf = KeyValue.parseColumn(getBytes(column));
1494             if(famQf.length == 1) {
1495               scan.addFamily(famQf[0]);
1496             } else {
1497               scan.addColumn(famQf[0], famQf[1]);
1498             }
1499           }
1500         }
1501         return addScanner(table.getScanner(scan), false);
1502       } catch (IOException e) {
1503         LOG.warn(e.getMessage(), e);
1504         throw new IOError(Throwables.getStackTraceAsString(e));
1505       }
1506     }
1507 
1508     @Override
1509     public int scannerOpenWithPrefix(ByteBuffer tableName,
1510                                      ByteBuffer startAndPrefix,
1511                                      List<ByteBuffer> columns,
1512         Map<ByteBuffer, ByteBuffer> attributes)
1513         throws IOError, TException {
1514       try {
1515         Table table = getTable(tableName);
1516         Scan scan = new Scan(getBytes(startAndPrefix));
1517         addAttributes(scan, attributes);
1518         Filter f = new WhileMatchFilter(
1519             new PrefixFilter(getBytes(startAndPrefix)));
1520         scan.setFilter(f);
1521         if (columns != null && columns.size() != 0) {
1522           for(ByteBuffer column : columns) {
1523             byte [][] famQf = KeyValue.parseColumn(getBytes(column));
1524             if(famQf.length == 1) {
1525               scan.addFamily(famQf[0]);
1526             } else {
1527               scan.addColumn(famQf[0], famQf[1]);
1528             }
1529           }
1530         }
1531         return addScanner(table.getScanner(scan), false);
1532       } catch (IOException e) {
1533         LOG.warn(e.getMessage(), e);
1534         throw new IOError(Throwables.getStackTraceAsString(e));
1535       }
1536     }
1537 
1538     @Override
1539     public int scannerOpenTs(ByteBuffer tableName, ByteBuffer startRow,
1540         List<ByteBuffer> columns, long timestamp,
1541         Map<ByteBuffer, ByteBuffer> attributes) throws IOError, TException {
1542       try {
1543         Table table = getTable(tableName);
1544         Scan scan = new Scan(getBytes(startRow));
1545         addAttributes(scan, attributes);
1546         scan.setTimeRange(0, timestamp);
1547         if (columns != null && columns.size() != 0) {
1548           for (ByteBuffer column : columns) {
1549             byte [][] famQf = KeyValue.parseColumn(getBytes(column));
1550             if(famQf.length == 1) {
1551               scan.addFamily(famQf[0]);
1552             } else {
1553               scan.addColumn(famQf[0], famQf[1]);
1554             }
1555           }
1556         }
1557         return addScanner(table.getScanner(scan), false);
1558       } catch (IOException e) {
1559         LOG.warn(e.getMessage(), e);
1560         throw new IOError(Throwables.getStackTraceAsString(e));
1561       }
1562     }
1563 
1564     @Override
1565     public int scannerOpenWithStopTs(ByteBuffer tableName, ByteBuffer startRow,
1566         ByteBuffer stopRow, List<ByteBuffer> columns, long timestamp,
1567         Map<ByteBuffer, ByteBuffer> attributes)
1568         throws IOError, TException {
1569       try {
1570         Table table = getTable(tableName);
1571         Scan scan = new Scan(getBytes(startRow), getBytes(stopRow));
1572         addAttributes(scan, attributes);
1573         scan.setTimeRange(0, timestamp);
1574         if (columns != null && columns.size() != 0) {
1575           for (ByteBuffer column : columns) {
1576             byte [][] famQf = KeyValue.parseColumn(getBytes(column));
1577             if(famQf.length == 1) {
1578               scan.addFamily(famQf[0]);
1579             } else {
1580               scan.addColumn(famQf[0], famQf[1]);
1581             }
1582           }
1583         }
1584         scan.setTimeRange(0, timestamp);
1585         return addScanner(table.getScanner(scan), false);
1586       } catch (IOException e) {
1587         LOG.warn(e.getMessage(), e);
1588         throw new IOError(Throwables.getStackTraceAsString(e));
1589       }
1590     }
1591 
1592     @Override
1593     public Map<ByteBuffer, ColumnDescriptor> getColumnDescriptors(
1594         ByteBuffer tableName) throws IOError, TException {
1595       try {
1596         TreeMap<ByteBuffer, ColumnDescriptor> columns =
1597           new TreeMap<ByteBuffer, ColumnDescriptor>();
1598 
1599         Table table = getTable(tableName);
1600         HTableDescriptor desc = table.getTableDescriptor();
1601 
1602         for (HColumnDescriptor e : desc.getFamilies()) {
1603           ColumnDescriptor col = ThriftUtilities.colDescFromHbase(e);
1604           columns.put(col.name, col);
1605         }
1606         return columns;
1607       } catch (IOException e) {
1608         LOG.warn(e.getMessage(), e);
1609         throw new IOError(Throwables.getStackTraceAsString(e));
1610       }
1611     }
1612 
1613     @Deprecated
1614     @Override
1615     public List<TCell> getRowOrBefore(ByteBuffer tableName, ByteBuffer row,
1616         ByteBuffer family) throws IOError {
1617       try {
1618         Result result = getRowOrBefore(getBytes(tableName), getBytes(row), getBytes(family));
1619         return ThriftUtilities.cellFromHBase(result.rawCells());
1620       } catch (IOException e) {
1621         LOG.warn(e.getMessage(), e);
1622         throw new IOError(Throwables.getStackTraceAsString(e));
1623       }
1624     }
1625 
1626     @Override
1627     public TRegionInfo getRegionInfo(ByteBuffer searchRow) throws IOError {
1628       try {
1629         byte[] row = getBytes(searchRow);
1630         Result startRowResult =
1631             getRowOrBefore(TableName.META_TABLE_NAME.getName(), row, HConstants.CATALOG_FAMILY);
1632 
1633         if (startRowResult == null) {
1634           throw new IOException("Cannot find row in "+ TableName.META_TABLE_NAME+", row="
1635                                 + Bytes.toStringBinary(row));
1636         }
1637 
1638         // find region start and end keys
1639         HRegionInfo regionInfo = HRegionInfo.getHRegionInfo(startRowResult);
1640         if (regionInfo == null) {
1641           throw new IOException("HRegionInfo REGIONINFO was null or " +
1642                                 " empty in Meta for row="
1643                                 + Bytes.toStringBinary(row));
1644         }
1645         TRegionInfo region = new TRegionInfo();
1646         region.setStartKey(regionInfo.getStartKey());
1647         region.setEndKey(regionInfo.getEndKey());
1648         region.id = regionInfo.getRegionId();
1649         region.setName(regionInfo.getRegionName());
1650         region.version = HREGION_VERSION; // version not used anymore, PB encoding used.
1651 
1652         // find region assignment to server
1653         ServerName serverName = HRegionInfo.getServerName(startRowResult);
1654         if (serverName != null) {
1655           region.setServerName(Bytes.toBytes(serverName.getHostname()));
1656           region.port = serverName.getPort();
1657         }
1658         return region;
1659       } catch (IOException e) {
1660         LOG.warn(e.getMessage(), e);
1661         throw new IOError(Throwables.getStackTraceAsString(e));
1662       }
1663     }
1664 
1665     private Result getRowOrBefore(byte[] tableName, byte[] row, byte[] family) throws IOException {
1666       Scan scan = new Scan(row);
1667       scan.setReversed(true);
1668       scan.addFamily(family);
1669       scan.setStartRow(row);
1670 
1671       Table table = getTable(tableName);
1672       try (ResultScanner scanner = table.getScanner(scan)) {
1673         return scanner.next();
1674       }
1675     }
1676 
1677     private void initMetrics(ThriftMetrics metrics) {
1678       this.metrics = metrics;
1679     }
1680 
1681     @Override
1682     public void increment(TIncrement tincrement) throws IOError, TException {
1683 
1684       if (tincrement.getRow().length == 0 || tincrement.getTable().length == 0) {
1685         throw new TException("Must supply a table and a row key; can't increment");
1686       }
1687 
1688       if (conf.getBoolean(COALESCE_INC_KEY, false)) {
1689         this.coalescer.queueIncrement(tincrement);
1690         return;
1691       }
1692 
1693       try {
1694         Table table = getTable(tincrement.getTable());
1695         Increment inc = ThriftUtilities.incrementFromThrift(tincrement);
1696         table.increment(inc);
1697       } catch (IOException e) {
1698         LOG.warn(e.getMessage(), e);
1699         throw new IOError(Throwables.getStackTraceAsString(e));
1700       }
1701     }
1702 
1703     @Override
1704     public void incrementRows(List<TIncrement> tincrements) throws IOError, TException {
1705       if (conf.getBoolean(COALESCE_INC_KEY, false)) {
1706         this.coalescer.queueIncrements(tincrements);
1707         return;
1708       }
1709       for (TIncrement tinc : tincrements) {
1710         increment(tinc);
1711       }
1712     }
1713 
1714     @Override
1715     public List<TCell> append(TAppend tappend) throws IOError, TException {
1716       if (tappend.getRow().length == 0 || tappend.getTable().length == 0) {
1717         throw new TException("Must supply a table and a row key; can't append");
1718       }
1719 
1720       try {
1721         Table table = getTable(tappend.getTable());
1722         Append append = ThriftUtilities.appendFromThrift(tappend);
1723         Result result = table.append(append);
1724         return ThriftUtilities.cellFromHBase(result.rawCells());
1725       } catch (IOException e) {
1726         LOG.warn(e.getMessage(), e);
1727         throw new IOError(Throwables.getStackTraceAsString(e));
1728       }
1729     }
1730 
1731     @Override
1732     public boolean checkAndPut(ByteBuffer tableName, ByteBuffer row, ByteBuffer column,
1733         ByteBuffer value, Mutation mput, Map<ByteBuffer, ByteBuffer> attributes) throws IOError,
1734         IllegalArgument, TException {
1735       Put put;
1736       try {
1737         put = new Put(getBytes(row), HConstants.LATEST_TIMESTAMP);
1738         addAttributes(put, attributes);
1739 
1740         byte[][] famAndQf = KeyValue.parseColumn(getBytes(mput.column));
1741 
1742         put.addImmutable(famAndQf[0], famAndQf[1], mput.value != null ? getBytes(mput.value)
1743             : HConstants.EMPTY_BYTE_ARRAY);
1744 
1745         put.setDurability(mput.writeToWAL ? Durability.SYNC_WAL : Durability.SKIP_WAL);
1746       } catch (IllegalArgumentException e) {
1747         LOG.warn(e.getMessage(), e);
1748         throw new IllegalArgument(Throwables.getStackTraceAsString(e));
1749       }
1750 
1751       Table table = null;
1752       try {
1753         table = getTable(tableName);
1754         byte[][] famAndQf = KeyValue.parseColumn(getBytes(column));
1755         return table.checkAndPut(getBytes(row), famAndQf[0], famAndQf[1],
1756           value != null ? getBytes(value) : HConstants.EMPTY_BYTE_ARRAY, put);
1757       } catch (IOException e) {
1758         LOG.warn(e.getMessage(), e);
1759         throw new IOError(Throwables.getStackTraceAsString(e));
1760       } catch (IllegalArgumentException e) {
1761         LOG.warn(e.getMessage(), e);
1762         throw new IllegalArgument(Throwables.getStackTraceAsString(e));
1763       }
1764     }
1765   }
1766 
1767 
1768 
1769   /**
1770    * Adds all the attributes into the Operation object
1771    */
1772   private static void addAttributes(OperationWithAttributes op,
1773     Map<ByteBuffer, ByteBuffer> attributes) {
1774     if (attributes == null || attributes.size() == 0) {
1775       return;
1776     }
1777     for (Map.Entry<ByteBuffer, ByteBuffer> entry : attributes.entrySet()) {
1778       String name = Bytes.toStringBinary(getBytes(entry.getKey()));
1779       byte[] value =  getBytes(entry.getValue());
1780       op.setAttribute(name, value);
1781     }
1782   }
1783 
1784   public static void registerFilters(Configuration conf) {
1785     String[] filters = conf.getStrings("hbase.thrift.filters");
1786     if(filters != null) {
1787       for(String filterClass: filters) {
1788         String[] filterPart = filterClass.split(":");
1789         if(filterPart.length != 2) {
1790           LOG.warn("Invalid filter specification " + filterClass + " - skipping");
1791         } else {
1792           ParseFilter.registerFilter(filterPart[0], filterPart[1]);
1793         }
1794       }
1795     }
1796   }
1797 }