Skip to content

Commit

Permalink
fix(Bigtable): prevent race condition (#7644)
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer authored Sep 5, 2024
1 parent 7c699f0 commit f94f1d4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Bigtable/src/ChunkFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function __construct(
$this->gapicClient = $gapicClient;
$this->request = $request;
$this->options = $options;

if ($request->getRowsLimit()) {
$this->originalRowsLimit = $request->getRowsLimit();
}
Expand Down Expand Up @@ -228,6 +228,9 @@ private function updateReadRowsRequest($request, $options, $prevRowKey)
{
if ($this->originalRowsLimit) {
$request->setRowsLimit($this->originalRowsLimit - $this->numberOfRowsRead);
if ($this->numberOfRowsRead === $this->originalRowsLimit) {
$options['requestCompleted'] = true;
}
}

if ($request->hasRows()) {
Expand Down
28 changes: 28 additions & 0 deletions Bigtable/tests/Unit/SmartRetriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,34 @@ public function testReadRowsWithRowsLimit()
$this->assertEquals($expectedRows, $rows);
}

public function testReadRowsWithRowsLimitAndExceptionThrownAfterSuccess()
{
$args = ['rowsLimit' => 1];
$expectedArgs = $args + $this->options;
$this->serverStream->readAll()
->shouldBeCalledTimes(1)
->willReturn(
$this->arrayAsGeneratorWithException(
$this->generateRowsResponse(1, 1),
$this->retryingApiException
)
);
$this->bigtableClient->readRows(
Argument::that(function ($request) use (&$allowedRowsLimit) {
return $request->getRowsLimit() === 1;
}),
Argument::type('array')
)
->shouldBeCalledTimes(1)
->willReturn(
$this->serverStream->reveal()
);

$rows = $this->table->readRows($args);
$expectedRows = $this->generateExpectedRows(1, 1);
$this->assertEquals($expectedRows, iterator_to_array($rows));
}

public function testReadRowsWithRowKeys()
{
$args = ['rowKeys' => ['rk1', 'rk2', 'rk3', 'rk4']];
Expand Down

0 comments on commit f94f1d4

Please sign in to comment.