@@ -361,9 +361,10 @@ public function reload(array $options = []): array
361361 $ data ['name ' ] = $ this ->name ;
362362
363363 $ request = $ this ->serializer ->decodeMessage (new GetDatabaseRequest (), $ data );
364- $ callOptions = $ this ->addResourcePrefixHeader ($ callOptions , $ this ->name );
365364
366- $ response = $ this ->databaseAdminClient ->getDatabase ($ request , $ callOptions );
365+ $ response = $ this ->databaseAdminClient ->getDatabase ($ request , $ callOptions + [
366+ 'resource-prefix ' => $ this ->name ,
367+ ]);
367368 return $ this ->info = $ this ->handleResponse ($ response );
368369 }
369370
@@ -430,9 +431,9 @@ public function create(array $options = []): OperationResponse
430431 ];
431432
432433 $ request = $ this ->serializer ->decodeMessage (new CreateDatabaseRequest (), $ data );
433- $ callOptions = $ this ->addResourcePrefixHeader ( $ callOptions , $ this -> instance -> name ());
434-
435- return $ this -> databaseAdminClient -> createDatabase ( $ request , $ callOptions )
434+ return $ this ->databaseAdminClient -> createDatabase ( $ request , $ callOptions + [
435+ ' resource-prefix ' => $ this -> instance -> name (),
436+ ] )
436437 ->withResultFunction ($ this ->databaseResultFunction ());
437438 }
438439
@@ -495,9 +496,10 @@ public function updateDatabase(array $options = []): OperationResponse
495496 ];
496497
497498 $ request = $ this ->serializer ->decodeMessage (new UpdateDatabaseRequest (), $ data );
498- $ callOptions = $ this ->addResourcePrefixHeader ($ callOptions , $ this ->name );
499499
500- return $ this ->databaseAdminClient ->updateDatabase ($ request , $ callOptions )
500+ return $ this ->databaseAdminClient ->updateDatabase ($ request , $ callOptions + [
501+ 'resource-prefix ' => $ this ->name ,
502+ ])
501503 ->withResultFunction ($ this ->databaseResultFunction ());
502504 }
503505
@@ -570,9 +572,9 @@ public function updateDdlBatch(array $statements, array $options = []): Operatio
570572 ];
571573
572574 $ request = $ this ->serializer ->decodeMessage (new UpdateDatabaseDdlRequest (), $ data );
573- $ callOptions = $ this ->addResourcePrefixHeader ( $ callOptions , $ this -> name );
574-
575- return $ this -> databaseAdminClient -> updateDatabaseDdl ( $ request , $ callOptions );
575+ return $ this ->databaseAdminClient -> updateDatabaseDdl ( $ request , $ callOptions + [
576+ ' resource-prefix ' => $ this -> name
577+ ] );
576578 }
577579
578580 /**
@@ -603,9 +605,10 @@ public function drop(array $options = []): void
603605 $ data ['database ' ] = $ this ->name ;
604606
605607 $ request = $ this ->serializer ->decodeMessage (new DropDatabaseRequest (), $ data );
606- $ callOptions = $ this ->addResourcePrefixHeader ($ callOptions , $ this ->name );
607608
608- $ this ->databaseAdminClient ->dropDatabase ($ request , $ callOptions );
609+ $ this ->databaseAdminClient ->dropDatabase ($ request , $ callOptions + [
610+ 'resource-prefix ' => $ this ->name
611+ ]);
609612
610613 if ($ this ->sessionPool ) {
611614 $ this ->sessionPool ->clear ();
@@ -640,9 +643,10 @@ public function ddl(array $options = []): array
640643 $ data ['database ' ] = $ this ->name ;
641644
642645 $ request = $ this ->serializer ->decodeMessage (new GetDatabaseDdlRequest (), $ data );
643- $ callOptions = $ this ->addResourcePrefixHeader ($ callOptions , $ this ->name );
644646
645- $ response = $ this ->databaseAdminClient ->getDatabaseDdl ($ request , $ callOptions );
647+ $ response = $ this ->databaseAdminClient ->getDatabaseDdl ($ request , $ callOptions + [
648+ 'resource-prefix ' => $ this ->name
649+ ]);
646650 $ ddl = $ this ->handleResponse ($ response );
647651
648652 if (isset ($ ddl ['statements ' ])) {
@@ -1690,7 +1694,6 @@ public function execute($sql, array $options = []): Result
16901694 $ options ['transaction ' ],
16911695 $ options ['transactionContext ' ]
16921696 ) = $ this ->transactionSelector ($ options );
1693- $ options = $ this ->addLarHeader ($ options , true , $ options ['transactionContext ' ]);
16941697
16951698 $ options ['directedReadOptions ' ] = $ this ->configureDirectedReadOptions (
16961699 $ options ,
@@ -1700,7 +1703,9 @@ public function execute($sql, array $options = []): Result
17001703 try {
17011704 // Unset the internal flag.
17021705 unset($ options ['singleUse ' ]);
1703- return $ this ->operation ->execute ($ session , $ sql , $ options );
1706+ return $ this ->operation ->execute ($ session , $ sql , $ options + [
1707+ 'route-to-leader ' => $ options ['transactionContext ' ] === SessionPoolInterface::CONTEXT_READWRITE
1708+ ]);
17041709 } finally {
17051710 $ session ->setExpiration ();
17061711 }
@@ -1789,10 +1794,11 @@ public function batchWrite(array $mutationGroups, array $options = []): \Generat
17891794 ];
17901795
17911796 $ request = $ this ->serializer ->decodeMessage (new BatchWriteRequest (), $ data );
1792- $ callOptions = $ this ->addResourcePrefixHeader ($ callOptions , $ this ->name );
1793- $ callOptions = $ this ->addLarHeader ($ callOptions , $ this ->routeToLeader );
17941797
1795- $ response = $ this ->spannerClient ->batchWrite ($ request , $ callOptions );
1798+ $ response = $ this ->spannerClient ->batchWrite ($ request , $ callOptions + [
1799+ 'resource-prefix ' => $ this ->name ,
1800+ 'route-to-leader ' => $ this ->routeToLeader ,
1801+ ]);
17961802 return $ this ->handleResponse ($ response );
17971803 } finally {
17981804 $ this ->isRunningTransaction = false ;
@@ -1934,11 +1940,10 @@ public function executePartitionedUpdate($statement, array $options = []): int
19341940 }
19351941 $ transaction = $ this ->operation ->transaction ($ session , $ beginTransactionOptions );
19361942
1937- $ options = $ this ->addLarHeader ($ options );
1938-
19391943 try {
19401944 return $ this ->operation ->executeUpdate ($ session , $ transaction , $ statement , [
1941- 'statsItem ' => 'rowCountLowerBound '
1945+ 'statsItem ' => 'rowCountLowerBound ' ,
1946+ 'route-to-leader ' => true ,
19421947 ] + $ options );
19431948 } finally {
19441949 $ session ->setExpiration ();
@@ -2079,12 +2084,12 @@ public function read($table, KeySet $keySet, array $columns, array $options = []
20792084 $ this ->directedReadOptions ?? []
20802085 );
20812086
2082- $ options = $ this ->addLarHeader ($ options , true , $ context );
2083-
20842087 try {
20852088 // Unset the internal flag.
20862089 unset($ options ['singleUse ' ]);
2087- return $ this ->operation ->read ($ session , $ table , $ keySet , $ columns , $ options );
2090+ return $ this ->operation ->read ($ session , $ table , $ keySet , $ columns , $ options + [
2091+ 'route-to-leader ' => $ context === SessionPoolInterface::CONTEXT_READ
2092+ ]);
20882093 } finally {
20892094 $ session ->setExpiration ();
20902095 }
@@ -2210,10 +2215,10 @@ public function batchCreateSessions(array $options): array
22102215 $ data ['database ' ] = $ this ->name ;
22112216
22122217 $ request = $ this ->serializer ->decodeMessage (new BatchCreateSessionsRequest (), $ data );
2213- $ callOptions = $ this ->addResourcePrefixHeader ( $ callOptions , $ this -> name );
2214- $ callOptions = $ this -> addLarHeader ( $ callOptions , $ this ->routeToLeader );
2215-
2216- $ response = $ this -> spannerClient -> batchCreateSessions ( $ request , $ callOptions );
2218+ $ response = $ this ->spannerClient -> batchCreateSessions ( $ request , $ callOptions + [
2219+ ' resource-prefix ' => $ this ->name ,
2220+ ' route-to-leader ' => $ this -> routeToLeader
2221+ ] );
22172222 return $ this ->handleResponse ($ response );
22182223 }
22192224
@@ -2232,9 +2237,9 @@ public function deleteSessionAsync(array $options): PromiseInterface
22322237 [$ data , $ callOptions ] = $ this ->splitOptionalArgs ($ options );
22332238
22342239 $ request = $ this ->serializer ->decodeMessage (new DeleteSessionRequest (), $ data );
2235- $ callOptions = $ this ->addResourcePrefixHeader ( $ callOptions , $ this -> name );
2236-
2237- return $ this -> spannerClient -> deleteSessionAsync ( $ request , $ callOptions );
2240+ return $ this ->spannerClient -> deleteSessionAsync ( $ request , $ callOptions + [
2241+ ' resource-prefix ' => $ this -> name
2242+ ] );
22382243 }
22392244
22402245 /**
@@ -2261,14 +2266,13 @@ public function deleteSessionAsync(array $options): PromiseInterface
22612266 public function backupOperations (array $ options = []): ItemIterator
22622267 {
22632268 [$ data , $ callOptions ] = $ this ->splitOptionalArgs ($ options );
2264- $ callOptions = $ this ->addResourcePrefixHeader ($ callOptions , $ this ->name );
22652269 $ request = $ this ->serializer ->decodeMessage (new ListBackupOperationsRequest (), $ data );
22662270 $ request ->setParent ($ this ->instance ->name ());
22672271
22682272 return $ this ->buildLongRunningIterator (
22692273 [$ this ->databaseAdminClient , 'listBackupOperations ' ],
22702274 $ request ,
2271- $ callOptions
2275+ $ callOptions + [ ' resource-prefix ' => $ this -> name ]
22722276 );
22732277 }
22742278
@@ -2293,9 +2297,9 @@ public function createDatabaseFromBackup($name, $backup, array $options = []): O
22932297 ];
22942298
22952299 $ request = $ this ->serializer ->decodeMessage (new RestoreDatabaseRequest (), $ data );
2296- $ callOptions = $ this ->addResourcePrefixHeader ( $ callOptions , $ this -> name );
2297-
2298- return $ this -> databaseAdminClient -> restoreDatabase ( $ request , $ callOptions )
2300+ return $ this ->databaseAdminClient -> restoreDatabase ( $ request , $ callOptions + [
2301+ ' resource-prefix ' => $ this -> name
2302+ ] )
22992303 ->withResultFunction ($ this ->databaseResultFunction ());
23002304 }
23012305
@@ -2323,14 +2327,13 @@ public function createDatabaseFromBackup($name, $backup, array $options = []): O
23232327 public function databaseOperations (array $ options = []): ItemIterator
23242328 {
23252329 [$ data , $ callOptions ] = $ this ->splitOptionalArgs ($ options );
2326- $ callOptions = $ this ->addResourcePrefixHeader ($ callOptions , $ this ->name );
23272330 $ request = $ this ->serializer ->decodeMessage (new ListDatabaseOperationsRequest (), $ data );
23282331 $ request ->setParent ($ this ->instance ->name ());
23292332
23302333 return $ this ->buildLongRunningIterator (
23312334 [$ this ->databaseAdminClient , 'listDatabaseOperations ' ],
23322335 $ request ,
2333- $ callOptions
2336+ $ callOptions + [ ' resource-prefix ' => $ this -> name ]
23342337 );
23352338 }
23362339
0 commit comments