pinot-client 1.23.0 → 1.25.0
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 +4 -4
- data/lib/pinot/connection.rb +35 -0
- data/lib/pinot/query_result.rb +11 -0
- data/lib/pinot/transport.rb +13 -2
- data/lib/pinot/version.rb +1 -1
- data/lib/pinot.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1f76e9f295ba992d3a6c2ec7a4dc738230c8676bda0f64bafb3aa85af1530c34
|
|
4
|
+
data.tar.gz: 4ea8dfd7e0c530f38c860928c18c1facc76d5fabb7667cf7b802864629365dd1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2a07d7e620bf3adbbcd2f809c37854a1c96da7e1bbb416cbe994d6ce7ea5d17620839aad66b2059e5f1f0de683cd5a405868d1729b5da7dbba19ff820c1ac704
|
|
7
|
+
data.tar.gz: 2da45bfbb16a63ed13c72fdec7c2684511d27caac9a211155135a3697c88cbf36686a7ded2d569859cb751e8dac59a04b7d91aaf06b3d06136461a217166924e
|
data/lib/pinot/connection.rb
CHANGED
|
@@ -50,6 +50,35 @@ module Pinot
|
|
|
50
50
|
raise e
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
+
def execute_many(queries, max_concurrency: nil)
|
|
54
|
+
return [] if queries.empty?
|
|
55
|
+
|
|
56
|
+
results = Array.new(queries.size)
|
|
57
|
+
# Queue acts as a counting semaphore: pre-filled with N tokens.
|
|
58
|
+
sem = max_concurrency ? build_semaphore(max_concurrency) : nil
|
|
59
|
+
|
|
60
|
+
threads = queries.each_with_index.map do |item, idx|
|
|
61
|
+
table = item[:table] || item["table"] || ""
|
|
62
|
+
query = item[:query] || item["query"] || ""
|
|
63
|
+
timeout_ms = item[:query_timeout_ms] || item["query_timeout_ms"]
|
|
64
|
+
|
|
65
|
+
Thread.new do
|
|
66
|
+
sem&.pop # acquire
|
|
67
|
+
begin
|
|
68
|
+
resp = execute_sql(table, query, query_timeout_ms: timeout_ms)
|
|
69
|
+
results[idx] = QueryResult.new(table: table, query: query, response: resp, error: nil)
|
|
70
|
+
rescue => e
|
|
71
|
+
results[idx] = QueryResult.new(table: table, query: query, response: nil, error: e)
|
|
72
|
+
ensure
|
|
73
|
+
sem&.push(:token) # release
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
threads.each(&:join)
|
|
79
|
+
results
|
|
80
|
+
end
|
|
81
|
+
|
|
53
82
|
def prepare(table, query_template)
|
|
54
83
|
raise ArgumentError, "table name cannot be empty" if table.nil? || table.strip.empty?
|
|
55
84
|
raise ArgumentError, "query template cannot be empty" if query_template.nil? || query_template.strip.empty?
|
|
@@ -101,6 +130,12 @@ module Pinot
|
|
|
101
130
|
|
|
102
131
|
private
|
|
103
132
|
|
|
133
|
+
def build_semaphore(n)
|
|
134
|
+
q = SizedQueue.new(n)
|
|
135
|
+
n.times { q.push(:token) }
|
|
136
|
+
q
|
|
137
|
+
end
|
|
138
|
+
|
|
104
139
|
def run_with_circuit_breaker(broker, &block)
|
|
105
140
|
return yield unless @circuit_breaker_registry
|
|
106
141
|
@circuit_breaker_registry.for(broker).call(broker, &block)
|
data/lib/pinot/transport.rb
CHANGED
|
@@ -171,6 +171,7 @@ module Pinot
|
|
|
171
171
|
|
|
172
172
|
# HTTP status codes that map to specific error classes and are safe to retry
|
|
173
173
|
HTTP_ERROR_MAP = {
|
|
174
|
+
"408" => QueryTimeoutError,
|
|
174
175
|
"429" => RateLimitError,
|
|
175
176
|
"503" => BrokerUnavailableError,
|
|
176
177
|
"504" => BrokerUnavailableError
|
|
@@ -178,6 +179,10 @@ module Pinot
|
|
|
178
179
|
|
|
179
180
|
RETRYABLE_HTTP_ERRORS = [RateLimitError, BrokerUnavailableError].freeze
|
|
180
181
|
|
|
182
|
+
# Pinot exception errorCode values that indicate query timeout.
|
|
183
|
+
# 250 = ExecutionTimeoutError (server-side), 400 = BrokerTimeoutError.
|
|
184
|
+
TIMEOUT_ERROR_CODES = [250, 400].freeze
|
|
185
|
+
|
|
181
186
|
def initialize(http_client:, extra_headers: {}, timeout_ms: nil, logger: nil,
|
|
182
187
|
max_retries: 0, retry_interval_ms: 200)
|
|
183
188
|
@http_client = http_client
|
|
@@ -216,18 +221,24 @@ module Pinot
|
|
|
216
221
|
raise TransportError, "http exception with HTTP status code #{resp.code}"
|
|
217
222
|
end
|
|
218
223
|
|
|
219
|
-
begin
|
|
224
|
+
broker_response = begin
|
|
220
225
|
BrokerResponse.from_json(resp.body)
|
|
221
226
|
rescue JSON::ParserError => e
|
|
222
227
|
raise e.message
|
|
223
228
|
end
|
|
229
|
+
|
|
230
|
+
if (timeout_ex = broker_response.exceptions.find { |ex| TIMEOUT_ERROR_CODES.include?(ex.error_code) })
|
|
231
|
+
raise QueryTimeoutError, timeout_ex.message
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
broker_response
|
|
224
235
|
rescue *RETRYABLE_HTTP_ERRORS, *RETRYABLE_ERRORS => e
|
|
225
236
|
if attempts < max_attempts
|
|
226
237
|
sleep_ms = (@retry_interval_ms || 200) * (2 ** (attempts - 1))
|
|
227
238
|
sleep(sleep_ms / 1000.0)
|
|
228
239
|
retry
|
|
229
240
|
end
|
|
230
|
-
raise
|
|
241
|
+
raise Net::ReadTimeout === e || Net::WriteTimeout === e ? QueryTimeoutError.new(e.message) : e
|
|
231
242
|
end
|
|
232
243
|
end
|
|
233
244
|
|
data/lib/pinot/version.rb
CHANGED
data/lib/pinot.rb
CHANGED
|
@@ -19,6 +19,7 @@ require_relative "pinot/controller_response"
|
|
|
19
19
|
require_relative "pinot/controller_based_broker_selector"
|
|
20
20
|
require_relative "pinot/transport"
|
|
21
21
|
require_relative "pinot/circuit_breaker"
|
|
22
|
+
require_relative "pinot/query_result"
|
|
22
23
|
require_relative "pinot/connection"
|
|
23
24
|
require_relative "pinot/prepared_statement"
|
|
24
25
|
require_relative "pinot/connection_factory"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pinot-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.25.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Xiang Fu
|
|
@@ -119,6 +119,7 @@ files:
|
|
|
119
119
|
- lib/pinot/proto/broker_service.proto
|
|
120
120
|
- lib/pinot/proto/broker_service_pb.rb
|
|
121
121
|
- lib/pinot/proto/broker_service_services_pb.rb
|
|
122
|
+
- lib/pinot/query_result.rb
|
|
122
123
|
- lib/pinot/request.rb
|
|
123
124
|
- lib/pinot/response.rb
|
|
124
125
|
- lib/pinot/simple_broker_selector.rb
|