mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-21 22:12:36 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3134e4112d | ||
|
|
e7fe274e17 |
@@ -61,11 +61,7 @@ func (lc *LockClient) NewShortLivedLock(key string, owner string) (lock *LiveLoc
|
||||
}
|
||||
|
||||
// StartLongLivedLock starts a goroutine to lock the key and returns immediately.
|
||||
func (lc *LockClient) StartLongLivedLock(key string, owner string, renewInterval time.Duration, onLockOwnerChange func(newLockOwner string)) (lock *LiveLock) {
|
||||
// Default to lock_manager.RenewInterval if zero duration is passed
|
||||
if renewInterval == 0 {
|
||||
renewInterval = lock_manager.RenewInterval
|
||||
}
|
||||
func (lc *LockClient) StartLongLivedLock(key string, owner string, onLockOwnerChange func(newLockOwner string), renewInterval time.Duration) (lock *LiveLock) {
|
||||
lock = &LiveLock{
|
||||
key: key,
|
||||
hostFiler: lc.seedFiler,
|
||||
@@ -76,6 +72,9 @@ func (lc *LockClient) StartLongLivedLock(key string, owner string, renewInterval
|
||||
lc: lc,
|
||||
renewInterval: renewInterval,
|
||||
}
|
||||
if lock.renewInterval == 0 {
|
||||
lock.renewInterval = lock_manager.RenewInterval
|
||||
}
|
||||
go func() {
|
||||
isLocked := false
|
||||
lockOwner := ""
|
||||
|
||||
@@ -140,10 +140,10 @@ func NewMessageBroker(option *MessageQueueBrokerOption, grpcDialOption grpc.Dial
|
||||
|
||||
newBrokerBalancerCh := make(chan string, 1)
|
||||
lockClient := cluster.NewLockClient(grpcDialOption, mqBroker.currentFiler)
|
||||
mqBroker.lockAsBalancer = lockClient.StartLongLivedLock(pub_balancer.LockBrokerBalancer, string(self), lock_manager.RenewInterval, func(newLockOwner string) {
|
||||
mqBroker.lockAsBalancer = lockClient.StartLongLivedLock(pub_balancer.LockBrokerBalancer, string(self), func(newLockOwner string) {
|
||||
glog.V(0).Infof("broker %s found balanacer %s", self, newLockOwner)
|
||||
newBrokerBalancerCh <- newLockOwner
|
||||
})
|
||||
}, lock_manager.RenewInterval)
|
||||
mqBroker.KeepConnectedToBrokerBalancer(newBrokerBalancerCh)
|
||||
}()
|
||||
|
||||
|
||||
@@ -180,8 +180,8 @@ func (cr *CoordinatorRegistry) startLeaderElection() {
|
||||
cr.leaderLock = cr.lockClient.StartLongLivedLock(
|
||||
GatewayLeaderLockKey,
|
||||
cr.gatewayAddress,
|
||||
lock_manager.RenewInterval,
|
||||
cr.onLeadershipChange,
|
||||
lock_manager.RenewInterval,
|
||||
)
|
||||
|
||||
// Wait for shutdown
|
||||
|
||||
@@ -60,9 +60,9 @@ func (s3a *S3ApiServer) startBucketSizeMetricsLoop(ctx context.Context) {
|
||||
owner := string(filer) + "-s3-metrics"
|
||||
|
||||
// Start long-lived lock - this S3 instance will only collect metrics when it holds the lock
|
||||
lock := lockClient.StartLongLivedLock(s3MetricsLockName, owner, lock_manager.RenewInterval, func(newLockOwner string) {
|
||||
lock := lockClient.StartLongLivedLock(s3MetricsLockName, owner, func(newLockOwner string) {
|
||||
glog.V(1).Infof("S3 bucket size metrics lock owner changed to: %s", newLockOwner)
|
||||
})
|
||||
}, lock_manager.RenewInterval)
|
||||
defer lock.Stop()
|
||||
|
||||
ticker := time.NewTicker(bucketSizeMetricsInterval)
|
||||
|
||||
Reference in New Issue
Block a user