Skip to content

Commit

Permalink
[dss/crdb] upgrade github.com/cockroachdb/cockroach-go/v2 to v2.2.8 (#…
Browse files Browse the repository at this point in the history
…740)

* [dss] upgrade github.com/cockroachdb/cockroach-go/v2 to v2.2.8

* [dss] set default max_retries to 100 and allow override with commandline
  • Loading branch information
barroco authored Mar 15, 2022
1 parent 6ab2134 commit 52be26c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ go 1.14

require (
cloud.google.com/go v0.64.0
github.com/cockroachdb/cockroach-go/v2 v2.2.0
github.com/cockroachdb/cockroach-go/v2 v2.2.8
github.com/coreos/go-semver v0.3.0
github.com/golang-jwt/jwt v3.2.1+incompatible
github.com/golang/geo v0.0.0-20190916061304-5b978397cfec
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
github.com/cockroachdb/cockroach-go/v2 v2.2.0 h1:/5znzg5n373N/3ESjHF5SMLxiW4RKB05Ql//KWfeTFs=
github.com/cockroachdb/cockroach-go/v2 v2.2.0/go.mod h1:u3MiKYGupPPjkn3ozknpMUpxPaNLTFWAya419/zv6eI=
github.com/cockroachdb/cockroach-go/v2 v2.2.8/go.mod h1:q4ZRgO6CQpwNyEvEwSxwNrOSVchsmzrBnAv3HuZ3Abc=
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
Expand Down
1 change: 1 addition & 0 deletions pkg/cockroach/cockroach.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type (
SSL SSL
MaxOpenConns int
MaxConnIdleSeconds int
MaxRetries int
}
)

Expand Down
1 change: 1 addition & 0 deletions pkg/cockroach/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ func init() {
flag.StringVar(&connectParameters.Credentials.Username, "cockroach_user", "root", "cockroach user to authenticate as")
flag.IntVar(&connectParameters.MaxOpenConns, "max_open_conns", 4, "maximum number of open connections to the database, default is 4")
flag.IntVar(&connectParameters.MaxConnIdleSeconds, "max_conn_idle_secs", 30, "maximum amount of time in seconds a connection may be idle, default is 30 seconds")
flag.IntVar(&connectParameters.MaxRetries, "cockroach_max_retries", 100, "maximum number of attempts to retry a query in case of contention, default is 100")
}
4 changes: 4 additions & 0 deletions pkg/rid/store/cockroach/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package cockroach

import (
"context"
"github.com/cockroachdb/cockroach-go/v2/crdb"
"github.com/interuss/dss/pkg/cockroach/flags"
"time"

"github.com/cockroachdb/cockroach-go/v2/crdb/crdbpgx"
Expand Down Expand Up @@ -121,6 +123,8 @@ func (s *Store) Transact(ctx context.Context, f func(repo repos.Repository) erro
ctx, cancel := context.WithTimeout(ctx, DefaultTimeout)
defer cancel()

ctx = crdb.WithMaxRetries(ctx, flags.ConnectParameters().MaxRetries)

storeVersion, err := s.GetVersion(ctx)
if err != nil {
return stacktrace.Propagate(err, "Error determining database RID schema version")
Expand Down
4 changes: 3 additions & 1 deletion pkg/scd/store/cockroach/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cockroach

import (
"context"

"github.com/cockroachdb/cockroach-go/v2/crdb"
"github.com/cockroachdb/cockroach-go/v2/crdb/crdbpgx"
"github.com/coreos/go-semver/semver"
"github.com/interuss/dss/pkg/cockroach"
"github.com/interuss/dss/pkg/cockroach/flags"
"github.com/interuss/dss/pkg/scd/repos"
dsssql "github.com/interuss/dss/pkg/sql"
"github.com/interuss/stacktrace"
Expand Down Expand Up @@ -86,6 +87,7 @@ func (s *Store) Interact(_ context.Context) (repos.Repository, error) {

// Transact implements store.Transactor interface.
func (s *Store) Transact(ctx context.Context, f func(context.Context, repos.Repository) error) error {
ctx = crdb.WithMaxRetries(ctx, flags.ConnectParameters().MaxRetries)
return crdbpgx.ExecuteTx(ctx, s.db.Pool, pgx.TxOptions{}, func(tx pgx.Tx) error {
return f(ctx, &repo{
q: tx,
Expand Down

0 comments on commit 52be26c

Please sign in to comment.