Skip to content

Instantly share code, notes, and snippets.

@prashanthpai
Last active July 10, 2017 03:47
Show Gist options
  • Save prashanthpai/018eb01dc261ddd7d5fa to your computer and use it in GitHub Desktop.
Save prashanthpai/018eb01dc261ddd7d5fa to your computer and use it in GitHub Desktop.

DiskFile API call flow for different requests

GET

disk_file = self.get_diskfile(...)
with disk_file.open():
    metadata = disk_file.get_metadata()
    response = Response(app_iter=disk_file.reader, ...)

POST

disk_file = self.get_diskfile(...)
orig_metadata = disk_file.read_metadata()
disk_file.write_metadata(metadata)

PUT

disk_file = self.get_diskfile(...)
orig_metadata = disk_file.read_metadata()
with disk_file.create(size=fsize) as writer:
    writer.write(chunk)
    writer.put(metadata)
    writer.commit(request.timestamp)

HEAD

disk_file = self.get_diskfile(...)
orig_metadata = disk_file.read_metadata()

DELETE

disk_file = self.get_diskfile(...)
orig_metadata = disk_file.read_metadata()
disk_file.delete(req_timestamp)

As one can note from above flow, the processing of only GET request actually needs to open the file. All other requests only ask for metadata by calling disk_file.read_metadata(). The problem here is, internally disk_file.read_metadata() calls disk_file.open() which results in the file being opened (optionally read if etag is stale) and closed. DiskFile implementations are free to implement disk_file.read_metadata() in any way it chooses to.

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