clickhouse-native 0.4.0-x86_64-linux-gnu → 0.4.1-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: d2bacbc39cae175fcb06326a7cf6cd60e5e4f5f72572b95d427f35a670b03a2f
4
- data.tar.gz: 18738124e3cdd513bb62c70ddb76fc506d76184a8e430d914c5331474a400888
3
+ metadata.gz: 386a7111a30efc9701a76d4bb8e41dffe643cdd769f3f03bd70b1a9b09f6ad80
4
+ data.tar.gz: 2d1e897786ce05c6631e4c90404731c44f25925f4419a81466a3c96f2db07166
5
5
  SHA512:
6
- metadata.gz: 1658b5be541cc7a4263dd52eaab1a978d297110e359909654ef22b8a27dc1d8a79ada33eb5c6b7944fa1b0aadde96ec56e170e6daf5d463c15df1d9b0a013e52
7
- data.tar.gz: 11edbebf63a611c6f44160d9c0eb63ffab39ea07e55c6f063e4049358a31cdc523ab4cce6ed1eb46762c5f5cae74b732d178a1899673ae05b16ee1ae60c3b071
6
+ metadata.gz: 4f30f23d1512615d846ca53721ba6ccc427e00e85285fe8178a023c13d45b043188c17628e777838c5ad8ac3c951e92f8a16667e8b34281335fcae0d653e365d
7
+ data.tar.gz: 338826686b6e8ea8bdbe13d726ed6691918cf08a7230a51f3ec9b9deb880e655208d15e0a8b377d9ceb6ae288d6da821b302acbed880258911cc2e26600105a0
@@ -4,6 +4,8 @@ require "connection_pool"
4
4
 
5
5
  module ClickhouseNative
6
6
  class Pool
7
+ STALE_IVAR = :@clickhouse_native_settings_stale
8
+
7
9
  attr_reader :host, :port, :database
8
10
 
9
11
  def initialize(host:, port:, database: "default", user: "default", password: "",
@@ -13,52 +15,71 @@ module ClickhouseNative
13
15
  @port = port
14
16
  @database = database
15
17
  client_kwargs = { host:, port:, database:, user:, password:, compression:, logger: }
16
- set_sql = settings_sql(settings)
18
+ @set_sql = settings_sql(settings)
17
19
  @pool = ConnectionPool.new(size: pool_size, timeout: pool_timeout) do
18
20
  client = Client.new(**client_kwargs)
19
- client.execute(set_sql) if set_sql
21
+ client.execute(@set_sql) if @set_sql
20
22
  client
21
23
  end
22
24
  end
23
25
 
24
- def with(&)
25
- @pool.with(&)
26
+ # Yields a client with the pool's session settings applied. If the
27
+ # previous checkout raised (which, in this gem's C++ bindings, always
28
+ # triggers a ResetConnection that wipes the session), re-apply the SET
29
+ # before yielding. Exceptions re-raise after marking the client stale.
30
+ def with
31
+ @pool.with do |client|
32
+ reapply_settings_if_stale(client)
33
+ begin
34
+ yield client
35
+ rescue
36
+ client.instance_variable_set(STALE_IVAR, true)
37
+ raise
38
+ end
39
+ end
26
40
  end
27
41
 
28
42
  def execute(sql)
29
- @pool.with { |c| c.execute(sql) }
43
+ with { |c| c.execute(sql) }
30
44
  end
31
45
 
32
46
  def query(sql)
33
- @pool.with { |c| c.query(sql) }
47
+ with { |c| c.query(sql) }
34
48
  end
35
49
 
36
50
  def query_each(sql, &block)
37
- @pool.with { |c| c.query_each(sql, &block) }
51
+ with { |c| c.query_each(sql, &block) }
38
52
  end
39
53
 
40
54
  def query_value(sql)
41
- @pool.with { |c| c.query_value(sql) }
55
+ with { |c| c.query_value(sql) }
42
56
  end
43
57
 
44
58
  def insert(table, rows, **opts)
45
- @pool.with { |c| c.insert(table, rows, **opts) }
59
+ with { |c| c.insert(table, rows, **opts) }
46
60
  end
47
61
 
48
62
  def ping
49
- @pool.with(&:ping)
63
+ with(&:ping)
50
64
  end
51
65
 
52
66
  def server_version
53
- @pool.with(&:server_version)
67
+ with(&:server_version)
54
68
  end
55
69
 
56
70
  def describe_table(table, db_name: nil)
57
- @pool.with { |c| c.describe_table(table, db_name:) }
71
+ with { |c| c.describe_table(table, db_name:) }
58
72
  end
59
73
 
60
74
  private
61
75
 
76
+ def reapply_settings_if_stale(client)
77
+ return unless @set_sql
78
+ return unless client.instance_variable_get(STALE_IVAR)
79
+ client.execute(@set_sql)
80
+ client.instance_variable_set(STALE_IVAR, false)
81
+ end
82
+
62
83
  # Render a `SET key1 = val1, key2 = val2` statement once at pool setup
63
84
  # so every checked-out connection starts with the same session
64
85
  # settings. Matches how the HTTP driver injected global_params per
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ClickhouseNative
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.1"
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.4.0
4
+ version: 0.4.1
5
5
  platform: x86_64-linux-gnu
6
6
  authors:
7
7
  - Yuri Smirnov