chroe: polish code according to golangci-lint hint

This commit is contained in:
skyjiang 2023-12-26 15:55:45 +08:00 committed by suxb201
parent c2aa81769a
commit 56abca8417
7 changed files with 27 additions and 40 deletions

View File

@ -150,10 +150,7 @@ func (ld *Loader) LoadSingleAppendOnlyFile(ctx context.Context, timestamp int64)
argString = argString[:v64] argString = argString[:v64]
argv = append(argv, string(argString)) argv = append(argv, string(argString))
} }
e.Argv = append(e.Argv, argv...)
for _, value := range argv {
e.Argv = append(e.Argv, value)
}
ld.ch <- e ld.ch <- e
} }
} }

View File

@ -110,8 +110,9 @@ func (ld *Loader) parseRDBEntry(ctx context.Context, rd *bufio.Reader) {
defer updateProcessSize() defer updateProcessSize()
// read one entry // read one entry
tick := time.Tick(time.Second * 1) ticker := time.NewTicker(time.Second * 1)
for true { defer ticker.Stop()
for {
typeByte := structure.ReadByte(rd) typeByte := structure.ReadByte(rd)
switch typeByte { switch typeByte {
case kFlagIdle: case kFlagIdle:
@ -197,9 +198,9 @@ func (ld *Loader) parseRDBEntry(ctx context.Context, rd *bufio.Reader) {
ld.freq = 0 ld.freq = 0
} }
select { select {
case <-tick: case <-ticker.C:
updateProcessSize() updateProcessSize()
case <- ctx.Done(): case <-ctx.Done():
return return
default: default:
} }

View File

@ -61,11 +61,9 @@ func ReadModuleString(rd io.Reader) string {
return ReadString(rd) return ReadString(rd)
} }
func ReadModuleEof(rd io.Reader) error { func ReadModuleEof(rd io.Reader) {
eof := ReadLength(rd) eof := ReadLength(rd)
if eof != rdbModuleOpcodeEOF { if eof != rdbModuleOpcodeEOF {
log.Panicf("The RDB file is not teminated by the proper module value EOF marker") log.Panicf("The RDB file is not teminated by the proper module value EOF marker")
} }
return nil
} }

View File

@ -104,7 +104,6 @@ func (o *BloomObject) LoadFromBuffer(rd io.Reader, key string, typeByte byte) {
} }
o.sb = sb o.sb = sb
structure.ReadModuleEof(rd) structure.ReadModuleEof(rd)
return
} }
func readUnsigned(rd io.Reader) uint64 { func readUnsigned(rd io.Reader) uint64 {

View File

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

View File

@ -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. // sendReplconfAck send replconf ack to master to keep heartbeat between redis-shake and source redis.
func (r *syncStandaloneReader) sendReplconfAck() { 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 { select {
case <-r.ctx.Done(): case <-r.ctx.Done():
return return

View File

@ -73,20 +73,17 @@ func Init(r Statusable, w Statusable) {
ticker := time.NewTicker(1 * time.Second) ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop() defer ticker.Stop()
lastConsistent := false lastConsistent := false
for { for range ticker.C {
select { ch <- func() {
case <-ticker.C: // update reader/writer stat
ch <- func() { stat.Reader = theReader.Status()
// update reader/writer stat stat.Writer = theWriter.Status()
stat.Reader = theReader.Status() stat.Consistent = lastConsistent && theReader.StatusConsistent() && theWriter.StatusConsistent()
stat.Writer = theWriter.Status() lastConsistent = stat.Consistent
stat.Consistent = lastConsistent && theReader.StatusConsistent() && theWriter.StatusConsistent() // update OPS
lastConsistent = stat.Consistent stat.TotalEntriesCount.updateOPS()
// update OPS for _, cmdEntryCount := range stat.PerCmdEntriesCount {
stat.TotalEntriesCount.updateOPS() cmdEntryCount.updateOPS()
for _, cmdEntryCount := range stat.PerCmdEntriesCount {
cmdEntryCount.updateOPS()
}
} }
} }
} }
@ -100,12 +97,9 @@ func Init(r Statusable, w Statusable) {
} }
ticker := time.NewTicker(time.Duration(config.Opt.Advanced.LogInterval) * time.Second) ticker := time.NewTicker(time.Duration(config.Opt.Advanced.LogInterval) * time.Second)
defer ticker.Stop() defer ticker.Stop()
for { for range ticker.C {
select { ch <- func() {
case <-ticker.C: log.Infof("%s, %s", stat.TotalEntriesCount.String(), theReader.StatusString())
ch <- func() {
log.Infof("%s, %s", stat.TotalEntriesCount.String(), theReader.StatusString())
}
} }
} }
}() }()