You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@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.
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).
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?
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.
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.
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')
@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?
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){varparts=blob.count().div(1024).ceil();// ceil available in v2.1 releasereturnr.range(parts).map(function(part){returnblob.slice(part.mul(1024),part.add(1).mul(1024))});})
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.
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.
@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.
@usergit I don't know if this is what you're looking for but as far as I know there are two drivers that support a concept called ReGrid. ReGrid is analogous to Mongo DB's GridFS.
Activity
wojons commentedon Jul 3, 2014
@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.
mlucy commentedon Jul 4, 2014
Alright, here's my proposal:
metadataandchunkstable.system(or$system$) database, and you can access these tables to shard them or whatever by writingr.db('system').table('chunks'). (I prefer this one.)r.file_metadata()to get the metadata table orr.file_chunks()to get the chunks table.r.file_create(File.open(...))# creates a file with the same name as the local filer.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 referencingfile_namer.file(file_name).metadata()-- gets the metadata for a file.file_createtakes two optargsmetadata_tableandchunks_table, defaulting to the system metadata table and the system chunks table. All the other file commands take an optargmetadata_tabledefaulting to the system metadata table (the metadata says which chunks table to use).r.table('test').insert({name: ..., data: File.open(...)})file_createagain 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).r.file_cleanupwhich takes two optargsmetadata_tablesandchunks_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.)Possible Simplifications:
cleanup.When talking with @coffeemug, he suggested we use a name other than
.fileto make it clear it's a reference to a file (like maybe.file_handleor something).coffeemug commentedon Jul 7, 2014
There are a few things missing:
Also, I think we should consider exposing the file system via a namespace/object to make the API more accessible:
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?
srh commentedon Jul 7, 2014
This is completely underspecified.
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?
Do you know why tables are put in databases? Why would files be outside them?
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.
Well, what does this return?
What does this return?
What does this return?
What is the filename? For what table of files? What is the format of a file name?
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.
What is "our" metadata?
Then this is spec bloat, let's not waste our time thinking about this right now.
So... uploads are resumed from the beginning?
We let users silently overwrite files with the same name?
I don't feel like reading the whole issue to find where you specified it so copy that specification 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?
How would the metadata know about lost file chunks?
What do you mean, "writing"?
srh commentedon Jul 7, 2014
This spec doesn't describe the interface for reading to or writing from a file.
srh commentedon Jul 7, 2014
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.
AtnNn commentedon Jul 7, 2014
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 forr.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 evenr.cd('/foo/bar/').file_list(), and then perhapsr.cd('/foo').file_drop('bar')instead ofr.file_drop('/foo/bar')mlucy commentedon Jul 8, 2014
@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?
coffeemug commentedon Jul 9, 2014
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.
4 remaining items
marshall007 commentedon Jul 16, 2015
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.danielmewes commentedon Jul 16, 2015
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
slicelike @marshall007 suggested are the only options with RethinkDB.nkev commentedon Aug 17, 2015
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... :)
danielmewes commentedon Aug 18, 2015
@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.
usergit commentedon May 11, 2016
what's the status on this? any updates
bchavez commentedon May 11, 2016
@usergit I don't know if this is what you're looking for but as far as I know there are two drivers that support a concept called ReGrid. ReGrid is analogous to Mongo DB's GridFS.
C# Driver
https://github.com/bchavez/RethinkDb.Driver/wiki/ReGrid-File-Storage
NodeJS:
https://github.com/internalfx/regrid
ReGrid Specification:
https://github.com/internalfx/regrid-spec
nkev commentedon May 12, 2016
@bchavez ReGrid looks great. I like the "file system" notification events via change feeds. @danielmewes have you looked at ReGrid?
danielmewes commentedon May 16, 2016
@nkev Yes. I'm actually hoping to add support for ReGrid to our official drivers eventually.