public function getSrvKeyspace(VTContext $ctx, $keyspace) { $req = array('Keyspace' => $keyspace); if ($ctx->getCallerId()) { $req['CallerId'] = $ctx->getCallerId()->toBsonP3(); } $resp = $this->client->call($ctx, 'VTGateP3.GetSrvKeyspace', $req)->reply; return VTSrvKeyspace::fromBsonP3($resp['SrvKeyspace']); }
public function rollback(VTContext $ctx) { if (!$this->inTransaction()) { throw new VTException('rollback called while not in transaction.'); } $request = new \vtgate\RollbackRequest(); $request->setSession($this->session); if ($ctx->getCallerId()) { $request->setCallerId($ctx->getCallerId()); } $response = $this->client->rollback($ctx, $request); $this->session = NULL; }
public function setUp() { $this->ctx = VTContext::getDefault()->withDeadlineAfter(5.0)->withCallerId(self::$CALLER_ID); $this->conn = new VTGateconn(self::$client); }
* This is a sample for using the PHP Vitess client with an unsharded keyspace. * * Before running this, start up a local example cluster as described in the * README.md file. * * Then run: * vitess/examples/local$ php client.php --server=localhost:15991 */ require_once __DIR__ . '/../../php/vendor/autoload.php'; $opts = getopt('', array('server:')); $keyspace = 'test_keyspace'; // An unsharded keyspace is the same as custom sharding (0, 1, 2, ...), // but with only a single shard (0). $shards = array('0'); // Create a connection. $ctx = VTContext::getDefault(); $conn = new VTGateConn(new VTGrpcClient($opts['server'])); // Insert something. echo "Inserting into master...\n"; $tx = $conn->begin($ctx); $tx->executeShards($ctx, 'INSERT INTO test_table (msg) VALUES (:msg)', $keyspace, $shards, array('msg' => 'V is for speed')); $tx->commit($ctx); // Read it back from the master. echo "Reading from master...\n"; $cursor = $conn->executeShards($ctx, 'SELECT * FROM test_table', $keyspace, $shards, array(), \topodata\TabletType::MASTER); while (($row = $cursor->next()) !== FALSE) { printf("(%s)\n", implode(', ', $row)); } // Read from a replica. // Note that this may be behind master due to replication lag. echo "Reading from replica...\n";
public function splitQuery(VTContext $ctx, $keyspace, $query, array $bind_vars, $split_column, $split_count) { $request = new \vtgate\SplitQueryRequest(); $request->setKeyspace($keyspace); $request->setQuery(VTProto::BoundQuery($query, $bind_vars)); $request->setSplitColumn($split_column); $request->setSplitCount($split_count); if ($ctx->getCallerId()) { $request->setCallerId($ctx->getCallerId()); } $response = $this->client->splitQuery($ctx, $request); return $response->getSplitsList(); }
public function begin(VTContext $ctx) { $req = array(); if ($ctx->getCallerId()) { $req['CallerId'] = $ctx->getCallerId()->toBsonP3(); } $resp = $this->client->call($ctx, 'VTGateP3.Begin', $req)->reply; return new VTGateTx($this->client, $resp['Session']); }