clickhouse-native 0.10.0-x86_64-linux-gnu → 0.11.0-x86_64-linux-gnu

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcdd476f794de7aac41b071f831ecd5a55ccef28a971c4d6e9c7c1e9c5d84963
4
- data.tar.gz: d6882f8176d9842ec164dd3c67bd5138791b387ebc05c30af4e48a9af992216e
3
+ metadata.gz: d6186352daf6afcb3b55c2b1839055b8d4bc1d414067f6c52bf6353cfce221d5
4
+ data.tar.gz: e5b25c22dc3d3e66987a3d5c03bf1e91829507b5cc6c31522e96adaa6a820554
5
5
  SHA512:
6
- metadata.gz: 9ab472f6538862903b117c6c355d9b82e0b0f7d4fc8e428b62dbc1acb5fde79a01aceea99fd49b2ebdad32bb59c55881f47e5a3ebd7e81e886a0c11a0b3a9270
7
- data.tar.gz: 1782fe9cb311931c8af39da6a0bbd46754d35d43c73913aab224b9d3568c52fe5f142e71273d809ab59d5905c9e56a9b6b4850b3cd30c9ab9b5b55e7ebcc9469
6
+ metadata.gz: b37f44e1705a8a5fef335e8be1b7b493e1b5622721b4bfa9d13133b7ab14d44d3fab4ee0b3128bfdfc0c809544804b72678bbe4491d206233fda75443777ca14
7
+ data.tar.gz: 97605a75f445c3b74360aec37c247cd0219eb741894e4623504481afe2ae7deabe63c9aa3638377e68f07ddb562e42c4c504c9ad1a6274aa3959d7315392ba90
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ClickhouseNative
4
4
  class Client
5
- attr_reader :host, :port, :database
5
+ attr_reader :host, :port, :database, :ping_before_query, :tcp_keepalive, :retry_timeout
6
6
 
7
7
  def describe_table(table, db_name: nil)
8
8
  fq = db_name ? "#{db_name}.#{table}" : table
@@ -8,16 +8,17 @@ module ClickhouseNative
8
8
 
9
9
  def initialize(host:, port:, database: "default", user: "default", password: "",
10
10
  compression: :none, logger: nil, settings: {},
11
- pool_size: 5, pool_timeout: 5)
11
+ pool_size: 5, pool_timeout: 5,
12
+ ping_before_query: true, tcp_keepalive: true, retry_timeout: 1)
12
13
  @host = host
13
14
  @port = port
14
15
  @database = database
15
- client_kwargs = { host:, port:, database:, user:, password:, compression:, logger: }
16
- @set_sql = settings_sql(settings)
16
+ client_kwargs = {
17
+ host:, port:, database:, user:, password:, compression:, logger:, settings:,
18
+ ping_before_query:, tcp_keepalive:, retry_timeout:
19
+ }
17
20
  @pool = ConnectionPool.new(size: pool_size, timeout: pool_timeout) do
18
- client = Client.new(**client_kwargs)
19
- client.execute(@set_sql) if @set_sql
20
- client
21
+ Client.new(**client_kwargs)
21
22
  end
22
23
  end
23
24
 
@@ -25,18 +26,24 @@ module ClickhouseNative
25
26
  # path leaves the socket in an unknown state. The C++ binding issues
26
27
  # ResetConnection, but a subsequent send can still surface buffered
27
28
  # protocol errors from the prior aborted operation — those get
28
- # attributed to whatever SQL we tried next (e.g. the SET reapplying
29
- # session settings), producing misleading log lines and re-raises in
30
- # unrelated code. A fresh socket + handshake is cheap relative to
31
- # debugging that.
29
+ # attributed to whatever SQL we tried next, producing misleading log
30
+ # lines and re-raises in unrelated code. A fresh socket + handshake is
31
+ # cheap relative to debugging that.
32
32
  #
33
33
  # ConnectionError gets one automatic retry: pooled connections that
34
34
  # have been idle long enough for the server / an LB to FIN them
35
- # surface as "closed" on the very next recv (errno 0, message
36
- # "closed: Success"). Discarding and re-checking out lands a fresh
37
- # socket and the operation succeeds. The retry only triggers when
38
- # the dead-connection error fired before any data was sent, so
39
- # write operations don't risk double-execution from this path.
35
+ # surface as "closed" on the very next recv (errno is whatever stale
36
+ # value was left in the thread — "closed: Success", "closed: Operation
37
+ # now in progress", etc. all mean the same recv()==0). Discarding and
38
+ # re-checking out lands a fresh socket and the operation succeeds. The
39
+ # retry only triggers when the dead-connection error fired before any
40
+ # data was sent, so write operations don't risk double-execution.
41
+ #
42
+ # This is the backstop: with ping_before_query on (the default) the
43
+ # driver already pings and transparently reconnects a dead socket
44
+ # before running the query, so most stale connections never surface as
45
+ # a ConnectionError here at all. This retry still covers the residual
46
+ # race (socket dies between the ping and the query).
40
47
  def with
41
48
  attempts = 0
42
49
  begin
@@ -84,21 +91,5 @@ module ClickhouseNative
84
91
  def describe_table(table, db_name: nil)
85
92
  with { |c| c.describe_table(table, db_name:) }
86
93
  end
87
-
88
- private
89
-
90
- # Render a `SET key1 = val1, key2 = val2` statement once at pool setup
91
- # so every checked-out connection starts with the same session
92
- # settings. Matches how the HTTP driver injected global_params per
93
- # request. Values: Integer / Float render bare; anything else is
94
- # quoted as a SQL string literal.
95
- def settings_sql(settings)
96
- return nil if settings.nil? || settings.empty?
97
- parts = settings.map do |k, v|
98
- literal = v.is_a?(Numeric) ? v.to_s : "'#{v.to_s.gsub("'", "''")}'"
99
- "#{k} = #{literal}"
100
- end
101
- "SET #{parts.join(', ')}"
102
- end
103
94
  end
104
95
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ClickhouseNative
4
- VERSION = "0.10.0"
4
+ VERSION = "0.11.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clickhouse-native
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: x86_64-linux-gnu
6
6
  authors:
7
7
  - Yuri Smirnov