|
21 | 21 | #include "util/tls/tls_socket.h"
|
22 | 22 | #endif
|
23 | 23 |
|
| 24 | +using namespace std; |
| 25 | + |
24 | 26 | ABSL_FLAG(bool, tcp_nodelay, false,
|
25 | 27 | "Configures dragonfly connections with socket option TCP_NODELAY");
|
26 | 28 | ABSL_FLAG(bool, primary_port_http_enabled, true,
|
27 | 29 | "If true allows accessing http console on main TCP port");
|
28 | 30 |
|
29 |
| -ABSL_FLAG( |
30 |
| - std::uint16_t, admin_port, 0, |
31 |
| - "If set, would enable admin access to console on the assigned port. This supports both HTTP " |
32 |
| - "and RESP protocols"); |
33 |
| -ABSL_FLAG(std::string, admin_bind, "", |
| 31 | +ABSL_FLAG(uint16_t, admin_port, 0, |
| 32 | + "If set, would enable admin access to console on the assigned port. " |
| 33 | + "This supports both HTTP and RESP protocols"); |
| 34 | + |
| 35 | +ABSL_FLAG(string, admin_bind, "", |
34 | 36 | "If set, the admin consol TCP connection would be bind the given address. "
|
35 |
| - "This supports both HTTP and RESP " |
36 |
| - "protocols"); |
| 37 | + "This supports both HTTP and RESP protocols"); |
37 | 38 |
|
38 |
| -ABSL_FLAG(std::uint64_t, request_cache_limit, 1ULL << 26, // 64MB |
| 39 | +ABSL_FLAG(uint64_t, request_cache_limit, 1ULL << 26, // 64MB |
39 | 40 | "Amount of memory to use for request cache in bytes - per IO thread.");
|
40 | 41 |
|
41 | 42 | ABSL_FLAG(bool, no_tls_on_admin_port, false, "Allow non-tls connections on admin port");
|
42 | 43 |
|
43 |
| -ABSL_FLAG(std::uint64_t, pipeline_squash, 0, |
| 44 | +ABSL_FLAG(uint64_t, pipeline_squash, 0, |
44 | 45 | "Number of queued pipelined commands above which squashing is enabled, 0 means disabled");
|
45 | 46 |
|
| 47 | +// When changing this constant, also update `test_large_cmd` test in connection_test.py. |
| 48 | +ABSL_FLAG(uint32_t, max_multi_bulk_len, 1u << 16, |
| 49 | + "Maximum multi-bulk (array) length that is " |
| 50 | + "allowed to be accepted when parsing RESP protocol"); |
| 51 | + |
| 52 | +ABSL_FLAG(size_t, max_client_iobuf_len, 1u << 16, |
| 53 | + "Maximum io buffer length that is used to read client requests."); |
| 54 | + |
46 | 55 | using namespace util;
|
47 |
| -using namespace std; |
48 | 56 | using nonstd::make_unexpected;
|
49 | 57 |
|
50 | 58 | namespace facade {
|
@@ -79,8 +87,6 @@ bool MatchHttp11Line(string_view line) {
|
79 | 87 | }
|
80 | 88 |
|
81 | 89 | constexpr size_t kMinReadSize = 256;
|
82 |
| -constexpr size_t kMaxReadSize = 64_KB; |
83 |
| - |
84 | 90 | constexpr size_t kMaxDispatchQMemory = 5_MB;
|
85 | 91 |
|
86 | 92 | thread_local uint32_t free_req_release_weight = 0;
|
@@ -235,7 +241,7 @@ Connection::Connection(Protocol protocol, util::HttpListenerBase* http_listener,
|
235 | 241 |
|
236 | 242 | switch (protocol) {
|
237 | 243 | case Protocol::REDIS:
|
238 |
| - redis_parser_.reset(new RedisParser); |
| 244 | + redis_parser_.reset(new RedisParser(absl::GetFlag(FLAGS_max_multi_bulk_len))); |
239 | 245 | break;
|
240 | 246 | case Protocol::MEMCACHE:
|
241 | 247 | memcache_parser_.reset(new MemcacheParser);
|
@@ -676,6 +682,8 @@ auto Connection::IoLoop(util::FiberSocketBase* peer, SinkReplyBuilder* orig_buil
|
676 | 682 | error_code ec;
|
677 | 683 | ParserStatus parse_status = OK;
|
678 | 684 |
|
| 685 | + size_t max_iobfuf_len = absl::GetFlag(FLAGS_max_client_iobuf_len); |
| 686 | + |
679 | 687 | do {
|
680 | 688 | FetchBuilderStats(stats_, orig_builder);
|
681 | 689 |
|
@@ -709,13 +717,13 @@ auto Connection::IoLoop(util::FiberSocketBase* peer, SinkReplyBuilder* orig_buil
|
709 | 717 | parse_status = OK;
|
710 | 718 |
|
711 | 719 | size_t capacity = io_buf_.Capacity();
|
712 |
| - if (capacity < kMaxReadSize) { |
| 720 | + if (capacity < max_iobfuf_len) { |
713 | 721 | size_t parser_hint = 0;
|
714 | 722 | if (redis_parser_)
|
715 | 723 | parser_hint = redis_parser_->parselen_hint(); // Could be done for MC as well.
|
716 | 724 |
|
717 | 725 | if (parser_hint > capacity) {
|
718 |
| - io_buf_.Reserve(std::min(kMaxReadSize, parser_hint)); |
| 726 | + io_buf_.Reserve(std::min(max_iobfuf_len, parser_hint)); |
719 | 727 | }
|
720 | 728 |
|
721 | 729 | if (io_buf_.AppendLen() < 64u) {
|
|
0 commit comments