Is there any reason why Cap'n Proto couldn't be used encode/decode blobs that are stored in key/value stores, such as LevelDB or Berkeley DB?
Would FlatArrayMessageReader and messageToFlatArray be the best tools for this kind of job?
On Fri, Aug 1, 2014 at 6:56 PM, <emile.co...@gmail.com> wrote:
Is there any reason why Cap'n Proto couldn't be used encode/decode blobs that are stored in key/value stores, such as LevelDB or Berkeley DB?That should work great!Would FlatArrayMessageReader and messageToFlatArray be the best tools for this kind of job?messageToFlatArray() will require an extra copy, since message memory is allocated in multiple segments which would then have to be concatenated. If your DB API requires a flat array then there may be no way around this,
but if it can take an array of arrays, you may want to use MessageBuilder::getSegmentsForOutput() directly (and SegmentArrayMessageReader when reading back).I have been tempted to develop a simple Cap'n-Proto-based key-value store which just maps directly to the filesystem.
It feels silly to have these databases reinventing everything that the kernel VFS already does just fine.-Kenton
--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+...@googlegroups.com.
Visit this group at http://groups.google.com/group/capnproto.
messageToFlatArray() will require an extra copy, since message memory is allocated in multiple segments which would then have to be concatenated. If your DB API requires a flat array then there may be no way around this, but if it can take an array of arrays, you may want to use MessageBuilder::getSegmentsForOutput() directly (and SegmentArrayMessageReader when reading back).
I have been tempted to develop a simple Cap'n-Proto-based key-value store which just maps directly to the filesystem. It feels silly to have these databases reinventing everything that the kernel VFS already does just fine.
I could perhaps store the segments under different "sub keys", but that seems rather messy. I'm not concerned about performance, as the key/value store would only be used to persist app settings that are occasionally changed.
This remark made me consider using the filesystem as a simple key/value store. But the filesystem approach has no transactions or batch writes, so the DB could become inconsistent in the event of a crash or power failure.
To solve this you just need some sort of a journal or file naming scheme that allows you to tell, after reboot, what was going on at the time of the failure, and either complete or roll back the transaction. (Hmm, I wonder if it is possible to hook into the filesystem's own journal...)I would think that the biggest problem with using the filesystem is that most filesystems allocate space in 4k chunks, so small values may waste a lot of space. You could come up with schemes to deal with that, of course. Hmm, I wonder if it would make sense to encode small values into the targets of symlinks -- you should be able to get at least PATH_MAX * 7 bits in there, and PATH_MAX on Linux is 4096, so that's 3584 bytes, which is close enough that you can just switch to files for larger values.All that said, I'm no DB expert, so take what I say with a grain of salt. :)
--