clickhouse-native 0.3.1-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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 386a7111a30efc9701a76d4bb8e41dffe643cdd769f3f03bd70b1a9b09f6ad80
|
|
4
|
+
data.tar.gz: 2d1e897786ce05c6631e4c90404731c44f25925f4419a81466a3c96f2db07166
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4f30f23d1512615d846ca53721ba6ccc427e00e85285fe8178a023c13d45b043188c17628e777838c5ad8ac3c951e92f8a16667e8b34281335fcae0d653e365d
|
|
7
|
+
data.tar.gz: 338826686b6e8ea8bdbe13d726ed6691918cf08a7230a51f3ec9b9deb880e655208d15e0a8b377d9ceb6ae288d6da821b302acbed880258911cc2e26600105a0
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -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
|
-
|
|
25
|
-
|
|
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
|
-
|
|
43
|
+
with { |c| c.execute(sql) }
|
|
30
44
|
end
|
|
31
45
|
|
|
32
46
|
def query(sql)
|
|
33
|
-
|
|
47
|
+
with { |c| c.query(sql) }
|
|
34
48
|
end
|
|
35
49
|
|
|
36
50
|
def query_each(sql, &block)
|
|
37
|
-
|
|
51
|
+
with { |c| c.query_each(sql, &block) }
|
|
38
52
|
end
|
|
39
53
|
|
|
40
54
|
def query_value(sql)
|
|
41
|
-
|
|
55
|
+
with { |c| c.query_value(sql) }
|
|
42
56
|
end
|
|
43
57
|
|
|
44
58
|
def insert(table, rows, **opts)
|
|
45
|
-
|
|
59
|
+
with { |c| c.insert(table, rows, **opts) }
|
|
46
60
|
end
|
|
47
61
|
|
|
48
62
|
def ping
|
|
49
|
-
|
|
63
|
+
with(&:ping)
|
|
50
64
|
end
|
|
51
65
|
|
|
52
66
|
def server_version
|
|
53
|
-
|
|
67
|
+
with(&:server_version)
|
|
54
68
|
end
|
|
55
69
|
|
|
56
70
|
def describe_table(table, db_name: nil)
|
|
57
|
-
|
|
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
|