Replace lockfile with reference lock
Updates content service to handle lock errors and return them to the client. The client remote handler has been updated to retry when a resource is locked until the resource is unlocked or the expected resource exists. Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
@@ -13,6 +13,8 @@ func rewriteGRPCError(err error) error {
|
||||
return content.ErrExists
|
||||
case codes.NotFound:
|
||||
return content.ErrNotFound
|
||||
case codes.Unavailable:
|
||||
return content.ErrLocked
|
||||
}
|
||||
|
||||
return err
|
||||
@@ -24,6 +26,8 @@ func serverErrorToGRPC(err error, id string) error {
|
||||
return grpc.Errorf(codes.NotFound, "%v: not found", id)
|
||||
case content.IsExists(err):
|
||||
return grpc.Errorf(codes.AlreadyExists, "%v: exists", id)
|
||||
case content.IsLocked(err):
|
||||
return grpc.Errorf(codes.Unavailable, "%v: locked", id)
|
||||
}
|
||||
|
||||
return err
|
||||
|
||||
@@ -275,7 +275,7 @@ func (s *Service) Write(session api.Content_WriteServer) (err error) {
|
||||
// this action locks the writer for the session.
|
||||
wr, err := s.store.Writer(ctx, ref, total, expected)
|
||||
if err != nil {
|
||||
return err
|
||||
return serverErrorToGRPC(err, ref)
|
||||
}
|
||||
defer wr.Close()
|
||||
|
||||
@@ -283,7 +283,7 @@ func (s *Service) Write(session api.Content_WriteServer) (err error) {
|
||||
msg.Action = req.Action
|
||||
ws, err := wr.Status()
|
||||
if err != nil {
|
||||
return err
|
||||
return serverErrorToGRPC(err, ref)
|
||||
}
|
||||
|
||||
msg.Offset = ws.Offset // always set the offset.
|
||||
|
||||
Reference in New Issue
Block a user