Skip to content

Commit

Permalink
pass context to postgres queries (#15866)
Browse files Browse the repository at this point in the history
* pass context to postgres queries

* add changelog

* Update changelog/15866.txt

Co-authored-by: Alexander Scheel <[email protected]>

Co-authored-by: Alexander Scheel <[email protected]>
  • Loading branch information
bhowe34 and cipherboy authored Jun 8, 2022
1 parent 3ab0052 commit df279b9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions changelog/15866.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
physical/postgresql: pass context to queries to propagate timeouts and cancellations on requests.
```
8 changes: 4 additions & 4 deletions physical/postgresql/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (m *PostgreSQLBackend) Put(ctx context.Context, entry *physical.Entry) erro

parentPath, path, key := m.splitKey(entry.Key)

_, err := m.client.Exec(m.put_query, parentPath, path, key, entry.Value)
_, err := m.client.ExecContext(ctx, m.put_query, parentPath, path, key, entry.Value)
if err != nil {
return err
}
Expand All @@ -261,7 +261,7 @@ func (m *PostgreSQLBackend) Get(ctx context.Context, fullPath string) (*physical
_, path, key := m.splitKey(fullPath)

var result []byte
err := m.client.QueryRow(m.get_query, path, key).Scan(&result)
err := m.client.QueryRowContext(ctx, m.get_query, path, key).Scan(&result)
if err == sql.ErrNoRows {
return nil, nil
}
Expand All @@ -285,7 +285,7 @@ func (m *PostgreSQLBackend) Delete(ctx context.Context, fullPath string) error {

_, path, key := m.splitKey(fullPath)

_, err := m.client.Exec(m.delete_query, path, key)
_, err := m.client.ExecContext(ctx, m.delete_query, path, key)
if err != nil {
return err
}
Expand All @@ -300,7 +300,7 @@ func (m *PostgreSQLBackend) List(ctx context.Context, prefix string) ([]string,
m.permitPool.Acquire()
defer m.permitPool.Release()

rows, err := m.client.Query(m.list_query, "/"+prefix)
rows, err := m.client.QueryContext(ctx, m.list_query, "/"+prefix)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit df279b9

Please sign in to comment.