سؤال

I am looking to offer some free hosting for CouchDB. The authorization part is fairly straightforward (user has access to 1 database) but I was wondering if there is any simple way to assign a space quota for that database/user.

هل كانت مفيدة؟

المحلول

CouchDB does not support quotas natively, so you may need something custom.

You can enforce it yourself, either with a tiny fork of CouchDB or with your related hosting software, and use the usage information returned by CouchDB. Since version 1.2, CouchDB indicates not only the disk usage, but "data" size, not counting metadata and old data.

نصائح أخرى

I solved this by pairing together Linux inotify support combined with a read-only couchdb validation function.

This way I made it work is like this:

  1. I wrote an inotify program (python, in my case) with monitors all accesses to each file in /var/lib/couchdb/foo.couch. Each access is batched together up until a window of time is reached.

  2. When the window is reached, I query couch's "info" API on the DB itself to ask what is the current size of the database.

  3. If the database is within a quota, I install a validation function design document against the database in question that blocks new writes and thus honoring the quota. (Assigning quotas themselves is an exercise for the reader).

NOTE: CouchDB databases only shrink when both a) an attachment is deleted and b) you remember to compact the DB. Otherwise, without both of those, the size of the database will only continue to grow as new documents are added. If you get to the point where you have a sufficient number of deletes, but the user has still exhausted their quota, you really have no choice but to replicate to a new DB and destroy the old one.

  1. If the database file DOES shrink (as describe above), then remove the validation function and allow new writes to the DB.

But, at the very least, the above solutions gives you the confidence that you'll never run out of disk space until you take action at a later period of time.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top