rework size estimation & dry sends
- use control connection (gRPC) - use uint64 everywhere => fixes https://github.com/zrepl/zrepl/issues/463 - [BREAK] bump protocol version closes https://github.com/zrepl/zrepl/pull/518 fixes https://github.com/zrepl/zrepl/issues/463
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
// its interface and counting the bytes written to during copying.
|
||||
type ReadCloser interface {
|
||||
io.ReadCloser
|
||||
Count() int64
|
||||
Count() uint64
|
||||
}
|
||||
|
||||
// NewReadCloser wraps rc.
|
||||
@@ -19,11 +19,11 @@ func NewReadCloser(rc io.ReadCloser) ReadCloser {
|
||||
|
||||
type readCloser struct {
|
||||
rc io.ReadCloser
|
||||
count int64
|
||||
count uint64
|
||||
}
|
||||
|
||||
func (r *readCloser) Count() int64 {
|
||||
return atomic.LoadInt64(&r.count)
|
||||
func (r *readCloser) Count() uint64 {
|
||||
return atomic.LoadUint64(&r.count)
|
||||
}
|
||||
|
||||
var _ io.ReadCloser = &readCloser{}
|
||||
@@ -34,6 +34,9 @@ func (r *readCloser) Close() error {
|
||||
|
||||
func (r *readCloser) Read(p []byte) (int, error) {
|
||||
n, err := r.rc.Read(p)
|
||||
atomic.AddInt64(&r.count, int64(n))
|
||||
if n < 0 {
|
||||
panic("expecting n >= 0")
|
||||
}
|
||||
atomic.AddUint64(&r.count, uint64(n))
|
||||
return n, err
|
||||
}
|
||||
|
||||
@@ -73,6 +73,24 @@ func Int64(varname string, def int64) (d int64) {
|
||||
return d
|
||||
}
|
||||
|
||||
func Uint64(varname string, def uint64) (d uint64) {
|
||||
var err error
|
||||
if v, ok := cache.Load(varname); ok {
|
||||
return v.(uint64)
|
||||
}
|
||||
e := os.Getenv(varname)
|
||||
if e == "" {
|
||||
d = def
|
||||
} else {
|
||||
d, err = strconv.ParseUint(e, 10, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
cache.Store(varname, d)
|
||||
return d
|
||||
}
|
||||
|
||||
func Bool(varname string, def bool) (d bool) {
|
||||
var err error
|
||||
if v, ok := cache.Load(varname); ok {
|
||||
|
||||
Reference in New Issue
Block a user