"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
accounting: add AccountReadN for use in cluster
Nick Craig-Wood05d54a95b865
diff --git a/fs/accounting/accounting.go b/fs/accounting/accounting.goindex fed338586..d1110c32f 100644--- a/fs/accounting/accounting.go+++ b/fs/accounting/accounting.go@@ -82,7 +82,7 @@ type accountValues struct {max int64 // if >=0 the max number of bytes to transferstart time.Time // Start time of first readlpTime time.Time // Time of last average measurement- lpBytes int // Number of bytes read since last measurement+ lpBytes int64 // Number of bytes read since last measurementavg float64 // Moving average of last few measurements in Byte/s}@@ -344,15 +344,20 @@ func (acc *Account) limitPerFileBandwidth(n int) {}}-// Account the read and limit bandwidth-func (acc *Account) accountRead(n int) {+// Account the read+func (acc *Account) accountReadN(n int64) {// Update Statsacc.values.mu.Lock()acc.values.lpBytes += n- acc.values.bytes += int64(n)+ acc.values.bytes += nacc.values.mu.Unlock()- acc.stats.Bytes(int64(n))+ acc.stats.Bytes(n)+}++// Account the read and limit bandwidth+func (acc *Account) accountRead(n int) {+ acc.accountReadN(int64(n))TokenBucket.LimitBandwidth(TokenBucketSlotAccounting, n)acc.limitPerFileBandwidth(n)@@ -460,6 +465,15 @@ func (acc *Account) AccountRead(n int) (err error) {return err}+// AccountReadN account having read n bytes+//+// Does not obey any transfer limits, bandwidth limits, etc.+func (acc *Account) AccountReadN(n int64) {+ acc.mu.Lock()+ defer acc.mu.Unlock()+ acc.accountReadN(n)+}+// Close the objectfunc (acc *Account) Close() error {acc.mu.Lock()diff --git a/fs/accounting/accounting_test.go b/fs/accounting/accounting_test.goindex 4b3a876df..02dc0f1a4 100644--- a/fs/accounting/accounting_test.go+++ b/fs/accounting/accounting_test.go@@ -100,7 +100,7 @@ func TestAccountRead(t *testing.T) {assert.True(t, acc.values.start.IsZero())acc.values.mu.Lock()- assert.Equal(t, 0, acc.values.lpBytes)+ assert.Equal(t, int64(0), acc.values.lpBytes)assert.Equal(t, int64(0), acc.values.bytes)acc.values.mu.Unlock()assert.Equal(t, int64(0), stats.bytes)@@ -113,7 +113,7 @@ func TestAccountRead(t *testing.T) {assert.False(t, acc.values.start.IsZero())acc.values.mu.Lock()- assert.Equal(t, 2, acc.values.lpBytes)+ assert.Equal(t, int64(2), acc.values.lpBytes)assert.Equal(t, int64(2), acc.values.bytes)acc.values.mu.Unlock()assert.Equal(t, int64(2), stats.bytes)@@ -145,7 +145,7 @@ func testAccountWriteTo(t *testing.T, withBuffer bool) {assert.True(t, acc.values.start.IsZero())acc.values.mu.Lock()- assert.Equal(t, 0, acc.values.lpBytes)+ assert.Equal(t, int64(0), acc.values.lpBytes)assert.Equal(t, int64(0), acc.values.bytes)acc.values.mu.Unlock()assert.Equal(t, int64(0), stats.bytes)@@ -159,7 +159,7 @@ func testAccountWriteTo(t *testing.T, withBuffer bool) {assert.False(t, acc.values.start.IsZero())acc.values.mu.Lock()- assert.Equal(t, len(buf), acc.values.lpBytes)+ assert.Equal(t, int64(len(buf)), acc.values.lpBytes)assert.Equal(t, int64(len(buf)), acc.values.bytes)acc.values.mu.Unlock()assert.Equal(t, int64(len(buf)), stats.bytes)