Skip to content

Commit

Permalink
Nil-safe topo.lock
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <[email protected]>
  • Loading branch information
frouioui committed Nov 8, 2024
1 parent e3dc767 commit 8797ec7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions go/vt/topo/locks.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package topo
import (
"context"
"encoding/json"
"errors"
"os"
"os/user"
"sync"
Expand Down Expand Up @@ -158,9 +159,6 @@ type iTopoLock interface {

// perform the topo lock operation
func (l *Lock) lock(ctx context.Context, ts *Server, lt iTopoLock, opts ...LockOption) (LockDescriptor, error) {
if err := ctx.Err(); err != nil {
return nil, err
}
for _, o := range opts {
o.apply(&l.Options)
}
Expand All @@ -178,6 +176,12 @@ func (l *Lock) lock(ctx context.Context, ts *Server, lt iTopoLock, opts ...LockO
return nil, err
}

if err := ctx.Err(); err != nil {
return nil, err
}
if ts.globalCell == nil {
return nil, errors.New("no global cell connection on the topo server")
}
switch l.Options.lockType {
case NonBlocking:
return ts.globalCell.TryLock(ctx, lt.Path(), j)
Expand Down

0 comments on commit 8797ec7

Please sign in to comment.