| 1 | package ClickHouse::Encoder::TCP; ## no critic (Capitalization) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # Encoders/decoders for a useful subset of ClickHouse's native TCP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # protocol packets. Built for insert pipelines: pack a Hello + Query, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # then wrap encoded Native blocks in Data packets, then signal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # end-of-insert. Transport is the caller's job (IO::Socket, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # AnyEvent::Handle, IO::Async::Stream, etc.). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # Varint and length-prefixed string codecs are XS (shared with the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # main encoder's buffer helpers); packet-level layout stays in Perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # for readability since it's not a hot path. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # Targets negotiated revision 54429; newer fields require a full client. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # XS loader handled by the parent module; ensure it's loaded so the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # XSUBs under PACKAGE = ClickHouse::Encoder::TCP are available. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | ▶ | use ClickHouse::Encoder (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 4 | ▶ | use Errno (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ## no critic (ProhibitConstantPragma) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # Readability beats Readonly here - these are protocol-defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # numeric tags, used as bare identifiers throughout the module. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | ▶ | use constant DEFAULT_REVISION => 54429; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # Client packet types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 4 | ▶ | use constant CLIENT_HELLO => 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | ▶ | use constant CLIENT_QUERY => 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 4 | ▶ | use constant CLIENT_DATA => 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 4 | ▶ | use constant CLIENT_CANCEL => 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | ▶ | use constant CLIENT_PING => 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # Server packet types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 4 | ▶ | use constant SERVER_HELLO => 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | ▶ | use constant SERVER_DATA => 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 4 | ▶ | use constant SERVER_EXCEPTION => 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 4 | ▶ | use constant SERVER_PROGRESS => 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 4 | ▶ | use constant SERVER_PONG => 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 4 | ▶ | use constant SERVER_END_OF_STREAM => 5; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 4 | ▶ | use constant SERVER_PROFILE_INFO => 6; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 4 | ▶ | use constant SERVER_TOTALS => 7; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 4 | ▶ | use constant SERVER_EXTREMES => 8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 4 | ▶ | use constant SERVER_LOG => 10; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 4 | ▶ | use constant SERVER_TABLE_COLUMNS => 11; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 4 | ▶ | use constant SERVER_PROFILE_EVENTS => 14; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # Query processing stages | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 4 | ▶ | use constant STAGE_FETCH_COLUMNS => 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 4 | ▶ | use constant STAGE_WITH_MERGEABLE => 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 4 | ▶ | use constant STAGE_COMPLETE => 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # Compression flags in Query packet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 4 | ▶ | use constant COMPRESSION_DISABLE => 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 4 | ▶ | use constant COMPRESSION_ENABLE => 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # Varint and length-prefixed string codecs are XS-backed; the bound | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # subs (pack_varint, unpack_varint, pack_string, unpack_string) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # live in PACKAGE = ClickHouse::Encoder::TCP inside Encoder.xs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # ----- client packets ------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # Hello packet: announces our protocol revision and credentials. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # pack_hello( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # client_name => 'ClickHouse::Encoder', # default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # major => 1, # default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # minor => 0, # default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # revision => 54429, # default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # database => 'default', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # user => 'default', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # password => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | ▶ | sub pack_hello { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pack_hello: called CC=8 SCAR=25.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | my (undef, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | return pack_varint(CLIENT_HELLO) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | . pack_string($o{client_name} // 'ClickHouse::Encoder') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | . pack_varint($o{major} // 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | . pack_varint($o{minor} // 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | . pack_varint($o{revision} // DEFAULT_REVISION) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | . pack_string($o{database} // 'default') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | . pack_string($o{user} // 'default') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | ▶ | . pack_string($o{password} // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%7/14
$o{"client_name"} // "ClickHouse::Encoder"
$o{"major"} // 1
$o{"minor"} // 0
$o{"revision"} // 54429
$o{"database"} // "default"
$o{"user"} // "default"
$o{"password"} // ""
MC/DC0%0/1
$o{"client_name"} // "ClickHouse::Encoder"
$o{"client_name"}
MC/DC0%0/1
$o{"major"} // 1
$o{"major"}
MC/DC0%0/1
$o{"minor"} // 0
$o{"minor"}
MC/DC0%0/1
$o{"revision"} // 54429
$o{"revision"}
MC/DC0%0/1
$o{"database"} // "default"
$o{"database"}
MC/DC0%0/1
$o{"user"} // "default"
$o{"user"}
MC/DC0%0/1
$o{"password"} // ""
$o{"password"}
Truth table50%1/2
A
A= $o{"client_name"}
Truth table50%1/2
A
A= $o{"major"}
Truth table50%1/2
A
A= $o{"minor"}
Truth table50%1/2
A
A= $o{"revision"}
Truth table50%1/2
A
A= $o{"database"}
Truth table50%1/2
A
A= $o{"user"}
Truth table50%1/2
A
A= $o{"password"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # Query packet. At revision 54429 the body is: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # varint CLIENT_QUERY (=1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # string query_id (often empty so the server generates one) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # <ClientInfo> (block - see _pack_client_info) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # <Settings> (see _pack_settings) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # varint query_processing_stage (default Complete) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # varint compression flag (default Disable) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # string query SQL text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 13 | ▶ | sub pack_query { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pack_query: called CC=9 SCAR=23.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 13 | my (undef, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 13 | ▶ | my $rev = $o{revision} // DEFAULT_REVISION; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$o{"revision"} // 54429
MC/DC100%1/1
$o{"revision"} // 54429
$o{"revision"}
Truth table100%2/2
A
A= $o{"revision"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | return pack_varint(CLIENT_QUERY) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | . pack_string($o{query_id} // '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | . ($rev >= 54032 ? _pack_client_info(\%o) : '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | . _pack_settings($o{settings}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | . pack_varint($o{stage} // STAGE_COMPLETE) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | . pack_varint($o{compression} // COMPRESSION_DISABLE) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | . pack_string($o{query} // die "pack_query: 'query' is required\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | . __PACKAGE__->pack_data_end(revision => $rev, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 13 | ▶ | compress => $o{compression} ? ($o{compress} // 'lz4') : 'raw'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition70%7/10
$o{"query_id"} // ""
$o{"stage"} // 2
$o{"compression"} // 0
$o{"query"} // die("pack_query: 'query' is required\n")
$o{"compress"} // "lz4"
MC/DC100%1/1
$o{"query_id"} // ""
$o{"query_id"}
MC/DC100%1/1
$o{"stage"} // 2
$o{"stage"}
MC/DC0%0/1
$o{"compression"} // 0
$o{"compression"}
MC/DC100%1/1
$o{"query"} // die("pack_query: 'query' is required\n")
$o{"query"}
MC/DC0%0/1
$o{"compress"} // "lz4"
$o{"compress"}
Truth table100%2/2
A
A= $o{"query_id"}
Truth table100%2/2
A
A= $o{"stage"}
Truth table50%1/2
A
A= $o{"compression"}
Truth table100%2/2
A
A= $o{"query"}
Truth table0%0/2
A
A= $o{"compress"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # ClientInfo subblock. At revision 54429 the fields after the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # fixed prefix are: quota_key (since 54058), version_patch (since | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # 54401). We use those defaults; later-revision fields (interserver | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # secret, OpenTelemetry trace context, parallel-replica metadata) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # would need a higher client revision to be negotiated. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 13 | ▶ | sub _pack_client_info { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pack_client_info: called CC=17 SCAR=31.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 13 | my $o = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 13 | ▶ | my $rev = $o->{revision} // DEFAULT_REVISION; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$o->{"revision"} // 54429
MC/DC100%1/1
$o->{"revision"} // 54429
$o->{"revision"}
Truth table100%2/2
A
A= $o->{"revision"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 13 | my $out = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 13 | ▶ | my $kind = $o->{query_kind} // 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$o->{"query_kind"} // 1
MC/DC0%0/1
$o->{"query_kind"} // 1
$o->{"query_kind"}
Truth table50%1/2
A
A= $o->{"query_kind"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 13 | ▶ | return chr(0) if !$kind; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 13 | $out .= chr($kind); # 1 = initial query | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 13 | ▶ | $out .= pack_string($o->{initial_user} // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$o->{"initial_user"} // ""
MC/DC0%0/1
$o->{"initial_user"} // ""
$o->{"initial_user"}
Truth table50%1/2
A
A= $o->{"initial_user"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 13 | ▶ | $out .= pack_string($o->{initial_query_id} // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$o->{"initial_query_id"} // ""
MC/DC0%0/1
$o->{"initial_query_id"} // ""
$o->{"initial_query_id"}
Truth table50%1/2
A
A= $o->{"initial_query_id"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 13 | ▶ | $out .= pack_string($o->{initial_address} // '0.0.0.0:0'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$o->{"initial_address"} // "0.0.0.0:0"
MC/DC0%0/1
$o->{"initial_address"} // "0.0.0.0:0"
$o->{"initial_address"}
Truth table50%1/2
A
A= $o->{"initial_address"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # interface: 1 = TCP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 13 | $out .= chr(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # os_user, client_hostname, client_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 13 | ▶ | $out .= pack_string($o->{os_user} // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$o->{"os_user"} // ""
MC/DC0%0/1
$o->{"os_user"} // ""
$o->{"os_user"}
Truth table50%1/2
A
A= $o->{"os_user"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 13 | ▶ | $out .= pack_string($o->{client_hostname} // 'localhost'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$o->{"client_hostname"} // "localhost"
MC/DC0%0/1
$o->{"client_hostname"} // "localhost"
$o->{"client_hostname"}
Truth table50%1/2
A
A= $o->{"client_hostname"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 13 | ▶ | $out .= pack_string($o->{client_name} // 'ClickHouse::Encoder'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$o->{"client_name"} // "ClickHouse::Encoder"
MC/DC0%0/1
$o->{"client_name"} // "ClickHouse::Encoder"
$o->{"client_name"}
Truth table50%1/2
A
A= $o->{"client_name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # client_version_{major,minor}, client_revision | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 13 | ▶ | $out .= pack_varint($o->{client_version_major} // 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$o->{"client_version_major"} // 1
MC/DC0%0/1
$o->{"client_version_major"} // 1
$o->{"client_version_major"}
Truth table50%1/2
A
A= $o->{"client_version_major"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 13 | ▶ | $out .= pack_varint($o->{client_version_minor} // 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$o->{"client_version_minor"} // 0
MC/DC0%0/1
$o->{"client_version_minor"} // 0
$o->{"client_version_minor"}
Truth table50%1/2
A
A= $o->{"client_version_minor"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 13 | ▶ | $out .= pack_varint($o->{client_revision} // $rev); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$o->{"client_revision"} // $rev
MC/DC0%0/2
$o->{"client_revision"} // $rev
$o->{"client_revision"}
$rev
Truth table33%1/3
A // B
A= $o->{"client_revision"}B= $rev
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # quota_key (rev >= 54058) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 13 | ▶ | $out .= pack_string($o->{quota_key} // '') if $rev >= 54058; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$o->{"quota_key"} // ""
MC/DC0%0/1
$o->{"quota_key"} // ""
$o->{"quota_key"}
Truth table50%1/2
A
A= $o->{"quota_key"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # client_version_patch (rev >= 54401) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 13 | ▶ | $out .= pack_varint($o->{client_version_patch} // 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$o->{"client_version_patch"} // 0
MC/DC0%0/1
$o->{"client_version_patch"} // 0
$o->{"client_version_patch"}
Truth table50%1/2
A
A= $o->{"client_version_patch"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | if $rev >= 54401; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 13 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # Settings block. At revision >= 54429 each entry is: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # string name + varint flags + string value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # terminated by an empty-key string. flags is a bitmask where 0 means | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # "ordinary setting"; bit 0x01 = IMPORTANT, bit 0x02 = CUSTOM. We | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # always emit flags=0 - the server still accepts any setting at flag 0. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 14 | ▶ | sub _pack_settings { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pack_settings: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 14 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 14 | ▶ | return pack_string('') unless defined $s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 4 | ▶ | if (ref $s eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 3 | my $body = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 3 | for my $k (sort keys %$s) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 4 | $body .= pack_string($k); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 4 | $body .= pack_varint(0); # flags: ordinary | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 4 | $body .= pack_string($s->{$k}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 3 | $body .= pack_string(''); # end marker | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 3 | return $body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # Allow caller to pass raw bytes (already in the right shape). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | return $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # Data packet wrapping a Native block. table_name is usually empty | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # for inserts; the server already knows the target from the Query. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # With compress => 'lz4' (or 'zstd') the block is wrapped in CH's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # compressed-block framing (16-byte CityHash128 + 9-byte header + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # compressed payload) before being placed on the wire; the server | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # must have been told to expect compressed data via the Query packet's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # compression flag (see pack_query's `compression =E<gt> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # COMPRESSION_ENABLE`). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 21 | ▶ | sub pack_block_info { return "\x01\x00\x02\xff\xff\xff\xff\x00" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pack_block_info: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 13 | ▶ | sub unpack_block_info { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unpack_block_info: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 13 | my ($bytes, $offset) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 13 | my %info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 13 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 39 | (my $field, $offset) = unpack_varint($bytes, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 39 | ▶ | last if !$field; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 26 | ▶ | my $width = $field == 1 ? 1 : $field == 2 ? 4 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 26 | ▶ | die "BlockInfo: unknown field $field\n" unless $width; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 26 | ▶ | die "BlockInfo: truncated at offset $offset\n" if $offset + $width > length $bytes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 26 | ▶ | $info{$field == 1 ? 'is_overflows' : 'bucket_num'} = $field == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | ? ord substr($bytes, $offset, 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | : unpack('l<', substr($bytes, $offset, 4)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 26 | $offset += $width; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 13 | return (\%info, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 19 | ▶ | sub pack_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pack_data: called CC=9 SCAR=22.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 19 | my (undef, $block_bytes, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 19 | ▶ | die "pack_data: block bytes required\n" unless defined $block_bytes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 18 | ▶ | my $rev = $o{revision} // DEFAULT_REVISION; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$o{"revision"} // 54429
MC/DC100%1/1
$o{"revision"} // 54429
$o{"revision"}
Truth table100%2/2
A
A= $o{"revision"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 18 | ▶ | $block_bytes = pack_block_info() . $block_bytes if $rev >= 51903; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 18 | ▶ | if (defined $o{compress} && $o{compress} ne 'none' && $o{compress} ne 'raw') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $o{"compress"} and $o{"compress"} ne "none" and $o{"compress"} ne "raw"
defined $o{"compress"} and $o{"compress"} ne "none"
MC/DC66%2/3
defined $o{"compress"} and $o{"compress"} ne "none" and $o{"compress"} ne "raw"
defined $o{"compress"}
$o{"compress"} ne "none"
$o{"compress"} ne "raw"
Truth table75%3/4
A and B and C
A= defined $o{"compress"}B= $o{"compress"} ne "none"C= $o{"compress"} ne "raw"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 4 | $block_bytes = ClickHouse::Encoder->compress_native_block($block_bytes, mode => $o{compress}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | return pack_varint(CLIENT_DATA) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 18 | ▶ | . ($rev >= 50264 ? pack_string($o{table_name} // '') : '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$o{"table_name"} // ""
MC/DC0%0/1
$o{"table_name"} // ""
$o{"table_name"}
Truth table50%1/2
A
A= $o{"table_name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | . $block_bytes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 15 | ▶ | sub pack_data_end { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pack_data_end: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 15 | my ($class, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 15 | return $class->pack_data("\x00\x00", %o); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 1 | ▶ | sub pack_ping { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pack_ping: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 1 | return pack_varint(CLIENT_PING); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 1 | ▶ | sub pack_cancel { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pack_cancel: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 1 | return pack_varint(CLIENT_CANCEL); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # ----- server packet decoder ----------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | # Parse one server packet from $bytes starting at $offset. Returns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # (\%packet, $new_offset). %packet always has 'type' (numeric); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # payload fields depend on type. Croaks on truncation; caller can | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # pre-screen by ensuring at least 1 byte is available. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 44 | ▶ | sub unpack_packet { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unpack_packet: called CC=29 SCAR=33.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 44 | my (undef, $bytes, $offset, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 44 | ▶ | $offset //= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$offset //= 0
MC/DC100%1/1
$offset //= 0
$offset
Truth table100%2/2
A
A= $offset
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 44 | (my $type, $offset) = unpack_varint($bytes, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 32 | my %pkt = (type => $type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 32 | ▶ | my $rev = $opts{revision} // DEFAULT_REVISION; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"revision"} // 54429
MC/DC0%0/1
$opts{"revision"} // 54429
$opts{"revision"}
Truth table50%1/2
A
A= $opts{"revision"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 32 | ▶ | if ($type == SERVER_HELLO) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 7 | ($pkt{name}, $offset) = unpack_string($bytes, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 5 | ($pkt{major}, $offset) = unpack_varint($bytes, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 5 | ($pkt{minor}, $offset) = unpack_varint($bytes, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 5 | ($pkt{revision}, $offset) = unpack_varint($bytes, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # Newer revisions add timezone / display_name / version_patch. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | # Gate on the revision the server just reported, not on "are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # there bytes left": a buffer that ends mid-Hello must croak | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | # 'truncated' so the reader fetches more, not silently drop a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # field whose bytes simply have not arrived yet. Thresholds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # match ClickHouse's DBMS_MIN_REVISION_WITH_* constants. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 5 | ▶ | my $hello_rev = $pkt{revision} < $rev ? $pkt{revision} : $rev; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 5 | ▶ | if ($hello_rev >= 54058) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 4 | ($pkt{timezone}, $offset) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | = unpack_string($bytes, $offset); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 4 | ▶ | if ($hello_rev >= 54372) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 3 | ($pkt{display_name}, $offset) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | = unpack_string($bytes, $offset); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 4 | ▶ | if ($hello_rev >= 54401) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 3 | ($pkt{version_patch}, $offset) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | = unpack_varint($bytes, $offset); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | elsif ($type == SERVER_EXCEPTION) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # ExceptionPacket: code(Int32 LE), name, message, stack_trace, has_nested(byte) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 3 | ▶ | die "unpack_packet: truncated at offset $offset" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | if $offset + 4 > length $bytes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 3 | $pkt{code} = unpack 'l<', substr($bytes, $offset, 4); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 3 | $offset += 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 3 | ($pkt{name}, $offset) = unpack_string($bytes, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 3 | ($pkt{message}, $offset) = unpack_string($bytes, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 3 | ($pkt{stack_trace}, $offset) = unpack_string($bytes, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 3 | ▶ | die "unpack_packet: truncated at offset $offset" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | if $offset >= length $bytes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 3 | $pkt{has_nested} = ord substr($bytes, $offset++, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 3 | ▶ | if ($pkt{has_nested}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | my ($nested, $next) = __PACKAGE__->unpack_packet( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | pack_varint(SERVER_EXCEPTION) . substr($bytes, $offset)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | $pkt{nested} = $nested; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | $offset += $next - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | elsif ($type == SERVER_PROGRESS) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # At the targeted protocol revision (54429) a Progress packet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # is exactly these five varints. Later revisions append fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # (elapsed_ns, ...), but the Progress packet carries no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | # revision of its own, so the only safe stopping point without | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # threading the negotiated revision through is the end of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # 54429 layout. Reading a trailing field "if bytes remain" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # would, on a buffer that already holds the next packet, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # consume that packet's bytes instead. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 2 | ($pkt{rows}, $offset) = unpack_varint($bytes, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 2 | ($pkt{bytes}, $offset) = unpack_varint($bytes, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 2 | ($pkt{total_rows}, $offset) = unpack_varint($bytes, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 2 | ($pkt{written_rows}, $offset) = unpack_varint($bytes, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 2 | ($pkt{written_bytes}, $offset) = unpack_varint($bytes, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | ▶ | elsif ($type == SERVER_PONG || $type == SERVER_END_OF_STREAM) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$type == 4 or $type == 5
MC/DC100%2/2
$type == 4 or $type == 5
$type == 4
$type == 5
Truth table100%3/3
A or B
A= $type == 4B= $type == 5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # No payload. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | elsif ($type == SERVER_PROFILE_INFO) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 1 | ($pkt{rows}, $offset) = unpack_varint($bytes, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 1 | ($pkt{blocks}, $offset) = unpack_varint($bytes, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 1 | ($pkt{rows_bytes}, $offset) = unpack_varint($bytes, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 1 | ▶ | die "unpack_packet: truncated at offset $offset" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | if $offset >= length $bytes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 1 | $pkt{applied_limit} = ord substr($bytes, $offset++, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | ($pkt{rows_before_limit}, $offset) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | = unpack_varint($bytes, $offset); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 1 | ▶ | die "unpack_packet: truncated at offset $offset" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | if $offset >= length $bytes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | $pkt{calculated_rows_before_limit} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 1 | = ord substr($bytes, $offset++, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | ▶ | elsif ($type == SERVER_DATA || $type == SERVER_TOTALS || $type == SERVER_EXTREMES | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%12/12
$type == 1 or $type == 7 or $type == 8 or $type == 10 or $type == 14
$type == 1 or $type == 7 or $type == 8 or $type == 10
$type == 1 or $type == 7 or $type == 8
$type == 1 or $type == 7
MC/DC100%5/5
$type == 1 or $type == 7 or $type == 8 or $type == 10 or $type == 14
$type == 1
$type == 7
$type == 8
$type == 10
$type == 14
Truth table100%6/6
A or B or C or D or E
A= $type == 1B= $type == 7C= $type == 8D= $type == 10E= $type == 14
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | || $type == SERVER_LOG || $type == SERVER_PROFILE_EVENTS) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 8 | ▶ | ($pkt{table_name}, $offset) = unpack_string($bytes, $offset) if $rev >= 50264; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 8 | ▶ | my $compressed = $opts{compressed} && $type != SERVER_LOG && $type != SERVER_PROFILE_EVENTS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$opts{'compressed'} && $type != 10 && $type != 14
$opts{"compressed"} and $type != 10
MC/DC66%2/3
$opts{'compressed'} && $type != 10 && $type != 14
$opts{"compressed"}
$type != 10
$type != 14
Truth table75%3/4
A and B && C
A= $opts{"compressed"}B= $type != 10C= $type != 14
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 8 | ▶ | if (!$compressed && $rev >= 51903) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $compressed and $rev >= 51903
MC/DC50%1/2
not $compressed and $rev >= 51903
not $compressed
$rev >= 51903
Truth table66%2/3
not(A) and B
A= not $compressedB= $rev >= 51903
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 6 | ($pkt{block_info}, $offset) = unpack_block_info($bytes, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 8 | $pkt{block_offset} = $offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | elsif ($type == SERVER_TABLE_COLUMNS) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | ($pkt{table_name}, $offset) = unpack_string($bytes, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 1 | ($pkt{column_descriptor}, $offset) = unpack_string($bytes, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 1 | die "unpack_packet: unknown server packet type $type\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 28 | return (\%pkt, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | # Blocking read helper for IO::Socket / IO::Handle. Pulls bytes until | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | # one full packet parses, returns the packet hashref. For | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | # Data/Totals/Extremes/ProfileEvents packets the inner Native block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | # bytes are read into $pkt->{block_bytes} (the raw slice ready for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | # ClickHouse::Encoder->decode_block); $pkt->{block} carries the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | # pre-decoded block hashref. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | # Reads whatever sysread returns (up to 4 KiB at a time): the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | # protocol packets are size-self-describing, so we let unpack_packet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | # tell us when it has enough bytes. Avoids the trap of trying to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | # block-read N bytes when the server has only sent K < N. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 17 | ▶ | sub read_packet { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_packet: called CC=21 SCAR=30.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 17 | my (undef, $fh, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 17 | ▶ | my $bufref = $opts{buffer} // \my $local_buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts{"buffer"} // \my $local_buf
MC/DC100%1/1
$opts{"buffer"} // \my $local_buf
$opts{"buffer"}
Truth table100%2/2
A
A= $opts{"buffer"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 17 | ▶ | $$bufref //= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$bufref //= ""
MC/DC100%1/1
$$bufref //= ""
$$bufref
Truth table100%2/2
A
A= $$bufref
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 17 | my $timeout = $opts{timeout}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 17 | my ($deadline, $fd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 17 | ▶ | if (defined $timeout) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 4 | require Time::HiRes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 4 | $deadline = Time::HiRes::time() + $timeout; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 4 | $fd = fileno $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 18 | ▶ | my $read_some = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=11 SCAR=24.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 18 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 22 | ▶ | if (defined $fd && $fd >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $fd and $fd >= 0
MC/DC50%1/2
defined $fd and $fd >= 0
defined $fd
$fd >= 0
Truth table66%2/3
A and B
A= defined $fdB= $fd >= 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 8 | my $left = $deadline - Time::HiRes::time(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 8 | my $expired = "read_packet: timed out after ${timeout}s waiting for the server\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 8 | ▶ | die $expired if $left <= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 7 | my $ready = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 7 | vec($ready, $fd, 1) = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 7 | my $n = select($ready, undef, undef, $left); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 7 | ▶ | die $expired if $n == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 5 | ▶ | if ($n < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 3 | ▶ | next if $! == Errno::EINTR(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | die "read_packet: select failed: $!\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 16 | my $got = sysread $fh, my $chunk, 4096; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 16 | ▶ | next if !defined $got && $! == Errno::EINTR(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $got and $! == 4
MC/DC50%1/2
not defined $got and $! == 4
not defined $got
$! == 4
Truth table66%2/3
not(A) and B
A= not defined $gotB= $! == 4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 15 | ▶ | die "read_packet: read error: $!\n" unless defined $got; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 15 | ▶ | die "read_packet: connection closed mid-packet\n" if !$got; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 14 | $$bufref .= $chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 14 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 17 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 17 | my ($pkt, $end); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 17 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 27 | my $ok = eval { ($pkt, $end) = __PACKAGE__->unpack_packet($$bufref, 0, %opts); 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 27 | ▶ | last if $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 14 | ▶ | die $@ unless $@ =~ /truncated/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 14 | $read_some->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 13 | ▶ | if (exists $pkt->{block_offset}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | my $compressed = $opts{compressed} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 5 | ▶ | && $pkt->{type} != SERVER_LOG && $pkt->{type} != SERVER_PROFILE_EVENTS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$opts{'compressed'} && $pkt->{'type'} != 10 && $pkt->{'type'} != 14
$opts{"compressed"} and $pkt->{"type"} != 10
MC/DC66%2/3
$opts{'compressed'} && $pkt->{'type'} != 10 && $pkt->{'type'} != 14
$opts{"compressed"}
$pkt->{"type"} != 10
$pkt->{'type'} != 14
Truth table75%3/4
A and B && C
A= $opts{"compressed"}B= $pkt->{"type"} != 10C= $pkt->{'type'} != 14
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 5 | ▶ | if ($compressed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 2 | my $plain = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 2 | my $off = $pkt->{block_offset}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 2 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 6 | my ($frame, $consumed); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 6 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 7 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 7 | ($frame, $consumed) = ClickHouse::Encoder->decompress_native_block( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 6 | $$bufref, offset => $off); 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 7 | ▶ | last if $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 1 | ▶ | die $@ unless $@ =~ /truncated header|extends past buffer/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 1 | $read_some->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 6 | $off += $consumed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 6 | $plain .= $frame; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 6 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 6 | my $start = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 6 | ▶ | if (($opts{revision} // DEFAULT_REVISION) >= 51903) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$opts{"revision"} // 54429
MC/DC0%0/1
$opts{"revision"} // 54429
$opts{"revision"}
Truth table50%1/2
A
A= $opts{"revision"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 6 | ($pkt->{block_info}, $start) = unpack_block_info($plain, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 6 | my $b = ClickHouse::Encoder->decode_block($plain, $start); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | die "read_packet: trailing bytes in compressed Data packet\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 2 | ▶ | unless $start + $b->{consumed} == length $plain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 2 | $pkt->{block} = $b; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 2 | $pkt->{block_bytes} = substr($plain, $start); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 2 | $pkt->{compressed_consumed} = $off - $pkt->{block_offset}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 6 | ▶ | if ($ok) { $end = $off; last } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 4 | ▶ | die $@ unless $@ =~ /truncated|exceeds remaining buffer/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 3 | my $need_at = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 3 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 6 | ▶ | $read_some->() while length($$bufref) < $need_at; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 6 | my $b = eval { ClickHouse::Encoder->decode_block($$bufref, $pkt->{block_offset}) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 6 | ▶ | if (!$@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 3 | $pkt->{block} = $b; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 3 | $pkt->{block_bytes} = substr($$bufref, $pkt->{block_offset}, $b->{consumed}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 3 | $end = $pkt->{block_offset} + $b->{consumed}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 3 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 3 | ▶ | die $@ unless $@ =~ /truncated|exceeds remaining buffer/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 3 | ▶ | $need_at = length($$bufref) + ($@ =~ /need (\d+) more/ ? $1 : 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 13 | substr($$bufref, 0, $end, ''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 13 | return $pkt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||