Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CT-1894 BQ increase retry #1435

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function testCreateTableWithTimePartitioningAndClustering(): void
$dataset = $client->dataset($workspace['connection']['schema']);
$tableInWorkspace = $dataset->table('partitioned');
if ($tableInWorkspace->exists()) {
$tableInWorkspace->delete();
$tableInWorkspace->delete(['retries' => 20]);
}
$dataset->createTable('partitioned', [
'schema' => [
Expand Down
6 changes: 4 additions & 2 deletions tests/Backend/Bigquery/TableDefinitionOperationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function testDataPreviewExoticTypes(): void
new BigqueryColumn('geography', new Bigquery('GEOGRAPHY')),
new BigqueryColumn('json', new Bigquery('JSON')),
]),
)));
)), BigqueryWorkspaceBackend::addOptionRetry([]));
$backend->executeQuery(sprintf(
/** @lang BigQuery */
'
Expand Down Expand Up @@ -1262,6 +1262,7 @@ public function testLoadingNullValuesToNotNullTypedColumnsFromTable(): void
$dataset,
),
),
BigqueryWorkspaceBackend::addOptionRetry([]),
);
$client->runQuery(
$client->query(
Expand All @@ -1270,6 +1271,7 @@ public function testLoadingNullValuesToNotNullTypedColumnsFromTable(): void
$dataset,
),
),
BigqueryWorkspaceBackend::addOptionRetry([]),
);

try {
Expand Down Expand Up @@ -1389,7 +1391,7 @@ public function testInsertInvalidValueToTypedColumn(): void
new BigqueryColumn('id', new Bigquery('INT64')),
new BigqueryColumn('price', new Bigquery('STRING')),
]),
)));
)), BigqueryWorkspaceBackend::addOptionRetry([]));
$backend->executeQuery(sprintf(
/** @lang BigQuery */
'
Expand Down
5 changes: 4 additions & 1 deletion tests/Backend/WorkspaceConnectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
namespace Keboola\Test\Backend;

use Google\Cloud\BigQuery\BigQueryClient;
use Keboola\TableBackendUtils\Connection\Bigquery\BigQueryClientWrapper;
use Keboola\TableBackendUtils\Connection\Snowflake\SnowflakeConnectionFactory;
use Keboola\TableBackendUtils\Connection\Teradata\TeradataConnection;
use Doctrine\DBAL\Connection as DBALConnection;
use Keboola\Db\Import\Snowflake\Connection as SnowflakeConnection;
use Keboola\TableBackendUtils\Connection\Exasol\ExasolConnectionFactory;
use Keboola\TableBackendUtils\Escaping\Exasol\ExasolQuote;
use Keboola\TableBackendUtils\Escaping\Teradata\TeradataQuote;
use Keboola\Test\Backend\Workspaces\Backend\BigqueryWorkspaceBackend;
use Keboola\Test\StorageApiTestCase;

trait WorkspaceConnectionTrait
Expand Down Expand Up @@ -146,12 +148,13 @@ private function getDbConnectionTeradata(array $connection): DBALConnection

private function getDbConnectionBigquery(array $connection): BigQueryClient
{
$bqClient = new BigQueryClient([
$bqClient = new BigQueryClientWrapper([
'keyFile' => $connection['credentials'],
]);

$bqClient->runQuery(
$bqClient->query('SELECT SESSION_USER() AS USER'),
BigqueryWorkspaceBackend::addOptionRetry([]),
)->getIterator()->current();

return $bqClient;
Expand Down
19 changes: 13 additions & 6 deletions tests/Backend/Workspaces/Backend/BigqueryWorkspaceBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use Google\Cloud\BigQuery\Dataset;
use Keboola\Datatype\Definition\Bigquery;
use Keboola\StorageApi\Exception;
use Keboola\StorageDriver\BigQuery\Client\BigQuery\Retry;
use Keboola\StorageDriver\BigQuery\CredentialsHelper;
use Keboola\TableBackendUtils\Column\Bigquery\BigqueryColumn;
use Keboola\TableBackendUtils\Column\ColumnCollection;
use Keboola\TableBackendUtils\Connection\Bigquery\BigQueryClientWrapper;
Expand All @@ -17,6 +15,7 @@
use Keboola\TableBackendUtils\Table\Bigquery\BigqueryTableReflection;
use Keboola\TableBackendUtils\View\ViewReflectionInterface;
use PDO;
use Retry\BackOff\ExponentialRandomBackOffPolicy;
use Retry\Policy\SimpleRetryPolicy;
use Retry\RetryProxy;

Expand Down Expand Up @@ -63,7 +62,7 @@ public function executeQuery(string $sql): void
'datasetId' => $this->schema,
],
],
]));
]), self::addOptionRetry([]));
}

/**
Expand Down Expand Up @@ -99,7 +98,7 @@ public function createTable($tableName, $columns)
$this->schema,
$tableName,
new ColumnCollection($cols),
)));
)), self::addOptionRetry([]));
}

/**
Expand Down Expand Up @@ -138,7 +137,7 @@ public function dropTableIfExists($table)
{
if ($this->isTableExists($this->schema, $table)) {
$dataset = $this->bqClient->dataset($this->schema);
$dataset->table($table)->delete(['retries' => 5]);
$dataset->table($table)->delete(['retries' => 20]);
}
}

Expand Down Expand Up @@ -178,7 +177,7 @@ public function fetchAll($table, $style = PDO::FETCH_NUM, $orderBy = null)
$orderBy !== null ? " ORDER BY $orderBy" : null,
),
);
$queryResults = $this->bqClient->runQuery($query);
$queryResults = $this->bqClient->runQuery($query, self::addOptionRetry([]));

$data = [];
switch ($style) {
Expand Down Expand Up @@ -246,4 +245,12 @@ public function getSchemaReflection(): BigquerySchemaReflection
{
return new BigquerySchemaReflection($this->bqClient, $this->schema);
}

public static function addOptionRetry(array $options): array
{
return [
'retryCount' => 20,
'backOffPolicy' => new ExponentialRandomBackOffPolicy(10, 1.8, 1000),
];
}
}
Loading