Skip to content

Commit

Permalink
Lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Sushisource committed Mar 14, 2023
1 parent fb70007 commit 27ca14f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.50.1
version: v1.51.2
args: --verbose --timeout 10m --fix=false --new-from-rev=HEAD~ --config=.golangci.yml
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ update-goimports:

update-linters:
@printf $(COLOR) "Install/update linters..."
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.1
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2

update-mockgen:
@printf $(COLOR) "Install/update mockgen tool..."
Expand Down
6 changes: 3 additions & 3 deletions api/adminservice/v1/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions api/historyservice/v1/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions api/matchingservice/v1/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions service/frontend/workflow_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4351,6 +4351,7 @@ func (wh *WorkflowHandler) validateTaskQueue(t *taskqueuepb.TaskQueue) error {
return nil
}

//nolint:revive // cyclomatic complexity
func (wh *WorkflowHandler) validateBuildIdCompatabilityUpdate(
req *workflowservice.UpdateWorkerBuildIdCompatabilityRequest,
) error {
Expand Down
34 changes: 23 additions & 11 deletions service/matching/version_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package matching
import (
"encoding/binary"
"fmt"

"github.com/dgryski/go-farm"
"github.com/pborman/uuid"
"go.temporal.io/api/serviceerror"
Expand All @@ -37,7 +38,7 @@ import (
)

func ToBuildIdOrderingResponse(g *persistence.VersioningData, maxDepth int) *workflowservice.GetWorkerBuildIdCompatabilityResponse {
return depthLimiter(g, maxDepth, false)
return depthLimiter(g, maxDepth)
}

// HashVersioningData returns a farm.Fingerprint64 hash of the versioning data as bytes. If the data is nonexistent or
Expand All @@ -55,14 +56,11 @@ func HashVersioningData(data *persistence.VersioningData) []byte {
return b
}

func depthLimiter(g *persistence.VersioningData, maxDepth int, mutate bool) *workflowservice.GetWorkerBuildIdCompatabilityResponse {
func depthLimiter(g *persistence.VersioningData, maxDepth int) *workflowservice.GetWorkerBuildIdCompatabilityResponse {
if maxDepth <= 0 || maxDepth >= len(g.GetVersionSets()) {
return &workflowservice.GetWorkerBuildIdCompatabilityResponse{MajorVersionSets: g.GetVersionSets()}
}
shortened := util.SliceTail(g.GetVersionSets(), maxDepth)
if mutate {
g.VersionSets = shortened
}
return &workflowservice.GetWorkerBuildIdCompatabilityResponse{MajorVersionSets: shortened}
}

Expand Down Expand Up @@ -99,14 +97,17 @@ func UpdateVersionSets(existingData *persistence.VersioningData, req *workflowse
return err
}
// Limit graph size if it's grown too large
depthLimiter(existingData, maxSize, true)
newResp := depthLimiter(existingData, maxSize)
existingData.VersionSets = newResp.GetMajorVersionSets()
return nil
}

//nolint:revive // cyclomatic complexity
func updateImpl(existingData *persistence.VersioningData, req *workflowservice.UpdateWorkerBuildIdCompatabilityRequest) error {
// First find if the targeted version is already in the sets
targetedVersion := extractTargetedVersion(req)
targetSetIx, versionInSetIx := findVersion(existingData, targetedVersion)
findRes := findVersion(existingData, targetedVersion)
targetSetIx, versionInSetIx := findRes.setIx, findRes.indexInSet

if req.GetAddNewBuildIdInNewDefaultSet() != "" {
// If it's not already in the sets, add it as the new default set
Expand All @@ -120,7 +121,7 @@ func updateImpl(existingData *persistence.VersioningData, req *workflowservice.U
})
} else if addNew := req.GetAddNewCompatibleBuildId(); addNew != nil {
compatVer := addNew.GetExistingCompatibleBuildId()
compatSetIx, _ := findVersion(existingData, compatVer)
compatSetIx := findVersion(existingData, compatVer).setIx
if compatSetIx == -1 {
return serviceerror.NewNotFound(
fmt.Sprintf("targeted compatible_version %v not found", compatVer))
Expand Down Expand Up @@ -163,17 +164,28 @@ func extractTargetedVersion(req *workflowservice.UpdateWorkerBuildIdCompatabilit
return req.GetAddNewBuildIdInNewDefaultSet()
}

type findVersionRes struct {
setIx int
indexInSet int
}

// Finds the version in the version sets, returning (set index, index within that set)
// Returns -1, -1 if not found.
func findVersion(data *persistence.VersioningData, buildID string) (int, int) {
func findVersion(data *persistence.VersioningData, buildID string) findVersionRes {
for setIx, set := range data.GetVersionSets() {
for versionIx, version := range set.GetBuildIds() {
if version == buildID {
return setIx, versionIx
return findVersionRes{
setIx: setIx,
indexInSet: versionIx,
}
}
}
}
return -1, -1
return findVersionRes{
setIx: -1,
indexInSet: -1,
}
}

func makeDefaultSet(data *persistence.VersioningData, setIx int) {
Expand Down

0 comments on commit 27ca14f

Please sign in to comment.