Skip to content

ReQL: distributed file system #2647

Open

Description

@coffeemug

#137 has largely been about debating different distributed file system designs, so I'd like to open a new issue to discuss a specific design:

  • Users need to be able to shard individual files, which means we'll have to build this feature on top of tables.
  • Users need to be able to insert, list, and delete files as first class objects.
  • We should try and allow linking files from documents and to be able to specify and query user-defined metadata.

@mlucy -- could you write up a proposal?

Activity

  1. added this to the 1.14 milestone on Jul 3, 2014
  2. wojons commented on Jul 3, 2014

    @wojons
    Contributor

    @coffeemug we could write a template version of this using a fuse file system its a least a decent way to try to prototype something like this? If you want i been planing on writing a Fuse file system using rethinkdb.

  3. mlucy commented on Jul 4, 2014

    @mlucy
    Member

    Alright, here's my proposal:

    • We have a special metadata and chunks table.
      • Option 1: We have a special system (or $system$) database, and you can access these tables to shard them or whatever by writing r.db('system').table('chunks'). (I prefer this one.)
      • Option 2: We don't expose these as normal tables, and you can write r.file_metadata() to get the metadata table or r.file_chunks() to get the chunks table.
    • We treat files as first-class objects. We offer the following commands:
      • r.file_create(File.open(...)) # creates a file with the same name as the local file
      • r.file_create(File.open(...), name: ...)
      • r.file_list()
      • r.file_status(file_name)
      • r.file_drop(file_name)
      • r.file(file_name) -- produces a file pseudotype referencing file_name
      • r.file(file_name).metadata() -- gets the metadata for a file.
        • OPTIONAL: We can make this return a single row selection on the metadata if we want to let users update it here.
    • file_create takes two optargs metadata_table and chunks_table, defaulting to the system metadata table and the system chunks table. All the other file commands take an optarg metadata_table defaulting to the system metadata table (the metadata says which chunks table to use).
      • Note that this is our metadata, not user metadata.
    • OPTIONAL: Optionally, we can support r.table('test').insert({name: ..., data: File.open(...)})
      • This will create the file with a UUID as its name.
      • If the user is interrupted while uploading it (see below), they can get the uuid out of the metadata to resume the upload.
    • Resuming uploads -- we will support resuming uploads by just calling file_create again with the same name and file. (If the state of the metadata is INCOMPLETE, we will just resume uploading chunks. We can also optionally include a hash of the file in the metadata to make sure people don't resume with the wrong one).
    • Deletes -- deletes will be handled the way I specified in Support binary data type #137, including the ability to resume deleting.
    • Cleanup -- to account for loss of consistency in certain cluster scenarios (once again, see Support binary data type #137), we will offer a command r.file_cleanup which takes two optargs metadata_tables and chunks_tables. It will remove any rows in the chunks tables that do not correspond to valid file chunk based on the information in the metadata tables. (This is a tiny bit tricky, but we can be conservative here.)
    • Lost file chunks -- if some chunks of a file are lost, we have a state in the metadata for that, and the user has to resume uploading to replace the lost chunks.
    • File pseudotype -- the file pseudotype will turn into a native type in the clients that supports seeking and reading like a normal file. Optionally, we can also support writing.

    Possible Simplifications:

    • We can drop all the optional components.
    • We can skip the part where we let users specify different metadata and chunks tables for the first version. (Or we can just drop the metadata table: specifying a custom chunks table is pretty easy. Dropping custom metadata tables also makes cleanup way easier.)
    • We can skip resumable deletes -- if a delete fails in the middle, you have to call cleanup.

    When talking with @coffeemug, he suggested we use a name other than .file to make it clear it's a reference to a file (like maybe .file_handle or something).

  4. coffeemug commented on Jul 7, 2014

    @coffeemug
    ContributorAuthor

    There are a few things missing:

    • Commands available on the pseudotype. For example, reading from the middle of a file, writing to the middle of a file, appending to a file. We also need those for streaming to work on the client.
    • How do I query files by metadata?
    • We should allow the user to optionally set chunk size on a file.

    Also, I think we should consider exposing the file system via a namespace/object to make the API more accessible:

    fs = RethinkFS(conn, db=media, table=videos)
    file = fs.open('name', 'w+') # note, no .run()
    file.write(r.binary(...))

    The whole thing is still wonky. What if we settled the API for everything else so everyone can start working on the next batch of features (I think we're basically there and can do it tomorrow), and then come back to this proposal when #2612 is done?

  5. srh commented on Jul 7, 2014

    @srh
    Contributor

    This is completely underspecified.

    We have a special metadata and chunks table.

    What does the metadata table contain and what does the chunks table contain?

    How big can a chunk be? How small can a chunk be? Are the chunks of fixed size? (We don't want chunks to be too big, and we don't want there to be too many chunks for a big file, because then the metadata will be too big.)

    What is the actual algorithm for uploading a file chunk and updating
    the metadata?

    What alternative choices for representing files (in chunks) have you
    considered?

    Option 1: We have a special system (or $system$) database, and you can access these tables to shard them or whatever by writing r.db('system').table('chunks'). (I prefer this one.)

    Do you know why tables are put in databases? Why would files be outside them?

    r.file_create(File.open(...)) # creates a file with the same name as the local file

    Why would we want to use the same name as the local file? Why do we want filenames in the first place? How are we even going to access the file name? (This is completely ridiculous.)

    Who is going to be creating a file from some local system file anyway?

    HTTP file uploads can come with browser-supplied names. We certainly don't want to blindly pull the filename from the browser-supplied name.

    r.file_list()

    Well, what does this return?

    r.file_status(file_name)

    What does this return?

    r.file_drop(file_name)

    What does this return?

    r.file(file_name) -- produces a file pseudotype referencing file_name

    What is the filename? For what table of files? What is the format of a file name?

    r.file(file_name).metadata() -- gets the metadata for a file.

    This is backwards. This is like saying
    r.expr(key).get_from_table(table_name). You can't get the metadata
    from a file reference. That's a query.

    file_create takes two optargs metadata_table and chunks_table, defaulting to the system metadata table and the system chunks table. All the other file commands take an optarg metadata_table defaulting to the system metadata table (the metadata says which chunks table to use).

    Note that this is our metadata, not user metadata.

    What is "our" metadata?

    OPTIONAL: Optionally, we can support r.table('test').insert({name: ..., data: File.open(...)})

    Then this is spec bloat, let's not waste our time thinking about this right now.

    Resuming uploads -- we will support resuming uploads by just calling file_create again with the same name and file. (If the state of the metadata is INCOMPLETE, we will just resume uploading chunks. We can also optionally include a hash of the file in the metadata to make sure people don't resume with the wrong one).

    So... uploads are resumed from the beginning?

    We let users silently overwrite files with the same name?

    Deletes -- deletes will be handled the way I specified in #137, including the ability to resume deleting.

    I don't feel like reading the whole issue to find where you specified it so copy that specification here.

    Cleanup -- to account for loss of consistency in certain cluster scenarios (once again, see #137), we will offer a command r.file_cleanup which takes two optargs metadata_tables and chunks_tables. It will remove any rows in the chunks tables that do not correspond to valid file chunk based on the information in the metadata tables. (This is a tiny bit tricky, but we can be conservative here.)

    What if a different metadata table refers to the chunk in the chunks table? Specify why that's not a problem.

    What if somebody's in the process of uploading a file to these tables? What prevents us from messing that up?

    Lost file chunks -- if some chunks of a file are lost, we have a state in the metadata for that, and the user has to resume uploading to replace the lost chunks.

    How would the metadata know about lost file chunks?

    File pseudotype -- the file pseudotype will turn into a native type in the clients that supports seeking and reading like a normal file. Optionally, we can also support writing.

    What do you mean, "writing"?

  6. srh commented on Jul 7, 2014

    @srh
    Contributor

    This spec doesn't describe the interface for reading to or writing from a file.

  7. srh commented on Jul 7, 2014

    @srh
    Contributor

    Also, chunk tables are something that we usually do not want to naively reshard. Resharding of chunk tables should entail adding a new empty shard, with no need for any data to be moved around for the sake of rebalancing.

  8. AtnNn commented on Jul 7, 2014

    @AtnNn
    Member

    It would be a bad idea to have a unique default set of files per cluster. Perhaps there could be a different set of files for each database, and r.file* would simply be a shortcut for r.db('test').file* if 'test' is the current default database.

    It would be very nice to also be able to do r.file_list('/foo/bar'), r.file_list().between('/foo/bar/', '/foo/bar0', index='name') or even r.cd('/foo/bar/').file_list(), and then perhaps r.cd('/foo').file_drop('bar') instead of r.file_drop('/foo/bar')

  9. mlucy commented on Jul 8, 2014

    @mlucy
    Member

    @coffeemug -- this has missed the window for ReQL discussion pretty thoroughly at this point. I don't think we're close to being able to mark it settled, and I don't want to extend the discussion period another week since everything else is in a good place.

    Since everyone has work to do, could we move this to polish and come back to it?

  10. modified the milestones: , 1.14 on Jul 9, 2014
  11. coffeemug commented on Jul 9, 2014

    @coffeemug
    ContributorAuthor

    Yes, done. I'll do some work to find out if sharding individual files is as important in people's minds as I think it is and report here.

  12. removed this from the milestone on Aug 13, 2014
  13. 4 remaining items

  14. removed this from the milestone on Sep 4, 2014
  15. modified the milestones: subsequent, on Oct 16, 2014
  16. marshall007 commented on Jul 16, 2015

    @marshall007
    Contributor

    I suppose this is achievable already, now by storing data in chunks in separate documents.

    You could also use .slice() to chunk the response and then convert the cursor to a stream on the client-side. You'll still probably run into the query size limit trying to persist large files, though. It would definitely be nice to just be able to query any binary field in a document as a stream.

    r.http('http://httpbin.org/image/png')
      .do(function (blob) {
        var parts = blob.count().div(1024).ceil(); // ceil available in v2.1 release
        return r.range(parts).map(function (part) {
          return blob.slice(part.mul(1024), part.add(1).mul(1024))
        });
      })
  17. danielmewes commented on Jul 16, 2015

    @danielmewes
    Member

    I agree that large documents should definitely be streamable once we add proper support for them.

    At the moment I think either manually splitting them up into smaller chunks/documents or using slice like @marshall007 suggested are the only options with RethinkDB.

  18. nkev commented on Aug 17, 2015

    @nkev

    To keep it simple, how about just storing the files where they are most at home, in the OS file system but storing meta-data for them in a RethinkDB system table so that from ReQL it feels like they are inside the database?

    For replication, a separate file watcher micro-process launched by RethinkDB on start-up could perhaps keep the metadata in sync as well as copy new/modified files across to peer servers (maybe with compression, except for image, audio and video file types).

    It shouldn't be too hard to find an existing library to efficiently sync file changes between servers. The rsync protocol comes to mind.

    Sorry, just thinking out loud... :)

  19. danielmewes commented on Aug 18, 2015

    @danielmewes
    Member

    @nkev my feeling is that building a completely decoupled system for file synchronization might add more edge cases that it solves, but I haven't thought it through completely yet. We'll keep that option in mind. I guess it would allow us to take some shortcuts.

  20. usergit commented on May 11, 2016

    @usergit

    what's the status on this? any updates

  21. bchavez commented on May 11, 2016

    @bchavez
    Contributor
  22. nkev commented on May 12, 2016

    @nkev

    @bchavez ReGrid looks great. I like the "file system" notification events via change feeds. @danielmewes have you looked at ReGrid?

  23. danielmewes commented on May 16, 2016

    @danielmewes
    Member

    @nkev Yes. I'm actually hoping to add support for ReGrid to our official drivers eventually.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions