google-cloud-bigtable 2.8.0 → 2.9.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: 735e0a2c4fcb24227bbdf5e7f1ee76d6e8f718b6d23cf30bdf56fd8c6f13f830
4
- data.tar.gz: fd7c5cb8fa45cd44a7e0a39c78a88bf63e52214c133505dbfbc2977a86b89cd0
3
+ metadata.gz: bf857acc4d00f606d2712fea755ba9f18d8c7d898599144029ff341081549f4c
4
+ data.tar.gz: aed266e0fabdd16d2ac25c21dde0501e4a0e4172a828f7cc5e468ec9b9caa190
5
5
  SHA512:
6
- metadata.gz: 2ee38cb00b572386d02f7b7f4f7abd593b0d8022e4dd366a54b2789bf8f4e8ee04b73a9ece3286707a81ce68006fb8f2f84685a721057c16b607911e4d8da5e2
7
- data.tar.gz: a9686ba49ac1a4761761570f0486edcbb6d628eaaa5c8183df65b6f697c9f50022abf8b61f7420f6b79b5f7e00ad4b9a99f1f0f45266ca248fc47ae8e874ec5a
6
+ metadata.gz: 4f232903645d9d3e5614c862813005f2e35d998e369f6f1b0b949245e3f5a0a8fb5735d57ac3fb721c7b244d2d8e659ae94e7addef250b2fdd6cc01ad76fd6a5
7
+ data.tar.gz: 81cc42b99915c8fc15b42020a2582075bfaf5108420d9e3f8350dbece58da63a620316216fd1459ce34feb6b2d6c2341375b800a3c840ec2d7e1b647a09e1647
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Release History
2
2
 
3
+ ### 2.9.0 (2023-09-14)
4
+
5
+ #### Features
6
+
7
+ * Add support for channel pooling ([#22747](https://github.com/googleapis/google-cloud-ruby/issues/22747))
8
+
3
9
  ### 2.8.0 (2023-08-17)
4
10
 
5
11
  #### Features
@@ -17,6 +17,13 @@
17
17
 
18
18
  require "time"
19
19
  require "date"
20
+ require "gapic/protobuf"
21
+ require "gapic/call_options"
22
+ require "gapic/headers"
23
+ require "google/cloud/bigtable/version"
24
+ require "google/cloud/bigtable/v2/version"
25
+ require "google/bigtable/v2/bigtable_pb"
26
+ require "google/cloud/bigtable/admin/v2"
20
27
 
21
28
  module Google
22
29
  module Cloud
@@ -89,6 +96,33 @@ module Google
89
96
  return [value].pack "q>" if value.is_a? Integer
90
97
  value
91
98
  end
99
+
100
+ def ping_and_warm_request table_path, app_profile_id, timeout
101
+ request = {
102
+ name: table_path.split("/").slice(0, 4).join("/"),
103
+ app_profile_id: app_profile_id
104
+ }
105
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Bigtable::V2::PingAndWarmRequest
106
+
107
+ header_params = {}
108
+ if request.name && %r{^projects/[^/]+/instances/[^/]+/?$}.match?(request.name)
109
+ header_params["name"] = request.name
110
+ end
111
+ if request.app_profile_id && !request.app_profile_id.empty?
112
+ header_params["app_profile_id"] = request.app_profile_id
113
+ end
114
+ request_params_header = URI.encode_www_form header_params
115
+ metadata = {
116
+ "x-goog-request-params": request_params_header,
117
+ "x-goog-api-client":
118
+ ::Gapic::Headers.x_goog_api_client(lib_name: "gccl",
119
+ lib_version: ::Google::Cloud::Bigtable::VERSION,
120
+ gapic_version: ::Google::Cloud::Bigtable::V2::VERSION),
121
+ "google-cloud-resource-prefix": "projects/#{table_path.split('/')[1]}"
122
+ }
123
+ options = ::Gapic::CallOptions.new timeout: timeout, metadata: metadata
124
+ [request, options]
125
+ end
92
126
  end
93
127
  end
94
128
  end
@@ -521,15 +521,12 @@ module Google
521
521
  ensure_service!
522
522
 
523
523
  view ||= :SCHEMA_VIEW
524
- table = if perform_lookup
525
- grpc = service.get_table instance_id, table_id, view: view
526
- Table.from_grpc grpc, service, view: view
527
- else
528
- Table.from_path service.table_path(instance_id, table_id), service
529
- end
530
-
531
- table.app_profile_id = app_profile_id
532
- table
524
+ if perform_lookup
525
+ grpc = service.get_table instance_id, table_id, view: view
526
+ Table.from_grpc grpc, service, view: view, app_profile_id: app_profile_id
527
+ else
528
+ Table.from_path service.table_path(instance_id, table_id), service, app_profile_id: app_profile_id
529
+ end
533
530
  rescue Google::Cloud::NotFoundError
534
531
  nil
535
532
  end
@@ -343,15 +343,12 @@ module Google
343
343
  ensure_service!
344
344
 
345
345
  view ||= :SCHEMA_VIEW
346
- table = if perform_lookup
347
- grpc = service.get_table instance_id, table_id, view: view
348
- Table.from_grpc grpc, service, view: view
349
- else
350
- Table.from_path service.table_path(instance_id, table_id), service
351
- end
352
-
353
- table.app_profile_id = app_profile_id
354
- table
346
+ if perform_lookup
347
+ grpc = service.get_table instance_id, table_id, view: view
348
+ Table.from_grpc grpc, service, view: view, app_profile_id: app_profile_id
349
+ else
350
+ Table.from_path service.table_path(instance_id, table_id), service, app_profile_id: app_profile_id
351
+ end
355
352
  rescue Google::Cloud::NotFoundError
356
353
  nil
357
354
  end
@@ -20,6 +20,9 @@ require "google/cloud/bigtable/errors"
20
20
  require "google/cloud/bigtable/credentials"
21
21
  require "google/cloud/bigtable/v2"
22
22
  require "google/cloud/bigtable/admin/v2"
23
+ require "google/cloud/bigtable/convert"
24
+ require "gapic/lru_hash"
25
+ require "concurrent"
23
26
 
24
27
  module Google
25
28
  module Cloud
@@ -49,12 +52,17 @@ module Google
49
52
  # @param timeout [Integer]
50
53
  # The default timeout, in seconds, for calls made through this client.
51
54
  #
52
- def initialize project_id, credentials, host: nil, host_admin: nil, timeout: nil
55
+ def initialize project_id, credentials, host: nil, host_admin: nil, timeout: nil,
56
+ channel_selection: nil, channel_count: nil
53
57
  @project_id = project_id
54
58
  @credentials = credentials
55
59
  @host = host
56
60
  @host_admin = host_admin
57
61
  @timeout = timeout
62
+ @channel_selection = channel_selection
63
+ @channel_count = channel_count
64
+ @bigtable_clients = ::Gapic::LruHash.new 10
65
+ @mutex = Mutex.new
58
66
  end
59
67
 
60
68
  def instances
@@ -83,15 +91,15 @@ module Google
83
91
  end
84
92
  attr_accessor :mocked_tables
85
93
 
86
- def client
94
+ def client table_path, app_profile_id
87
95
  return mocked_client if mocked_client
88
- @client ||= V2::Bigtable::Client.new do |config|
89
- config.credentials = credentials if credentials
90
- config.timeout = timeout if timeout
91
- config.endpoint = host if host
92
- config.lib_name = "gccl"
93
- config.lib_version = Google::Cloud::Bigtable::VERSION
94
- config.metadata = { "google-cloud-resource-prefix": "projects/#{@project_id}" }
96
+ table_key = "#{table_path}_#{app_profile_id}"
97
+ @mutex.synchronize do
98
+ if @bigtable_clients.get(table_key).nil?
99
+ bigtable_client = create_bigtable_client table_path, app_profile_id
100
+ @bigtable_clients.put table_key, bigtable_client
101
+ end
102
+ @bigtable_clients.get table_key
95
103
  end
96
104
  end
97
105
  attr_accessor :mocked_client
@@ -649,7 +657,7 @@ module Google
649
657
  end
650
658
 
651
659
  def read_rows instance_id, table_id, app_profile_id: nil, rows: nil, filter: nil, rows_limit: nil
652
- client.read_rows(
660
+ client(table_path(instance_id, table_id), app_profile_id).read_rows(
653
661
  **{
654
662
  table_name: table_path(instance_id, table_id),
655
663
  rows: rows,
@@ -661,11 +669,11 @@ module Google
661
669
  end
662
670
 
663
671
  def sample_row_keys table_name, app_profile_id: nil
664
- client.sample_row_keys table_name: table_name, app_profile_id: app_profile_id
672
+ client(table_name, app_profile_id).sample_row_keys table_name: table_name, app_profile_id: app_profile_id
665
673
  end
666
674
 
667
675
  def mutate_row table_name, row_key, mutations, app_profile_id: nil
668
- client.mutate_row(
676
+ client(table_name, app_profile_id).mutate_row(
669
677
  **{
670
678
  table_name: table_name,
671
679
  app_profile_id: app_profile_id,
@@ -676,7 +684,7 @@ module Google
676
684
  end
677
685
 
678
686
  def mutate_rows table_name, entries, app_profile_id: nil
679
- client.mutate_rows(
687
+ client(table_name, app_profile_id).mutate_rows(
680
688
  **{
681
689
  table_name: table_name,
682
690
  app_profile_id: app_profile_id,
@@ -691,7 +699,7 @@ module Google
691
699
  predicate_filter: nil,
692
700
  true_mutations: nil,
693
701
  false_mutations: nil
694
- client.check_and_mutate_row(
702
+ client(table_name, app_profile_id).check_and_mutate_row(
695
703
  **{
696
704
  table_name: table_name,
697
705
  app_profile_id: app_profile_id,
@@ -704,7 +712,7 @@ module Google
704
712
  end
705
713
 
706
714
  def read_modify_write_row table_name, row_key, rules, app_profile_id: nil
707
- client.read_modify_write_row(
715
+ client(table_name, app_profile_id).read_modify_write_row(
708
716
  **{
709
717
  table_name: table_name,
710
718
  app_profile_id: app_profile_id,
@@ -885,6 +893,23 @@ module Google
885
893
  def inspect
886
894
  "#{self.class}(#{@project_id})"
887
895
  end
896
+
897
+ def create_bigtable_client table_path, app_profile_id
898
+ V2::Bigtable::Client.new do |config|
899
+ config.credentials = credentials if credentials
900
+ config.timeout = timeout if timeout
901
+ config.endpoint = host if host
902
+ config.lib_name = "gccl"
903
+ config.lib_version = Google::Cloud::Bigtable::VERSION
904
+ config.metadata = { "google-cloud-resource-prefix": "projects/#{@project_id}" }
905
+ config.channel_pool.channel_selection = @channel_selection
906
+ config.channel_pool.channel_count = @channel_count
907
+ request, options = Convert.ping_and_warm_request table_path, app_profile_id, timeout
908
+ config.channel_pool.on_channel_create = proc do |channel|
909
+ channel.call_rpc :ping_and_warm, request, options: options
910
+ end
911
+ end
912
+ end
888
913
  end
889
914
  end
890
915
  end
@@ -72,11 +72,13 @@ module Google
72
72
  # @private
73
73
  #
74
74
  # Creates a new Table instance.
75
- def initialize grpc, service, view:
75
+ def initialize grpc, service, view:, app_profile_id: nil
76
76
  @grpc = grpc
77
77
  @service = service
78
+ @app_profile_id = app_profile_id
78
79
  raise ArgumentError, "view must not be nil" if view.nil?
79
80
  @loaded_views = Set[view]
81
+ @service.client path, app_profile_id
80
82
  end
81
83
 
82
84
  ##
@@ -659,8 +661,8 @@ module Google
659
661
  # @param view [Symbol] View type.
660
662
  # @return [Google::Cloud::Bigtable::Table]
661
663
  #
662
- def self.from_grpc grpc, service, view:
663
- new grpc, service, view: view
664
+ def self.from_grpc grpc, service, view:, app_profile_id: nil
665
+ new grpc, service, view: view, app_profile_id: app_profile_id
664
666
  end
665
667
 
666
668
  # @private
@@ -672,9 +674,9 @@ module Google
672
674
  # @param service [Google::Cloud::Bigtable::Service]
673
675
  # @return [Google::Cloud::Bigtable::Table]
674
676
  #
675
- def self.from_path path, service
677
+ def self.from_path path, service, app_profile_id: nil
676
678
  grpc = Google::Cloud::Bigtable::Admin::V2::Table.new name: path
677
- new grpc, service, view: :NAME_ONLY
679
+ new grpc, service, view: :NAME_ONLY, app_profile_id: app_profile_id
678
680
  end
679
681
 
680
682
  protected
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Bigtable
19
- VERSION = "2.8.0".freeze
19
+ VERSION = "2.9.0".freeze
20
20
  end
21
21
  end
22
22
  end
@@ -63,6 +63,10 @@ module Google
63
63
  # updater_proc is supplied.
64
64
  # @param timeout [Integer]
65
65
  # The default timeout, in seconds, for calls made through this client. Optional.
66
+ # @param channel_selection [Symbol] The algorithm for selecting a channel from the
67
+ # pool of available channels. This parameter can have the following symbols:
68
+ # * `:least_loaded` selects the channel having least number of concurrent streams.
69
+ # @param channel_count [Integer] The number of channels in the pool.
66
70
  # @return [Google::Cloud::Bigtable::Project]
67
71
  #
68
72
  # @example
@@ -70,19 +74,25 @@ module Google
70
74
  #
71
75
  # client = Google::Cloud::Bigtable.new
72
76
  #
77
+ # rubocop:disable Metrics/CyclomaticComplexity
78
+ # rubocop:disable Metrics/AbcSize
73
79
  def self.new project_id: nil,
74
80
  credentials: nil,
75
81
  emulator_host: nil,
76
82
  scope: nil,
77
83
  endpoint: nil,
78
84
  endpoint_admin: nil,
79
- timeout: nil
80
- project_id ||= default_project_id
81
- scope ||= configure.scope
82
- timeout ||= configure.timeout
85
+ timeout: nil,
86
+ channel_selection: nil,
87
+ channel_count: nil
88
+ project_id ||= default_project_id
89
+ scope ||= configure.scope
90
+ timeout ||= configure.timeout
83
91
  emulator_host ||= configure.emulator_host
84
- endpoint ||= configure.endpoint
92
+ endpoint ||= configure.endpoint
85
93
  endpoint_admin ||= configure.endpoint_admin
94
+ channel_selection ||= configure.channel_selection
95
+ channel_count ||= configure.channel_count
86
96
 
87
97
  return new_with_emulator project_id, emulator_host, timeout if emulator_host
88
98
 
@@ -90,10 +100,15 @@ module Google
90
100
  project_id = resolve_project_id project_id, credentials
91
101
  raise ArgumentError, "project_id is missing" if project_id.empty?
92
102
 
93
- service = Bigtable::Service.new \
94
- project_id, credentials, host: endpoint, host_admin: endpoint_admin, timeout: timeout
103
+ service = Bigtable::Service.new project_id, credentials, host: endpoint,
104
+ host_admin: endpoint_admin, timeout: timeout,
105
+ channel_selection: channel_selection,
106
+ channel_count: channel_count
95
107
  Bigtable::Project.new service
96
108
  end
109
+ # rubocop:enable Metrics/CyclomaticComplexity
110
+ # rubocop:enable Metrics/AbcSize
111
+
97
112
 
98
113
  ##
99
114
  # Configure the Google Cloud Bigtable library.
@@ -116,6 +131,10 @@ module Google
116
131
  # to use the default endpoint.
117
132
  # * `endpoint_admin` - (String) Override of the admin service endpoint
118
133
  # host name, or `nil` to use the default admin endpoint.
134
+ # * `channel_selection` - (Symbol) The algorithm for selecting a channel from the
135
+ # pool of available channels. This parameter can have the following symbols:
136
+ # `:least_loaded` selects the channel having least number of concurrent streams.
137
+ # * `channel_count` - (Integer) The number of channels in the pool.
119
138
  #
120
139
  # @return [Google::Cloud::Config] The configuration object the
121
140
  # Google::Cloud::Bigtable library uses.
@@ -171,4 +171,6 @@ Google::Cloud.configure.add_config! :bigtable do |config|
171
171
  config.add_field! :emulator_host, default_emulator, match: String, allow_nil: true
172
172
  config.add_field! :endpoint, "bigtable.googleapis.com", match: String
173
173
  config.add_field! :endpoint_admin, "bigtableadmin.googleapis.com", match: String
174
+ config.add_field! :channel_selection, :least_loaded, match: Symbol
175
+ config.add_field! :channel_count, 1, match: Integer
174
176
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-bigtable
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.0
4
+ version: 2.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Google LLC
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-17 00:00:00.000000000 Z
11
+ date: 2023-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: concurrent-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: google-cloud-bigtable-admin-v2
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -30,14 +44,14 @@ dependencies:
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0.0'
47
+ version: '0.14'
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '0.0'
54
+ version: '0.14'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: google-cloud-core
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -249,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
249
263
  - !ruby/object:Gem::Version
250
264
  version: '0'
251
265
  requirements: []
252
- rubygems_version: 3.4.2
266
+ rubygems_version: 3.4.19
253
267
  signing_key:
254
268
  specification_version: 4
255
269
  summary: API Client library for Cloud Bigtable API