@@ -43,8 +43,18 @@ class Service
4343 RST_STREAM_INTERNAL_ERROR = "Received RST_STREAM" . freeze
4444 EOS_INTERNAL_ERROR = "Received unexpected EOS on DATA frame from server" . freeze
4545
46- ##
47- # Creates a new Service instance.
46+ # Creates a new `Spanner::Service` instance.
47+ # @param project [::String] The project id to use
48+ # @param credentials [::Symbol, ::Google::Auth::Credentials] Credentials
49+ # @param quota_project_id [::String, nil] Optional. The quota project id to use
50+ # @param host [::String, nil] Optional. The endpoint override.
51+ # @param timeout [::Numeric, nil] Optional. Timeout for Gapic client.
52+ # @param lib_name [::String, nil] Optional. Library name for headers.
53+ # @param lib_version [::String, nil] Optional. Library version for headers.
54+ # @param enable_leader_aware_routing [::Boolean, nil] Optional. Whether Leader
55+ # Aware Routing should be enabled.
56+ # @param universe_domain [::String, nil] Optional. The domain of the universe to connect to.
57+ # @private
4858 def initialize project , credentials , quota_project : nil ,
4959 host : nil , timeout : nil , lib_name : nil , lib_version : nil ,
5060 enable_leader_aware_routing : nil , universe_domain : nil
@@ -82,6 +92,8 @@ def chan_creds
8292 GRPC ::Core ::CallCredentials . new credentials . client . updater_proc
8393 end
8494
95+ # `V1::Spanner::Client` or mock.
96+ # @return [::Google::Cloud::Spanner::V1::Spanner::Client]
8597 def service
8698 return mocked_service if mocked_service
8799 @service ||=
@@ -329,13 +341,41 @@ def get_session session_name, call_options: nil
329341 service . get_session ( { name : session_name } , opts )
330342 end
331343
344+ # Creates a new Spanner session.
345+ # This creates a `V1::Session` protobuf object not wrapped in `Spanner::Session`.
346+ #
347+ # @param database_name [::String] The full name of the database.
348+ # @param labels [::Hash, nil] Optional. The labels to be applied to all sessions
349+ # created by the client. Example: `"team" => "billing-service"`.
350+ # @param call_options [::Hash, nil] Optional. A hash of values to specify the custom
351+ # call options. Example option `:timeout`.
352+ # @param database_role [::String, nil] Optional. The Spanner session creator role.
353+ # Example: `analyst`.
354+ # @param multiplexed [::Boolean] Optional. Default to `false`.
355+ # If `true`, specifies a multiplexed session.
356+ # @return [::Google::Cloud::Spanner::V1::Session]
357+ # @private
332358 def create_session database_name , labels : nil ,
333- call_options : nil , database_role : nil
359+ call_options : nil , database_role : nil ,
360+ multiplexed : false
334361 route_to_leader = LARHeaders . create_session
335- opts = default_options session_name : database_name ,
336- call_options : call_options ,
337- route_to_leader : route_to_leader
338- session = V1 ::Session . new labels : labels , creator_role : database_role if labels || database_role
362+ opts = default_options (
363+ session_name : database_name ,
364+ call_options : call_options ,
365+ route_to_leader : route_to_leader
366+ )
367+
368+ # check if we need a session object in request or server defaults would work.
369+ params_diff_from_default = !( labels . nil? && database_role . nil? && !multiplexed )
370+
371+ if params_diff_from_default
372+ session = V1 ::Session . new (
373+ labels : labels ,
374+ creator_role : database_role ,
375+ multiplexed : multiplexed
376+ )
377+ end
378+
339379 service . create_session (
340380 { database : database_name , session : session } , opts
341381 )
@@ -464,6 +504,29 @@ def partition_query session_name, sql, transaction, params: nil,
464504 service . partition_query request , opts
465505 end
466506
507+ # Commits a transaction. Can be a predefined (`transaction_id`) transaction
508+ # or a single-use created for this request. The request includes the mutations to be
509+ # applied to rows in the database.
510+ #
511+ # @param session_name [::String]
512+ # Required. The session in which the transaction to be committed is running.
513+ # @param mutations [::Array<::Google::Cloud::Spanner::V1::Mutation>] Optional.
514+ # The mutations to be executed when this transaction commits. All
515+ # mutations are applied atomically, in the order they appear in
516+ # this list. Defaults to an empty array.
517+ # @param transaction_id [::String, nil] Optional.
518+ # Commit a previously-started transaction. If nil, a new single-use transation will be used.
519+ # @param exclude_txn_from_change_streams [::Boolean] Optional. Defaults to `false`.
520+ # When `exclude_txn_from_change_streams` is set to `true`, it prevents read
521+ # or write transactions from being tracked in change streams.
522+ # @param commit_options [::Hash, nil] Optional. A hash of commit options.
523+ # Example option: `:return_commit_stats`.
524+ # @param request_options [::Hash, nil] Optional. Common request options.
525+ # Example option: `:priority`.
526+ # @param call_options [::Hash, nil] Optional. A hash of values to specify the custom
527+ # call options. Example option `:timeout`.
528+ # @return [::Google::Cloud::Spanner::V1::CommitResponse]
529+ # @private
467530 def commit session_name , mutations = [ ] ,
468531 transaction_id : nil , exclude_txn_from_change_streams : false ,
469532 commit_options : nil , request_options : nil , call_options : nil
@@ -485,10 +548,16 @@ def commit session_name, mutations = [],
485548 }
486549
487550 request = add_commit_options request , commit_options
488-
551+ # request is a hash equivalent of `::Google::Cloud::Spanner::V1::CommitRequest`
489552 service . commit request , opts
490553 end
491554
555+ # Merges commit options hash to a hash representing a `V1::CommitRequest`.
556+ # @param request [::Hash] A `::Google::Cloud::Spanner::V1::CommitRequest` in a hash form.
557+ # @param commit_options [::Hash, nil] Optional. A hash of commit options.
558+ # Example option: `:return_commit_stats`.
559+ # @return [Hash] An enriched `::Google::Cloud::Spanner::V1::CommitRequest` in a hash form.
560+ # @private
492561 def add_commit_options request , commit_options
493562 if commit_options
494563 if commit_options . key? :return_commit_stats
0 commit comments