Skip to content

Batch API: define semantics for partial failures #417

Closed

Description

@technoweenie

As it's currently designed, the batch api is very flexible. It receives a list of objects, and returns details on each object with either an upload or download link relation. This works great for the happy path, but not some potential failure cases:

  1. Client requests 5 objects to download. Server responds with all "download" relations for all 5 objects.
  2. Client requests 5 objects to upload. Server responds with either "download" (no need to re-upload existing objects) and "upload" relations for all 5 objects.
  3. Client requests 5 objects to download. Server responds with "download" relations for 4, but has no record of a fifth.
  4. Client requests 5 objects to upload, but without write access to the repository. Server responds with an empty array or "download" relations for existing objects.
  5. Client requests 5 objects to upload, but some or all of the objects fail some server side validation. Maybe some files are too large, the OID is the wrong format, the repo's usage quota is exceeded, etc.

For downloads: I'd like Git LFS to tolerate missing objects. It shouldn't bail out of a longer operation. It should download what it can, and write that some objects weren't found.

Uploads are trickier. There's no point even returning 200 if the user doesn't have write access to the repository. But currently there's no way for the server to know whether the client wants to upload or download the objects.

Proposal

I'd like to update the batch API to send and receive a bit more context. The client can send an operation key that specifies whether this request is for an upload or a download. Servers respond with an error property if it can't satisfy the operation for any given object. The error message will simply be written to STDERR without being parsed in any way by the client.

> POST https://git-lfs-server.com/objects/batch HTTP/1.1
> Accept: application/vnd.git-lfs+json
> Content-Type: application/vnd.git-lfs+json
> Authorization: Basic ... (if authentication is needed)
>
> {
>   "operation": "upload",
>   "objects": [
>     {
>       "oid": "1111111",
>       "size": 123
>     },
>     {
>       "oid": "2222222",
>       "size": 123
>     }
>   ]
> }
>
< HTTP/1.1 200 Accepted
< Content-Type: application/vnd.git-lfs+json
<
< {
<   "objects": [
<     {
<       "oid": "1111111",
<       "_links": {
<         "upload": {
<          "href": "https://some-upload.com",
<           "header": {
<             "Key": "value"
<           }
<         }
<       }
>     },
<     {
<       "oid": "2222222",
<       "error": "the file is too large"
>     }
<   ]
< }

This should work fine with all of the scenarios above:

  1. Client requests 5 objects to download. Server responds with all "download" relations for all 5 objects.
  2. Client requests 5 objects to upload. Server responds "upload" relations for objects that don't exist on the server yet. Client ignores the missing objects in the response, assuming they already exist on the server.
  3. Client requests 5 objects to download. Server responds with "download" relations for 4, but has no record of a fifth. Client downloads the 4 objects, and writes the fifth object's error to STDERR.
  4. Client requests 5 objects to upload, but without write access to the repository. Server responds 403.
  5. Client requests 5 objects to upload, but some or all of the objects fail some server side validation. Server responds with "upload" link relations for the valid objects, and error properties for the others. Client uploads what it can, but prints any error messages to STDERR.

Does the idea sound good? Am I missing anything?

Activity

  1. rubyist commented on Jun 18, 2015

    @rubyist
    Contributor

    👍 I think this is good, adding an operation makes total sense. It also leaves open possible extensions where we might really be asking about both downloads and uploads at once.

    For downloads: I'd like Git LFS to tolerate missing objects. It shouldn't bail out of a longer operation. It should download what it can, and write that some objects weren't found.

    For downloads we're still relying on smudge outside of the fetch command, so there is no longer operation, they're all independent. For the fetch command (and possible future post-checkout triggers), the current batch code does not bail out for any missing objects or errors. All errors are collected and displayed at the end. Same thing happens for uploads. That type of client behavior, though, is outside of the API spec, IMO, those are client implementation details.

  2. technoweenie commented on Jun 18, 2015

    @technoweenie
    ContributorAuthor

    Sounds like the only thing missing is checking for and printing the error string to STDERR or whatever. 👍

  3. michael-k commented on Jun 19, 2015

    @michael-k
    Contributor

    The error message will simply be written to STDERR without being parsed in any way by the client.

    We shouldn't forget the use case where a client (not necessarily this one) can do something about some errors. Therefore we shouldn't forget machine readability. Maybe in form of error codes.

    Very simple use case: client wants to link to an error specific help page.

  4. technoweenie commented on Jun 19, 2015

    @technoweenie
    ContributorAuthor

    I thought about that, but wasn't sure what clients could even do about server side issues. Though we could start with a simple "fatal" error code, and define specific ones (too_large?) as we think of them.

    How should it be represented in the JSON?

    // extra attribute
    {
      "oid": "2222222",
      "error_code": "fatal",
      "error": "the file is too large"
    }
    
    // error object
    {
      "oid": "2222222",
      "error": {
        "code": "fatal",
        "message": "the file is too large"
      }
    }

    I tend to prefer nested objects in JSON over multiple attributes with an error_ prefix. For comparison, here's how the GitHub API returns validation errors:

     HTTP/1.1 422 Unprocessable Entity
     Content-Length: 149
    
     {
       "message": "Validation Failed",
       "errors": [
         {
           "resource": "Issue",
           "field": "title",
           "code": "missing_field"
         }
       ]
     }
    
  5. rubyist commented on Jun 19, 2015

    @rubyist
    Contributor

    nested version has my 👍

  6. michael-k commented on Jun 20, 2015

    @michael-k
    Contributor

    nested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions