Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

make second lock instant

Chris Lu842e3301ee3b
diff --git a/weed/server/master_grpc_server_admin.go b/weed/server/master_grpc_server_admin.go
index 260681e40d..8cc04f5755 100644
--- a/weed/server/master_grpc_server_admin.go
+++ b/weed/server/master_grpc_server_admin.go
@@ -65,7 +65,7 @@ const (
func (ms *MasterServer) LeaseAdminToken(ctx context.Context, req *master_pb.LeaseAdminTokenRequest) (*master_pb.LeaseAdminTokenResponse, error) {
resp := &master_pb.LeaseAdminTokenResponse{}
- if ms.adminAccessLockTime.Add(LockDuration).After(time.Now()) {
+ if ms.adminAccessSecret != 0 && ms.adminAccessLockTime.Add(LockDuration).After(time.Now()) {
if req.PreviousToken != 0 && ms.isValidToken(time.Unix(0, req.PreviousLockTime), req.PreviousToken) {
// for renew
ts, token := ms.generateToken()
diff --git a/weed/shell/exclusive_locker.go b/weed/shell/exclusive_locker.go
index 38f5caace2..f4938d3e63 100644
--- a/weed/shell/exclusive_locker.go
+++ b/weed/shell/exclusive_locker.go
@@ -13,6 +13,7 @@ import (
const (
RenewInteval = 4 * time.Second
SafeRenewInteval = 3 * time.Second
+ InitLockInteval = 1 * time.Second
)
type ExclusiveLocker struct {
@@ -40,17 +41,15 @@ func (l *ExclusiveLocker) RequestLock() {
// retry to get the lease
for {
if err := l.masterClient.WithClient(func(client master_pb.SeaweedClient) error {
- resp, err := client.LeaseAdminToken(context.Background(), &master_pb.LeaseAdminTokenRequest{
- PreviousToken: atomic.LoadInt64(&l.token),
- PreviousLockTime: atomic.LoadInt64(&l.lockTsNs),
- })
+ resp, err := client.LeaseAdminToken(context.Background(), &master_pb.LeaseAdminTokenRequest{})
if err == nil {
atomic.StoreInt64(&l.token, resp.Token)
atomic.StoreInt64(&l.lockTsNs, resp.LockTsNs)
}
return err
}); err != nil {
- time.Sleep(RenewInteval)
+ // println("leasing problem", err.Error())
+ time.Sleep(InitLockInteval)
} else {
break
}
@@ -93,4 +92,6 @@ func (l *ExclusiveLocker) ReleaseLock() {
})
return nil
})
+ atomic.StoreInt64(&l.token, 0)
+ atomic.StoreInt64(&l.lockTsNs, 0)
}