Skip to content

Commit

Permalink
chroe: polish code according to golangci-lint hint
Browse files Browse the repository at this point in the history
  • Loading branch information
jjz921024 authored and suxb201 committed Dec 28, 2023
1 parent c2aa817 commit 56abca8
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 40 deletions.
5 changes: 1 addition & 4 deletions internal/aof/aof.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ func (ld *Loader) LoadSingleAppendOnlyFile(ctx context.Context, timestamp int64)
argString = argString[:v64]
argv = append(argv, string(argString))
}

for _, value := range argv {
e.Argv = append(e.Argv, value)
}
e.Argv = append(e.Argv, argv...)
ld.ch <- e
}
}
Expand Down
9 changes: 5 additions & 4 deletions internal/rdb/rdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ func (ld *Loader) parseRDBEntry(ctx context.Context, rd *bufio.Reader) {
defer updateProcessSize()

// read one entry
tick := time.Tick(time.Second * 1)
for true {
ticker := time.NewTicker(time.Second * 1)
defer ticker.Stop()
for {
typeByte := structure.ReadByte(rd)
switch typeByte {
case kFlagIdle:
Expand Down Expand Up @@ -197,9 +198,9 @@ func (ld *Loader) parseRDBEntry(ctx context.Context, rd *bufio.Reader) {
ld.freq = 0
}
select {
case <-tick:
case <-ticker.C:
updateProcessSize()
case <- ctx.Done():
case <-ctx.Done():
return
default:
}
Expand Down
4 changes: 1 addition & 3 deletions internal/rdb/structure/module2_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ func ReadModuleString(rd io.Reader) string {
return ReadString(rd)
}

func ReadModuleEof(rd io.Reader) error {
func ReadModuleEof(rd io.Reader) {
eof := ReadLength(rd)
if eof != rdbModuleOpcodeEOF {
log.Panicf("The RDB file is not teminated by the proper module value EOF marker")
}
return nil

}
1 change: 0 additions & 1 deletion internal/rdb/types/mbbloom.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func (o *BloomObject) LoadFromBuffer(rd io.Reader, key string, typeByte byte) {
}
o.sb = sb
structure.ReadModuleEof(rd)
return
}

func readUnsigned(rd io.Reader) uint64 {
Expand Down
10 changes: 3 additions & 7 deletions internal/reader/parsing_aof.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ func (aofInfo *INFO) LoadAppendOnlyFile(ctx context.Context, am *AOFManifest, AO
status := AOFOk
ret := AOFOk
var start int64
var totalSize int64 = 0
var totalSize int64
var BaseSize int64 = 0
var AOFName string
var totalNum, AOFNum int
Expand Down Expand Up @@ -693,7 +693,6 @@ func (aofInfo *INFO) LoadAppendOnlyFile(ctx context.Context, am *AOFManifest, AO
}

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

return aofSingleReader.LoadSingleAppendOnlyFile(ctx, AOFTimeStamp)
}
4 changes: 3 additions & 1 deletion internal/reader/sync_standalone_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ func (r *syncStandaloneReader) sendAOF(offset int64) {

// sendReplconfAck send replconf ack to master to keep heartbeat between redis-shake and source redis.
func (r *syncStandaloneReader) sendReplconfAck() {
for range time.Tick(time.Millisecond * 100) {
ticker := time.NewTicker(time.Millisecond * 100)
defer ticker.Stop()
for range ticker.C {
select {
case <-r.ctx.Done():
return
Expand Down
34 changes: 14 additions & 20 deletions internal/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,17 @@ func Init(r Statusable, w Statusable) {
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()
lastConsistent := false
for {
select {
case <-ticker.C:
ch <- func() {
// update reader/writer stat
stat.Reader = theReader.Status()
stat.Writer = theWriter.Status()
stat.Consistent = lastConsistent && theReader.StatusConsistent() && theWriter.StatusConsistent()
lastConsistent = stat.Consistent
// update OPS
stat.TotalEntriesCount.updateOPS()
for _, cmdEntryCount := range stat.PerCmdEntriesCount {
cmdEntryCount.updateOPS()
}
for range ticker.C {
ch <- func() {
// update reader/writer stat
stat.Reader = theReader.Status()
stat.Writer = theWriter.Status()
stat.Consistent = lastConsistent && theReader.StatusConsistent() && theWriter.StatusConsistent()
lastConsistent = stat.Consistent
// update OPS
stat.TotalEntriesCount.updateOPS()
for _, cmdEntryCount := range stat.PerCmdEntriesCount {
cmdEntryCount.updateOPS()
}
}
}
Expand All @@ -100,12 +97,9 @@ func Init(r Statusable, w Statusable) {
}
ticker := time.NewTicker(time.Duration(config.Opt.Advanced.LogInterval) * time.Second)
defer ticker.Stop()
for {
select {
case <-ticker.C:
ch <- func() {
log.Infof("%s, %s", stat.TotalEntriesCount.String(), theReader.StatusString())
}
for range ticker.C {
ch <- func() {
log.Infof("%s, %s", stat.TotalEntriesCount.String(), theReader.StatusString())
}
}
}()
Expand Down

0 comments on commit 56abca8

Please sign in to comment.