diff --git a/src/main/java/org/apache/hadoop/hbase/thrift/TBoundedThreadPoolServer.java b/src/main/java/org/apache/hadoop/hbase/thrift/TBoundedThreadPoolServer.java index c7e104b..dd79aca 100644 --- a/src/main/java/org/apache/hadoop/hbase/thrift/TBoundedThreadPoolServer.java +++ b/src/main/java/org/apache/hadoop/hbase/thrift/TBoundedThreadPoolServer.java @@ -284,7 +284,15 @@ public class TBoundedThreadPoolServer extends TServer { outputProtocol = outputProtocolFactory_.getProtocol(outputTransport); // we check stopped_ first to make sure we're not supposed to be shutting // down. this is necessary for graceful shutdown. - while (!stopped && processor.process(inputProtocol, outputProtocol)) {} + while (!stopped && processor.process(inputProtocol, outputProtocol)) { + // message limit is reset for every request + // see THRIFT-601, working on thrift 0.8.0 + // NOTE that THRIFT-820 breaks this again in thrift 0.9.0 + // and TFramedTransport needs to be used from this version onwards + // to avoid the buffer overflow + inputProtocol = inputProtocolFactory_.getProtocol(inputTransport); + outputProtocol = outputProtocolFactory_.getProtocol(outputTransport); + } } catch (TTransportException ttx) { // Assume the client died and continue silently } catch (TException tx) { diff --git a/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java b/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java index 4aaa565..9b986f5 100644 --- a/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java +++ b/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java @@ -115,6 +115,9 @@ public class ThriftServerRunner implements Runnable { static final String COMPACT_CONF_KEY = "hbase.regionserver.thrift.compact"; static final String FRAMED_CONF_KEY = "hbase.regionserver.thrift.framed"; static final String PORT_CONF_KEY = "hbase.regionserver.thrift.port"; + //The max length of an individual thrift message and frames in MB + static final String MAX_MESSAGE_LENGTH_CONF_KEY = "hbase.regionserver.thrift.binary.max_message_length_in_mb"; + static final String MAX_FRAME_SIZE_CONF_KEY = "hbase.regionserver.thrift.framed.max_frame_size_in_mb"; static final String COALESCE_INC_KEY = "hbase.regionserver.thrift.coalesceIncrement"; private static final String DEFAULT_BIND_ADDR = "0.0.0.0"; @@ -269,7 +272,7 @@ public class ThriftServerRunner implements Runnable { protocolFactory = new TCompactProtocol.Factory(); } else { LOG.debug("Using binary protocol"); - protocolFactory = new TBinaryProtocol.Factory(); + protocolFactory = new TBinaryProtocol.Factory(false, true, conf.getInt(MAX_MESSAGE_LENGTH_CONF_KEY, 2) * 1024 * 1024); } Hbase.Processor processor = @@ -279,7 +282,7 @@ public class ThriftServerRunner implements Runnable { // Construct correct TransportFactory TTransportFactory transportFactory; if (conf.getBoolean(FRAMED_CONF_KEY, false) || implType.isAlwaysFramed) { - transportFactory = new TFramedTransport.Factory(); + transportFactory = new TFramedTransport.Factory(conf.getInt(MAX_FRAME_SIZE_CONF_KEY, 2) * 1024 * 1024); LOG.debug("Using framed transport"); } else { transportFactory = new TTransportFactory(); diff --git a/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftServer.java b/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftServer.java index b6235ac..dd6bf0d 100644 --- a/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftServer.java +++ b/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftServer.java @@ -124,10 +124,10 @@ public class ThriftServer { } } - private static TTransportFactory getTTransportFactory(boolean framed) { + private static TTransportFactory getTTransportFactory(boolean framed, int frameSize) { if (framed) { log.debug("Using framed transport"); - return new TFramedTransport.Factory(); + return new TFramedTransport.Factory(frameSize); } else { return new TTransportFactory(); } @@ -266,7 +266,7 @@ public class ThriftServer { // Construct correct ProtocolFactory boolean compact = cmd.hasOption("compact") || - conf.getBoolean("hbase.regionserver.thrift.compact", false); + conf.getBoolean("hbase.regionserver.thrift.compact", true); TProtocolFactory protocolFactory = getTProtocolFactory(compact); THBaseService.Iface handler = ThriftHBaseServiceHandler.newInstance(conf, metrics); @@ -274,8 +274,9 @@ public class ThriftServer { conf.setBoolean("hbase.regionserver.thrift.compact", compact); boolean framed = cmd.hasOption("framed") || - conf.getBoolean("hbase.regionserver.thrift.framed", false) || nonblocking || hsha; - TTransportFactory transportFactory = getTTransportFactory(framed); + conf.getBoolean("hbase.regionserver.thrift.framed", true) || nonblocking || hsha; + TTransportFactory transportFactory = getTTransportFactory(framed, + conf.getInt("hbase.regionserver.thrift.framed.max_frame_size_in_mb", 2) * 1024 * 1024); conf.setBoolean("hbase.regionserver.thrift.framed", framed); // TODO: Remove once HBASE-2155 is resolved