pinot-client 1.3.0 → 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6d0692d6f1de1178eb0c27cb2f69e3f6575362b1163e58032538b2b003e13cb
4
- data.tar.gz: d9ee2eb20b541cfe54ad640b223425ed16697e869b031349d021ef89c8bab5af
3
+ metadata.gz: 828dd3e3c441143fb0754adbcb1b50de4a070e777ad3a158c51dfabf91a3f877
4
+ data.tar.gz: 6c4a3f0ae7e703ae0d3ff18fd473030710e5a1954b9624207e0b2c6e944d2365
5
5
  SHA512:
6
- metadata.gz: d66f070cd740df59a8351724b954b902633052e0a94c0cffcc377cba887329709955b0c93075f5f90ea820abe453aa716b4f6eae80600ce90015eda669c33dd0
7
- data.tar.gz: '03345279b3e4ae8621fa75a4222dce2988cf61255663b659c7307296a9506680f29f804938ec1b5d28326bf15e4e5c4cf5984e71233b2e0fcf255f6123f0fa36'
6
+ metadata.gz: ca183a5d10a9b87a18cb61725e6810f1446cd70b627e6a6a8320a3db9b2ec27981bf7d282e684f2c2cca94c2a87be2fb1595c2c178d378465bb77628cf501bb7
7
+ data.tar.gz: 715e0acb71c456409c999da0207c4c2c1aac310d27024dae6d9154996811d51b1f4c665686b609d598128b031f766ae06ee18c111c6ef0f6801b69cd523b5c82
data/lib/pinot/config.rb CHANGED
@@ -1,4 +1,14 @@
1
1
  module Pinot
2
+ class ZookeeperConfig
3
+ attr_accessor :zk_path, # "host:port" or "host1:port,host2:port/chroot"
4
+ :session_timeout_ms # default 30000
5
+
6
+ def initialize(zk_path:, session_timeout_ms: 30_000)
7
+ @zk_path = zk_path
8
+ @session_timeout_ms = session_timeout_ms
9
+ end
10
+ end
11
+
2
12
  class ControllerConfig
3
13
  attr_accessor :controller_address, :update_freq_ms, :extra_controller_api_headers
4
14
 
@@ -12,7 +22,7 @@ module Pinot
12
22
  class ClientConfig
13
23
  attr_accessor :broker_list, :http_timeout, :extra_http_header,
14
24
  :use_multistage_engine, :controller_config, :logger, :tls_config,
15
- :grpc_config
25
+ :grpc_config, :zookeeper_config
16
26
 
17
27
  def initialize(
18
28
  broker_list: [],
@@ -22,7 +32,8 @@ module Pinot
22
32
  controller_config: nil,
23
33
  logger: nil,
24
34
  tls_config: nil,
25
- grpc_config: nil
35
+ grpc_config: nil,
36
+ zookeeper_config: nil
26
37
  )
27
38
  @broker_list = broker_list
28
39
  @http_timeout = http_timeout
@@ -32,6 +43,7 @@ module Pinot
32
43
  @logger = logger
33
44
  @tls_config = tls_config
34
45
  @grpc_config = grpc_config
46
+ @zookeeper_config = zookeeper_config
35
47
  end
36
48
  end
37
49
  end
@@ -27,6 +27,25 @@ module Pinot
27
27
  return conn
28
28
  end
29
29
 
30
+ if config.zookeeper_config
31
+ selector = ZookeeperBrokerSelector.new(zk_path: config.zookeeper_config.zk_path)
32
+ selector.init
33
+
34
+ inner = http_client || HttpClient.new(timeout: config.http_timeout, tls_config: config.tls_config)
35
+ transport = JsonHttpTransport.new(
36
+ http_client: inner,
37
+ extra_headers: config.extra_http_header || {},
38
+ logger: config.logger
39
+ )
40
+
41
+ return Connection.new(
42
+ transport: transport,
43
+ broker_selector: selector,
44
+ use_multistage_engine: config.use_multistage_engine || false,
45
+ logger: config.logger
46
+ )
47
+ end
48
+
30
49
  inner = http_client || HttpClient.new(timeout: config.http_timeout, tls_config: config.tls_config)
31
50
 
32
51
  transport = JsonHttpTransport.new(
data/lib/pinot/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pinot
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -0,0 +1,80 @@
1
+ require "json"
2
+ require "set"
3
+ require_relative "table_aware_broker_selector"
4
+ require_relative "errors"
5
+
6
+ module Pinot
7
+ class ZookeeperBrokerSelector < TableAwareBrokerSelector
8
+ # ZK path where Pinot stores broker external view
9
+ BROKER_EXTERNAL_VIEW_PATH = "/EXTERNALVIEW/brokerResource"
10
+
11
+ def initialize(zk_path:, zk_client: nil)
12
+ super()
13
+ @zk_path = zk_path # e.g. "localhost:2181"
14
+ @zk_client = zk_client # injectable for testing
15
+ end
16
+
17
+ def init
18
+ @zk = @zk_client || build_zk_client
19
+ fetch_and_update
20
+ setup_watcher
21
+ end
22
+
23
+ private
24
+
25
+ def build_zk_client
26
+ begin
27
+ require "zk"
28
+ rescue LoadError
29
+ raise ConfigurationError, "The 'zk' gem is required to use ZookeeperBrokerSelector. Add it to your Gemfile: gem \"zk\""
30
+ end
31
+ ZK.new(@zk_path)
32
+ end
33
+
34
+ def fetch_and_update
35
+ data, _stat = @zk.get(BROKER_EXTERNAL_VIEW_PATH)
36
+ parsed = JSON.parse(data)
37
+ all_brokers, table_map = parse_external_view(parsed)
38
+ update_broker_data(all_brokers, table_map)
39
+ end
40
+
41
+ def setup_watcher
42
+ @zk.register(BROKER_EXTERNAL_VIEW_PATH) do |event|
43
+ fetch_and_update rescue nil
44
+ setup_watcher # re-register watch after each trigger
45
+ end
46
+ # Set initial watch
47
+ @zk.exists?(BROKER_EXTERNAL_VIEW_PATH, watch: true)
48
+ end
49
+
50
+ def parse_external_view(data)
51
+ # Pinot external view format:
52
+ # { "mapFields": { "tableName_OFFLINE": { "Broker_host_port": "ONLINE" } } }
53
+ map_fields = data["mapFields"] || {}
54
+
55
+ all_brokers = Set.new
56
+ table_map = {}
57
+
58
+ map_fields.each do |raw_table, broker_map|
59
+ # Strip _OFFLINE / _REALTIME suffix from the table key, matching Go's extractTableName
60
+ table_name = raw_table.sub(/_OFFLINE\z/, "").sub(/_REALTIME\z/, "")
61
+ brokers = []
62
+ broker_map.each do |broker_key, state|
63
+ next unless state == "ONLINE"
64
+ # Broker key format: Broker_<hostname>_<port>
65
+ # Use the last segment as port and the second-to-last as host
66
+ parts = broker_key.split("_")
67
+ next if parts.length < 2
68
+ port = parts.last
69
+ next unless port =~ /\A\d+\z/
70
+ host = parts[-2]
71
+ brokers << "#{host}:#{port}"
72
+ end
73
+ table_map[table_name] = brokers
74
+ all_brokers.merge(brokers)
75
+ end
76
+
77
+ [all_brokers.to_a, table_map]
78
+ end
79
+ end
80
+ end
data/lib/pinot.rb CHANGED
@@ -27,3 +27,8 @@ begin
27
27
  rescue LoadError
28
28
  # grpc gem not available; GrpcTransport disabled
29
29
  end
30
+
31
+ begin
32
+ require_relative "pinot/zookeeper_broker_selector"
33
+ rescue LoadError
34
+ end
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.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xiang Fu
@@ -96,6 +96,7 @@ files:
96
96
  - lib/pinot/tls_config.rb
97
97
  - lib/pinot/transport.rb
98
98
  - lib/pinot/version.rb
99
+ - lib/pinot/zookeeper_broker_selector.rb
99
100
  homepage: https://github.com/startreedata/ruby-pinot-client
100
101
  licenses:
101
102
  - Apache-2.0