feat: add thread-safe access to CountingWriter byte total (#22620)
Use atomic operations to update and report CountingWriter.Total through a new method. closes https://github.com/influxdata/influxdb/issues/22618pull/22638/head
parent
3c811bcd81
commit
022b6e866b
|
@ -11,6 +11,7 @@ import (
|
|||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
internal "github.com/influxdata/influxdb/cmd/influxd/backup_util/internal"
|
||||
|
@ -209,10 +210,14 @@ type CountingWriter struct {
|
|||
|
||||
func (w *CountingWriter) Write(p []byte) (n int, err error) {
|
||||
n, err = w.Writer.Write(p)
|
||||
w.Total += int64(n)
|
||||
atomic.AddInt64(&w.Total, int64(n))
|
||||
return
|
||||
}
|
||||
|
||||
func (w *CountingWriter) BytesWritten() int64 {
|
||||
return atomic.LoadInt64(&w.Total)
|
||||
}
|
||||
|
||||
// retentionAndShardFromPath will take the shard relative path and split it into the
|
||||
// retention policy name and shard ID. The first part of the path should be the database name.
|
||||
func DBRetentionAndShardFromPath(path string) (db, retention, shard string, err error) {
|
||||
|
|
Loading…
Reference in New Issue