Skip to content

Commit 758432e

Browse files
authored
Fix code to be compatible with go 1.15.2 (#762)
* Add helper functions to convert package Add IntToString, Int64ToString, and Uint64ToString functions to convert package for correct conversion of ints. * Fix code for go 1.15 Go 1.15 is strict about string(int) conversions. This breaks builds with 1.15. To fix it, I replaced implicit conversions with calls to strconv.FormatInt via the helper functions I added to the convert package. * Replace other usages of strconv.FormatInt I added helper functions to the convert package: IntToString, Int64ToString, and Uint64ToString. For consistency, I replaced other usages of strconv.FormatInt with those helper functions. * FIx coding style. * Remove shardIDForOutput and use shardIDstr instead Addressing a comment by alexshtin. * Add convert.Int32ToString helper function * Replace remaining instances of string(ShardID) with convert.Int32ToString
1 parent 8fd6fd3 commit 758432e

File tree

13 files changed

+78
-44
lines changed

13 files changed

+78
-44
lines changed

client/history/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"go.temporal.io/server/api/historyservice/v1"
3535
replicationspb "go.temporal.io/server/api/replication/v1"
3636
"go.temporal.io/server/common"
37+
"go.temporal.io/server/common/convert"
3738
"go.temporal.io/server/common/log"
3839
"go.temporal.io/server/common/log/tag"
3940
serviceerrors "go.temporal.io/server/common/serviceerror"
@@ -993,7 +994,7 @@ func (c *clientImpl) getClientForWorkflowID(namespaceID, workflowID string) (his
993994
}
994995

995996
func (c *clientImpl) getClientForShardID(shardID int) (historyservice.HistoryServiceClient, error) {
996-
client, err := c.clients.GetClientForKey(string(shardID))
997+
client, err := c.clients.GetClientForKey(convert.IntToString(shardID))
997998
if err != nil {
998999
return nil, err
9991000
}

common/convert/convert.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ package convert
2626

2727
import (
2828
"math"
29+
"strconv"
2930
"time"
3031
)
3132

@@ -74,3 +75,19 @@ func Int32Ceil(v float64) int32 {
7475
func Int64Ceil(v float64) int64 {
7576
return int64(math.Ceil(v))
7677
}
78+
79+
func IntToString(v int) string {
80+
return Int64ToString(int64(v))
81+
}
82+
83+
func Uint64ToString(v uint64) string {
84+
return strconv.FormatUint(v, 10)
85+
}
86+
87+
func Int64ToString(v int64) string {
88+
return strconv.FormatInt(v, 10)
89+
}
90+
91+
func Int32ToString(v int32) string {
92+
return Int64ToString(int64(v))
93+
}

common/persistence/elasticsearch/esVisibilityStore.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import (
3737
"strings"
3838
"time"
3939

40+
"go.temporal.io/server/common/convert"
41+
4042
"github.com/cch123/elasticsql"
4143
"github.com/olivere/elastic"
4244
"github.com/valyala/fastjson"
@@ -740,8 +742,8 @@ func (v *esVisibilityStore) getSearchResult(request *p.ListWorkflowExecutionsReq
740742
if request.EarliestStartTime < math.MinInt64+oneMilliSecondInNano { // prevent earliestTime overflow
741743
request.EarliestStartTime = math.MinInt64 + oneMilliSecondInNano
742744
}
743-
earliestTimeStr := strconv.FormatInt(request.EarliestStartTime-oneMilliSecondInNano, 10)
744-
latestTimeStr := strconv.FormatInt(request.LatestStartTime+oneMilliSecondInNano, 10)
745+
earliestTimeStr := convert.Int64ToString(request.EarliestStartTime - oneMilliSecondInNano)
746+
latestTimeStr := convert.Int64ToString(request.LatestStartTime + oneMilliSecondInNano)
745747
rangeQuery = rangeQuery.
746748
Gte(earliestTimeStr).
747749
Lte(latestTimeStr)

common/persistence/elasticsearch/esVisibilityStore_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ import (
3030
"fmt"
3131
"io"
3232
"math"
33-
"strconv"
3433
"strings"
3534
"testing"
3635

36+
"go.temporal.io/server/common/convert"
37+
3738
"github.com/olivere/elastic"
3839
"github.com/stretchr/testify/mock"
3940
"github.com/stretchr/testify/require"
@@ -439,8 +440,8 @@ func (s *ESVisibilitySuite) TestGetSearchResult() {
439440
runningQuery := elastic.NewMatchQuery(es.ExecutionStatus, int(enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING))
440441
tieBreakerSorter := elastic.NewFieldSort(es.RunID).Desc()
441442

442-
earliestTime := strconv.FormatInt(request.EarliestStartTime-oneMilliSecondInNano, 10)
443-
latestTime := strconv.FormatInt(request.LatestStartTime+oneMilliSecondInNano, 10)
443+
earliestTime := convert.Int64ToString(request.EarliestStartTime - oneMilliSecondInNano)
444+
latestTime := convert.Int64ToString(request.LatestStartTime + oneMilliSecondInNano)
444445

445446
// test for open
446447
rangeQuery := elastic.NewRangeQuery(es.StartTime).Gte(earliestTime).Lte(latestTime)
@@ -458,7 +459,7 @@ func (s *ESVisibilitySuite) TestGetSearchResult() {
458459

459460
// test request latestTime overflow
460461
request.LatestStartTime = math.MaxInt64
461-
rangeQuery1 := elastic.NewRangeQuery(es.StartTime).Gte(earliestTime).Lte(strconv.FormatInt(request.LatestStartTime, 10))
462+
rangeQuery1 := elastic.NewRangeQuery(es.StartTime).Gte(earliestTime).Lte(convert.Int64ToString(request.LatestStartTime))
462463
boolQuery1 := elastic.NewBoolQuery().Must(runningQuery).Must(matchNamespaceQuery).Filter(rangeQuery1)
463464
param1 := &es.SearchParameters{
464465
Index: testIndex,

common/rpc/rpc_common_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030
"math/rand"
3131
"strings"
3232

33+
"go.temporal.io/server/common/convert"
34+
3335
"github.com/stretchr/testify/suite"
3436
"google.golang.org/grpc"
3537
"google.golang.org/grpc/examples/helloworld/helloworld"
@@ -122,7 +124,7 @@ func dialHello(s suite.Suite, hostport string, clientFactory *TestFactory, serve
122124
s.NoError(err)
123125
client := helloworld.NewGreeterClient(clientConn)
124126

125-
request := &helloworld.HelloRequest{Name: string(rand.Uint64())}
127+
request := &helloworld.HelloRequest{Name: convert.Uint64ToString(rand.Uint64())}
126128
reply, err := client.SayHello(context.Background(), request)
127129

128130
if err == nil {

host/activity_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import (
3333
"strconv"
3434
"time"
3535

36+
"go.temporal.io/server/common/convert"
37+
3638
"github.com/pborman/uuid"
3739
enumspb "go.temporal.io/api/enums/v1"
3840
"go.temporal.io/sdk/temporal"
@@ -846,7 +848,7 @@ func (s *integrationSuite) TestActivityTimeouts() {
846848
for i := 0; i < 6; i++ {
847849
s.Logger.Info("Heartbeating for activity", tag.WorkflowActivityID(activityID), tag.Counter(i))
848850
_, err := s.engine.RecordActivityTaskHeartbeat(NewContext(), &workflowservice.RecordActivityTaskHeartbeatRequest{
849-
TaskToken: taskToken, Details: payloads.EncodeString(string(i))})
851+
TaskToken: taskToken, Details: payloads.EncodeString(convert.IntToString(i))})
850852
s.NoError(err)
851853
time.Sleep(1 * time.Second)
852854
}

service/frontend/adminHandler.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ package frontend
2727
import (
2828
"context"
2929
"errors"
30-
"strconv"
3130
"time"
3231

32+
"go.temporal.io/server/common/convert"
33+
3334
"github.com/olivere/elastic"
3435
"github.com/pborman/uuid"
3536
commonpb "go.temporal.io/api/common/v1"
@@ -204,8 +205,7 @@ func (adh *AdminHandler) DescribeWorkflowExecution(ctx context.Context, request
204205
namespaceID, err := adh.GetNamespaceCache().GetNamespaceID(request.GetNamespace())
205206

206207
shardID := common.WorkflowIDToHistoryShard(namespaceID, request.Execution.WorkflowId, adh.numberOfHistoryShards)
207-
shardIDstr := string(shardID)
208-
shardIDForOutput := strconv.Itoa(shardID)
208+
shardIDstr := convert.IntToString(shardID)
209209

210210
historyHost, err := adh.GetMembershipMonitor().Lookup(common.HistoryServiceName, shardIDstr)
211211
if err != nil {
@@ -222,7 +222,7 @@ func (adh *AdminHandler) DescribeWorkflowExecution(ctx context.Context, request
222222
return &adminservice.DescribeWorkflowExecutionResponse{}, err
223223
}
224224
return &adminservice.DescribeWorkflowExecutionResponse{
225-
ShardId: shardIDForOutput,
225+
ShardId: shardIDstr,
226226
HistoryAddr: historyAddr,
227227
DatabaseMutableState: resp2.GetDatabaseMutableState(),
228228
CacheMutableState: resp2.GetCacheMutableState(),

service/history/handler.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929
"sync"
3030
"sync/atomic"
3131

32+
"go.temporal.io/server/common/convert"
33+
3234
"github.com/pborman/uuid"
3335
commonpb "go.temporal.io/api/common/v1"
3436
enumspb "go.temporal.io/api/enums/v1"
@@ -1733,7 +1735,7 @@ func (h *Handler) convertError(err error) error {
17331735
switch err.(type) {
17341736
case *persistence.ShardOwnershipLostError:
17351737
shardID := err.(*persistence.ShardOwnershipLostError).ShardID
1736-
info, err := h.GetHistoryServiceResolver().Lookup(string(shardID))
1738+
info, err := h.GetHistoryServiceResolver().Lookup(convert.IntToString(shardID))
17371739
if err == nil {
17381740
return serviceerrors.NewShardOwnershipLost(h.GetHostInfo().GetAddress(), info.GetAddress())
17391741
}

service/history/shardController.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030
"sync/atomic"
3131
"time"
3232

33+
"go.temporal.io/server/common/convert"
34+
3335
"go.temporal.io/server/common"
3436
"go.temporal.io/server/common/log"
3537
"go.temporal.io/server/common/log/tag"
@@ -236,7 +238,7 @@ func (c *shardController) getOrCreateHistoryShardItem(shardID int) (*historyShar
236238
if c.isShuttingDown() || atomic.LoadInt32(&c.status) == common.DaemonStatusStopped {
237239
return nil, fmt.Errorf("shardController for host '%v' shutting down", c.GetHostInfo().Identity())
238240
}
239-
info, err := c.GetHistoryServiceResolver().Lookup(string(shardID))
241+
info, err := c.GetHistoryServiceResolver().Lookup(convert.IntToString(shardID))
240242
if err != nil {
241243
return nil, err
242244
}
@@ -336,7 +338,7 @@ func (c *shardController) acquireShards() {
336338
if c.isShuttingDown() {
337339
return
338340
}
339-
info, err := c.GetHistoryServiceResolver().Lookup(string(shardID))
341+
info, err := c.GetHistoryServiceResolver().Lookup(convert.IntToString(shardID))
340342
if err != nil {
341343
c.logger.Error("Error looking up host for shardID", tag.Error(err), tag.OperationFailed, tag.ShardID(shardID))
342344
} else {

service/history/shardController_test.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import (
3131
"testing"
3232
"time"
3333

34+
"go.temporal.io/server/common/convert"
35+
3436
"go.temporal.io/server/api/persistenceblobs/v1"
3537

3638
"github.com/golang/mock/gomock"
@@ -117,7 +119,7 @@ func (s *shardControllerSuite) TestAcquireShardSuccess() {
117119
if hostID == 0 {
118120
myShards = append(myShards, int(shardID))
119121
s.mockHistoryEngine.EXPECT().Start().Return().Times(1)
120-
s.mockServiceResolver.EXPECT().Lookup(string(shardID)).Return(s.hostInfo, nil).Times(2)
122+
s.mockServiceResolver.EXPECT().Lookup(convert.Int32ToString(shardID)).Return(s.hostInfo, nil).Times(2)
121123
s.mockEngineFactory.On("CreateEngine", mock.Anything).Return(s.mockHistoryEngine).Once()
122124
s.mockShardManager.On("GetShard", &persistence.GetShardRequest{ShardID: shardID}).Return(
123125
&persistence.GetShardResponse{
@@ -162,7 +164,7 @@ func (s *shardControllerSuite) TestAcquireShardSuccess() {
162164
}).Return(nil).Once()
163165
} else {
164166
ownerHost := fmt.Sprintf("test-acquire-shard-host-%v", hostID)
165-
s.mockServiceResolver.EXPECT().Lookup(string(shardID)).Return(membership.NewHostInfo(ownerHost, nil), nil).Times(1)
167+
s.mockServiceResolver.EXPECT().Lookup(convert.Int32ToString(shardID)).Return(membership.NewHostInfo(ownerHost, nil), nil).Times(1)
166168
}
167169
}
168170

@@ -197,7 +199,7 @@ func (s *shardControllerSuite) TestAcquireShardsConcurrently() {
197199
if hostID == 0 {
198200
myShards = append(myShards, int(shardID))
199201
s.mockHistoryEngine.EXPECT().Start().Return().Times(1)
200-
s.mockServiceResolver.EXPECT().Lookup(string(shardID)).Return(s.hostInfo, nil).Times(2)
202+
s.mockServiceResolver.EXPECT().Lookup(convert.Int32ToString(shardID)).Return(s.hostInfo, nil).Times(2)
201203
s.mockEngineFactory.On("CreateEngine", mock.Anything).Return(s.mockHistoryEngine).Once()
202204
s.mockShardManager.On("GetShard", &persistence.GetShardRequest{ShardID: shardID}).Return(
203205
&persistence.GetShardResponse{
@@ -242,7 +244,7 @@ func (s *shardControllerSuite) TestAcquireShardsConcurrently() {
242244
}).Return(nil).Once()
243245
} else {
244246
ownerHost := fmt.Sprintf("test-acquire-shard-host-%v", hostID)
245-
s.mockServiceResolver.EXPECT().Lookup(string(shardID)).Return(membership.NewHostInfo(ownerHost, nil), nil).Times(1)
247+
s.mockServiceResolver.EXPECT().Lookup(convert.Int32ToString(shardID)).Return(membership.NewHostInfo(ownerHost, nil), nil).Times(1)
246248
}
247249
}
248250

@@ -262,12 +264,12 @@ func (s *shardControllerSuite) TestAcquireShardLookupFailure() {
262264
numShards := 2
263265
s.config.NumberOfShards = numShards
264266
for shardID := 1; shardID <= numShards; shardID++ {
265-
s.mockServiceResolver.EXPECT().Lookup(string(shardID)).Return(nil, errors.New("ring failure")).Times(1)
267+
s.mockServiceResolver.EXPECT().Lookup(convert.IntToString(shardID)).Return(nil, errors.New("ring failure")).Times(1)
266268
}
267269

268270
s.shardController.acquireShards()
269271
for shardID := 1; shardID <= numShards; shardID++ {
270-
s.mockServiceResolver.EXPECT().Lookup(string(shardID)).Return(nil, errors.New("ring failure")).Times(1)
272+
s.mockServiceResolver.EXPECT().Lookup(convert.IntToString(shardID)).Return(nil, errors.New("ring failure")).Times(1)
271273
s.Nil(s.shardController.getEngineForShard(shardID))
272274
}
273275
}
@@ -284,7 +286,7 @@ func (s *shardControllerSuite) TestAcquireShardRenewSuccess() {
284286

285287
for shardID := int32(1); shardID <= int32(numShards); shardID++ {
286288
s.mockHistoryEngine.EXPECT().Start().Return().Times(1)
287-
s.mockServiceResolver.EXPECT().Lookup(string(shardID)).Return(s.hostInfo, nil).Times(2)
289+
s.mockServiceResolver.EXPECT().Lookup(convert.Int32ToString(shardID)).Return(s.hostInfo, nil).Times(2)
288290
s.mockEngineFactory.On("CreateEngine", mock.Anything).Return(s.mockHistoryEngine).Once()
289291
s.mockShardManager.On("GetShard", &persistence.GetShardRequest{ShardID: shardID}).Return(
290292
&persistence.GetShardResponse{
@@ -335,7 +337,7 @@ func (s *shardControllerSuite) TestAcquireShardRenewSuccess() {
335337
s.shardController.acquireShards()
336338

337339
for shardID := 1; shardID <= numShards; shardID++ {
338-
s.mockServiceResolver.EXPECT().Lookup(string(shardID)).Return(s.hostInfo, nil).Times(1)
340+
s.mockServiceResolver.EXPECT().Lookup(convert.IntToString(shardID)).Return(s.hostInfo, nil).Times(1)
339341
}
340342
s.shardController.acquireShards()
341343

@@ -356,7 +358,7 @@ func (s *shardControllerSuite) TestAcquireShardRenewLookupFailed() {
356358

357359
for shardID := int32(1); shardID <= int32(numShards); shardID++ {
358360
s.mockHistoryEngine.EXPECT().Start().Return().Times(1)
359-
s.mockServiceResolver.EXPECT().Lookup(string(shardID)).Return(s.hostInfo, nil).Times(2)
361+
s.mockServiceResolver.EXPECT().Lookup(convert.Int32ToString(shardID)).Return(s.hostInfo, nil).Times(2)
360362
s.mockEngineFactory.On("CreateEngine", mock.Anything).Return(s.mockHistoryEngine).Once()
361363
s.mockShardManager.On("GetShard", &persistence.GetShardRequest{ShardID: shardID}).Return(
362364
&persistence.GetShardResponse{
@@ -407,7 +409,7 @@ func (s *shardControllerSuite) TestAcquireShardRenewLookupFailed() {
407409
s.shardController.acquireShards()
408410

409411
for shardID := 1; shardID <= numShards; shardID++ {
410-
s.mockServiceResolver.EXPECT().Lookup(string(shardID)).Return(nil, errors.New("ring failure")).Times(1)
412+
s.mockServiceResolver.EXPECT().Lookup(convert.IntToString(shardID)).Return(nil, errors.New("ring failure")).Times(1)
411413
}
412414
s.shardController.acquireShards()
413415

@@ -454,7 +456,7 @@ func (s *shardControllerSuite) TestHistoryEngineClosed() {
454456
for shardID := 1; shardID <= 2; shardID++ {
455457
mockEngine := historyEngines[shardID]
456458
mockEngine.EXPECT().Stop().Return().Times(1)
457-
s.mockServiceResolver.EXPECT().Lookup(string(shardID)).Return(differentHostInfo, nil).AnyTimes()
459+
s.mockServiceResolver.EXPECT().Lookup(convert.IntToString(shardID)).Return(differentHostInfo, nil).AnyTimes()
458460
s.shardController.shardClosedCallback(shardID, nil)
459461
}
460462

@@ -499,7 +501,7 @@ func (s *shardControllerSuite) TestHistoryEngineClosed() {
499501
for shardID := 3; shardID <= numShards; shardID++ {
500502
mockEngine := historyEngines[shardID]
501503
mockEngine.EXPECT().Stop().Return().Times(1)
502-
s.mockServiceResolver.EXPECT().Lookup(string(shardID)).Return(s.hostInfo, nil).AnyTimes()
504+
s.mockServiceResolver.EXPECT().Lookup(convert.IntToString(shardID)).Return(s.hostInfo, nil).AnyTimes()
503505
}
504506
s.shardController.Stop()
505507
}
@@ -546,7 +548,7 @@ func (s *shardControllerSuite) TestShardControllerClosed() {
546548
for shardID := 1; shardID <= numShards; shardID++ {
547549
mockEngine := historyEngines[shardID]
548550
mockEngine.EXPECT().Stop().Times(1)
549-
s.mockServiceResolver.EXPECT().Lookup(string(shardID)).Return(s.hostInfo, nil).AnyTimes()
551+
s.mockServiceResolver.EXPECT().Lookup(convert.IntToString(shardID)).Return(s.hostInfo, nil).AnyTimes()
550552
}
551553
s.shardController.Stop()
552554
workerWG.Wait()
@@ -563,7 +565,7 @@ func (s *shardControllerSuite) setupMocksForAcquireShard(shardID int, mockEngine
563565

564566
// s.mockResource.ExecutionMgr.On("Close").Return()
565567
mockEngine.EXPECT().Start().Times(1)
566-
s.mockServiceResolver.EXPECT().Lookup(string(shardID)).Return(s.hostInfo, nil).Times(2)
568+
s.mockServiceResolver.EXPECT().Lookup(convert.IntToString(shardID)).Return(s.hostInfo, nil).Times(2)
567569
s.mockEngineFactory.On("CreateEngine", mock.Anything).Return(mockEngine).Once()
568570
s.mockShardManager.On("GetShard", &persistence.GetShardRequest{ShardID: int32(shardID)}).Return(
569571
&persistence.GetShardResponse{

0 commit comments

Comments
 (0)