diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-11-17 11:30:43 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-11-18 14:44:03 +0300 |
commit | 0c9a7cf01773912fdb46318ff701329d8e88a7ba (patch) | |
tree | 2b345bdf2bef2e896dc02eab67210339f4ea7ed4 /internal/praefect/importer | |
parent | ceb74a98a167684aebff86f23a7d8ac6ffc8c91c (diff) |
nodes: Add context parameter to `GetShard()`
The `nodes.Manager` interface's method `GetShard()` doesn't currently
receive a context as parameter, even though some of its implementations
perform non-trivial and potentially blocking work like querying the
database. This commit thus adds this parameter and adjusts all current
callsites.
Diffstat (limited to 'internal/praefect/importer')
-rw-r--r-- | internal/praefect/importer/importer.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/internal/praefect/importer/importer.go b/internal/praefect/importer/importer.go index 4f9f35038..3c8da6f9a 100644 --- a/internal/praefect/importer/importer.go +++ b/internal/praefect/importer/importer.go @@ -84,7 +84,7 @@ func (imp *Importer) importVirtualStorage(ctx context.Context, virtualStorage st return nil } - shard, err := imp.nm.GetShard(virtualStorage) + shard, err := imp.nm.GetShard(ctx, virtualStorage) if err != nil { return fmt.Errorf("get shard: %w", err) } @@ -159,9 +159,9 @@ WHERE virtual_storage = $1 // again after successful completion. func (imp *Importer) markCompleted(ctx context.Context, virtualStorage string) error { _, err := imp.db.ExecContext(ctx, ` -INSERT INTO virtual_storages (virtual_storage, repositories_imported) +INSERT INTO virtual_storages (virtual_storage, repositories_imported) VALUES ($1, true) -ON CONFLICT (virtual_storage) +ON CONFLICT (virtual_storage) DO UPDATE SET repositories_imported = true `, virtualStorage) return err @@ -173,7 +173,7 @@ func (imp *Importer) storeBatch(ctx context.Context, virtualStorage, primary str rows, err := imp.db.QueryContext(ctx, ` WITH imported_repositories AS ( INSERT INTO repositories (virtual_storage, relative_path, generation) - SELECT $1 AS virtual_storage, unnest($2::text[]) AS relative_path, 0 AS generation + SELECT $1 AS virtual_storage, unnest($2::text[]) AS relative_path, 0 AS generation ON CONFLICT DO NOTHING RETURNING virtual_storage, relative_path, generation ), primary_records AS ( |