Skip to content

Commit

Permalink
Revert "move to compare-and-swap node hbs"
Browse files Browse the repository at this point in the history
revert compare-and-swap node hbs
  • Loading branch information
fspmarshall committed Oct 11, 2022
1 parent 7f8cf4c commit 9150afe
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions lib/services/local/presence.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,37 +248,19 @@ func (s *PresenceService) UpsertNode(ctx context.Context, server types.Server) (
if n := server.GetNamespace(); n != apidefaults.Namespace {
return nil, trace.BadParameter("cannot place node in namespace %q, custom namespaces are deprecated", n)
}

value, err := services.MarshalServer(server)
if err != nil {
return nil, trace.Wrap(err)
}

key := backend.Key(nodesPrefix, server.GetNamespace(), server.GetName())

item := backend.Item{
Key: key,
lease, err := s.Put(ctx, backend.Item{
Key: backend.Key(nodesPrefix, server.GetNamespace(), server.GetName()),
Value: value,
Expires: server.Expiry(),
ID: server.GetResourceID(),
}

prevItem, err := s.Get(ctx, key)
if err != nil && !trace.IsNotFound(err) {
return nil, trace.Wrap(err)
}

var lease *backend.Lease
if err == nil {
lease, err = s.CompareAndSwap(ctx, *prevItem, item)
} else {
lease, err = s.Create(ctx, item)
}

})
if err != nil {
return nil, trace.Wrap(err)
}

if server.Expiry().IsZero() {
return &types.KeepAlive{}, nil
}
Expand Down

0 comments on commit 9150afe

Please sign in to comment.