Skip to content

Commit 56abca8

Browse files
jjz921024suxb201
authored andcommitted
chroe: polish code according to golangci-lint hint
1 parent c2aa817 commit 56abca8

File tree

7 files changed

+27
-40
lines changed

7 files changed

+27
-40
lines changed

internal/aof/aof.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,7 @@ func (ld *Loader) LoadSingleAppendOnlyFile(ctx context.Context, timestamp int64)
150150
argString = argString[:v64]
151151
argv = append(argv, string(argString))
152152
}
153-
154-
for _, value := range argv {
155-
e.Argv = append(e.Argv, value)
156-
}
153+
e.Argv = append(e.Argv, argv...)
157154
ld.ch <- e
158155
}
159156
}

internal/rdb/rdb.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ func (ld *Loader) parseRDBEntry(ctx context.Context, rd *bufio.Reader) {
110110
defer updateProcessSize()
111111

112112
// read one entry
113-
tick := time.Tick(time.Second * 1)
114-
for true {
113+
ticker := time.NewTicker(time.Second * 1)
114+
defer ticker.Stop()
115+
for {
115116
typeByte := structure.ReadByte(rd)
116117
switch typeByte {
117118
case kFlagIdle:
@@ -197,9 +198,9 @@ func (ld *Loader) parseRDBEntry(ctx context.Context, rd *bufio.Reader) {
197198
ld.freq = 0
198199
}
199200
select {
200-
case <-tick:
201+
case <-ticker.C:
201202
updateProcessSize()
202-
case <- ctx.Done():
203+
case <-ctx.Done():
203204
return
204205
default:
205206
}

internal/rdb/structure/module2_struct.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,9 @@ func ReadModuleString(rd io.Reader) string {
6161
return ReadString(rd)
6262
}
6363

64-
func ReadModuleEof(rd io.Reader) error {
64+
func ReadModuleEof(rd io.Reader) {
6565
eof := ReadLength(rd)
6666
if eof != rdbModuleOpcodeEOF {
6767
log.Panicf("The RDB file is not teminated by the proper module value EOF marker")
6868
}
69-
return nil
70-
7169
}

internal/rdb/types/mbbloom.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ func (o *BloomObject) LoadFromBuffer(rd io.Reader, key string, typeByte byte) {
104104
}
105105
o.sb = sb
106106
structure.ReadModuleEof(rd)
107-
return
108107
}
109108

110109
func readUnsigned(rd io.Reader) uint64 {

internal/reader/parsing_aof.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ func (aofInfo *INFO) LoadAppendOnlyFile(ctx context.Context, am *AOFManifest, AO
563563
status := AOFOk
564564
ret := AOFOk
565565
var start int64
566-
var totalSize int64 = 0
566+
var totalSize int64
567567
var BaseSize int64 = 0
568568
var AOFName string
569569
var totalNum, AOFNum int
@@ -693,7 +693,6 @@ func (aofInfo *INFO) LoadAppendOnlyFile(ctx context.Context, am *AOFManifest, AO
693693
}
694694

695695
func (aofInfo *INFO) ParsingSingleAppendOnlyFile(ctx context.Context, FileName string, AOFTimeStamp int64) int {
696-
ret := AOFOk
697696
AOFFilepath := path.Join(aofInfo.AOFDirName, FileName)
698697
println(AOFFilepath)
699698
fp, err := os.Open(AOFFilepath)
@@ -719,8 +718,7 @@ func (aofInfo *INFO) ParsingSingleAppendOnlyFile(ctx context.Context, FileName s
719718
if n, err := fp.Read(sig); err != nil || n != 5 || !bytes.Equal(sig, []byte("REDIS")) {
720719
if _, err := fp.Seek(0, 0); err != nil {
721720
log.Infof("Unrecoverable error reading the append only File %v: %v", FileName, err)
722-
ret = AOFFailed
723-
return ret
721+
return AOFFailed
724722
}
725723
} else { //Skipped RDB checksum and has not been processed yet.
726724
log.Infof("Reading RDB Base File on AOF loading...")
@@ -731,7 +729,5 @@ func (aofInfo *INFO) ParsingSingleAppendOnlyFile(ctx context.Context, FileName s
731729
}
732730
// load single aof file
733731
aofSingleReader := aof.NewLoader(MakePath(aofInfo.AOFDirName, FileName), aofInfo.ch)
734-
ret = aofSingleReader.LoadSingleAppendOnlyFile(ctx, AOFTimeStamp)
735-
return ret
736-
732+
return aofSingleReader.LoadSingleAppendOnlyFile(ctx, AOFTimeStamp)
737733
}

internal/reader/sync_standalone_reader.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ func (r *syncStandaloneReader) sendAOF(offset int64) {
311311

312312
// sendReplconfAck send replconf ack to master to keep heartbeat between redis-shake and source redis.
313313
func (r *syncStandaloneReader) sendReplconfAck() {
314-
for range time.Tick(time.Millisecond * 100) {
314+
ticker := time.NewTicker(time.Millisecond * 100)
315+
defer ticker.Stop()
316+
for range ticker.C {
315317
select {
316318
case <-r.ctx.Done():
317319
return

internal/status/status.go

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,17 @@ func Init(r Statusable, w Statusable) {
7373
ticker := time.NewTicker(1 * time.Second)
7474
defer ticker.Stop()
7575
lastConsistent := false
76-
for {
77-
select {
78-
case <-ticker.C:
79-
ch <- func() {
80-
// update reader/writer stat
81-
stat.Reader = theReader.Status()
82-
stat.Writer = theWriter.Status()
83-
stat.Consistent = lastConsistent && theReader.StatusConsistent() && theWriter.StatusConsistent()
84-
lastConsistent = stat.Consistent
85-
// update OPS
86-
stat.TotalEntriesCount.updateOPS()
87-
for _, cmdEntryCount := range stat.PerCmdEntriesCount {
88-
cmdEntryCount.updateOPS()
89-
}
76+
for range ticker.C {
77+
ch <- func() {
78+
// update reader/writer stat
79+
stat.Reader = theReader.Status()
80+
stat.Writer = theWriter.Status()
81+
stat.Consistent = lastConsistent && theReader.StatusConsistent() && theWriter.StatusConsistent()
82+
lastConsistent = stat.Consistent
83+
// update OPS
84+
stat.TotalEntriesCount.updateOPS()
85+
for _, cmdEntryCount := range stat.PerCmdEntriesCount {
86+
cmdEntryCount.updateOPS()
9087
}
9188
}
9289
}
@@ -100,12 +97,9 @@ func Init(r Statusable, w Statusable) {
10097
}
10198
ticker := time.NewTicker(time.Duration(config.Opt.Advanced.LogInterval) * time.Second)
10299
defer ticker.Stop()
103-
for {
104-
select {
105-
case <-ticker.C:
106-
ch <- func() {
107-
log.Infof("%s, %s", stat.TotalEntriesCount.String(), theReader.StatusString())
108-
}
100+
for range ticker.C {
101+
ch <- func() {
102+
log.Infof("%s, %s", stat.TotalEntriesCount.String(), theReader.StatusString())
109103
}
110104
}
111105
}()

0 commit comments

Comments
 (0)