Skip to content

Commit

Permalink
style: resolve lint warnings - staticcheck
Browse files Browse the repository at this point in the history
It skips lint warnings related to #73, #74, and #75.
  • Loading branch information
ijsong committed Aug 25, 2022
1 parent e27ca48 commit b4d1f32
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 33 deletions.
5 changes: 3 additions & 2 deletions internal/metarepos/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

. "github.com/smartystreets/goconvey/convey"
"go.etcd.io/etcd/raft/raftpb"
"go.uber.org/multierr"
"go.uber.org/zap"

"github.com/kakao/varlog/pkg/types"
Expand Down Expand Up @@ -129,13 +130,13 @@ func (clus *cluster) close(i int) (err error) {
func (clus *cluster) Close() (err error) {
for i := range clus.peers {
if erri := clus.close(i); erri != nil {
err = erri
err = multierr.Append(err, erri)
}
}

os.RemoveAll("raftdata") //nolint:errcheck,revive // TODO:: Handle an error returned.

return clus.portLease.Release()
return multierr.Append(err, clus.portLease.Release())
}

func (clus *cluster) closeNoErrors(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/storagenode/logstream/replicate_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,5 @@ func newReplicateTaskSlice() []*replicateTask {

func releaseReplicateTaskSlice(rts []*replicateTask) {
rts = rts[0:0]
replicateTaskSlicePool.Put(rts)
replicateTaskSlicePool.Put(rts) //nolint:staticcheck
}
1 change: 1 addition & 0 deletions internal/storagenode/logstream/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (sq *sequencer) sequenceLoopInternal(ctx context.Context, st *sequenceTask)
// NOTE: Use "append" since the length of st.rts is not enough to use index. Its capacity is enough because it is created to be reused.
st.rts[replicaIdx].llsnList = append(st.rts[replicaIdx].llsnList, sq.llsn)
}
//nolint:staticcheck
if err := st.wb.Set(sq.llsn, st.dataBatch[dataIdx]); err != nil {
// TODO: handle error
}
Expand Down
3 changes: 2 additions & 1 deletion internal/stress/stress.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/kakao/varlog/pkg/types"
"github.com/kakao/varlog/pkg/varlog"
Expand Down Expand Up @@ -124,7 +125,7 @@ func Append(config Config) error {
go func() {
defer wg.Done()
vlog, err := varlog.Open(ctx, config.ClusterID, config.MRAddrs, varlog.WithGRPCDialOptions(
grpc.WithInsecure(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithReadBufferSize(1<<20),
grpc.WithWriteBufferSize(32<<20),
))
Expand Down
1 change: 0 additions & 1 deletion internal/varlogcli/append.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func appendInternal(mrAddrs []string, clusterID types.ClusterID, batchSize int,
batch = batch[0:0]
case <-ctx.Done():
return ctx.Err()
default:
}
}
if len(batch) > 0 {
Expand Down
3 changes: 1 addition & 2 deletions internal/varlogctl/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package varlogctl_test
import (
"context"
"flag"
"io/ioutil"
"os"
"testing"
"time"
Expand Down Expand Up @@ -416,7 +415,7 @@ func TestController(t *testing.T) {
return
}

want, err := ioutil.ReadFile(path)
want, err := os.ReadFile(path)
assert.NoError(t, err)

if len(got) > 0 || len(want) > 0 {
Expand Down
3 changes: 2 additions & 1 deletion pkg/rpc/rpc_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (

"github.com/pkg/errors"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

var (
defaultDialOption = []grpc.DialOption{grpc.WithInsecure()}
defaultDialOption = []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}
)

type Conn struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/fputil/dirsize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package fputil

import (
"io/fs"
"io/ioutil"
"os"
"path/filepath"
"testing"

Expand All @@ -18,7 +18,7 @@ func TestDirectorySize(t *testing.T) {
path := t.TempDir()
assert.Zero(t, DirectorySize(path))

assert.NoError(t, ioutil.WriteFile(filepath.Join(path, "foo"), []byte{'a'}, fs.FileMode(777)))
assert.NoError(t, os.WriteFile(filepath.Join(path, "foo"), []byte{'a'}, fs.FileMode(0777)))
assert.EqualValues(t, 1, DirectorySize(path))
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/util/fputil/filepath.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fputil

import (
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -19,7 +18,7 @@ func IsWritableDir(dir string) error {
return errors.WithStack(err)
}
filename := filepath.Join(dir, touchFileName)
if err := ioutil.WriteFile(filename, []byte(""), touchFileMode); err != nil {
if err := os.WriteFile(filename, []byte(""), touchFileMode); err != nil {
return errors.WithStack(err)
}
err = os.Remove(filename)
Expand Down
7 changes: 6 additions & 1 deletion pkg/util/testutil/conveyutil/conveyutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/smartystreets/goconvey/convey"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/kakao/varlog/pkg/util/netutil"
)
Expand Down Expand Up @@ -35,7 +36,11 @@ func WithServiceServer(s service, testf func(server *grpc.Server, addr string))
// addr := testutil.GetLocalAddress(lis)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
conn, err := grpc.DialContext(ctx, addr, grpc.WithInsecure(), grpc.WithBlock(), grpc.FailOnNonTempDialError(true))
conn, err := grpc.DialContext(ctx, addr,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
grpc.FailOnNonTempDialError(true),
)
convey.So(err, convey.ShouldBeNil)
convey.So(conn.Close(), convey.ShouldBeNil)

Expand Down
3 changes: 2 additions & 1 deletion pkg/varlog/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

const (
Expand Down Expand Up @@ -36,7 +37,7 @@ func defaultOptions() options {
expireDenyInterval: defaultExpireDenyInterval,
logger: zap.NewNop(),
grpcDialOptions: []grpc.DialOption{
grpc.WithInsecure(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithReadBufferSize(1 << 20),
grpc.WithWriteBufferSize(1 << 20),
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/varlogtest/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (c *testLog) LogStreamMetadata(_ context.Context, topicID types.TopicID, lo

logStreamDesc = *proto.Clone(&logStreamDesc).(*varlogpb.LogStreamDescriptor)
head, tail := c.vt.peek(topicID, logStreamID)
logStreamDesc.Head = head
logStreamDesc.Head = head //nolint:staticcheck
logStreamDesc.Tail = tail
return logStreamDesc, nil
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/varlogtest/varlogtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestVarlogTest(t *testing.T) {
require.Equal(t, varlogpb.LogEntryMeta{
TopicID: topicID,
LogStreamID: logStreamID,
}, logStreamDesc.Head)
}, logStreamDesc.Head) //nolint:staticcheck
require.Equal(t, varlogpb.LogEntryMeta{
TopicID: topicID,
LogStreamID: logStreamID,
Expand Down Expand Up @@ -326,8 +326,8 @@ func TestVarlogTest(t *testing.T) {
for _, lsID := range topicLogStreamsMap[tpID] {
lsDesc, err := vlg.LogStreamMetadata(context.Background(), tpID, lsID)
require.NoError(t, err)
require.GreaterOrEqual(t, lsDesc.Tail.LLSN, lsDesc.Head.LLSN)
subscribeTo(tpID, lsID, lsDesc.Head.LLSN, lsDesc.Tail.LLSN+1)
require.GreaterOrEqual(t, lsDesc.Tail.LLSN, lsDesc.Head.LLSN) //nolint:staticcheck
subscribeTo(tpID, lsID, lsDesc.Head.LLSN, lsDesc.Tail.LLSN+1) //nolint:staticcheck

lsd, err := adm.Unseal(context.Background(), tpID, lsID)
require.NoError(t, err)
Expand All @@ -345,8 +345,8 @@ func TestVarlogTest(t *testing.T) {
for _, lsID := range lsIDs {
lsDesc, err := vlg.LogStreamMetadata(context.Background(), tpID, lsID)
require.NoError(t, err)
require.GreaterOrEqual(t, lsDesc.Tail.LLSN, lsDesc.Head.LLSN)
subscribeTo(tpID, lsID, lsDesc.Head.LLSN, lsDesc.Tail.LLSN+1)
require.GreaterOrEqual(t, lsDesc.Tail.LLSN, lsDesc.Head.LLSN) //nolint:staticcheck
subscribeTo(tpID, lsID, lsDesc.Head.LLSN, lsDesc.Tail.LLSN+1) //nolint:staticcheck
}
}

Expand All @@ -356,7 +356,7 @@ func TestVarlogTest(t *testing.T) {

lsDesc, err := vlg.LogStreamMetadata(context.Background(), tpID, lsID)
require.NoError(t, err)
require.Equal(t, types.MinLLSN, lsDesc.Head.LLSN)
require.Equal(t, types.MinLLSN, lsDesc.Head.LLSN) //nolint:staticcheck
require.GreaterOrEqual(t, lsDesc.Tail.LLSN, types.LLSN(minLogsPerTopic))

ctx1, cancel1 := context.WithCancel(context.Background())
Expand Down Expand Up @@ -523,15 +523,15 @@ func TestVarlogTest_Trim(t *testing.T) {

lsd, err := vlg.LogStreamMetadata(context.Background(), td.TopicID, lsds[0].LogStreamID)
assert.NoError(t, err)
assert.Equal(t, types.LLSN(3), lsd.Head.LLSN)
assert.Equal(t, types.GLSN(5), lsd.Head.GLSN)
assert.Equal(t, types.LLSN(3), lsd.Head.LLSN) //nolint:staticcheck
assert.Equal(t, types.GLSN(5), lsd.Head.GLSN) //nolint:staticcheck
assert.Equal(t, types.LLSN(5), lsd.Tail.LLSN)
assert.Equal(t, types.GLSN(9), lsd.Tail.GLSN)

lsd, err = vlg.LogStreamMetadata(context.Background(), td.TopicID, lsds[1].LogStreamID)
assert.NoError(t, err)
assert.Equal(t, types.LLSN(2), lsd.Head.LLSN)
assert.Equal(t, types.GLSN(4), lsd.Head.GLSN)
assert.Equal(t, types.LLSN(2), lsd.Head.LLSN) //nolint:staticcheck
assert.Equal(t, types.GLSN(4), lsd.Head.GLSN) //nolint:staticcheck
assert.Equal(t, types.LLSN(5), lsd.Tail.LLSN)
assert.Equal(t, types.GLSN(10), lsd.Tail.GLSN)

Expand Down
4 changes: 2 additions & 2 deletions tests/ee/k8s/vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package vault
import (
"encoding/json"
"flag"
"io/ioutil"
"io"
"net/http"
"os"
"testing"
Expand Down Expand Up @@ -51,7 +51,7 @@ func GetClusterConnectionInfo(t *testing.T) ClusterConnectionInfo {
assert.NoError(t, err)
}()

body, err := ioutil.ReadAll(rsp.Body)
body, err := io.ReadAll(rsp.Body)
require.NoError(t, err)

var response Response
Expand Down
8 changes: 4 additions & 4 deletions tests/it/cluster/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ func TestClientAppend(t *testing.T) {
require.Equal(t, topicID, lsd.TopicID)
require.Equal(t, logStreamID, lsd.LogStreamID)

require.Equal(t, types.MinLLSN, lsd.Head.LLSN)
require.GreaterOrEqual(t, lsd.Head.GLSN, types.MinGLSN)
require.Equal(t, topicID, lsd.Head.TopicID)
require.Equal(t, logStreamID, lsd.Head.LogStreamID)
require.Equal(t, types.MinLLSN, lsd.Head.LLSN) //nolint:staticcheck
require.GreaterOrEqual(t, lsd.Head.GLSN, types.MinGLSN) //nolint:staticcheck
require.Equal(t, topicID, lsd.Head.TopicID) //nolint:staticcheck
require.Equal(t, logStreamID, lsd.Head.LogStreamID) //nolint:staticcheck

require.GreaterOrEqual(t, lsd.Tail.LLSN, types.MinLLSN)
require.GreaterOrEqual(t, lsd.Tail.GLSN, types.MinGLSN)
Expand Down
2 changes: 1 addition & 1 deletion tests/it/management/management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ func TestSealLogStreamSealedIncompletely(t *testing.T) {
So(err, ShouldBeNil)

So(testutil.CompareWaitN(100, func() bool {
meta, err := env.GetVMS().Metadata(context.TODO())
meta, err := env.GetVMS().Metadata(context.TODO()) //nolint:staticcheck
if err != nil {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion tests/it/testenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,7 @@ func (clus *VarlogCluster) WaitCommit(t *testing.T, lsID types.LogStreamID, vers
func (clus *VarlogCluster) WaitSealed(t *testing.T, lsID types.LogStreamID) {
// FIXME: do not use vms.RELOAD_INTERVAL
require.Eventually(t, func() bool {
vmsMeta, err := clus.vmsServer.Metadata(context.Background())
vmsMeta, err := clus.vmsServer.Metadata(context.Background()) //nolint:staticcheck
return err == nil && vmsMeta.GetLogStream(lsID) != nil
}, mrmanager.ReloadInterval*10, 100*time.Millisecond)

Expand Down

0 comments on commit b4d1f32

Please sign in to comment.