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

Replace go.uber.org/atomic with sync/atomic #1344

Merged
merged 1 commit into from
Jan 16, 2024
Merged
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
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ require (
github.com/robfig/cron v1.2.0
github.com/stretchr/testify v1.8.4
go.temporal.io/api v1.26.1-0.20240103185939-608bdd111e4b
go.uber.org/atomic v1.9.0
golang.org/x/sys v0.15.0
golang.org/x/time v0.3.0
google.golang.org/grpc v1.60.1
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
Expand All @@ -72,8 +71,6 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
go.temporal.io/api v1.26.1-0.20240103185939-608bdd111e4b h1:Fi5NWG08z7pfxBolgjchVp4PnmWrGIHjqboDlXve5Sg=
go.temporal.io/api v1.26.1-0.20240103185939-608bdd111e4b/go.mod h1:mix7Bpl8mFEfYud66rjYInxNpP43sqXvr1UiHv+mur0=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
9 changes: 4 additions & 5 deletions internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
enumspb "go.temporal.io/api/enums/v1"
"go.temporal.io/api/operatorservice/v1"
"go.temporal.io/api/workflowservice/v1"
uberatomic "go.uber.org/atomic"
"google.golang.org/grpc"

"go.temporal.io/sdk/converter"
Expand Down Expand Up @@ -532,7 +531,7 @@ type (
// other gRPC errors. If not present during service client creation, it will
// be created as false. This is set to true when server capabilities are
// fetched.
excludeInternalFromRetry *uberatomic.Bool
excludeInternalFromRetry *atomic.Bool
}

// StartWorkflowOptions configuration parameters for starting a workflow execution.
Expand Down Expand Up @@ -746,7 +745,7 @@ func newClient(options ClientOptions, existing *WorkflowClient) (Client, error)
var connection *grpc.ClientConn
var err error
if existing == nil {
options.ConnectionOptions.excludeInternalFromRetry = uberatomic.NewBool(false)
options.ConnectionOptions.excludeInternalFromRetry = &atomic.Bool{}
connection, err = dial(newDialParameters(&options, options.ConnectionOptions.excludeInternalFromRetry))
if err != nil {
return nil, err
Expand Down Expand Up @@ -780,7 +779,7 @@ func newClient(options ClientOptions, existing *WorkflowClient) (Client, error)
return client, nil
}

func newDialParameters(options *ClientOptions, excludeInternalFromRetry *uberatomic.Bool) dialParameters {
func newDialParameters(options *ClientOptions, excludeInternalFromRetry *atomic.Bool) dialParameters {
return dialParameters{
UserConnectionOptions: options.ConnectionOptions,
HostPort: options.HostPort,
Expand Down Expand Up @@ -818,7 +817,7 @@ func NewServiceClient(workflowServiceClient workflowservice.WorkflowServiceClien
}

if options.ConnectionOptions.excludeInternalFromRetry == nil {
options.ConnectionOptions.excludeInternalFromRetry = uberatomic.NewBool(false)
options.ConnectionOptions.excludeInternalFromRetry = &atomic.Bool{}
}

// Collect set of applicable worker interceptors
Expand Down
1 change: 0 additions & 1 deletion internal/cmd/build/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ require (
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
go.temporal.io/api v1.26.1 // indirect
go.uber.org/atomic v1.9.0 // indirect
golang.org/x/exp v0.0.0-20231127185646-65229373498e // indirect
golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect
golang.org/x/mod v0.14.0 // indirect
Expand Down
3 changes: 0 additions & 3 deletions internal/cmd/build/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
Expand All @@ -77,8 +76,6 @@ github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
go.temporal.io/api v1.26.1 h1:YqGQsOr/Tx4nVdA8wCv74AxesaIzCRHWb3KkHrYqI8k=
go.temporal.io/api v1.26.1/go.mod h1:Y/rALXTprFO+bvAlAfLFoJj7KpQIcL4GDQVN6fhYIa4=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
6 changes: 3 additions & 3 deletions internal/common/retry/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ package retry
import (
"context"
"math"
"sync/atomic"
"time"

"google.golang.org/grpc/status"
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
"github.com/grpc-ecosystem/go-grpc-middleware/util/backoffutils"
uberatomic "go.uber.org/atomic"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

const (
Expand Down Expand Up @@ -127,7 +127,7 @@ var (
// NewRetryOptionsInterceptor creates a new gRPC interceptor that populates retry options for each call based on values
// provided in the context. The atomic bool is checked each call to determine whether internals are included in retry.
// If not present or false, internals are assumed to be included.
func NewRetryOptionsInterceptor(excludeInternal *uberatomic.Bool) grpc.UnaryClientInterceptor {
func NewRetryOptionsInterceptor(excludeInternal *atomic.Bool) grpc.UnaryClientInterceptor {
return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
if rc, ok := ctx.Value(ConfigKey).(*GrpcRetryConfig); ok {
if _, ok := ctx.Deadline(); !ok {
Expand Down
4 changes: 2 additions & 2 deletions internal/grpc_dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ package internal

import (
"context"
"sync/atomic"
"time"

grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
"go.temporal.io/api/serviceerror"
"go.temporal.io/sdk/internal/common/metrics"
"go.temporal.io/sdk/internal/common/retry"
uberatomic "go.uber.org/atomic"
"google.golang.org/grpc"
"google.golang.org/grpc/backoff"
"google.golang.org/grpc/credentials"
Expand Down Expand Up @@ -148,7 +148,7 @@ func requiredInterceptors(
metricsHandler metrics.Handler,
headersProvider HeadersProvider,
controller TrafficController,
excludeInternalFromRetry *uberatomic.Bool,
excludeInternalFromRetry *atomic.Bool,
) []grpc.UnaryClientInterceptor {
interceptors := []grpc.UnaryClientInterceptor{
errorInterceptor,
Expand Down
2 changes: 1 addition & 1 deletion internal/internal_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ import (
"runtime"
"strings"
"sync"
"sync/atomic"
"time"
"unicode"

"golang.org/x/exp/slices"

commonpb "go.temporal.io/api/common/v1"
enumspb "go.temporal.io/api/enums/v1"
"go.uber.org/atomic"

"go.temporal.io/sdk/converter"
"go.temporal.io/sdk/internal/common/metrics"
Expand Down
3 changes: 1 addition & 2 deletions internal/internal_workflow_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"time"

"github.com/pborman/uuid"
uberatomic "go.uber.org/atomic"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
Expand Down Expand Up @@ -91,7 +90,7 @@ type (
contextPropagators []ContextPropagator
workerInterceptors []WorkerInterceptor
interceptor ClientOutboundInterceptor
excludeInternalFromRetry *uberatomic.Bool
excludeInternalFromRetry *atomic.Bool
capabilities *workflowservice.GetSystemInfoResponse_Capabilities
capabilitiesLock sync.RWMutex
eagerDispatcher *eagerWorkflowDispatcher
Expand Down
3 changes: 1 addition & 2 deletions internal/internal_workflow_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (

updatepb "go.temporal.io/api/update/v1"
workflowpb "go.temporal.io/api/workflow/v1"
uberatomic "go.uber.org/atomic"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/connectivity"
Expand Down Expand Up @@ -174,7 +173,7 @@ func (s *historyEventIteratorSuite) SetupTest() {
s.wfClient = &WorkflowClient{
workflowService: s.workflowServiceClient,
namespace: DefaultNamespace,
excludeInternalFromRetry: uberatomic.NewBool(false),
excludeInternalFromRetry: &atomic.Bool{},
}
}

Expand Down
11 changes: 5 additions & 6 deletions internal/internal_workflow_testsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (
commonpb "go.temporal.io/api/common/v1"
enumspb "go.temporal.io/api/enums/v1"
"go.temporal.io/api/serviceerror"
uberatomic "go.uber.org/atomic"
"google.golang.org/protobuf/proto"

"go.temporal.io/sdk/converter"
Expand Down Expand Up @@ -2331,8 +2330,8 @@ func (s *WorkflowTestSuiteUnitTest) Test_LocalActivity() {
}

func (s *WorkflowTestSuiteUnitTest) Test_WorkflowLocalActivityWithMockAndListeners() {
var localActivityFnCanceled uberatomic.Bool
var startedCount, completedCount, canceledCount uberatomic.Int32
var localActivityFnCanceled atomic.Bool
var startedCount, completedCount, canceledCount atomic.Int32
env := s.NewTestWorkflowEnvironment()

localActivityFn := func(_ context.Context, _ string) (string, error) {
Expand Down Expand Up @@ -2376,7 +2375,7 @@ func (s *WorkflowTestSuiteUnitTest) Test_WorkflowLocalActivityWithMockAndListene
env.RegisterWorkflow(workflowFn)
env.OnActivity(localActivityFn, mock.Anything, "local_activity").Return("hello mock", nil).Once()
env.SetOnLocalActivityStartedListener(func(activityInfo *ActivityInfo, ctx context.Context, args []interface{}) {
startedCount.Inc()
startedCount.Add(1)
})

env.SetOnLocalActivityCompletedListener(func(activityInfo *ActivityInfo, result converter.EncodedValue, err error) {
Expand All @@ -2385,11 +2384,11 @@ func (s *WorkflowTestSuiteUnitTest) Test_WorkflowLocalActivityWithMockAndListene
err = result.Get(&resultValue)
s.NoError(err)
s.Equal("hello mock", resultValue)
completedCount.Inc()
completedCount.Add(1)
})

env.SetOnLocalActivityCanceledListener(func(activityInfo *ActivityInfo) {
canceledCount.Inc()
canceledCount.Add(1)
})

env.ExecuteWorkflow(workflowFn)
Expand Down
Loading