Browse Source

fix: filer may crash by bucketLastActiveTsNs concurrency access. (#6350)

pull/6352/head
zouyixiong 1 week ago
committed by GitHub
parent
commit
d6f3e1970d
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 7
      weed/stats/metrics.go

7
weed/stats/metrics.go

@ -7,6 +7,7 @@ import (
"os" "os"
"strconv" "strconv"
"strings" "strings"
"sync"
"time" "time"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
@ -27,7 +28,9 @@ const (
) )
var readOnlyVolumeTypes = [4]string{IsReadOnly, NoWriteOrDelete, NoWriteCanDelete, IsDiskSpaceLow} var readOnlyVolumeTypes = [4]string{IsReadOnly, NoWriteOrDelete, NoWriteCanDelete, IsDiskSpaceLow}
var bucketLastActiveTsNs map[string]int64 = map[string]int64{} var bucketLastActiveTsNs map[string]int64 = map[string]int64{}
var bucketLastActiveLock sync.Mutex
var ( var (
Gather = prometheus.NewRegistry() Gather = prometheus.NewRegistry()
@ -409,7 +412,9 @@ func SourceName(port uint32) string {
} }
func RecordBucketActiveTime(bucket string) { func RecordBucketActiveTime(bucket string) {
bucketLastActiveLock.Lock()
bucketLastActiveTsNs[bucket] = time.Now().UnixNano() bucketLastActiveTsNs[bucket] = time.Now().UnixNano()
bucketLastActiveLock.Unlock()
} }
func DeleteCollectionMetrics(collection string) { func DeleteCollectionMetrics(collection string) {
@ -429,6 +434,7 @@ func bucketMetricTTLControl() {
for { for {
now := time.Now().UnixNano() now := time.Now().UnixNano()
bucketLastActiveLock.Lock()
for bucket, ts := range bucketLastActiveTsNs { for bucket, ts := range bucketLastActiveTsNs {
if (now - ts) > ttlNs { if (now - ts) > ttlNs {
delete(bucketLastActiveTsNs, bucket) delete(bucketLastActiveTsNs, bucket)
@ -441,6 +447,7 @@ func bucketMetricTTLControl() {
} }
} }
bucketLastActiveLock.Unlock()
time.Sleep(bucketAtiveTTL) time.Sleep(bucketAtiveTTL)
} }

Loading…
Cancel
Save