Skip to content

Commit

Permalink
improvement(go1.23): use any instead of inteface{}
Browse files Browse the repository at this point in the history
Since we switched to new go versions, we can take advantage in
readability that comes with it. This simple change, replaces all
`interface{}` with `any`.

Signed-off-by: Dusan Malusev <[email protected]>
  • Loading branch information
CodeLieutenant committed Oct 23, 2024
1 parent 783bd13 commit e6cc137
Show file tree
Hide file tree
Showing 31 changed files with 228 additions and 224 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ $(GOBIN)/golangci-lint: GOLANGCI_VERSION = 1.60.3
$(GOBIN)/golangci-lint: Makefile
$(call dl_tgz,golangci-lint,https://github.com/golangci/golangci-lint/releases/download/v$(GOLANGCI_VERSION)/golangci-lint-$(GOLANGCI_VERSION)-$(GOOS)-amd64.tar.gz)

.PHONY: fmt
fmt:
gofumpt -w -extra .

.PHONY: check
check: $(GOBIN)/golangci-lint
$(GOBIN)/golangci-lint run
Expand Down
2 changes: 1 addition & 1 deletion cmd/gemini/spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type spinningFeedback struct {
s *spinner.Spinner
}

func (sf *spinningFeedback) Set(format string, args ...interface{}) {
func (sf *spinningFeedback) Set(format string, args ...any) {
if sf.s != nil {
sf.s.Suffix = fmt.Sprintf(format, args...)
}
Expand Down
4 changes: 2 additions & 2 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ in use but the idea is to introduce some jitter into the execution flow.
The application generates partition ids through a `Generator` that creates a steady flow of partition
key components for the desired [concurrency](architecture.md#Concurrency).
Each goroutine is connected to a `partition` that the generator controls. This partition continuously emits
new partition ids in the form of a `[]interface{}`. These keys are created in the same way as the the
new partition ids in the form of a `[]any`. These keys are created in the same way as the the
driver does to ensure that each goroutine only processes partition keys from it's designated bucket.
These partition keys These values are copied into another list that keeps the old partition ids for
later reuse. The idea of reusing the partition keys is that probability of hitting the same partition
Expand Down Expand Up @@ -99,4 +99,4 @@ methods for creating queries of all kinds which are used in the main Gemini prog
There are complex types which each is a new Type such as `MapType` that is composed of simple types.
Each type is responsible for generating the actual data that is inserted into the database.
For example: the [generator](architecture.md#Partition Keys) is delegating the actual data
construction to the instantiated types of the table it is working on.
construction to the instantiated types of the table it is working on.
4 changes: 2 additions & 2 deletions pkg/generators/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"github.com/scylladb/gemini/pkg/typedef"
)

func CreatePartitionKeyValues(table *typedef.Table, r *rand.Rand, g *typedef.PartitionRangeConfig) []interface{} {
values := make([]interface{}, 0, table.PartitionKeysLenValues())
func CreatePartitionKeyValues(table *typedef.Table, r *rand.Rand, g *typedef.PartitionRangeConfig) []any {
values := make([]any, 0, table.PartitionKeysLenValues())
for _, pk := range table.PartitionKeys {
values = append(values, pk.Type.GenValue(r, g)...)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/inflight/inflight_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ func TestDeleteSharded(t *testing.T) {
func TestInflight(t *testing.T) {
t.Parallel()
flight := newSyncU64set(shrinkInflightsLimit)
f := func(v uint64) interface{} {
f := func(v uint64) any {
return flight.AddIfNotPresent(v)
}
g := func(v uint64) interface{} {
g := func(v uint64) any {
flight.Delete(v)
return !flight.Has(v)
}
Expand Down Expand Up @@ -105,10 +105,10 @@ func TestAutoShrink(t *testing.T) {
func TestInflightSharded(t *testing.T) {
t.Parallel()
flight := newShardedSyncU64set()
f := func(v uint64) interface{} {
f := func(v uint64) any {
return flight.AddIfNotPresent(v)
}
g := func(v uint64) interface{} {
g := func(v uint64) any {
flight.Delete(v)
return !flight.shards[v%256].Has(v)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/joberror/joberror_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestParallel(t *testing.T) {
wg := sync.WaitGroup{}
resultList := joberror.NewErrorList(1000)
expectedList := joberror.NewErrorList(1000)
baseDate := time.Date(2020, 02, 01, 0, 0, 0, 0, time.UTC)
baseDate := time.Date(2020, 0o2, 0o1, 0, 0, 0, 0, time.UTC)
idx := atomic.Int32{}
for y := 0; y < 1000; y++ {
expectedList.AddError(&joberror.JobError{
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestErrorSerialization(t *testing.T) {
t.Parallel()
expected := []byte(`{"timestamp":"2020-02-01T00:00:00Z","message":"Some Message","query":"Some Query","stmt-type":"Some Type"}`)
result, err := json.Marshal(joberror.JobError{
Timestamp: time.Date(2020, 02, 01, 0, 0, 0, 0, time.UTC),
Timestamp: time.Date(2020, 0o2, 0o1, 0, 0, 0, 0, time.UTC),
Message: "Some Message",
Query: "Some Query",
StmtType: "Some Type",
Expand All @@ -92,7 +92,7 @@ func TestErrorListSerialization(t *testing.T) {
//nolint:lll
expected := []byte(`[{"timestamp":"2020-02-01T00:00:00Z","message":"Some Message 0","query":"Some Query 0","stmt-type":"Some Stmt Type 0"},{"timestamp":"2020-02-02T00:00:00Z","message":"Some Message 1","query":"Some Query 1","stmt-type":"Some Stmt Type 1"},{"timestamp":"2020-02-03T00:00:00Z","message":"Some Message 2","query":"Some Query 2","stmt-type":"Some Stmt Type 2"},{"timestamp":"2020-02-04T00:00:00Z","message":"Some Message 3","query":"Some Query 3","stmt-type":"Some Stmt Type 3"},{"timestamp":"2020-02-05T00:00:00Z","message":"Some Message 4","query":"Some Query 4","stmt-type":"Some Stmt Type 4"},{"timestamp":"2020-02-06T00:00:00Z","message":"Some Message 5","query":"Some Query 5","stmt-type":"Some Stmt Type 5"},{"timestamp":"2020-02-07T00:00:00Z","message":"Some Message 6","query":"Some Query 6","stmt-type":"Some Stmt Type 6"},{"timestamp":"2020-02-08T00:00:00Z","message":"Some Message 7","query":"Some Query 7","stmt-type":"Some Stmt Type 7"},{"timestamp":"2020-02-09T00:00:00Z","message":"Some Message 8","query":"Some Query 8","stmt-type":"Some Stmt Type 8"},{"timestamp":"2020-02-10T00:00:00Z","message":"Some Message 9","query":"Some Query 9","stmt-type":"Some Stmt Type 9"}]`)
lst := joberror.NewErrorList(1000)
baseDate := time.Date(2020, 02, 01, 0, 0, 0, 0, time.UTC)
baseDate := time.Date(2020, 0o2, 0o1, 0, 0, 0, 0, time.UTC)
for y := 0; y < 10; y++ {
lst.AddError(&joberror.JobError{
Timestamp: baseDate.AddDate(0, 0, y),
Expand Down
12 changes: 6 additions & 6 deletions pkg/jobs/gen_check_stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func genSinglePartitionQueryMv(

values := valuesWithToken.Value.Copy()
if mv.HaveNonPrimaryKey() {
var mvValues []interface{}
var mvValues []any
mvValues = append(mvValues, mv.NonPrimaryKey.Type.GenValue(r, p)...)
values = append(mvValues, values...)
}
Expand All @@ -189,7 +189,7 @@ func genMultiplePartitionQuery(
t.RLock()
defer t.RUnlock()
typs := make([]typedef.Type, numQueryPKs*t.PartitionKeys.Len())
values := make([]interface{}, numQueryPKs*t.PartitionKeys.Len())
values := make([]any, numQueryPKs*t.PartitionKeys.Len())

builder := qb.Select(s.Keyspace.Name + "." + t.Name)
tokens := make([]*typedef.ValueWithToken, 0, numQueryPKs)
Expand Down Expand Up @@ -233,7 +233,7 @@ func genMultiplePartitionQueryMv(

mv := t.MaterializedViews[mvNum]
typs := make([]typedef.Type, numQueryPKs*mv.PartitionKeys.Len())
values := make([]interface{}, numQueryPKs*mv.PartitionKeys.Len())
values := make([]any, numQueryPKs*mv.PartitionKeys.Len())

builder := qb.Select(s.Keyspace.Name + "." + t.Name)
tokens := make([]*typedef.ValueWithToken, 0, numQueryPKs)
Expand All @@ -245,7 +245,7 @@ func genMultiplePartitionQueryMv(
return nil
}
tokens = append(tokens, vs)
vals := make([]interface{}, mv.PartitionKeys.Len())
vals := make([]any, mv.PartitionKeys.Len())
if mv.HaveNonPrimaryKey() {
vals[0] = mv.NonPrimaryKey.Type.GenValue(r, p)
copy(vals[1:], vs.Value.Copy())
Expand Down Expand Up @@ -335,7 +335,7 @@ func genClusteringRangeQueryMv(
values := vs.Value.Copy()
mv := t.MaterializedViews[mvNum]
if mv.HaveNonPrimaryKey() {
mvValues := append([]interface{}{}, mv.NonPrimaryKey.Type.GenValue(r, p)...)
mvValues := append([]any{}, mv.NonPrimaryKey.Type.GenValue(r, p)...)
values = append(mvValues, values...)
}
builder := qb.Select(s.Keyspace.Name + "." + mv.Name)
Expand Down Expand Up @@ -525,7 +525,7 @@ func genSingleIndexQuery(
defer t.RUnlock()

var (
values []interface{}
values []any
typs []typedef.Type
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/jobs/gen_ddl_stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func GenDDLStmt(s *typedef.Schema, t *typedef.Table, r *rand.Rand, _ *typedef.Pa
}
}

func appendValue(columnType typedef.Type, r *rand.Rand, p *typedef.PartitionRangeConfig, values []interface{}) []interface{} {
func appendValue(columnType typedef.Type, r *rand.Rand, p *typedef.PartitionRangeConfig, values []any) []any {
return append(values, columnType.GenValue(r, p)...)
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/jobs/gen_mutate_stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ func genInsertJSONStmt(
return nil, nil
}
vs := valuesWithToken.Value.Copy()
values := make(map[string]interface{})
values := make(map[string]any)
for i, pk := range table.PartitionKeys {
switch t := pk.Type.(type) {
case typedef.SimpleType:
values[pk.Name] = convertForJSON(t, vs[i])
case *typedef.TupleType:
tupVals := make([]interface{}, len(t.ValueTypes))
tupVals := make([]any, len(t.ValueTypes))
for j := 0; j < len(t.ValueTypes); j++ {
tupVals[i] = convertForJSON(t, vs[i])
i++
Expand All @@ -161,7 +161,7 @@ func genInsertJSONStmt(
QueryType: typedef.InsertJSONStatementType,
},
ValuesWithToken: []*typedef.ValueWithToken{valuesWithToken},
Values: []interface{}{string(jsonString)},
Values: []any{string(jsonString)},
}, nil
}

Expand All @@ -180,7 +180,7 @@ func genDeleteRows(_ *typedef.Schema, t *typedef.Table, valuesWithToken *typedef
}, nil
}

func convertForJSON(vType typedef.Type, value interface{}) interface{} {
func convertForJSON(vType typedef.Type, value any) any {
switch vType {
case typedef.TYPE_BLOB:
val, _ := value.(string)
Expand Down
4 changes: 2 additions & 2 deletions pkg/jobs/gen_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (r results) Diff(t results) string {
return strings.Join(out, "\n")
}

func convertStmtsToResults(stmt interface{}) results {
func convertStmtsToResults(stmt any) results {
var out results
switch stmts := stmt.(type) {
case *typedef.Stmts:
Expand Down Expand Up @@ -239,7 +239,7 @@ func GetCkCountFromOptions(options testutils.TestCaseOptions, allValue int) int
return ckCount
}

func validateStmt(t *testing.T, stmt interface{}, err error) {
func validateStmt(t *testing.T, stmt any, err error) {
t.Helper()
if err != nil {
t.Fatalf("error: get an error on create test inputs:%v", err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/replication/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"strings"
)

type Replication map[string]interface{}
type Replication map[string]any

func (r *Replication) ToCQL() string {
b, _ := json.Marshal(r)
Expand All @@ -41,7 +41,7 @@ func NewNetworkTopologyStrategy() *Replication {
}

func (r *Replication) UnmarshalJSON(data []byte) error {
dataMap := make(map[string]interface{})
dataMap := make(map[string]any)
if err := json.Unmarshal(data, &dataMap); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/routingkey/routing_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Creator struct {
routingKeyBuffer []byte
}

func (rc *Creator) CreateRoutingKey(table *typedef.Table, values []interface{}) ([]byte, error) {
func (rc *Creator) CreateRoutingKey(table *typedef.Table, values []any) ([]byte, error) {
partitionKeys := table.PartitionKeys
if len(partitionKeys) == 1 {
// single column routing key
Expand Down
Loading

0 comments on commit e6cc137

Please sign in to comment.