-
Notifications
You must be signed in to change notification settings - Fork 20
Closed
Description
Problem
When using the single_use specifier for execute_query, the Spanner gem creates a read-only transaction. However, execute_query is hard-coded to always route requests to the leader, which introduces unnecessary latency depending on the region of the leader and the querist.
I believe that we should be able to check if a read-only transaction is open when determining whether to route to the leader, like so:
single_use_tx = single_use_transaction single_use
- route_to_leader = LARHeaders.execute_query true
+ route_to_leader = LARHeaders.execute_query !single_use_txbut am unsure if I have the semantics correct.
This, however, has the underlying effect of setting the x-goog-spanner-route-to-leader value to "false" instead of just not setting it.
Environment details
- OS: Any
- Ruby version: Any
- Gem name and version:
google-cloud-spanner = 2.28.0and currentmainbranch
Steps to reproduce
- Create a client
- Run
execute_query(sql, single_use: { bounded_staleness: 10 }) - See the query route through the leader even when specifying a different placement
Code example
require "google/cloud/spanner"
puts "Starting"
emulator_host = ENV.fetch("SPANNER_EMULATOR_HOST", nil)
project_id = ENV.fetch("SPANNER_EMULATOR_PROJECT", "")
instance_id = ENV.fetch("SPANNER_EMULATOR_INSTANCE", "")
database_id = ENV.fetch("SPANNER_EMULATOR_DATABASE", "")
puts "Creating project"
project = Google::Cloud::Spanner.new(
project_id: project_id,
emulator_host: emulator_host,
)
puts "Creating client"
client = project.client(instance_id, database_id)
puts "Executing sql"
puts client.execute_sql("SELECT * FROM my_table", single_use: { bounded_staleness: 10 })Full backtrace
There is no backtrace, the query runs just not at the location one would expect.
Metadata
Metadata
Assignees
Labels
No labels