format full-sync RDB size

v4
vinllen 5 years ago
parent ebf1fda83b
commit 0cdea66373
  1. 17
      src/redis-shake/common/common.go
  2. 4
      src/redis-shake/decode.go
  3. 4
      src/redis-shake/dump.go
  4. 5
      src/redis-shake/restore.go
  5. 5
      src/redis-shake/sync.go

@ -146,4 +146,21 @@ func CheckVersionChecksum(d []byte) (uint, uint64, error) {
} }
return rdbVersion, checksum, nil return rdbVersion, checksum, nil
}
func GetMetric(input int64) string {
switch {
case input > PB:
return fmt.Sprintf("%.3fPB", float64(input) / PB)
case input > TB:
return fmt.Sprintf("%.3fTB", float64(input) / TB)
case input > GB:
return fmt.Sprintf("%.3fGB", float64(input) / GB)
case input > MB:
return fmt.Sprintf("%.3fMB", float64(input) / MB)
case input > KB:
return fmt.Sprintf("%.3fKB", float64(input) / KB)
default:
return fmt.Sprintf("%dB", input)
}
} }

@ -102,9 +102,9 @@ func (cmd *CmdDecode) decode(input, output string) {
var b bytes.Buffer var b bytes.Buffer
fmt.Fprintf(&b, "decode: ") fmt.Fprintf(&b, "decode: ")
if nsize != 0 { if nsize != 0 {
fmt.Fprintf(&b, "total = %d - %12d [%3d%%]", nsize, stat.rbytes, 100*stat.rbytes/nsize) fmt.Fprintf(&b, "total = %s - %12s [%3d%%]", utils.GetMetric(nsize), utils.GetMetric(stat.rbytes), 100*stat.rbytes/nsize)
} else { } else {
fmt.Fprintf(&b, "total = %12d", stat.rbytes) fmt.Fprintf(&b, "total = %12s", utils.GetMetric(stat.rbytes))
} }
fmt.Fprintf(&b, " write=%-12d", stat.wbytes) fmt.Fprintf(&b, " write=%-12d", stat.wbytes)
fmt.Fprintf(&b, " entry=%-12d", stat.nentry) fmt.Fprintf(&b, " entry=%-12d", stat.nentry)

@ -99,7 +99,7 @@ func (cmd *CmdDump) dumpCommand(reader *bufio.Reader, writer *bufio.Writer, nsiz
for { for {
time.Sleep(time.Second) time.Sleep(time.Second)
log.Infof("dump: total = %d\n", nsize+nread.Get()) log.Infof("dump: total = %s\n", utils.GetMetric(nsize+nread.Get()))
} }
} }
@ -175,7 +175,7 @@ func (dd *dbDumper) dumpRDBFile(reader *bufio.Reader, writer *bufio.Writer, nsiz
} }
n := nread.Get() n := nread.Get()
p := 100 * n / nsize p := 100 * n / nsize
log.Infof("routine[%v] total = %d - %12d [%3d%%]\n", dd.id, nsize, n, p) log.Infof("routine[%v] total = %s - %12s [%3d%%]\n", dd.id, utils.GetMetric(nsize), utils.GetMetric(n), p)
} }
log.Infof("routine[%v] dump: rdb done", dd.id) log.Infof("routine[%v] dump: rdb done", dd.id)
} }

@ -199,9 +199,10 @@ func (dr *dbRestorer) restoreRDBFile(reader *bufio.Reader, target []string, auth
stat := dr.Stat() stat := dr.Stat()
var b bytes.Buffer var b bytes.Buffer
if nsize != 0 { if nsize != 0 {
fmt.Fprintf(&b, "routine[%v] total = %d - %12d [%3d%%]", dr.id, nsize, stat.rbytes, 100*stat.rbytes/nsize) fmt.Fprintf(&b, "routine[%v] total = %s - %12s [%3d%%]", dr.id, utils.GetMetric(nsize),
utils.GetMetric(stat.rbytes), 100*stat.rbytes/nsize)
} else { } else {
fmt.Fprintf(&b, "routine[%v] total = %12d", dr.id, stat.rbytes) fmt.Fprintf(&b, "routine[%v] total = %12s", dr.id, utils.GetMetric(stat.rbytes))
} }
fmt.Fprintf(&b, " entry=%-12d", stat.nentry) fmt.Fprintf(&b, " entry=%-12d", stat.nentry)
if stat.ignore != 0 { if stat.ignore != 0 {

@ -464,8 +464,9 @@ func (ds *dbSyncer) syncRDBFile(reader *bufio.Reader, target []string, auth_type
} }
stat = ds.Stat() stat = ds.Stat()
var b bytes.Buffer var b bytes.Buffer
fmt.Fprintf(&b, "dbSyncer[%v] total=%d - %12d [%3d%%] entry=%-12d", // fmt.Fprintf(&b, "dbSyncer[%v] total=%s - %12d [%3d%%] entry=%-12d",
ds.id, nsize, stat.rbytes, 100*stat.rbytes/nsize, stat.nentry) fmt.Fprintf(&b, "dbSyncer[%v] total = %s - %12s [%3d%%] entry=%-12d",
ds.id, utils.GetMetric(nsize), utils.GetMetric(stat.rbytes), 100*stat.rbytes/nsize, stat.nentry)
if stat.ignore != 0 { if stat.ignore != 0 {
fmt.Fprintf(&b, " ignore=%-12d", stat.ignore) fmt.Fprintf(&b, " ignore=%-12d", stat.ignore)
} }

Loading…
Cancel
Save