Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can LevelDB snapshots survive a close of the database?

I'm wondering if the 'snapshot' facility of the LevelDB library can create a snapshot reference that could be saved even after a close of the open database object (and thus reused on a subsequent open).

I suspect not, which leads to a followup: is there a good/recommended way to make a consistent backup of the database as of a snapshot-instant, ideally even while other activity continues? (That is, short of iterating the entire snapshot keyrange via the API?)

(Essentially I'm looking for something analogous to saving aside the append-only JDB log files of BerkeleyDB-JE up through a certain checkpointed place.)

like image 927
gojomo Avatar asked Jan 17 '12 07:01

gojomo


2 Answers

A good approach would be to close the DB, then hard link all the sst files (cp -l) and copy all the non-sst files. This way you only actually copy a small amount of data (size of your log, 4MB by default). Then you can open the DB again.

You do have to block while this happens, but hopefully it should be quick.

like image 84
carrino Avatar answered Sep 28 '22 08:09

carrino


I suspect not, which leads to a followup: is there a good/recommended way to make a consistent backup of the database as of a snapshot-instant, ideally even while other activity continues? (That is, short of iterating the entire snapshot keyrange via the API?)

I haven't seen anything in leveldb that would allow you to save the snapshot, aside from doing what you don't really want to do: create a new leveldb instance, iterate over the entire current snapshot key range and write it into the new leveldb instance. Does your situation prevent you from doing that?

like image 45
Kiril Avatar answered Sep 28 '22 10:09

Kiril