leveldb icon indicating copy to clipboard operation
leveldb copied to clipboard

[FR] readonly mode

Open mrx23dot opened this issue 2 years ago • 8 comments

Please add a new parameter during database opening to make it only readable, in case big/expensive database is used or database is on a CD/DVD.

This would also make it possible to open it within multiple processes (LOCK file wont be created). It would also help with power interruption caused corruption. eg https://groups.google.com/g/leveldb/c/YvszWNio2-Q

Access denied could be returned with write/compaction operation. I don't mind if leveldb dies because of content changed on disk.

mrx23dot avatar Jan 05 '23 15:01 mrx23dot

We provide further tooling around software that makes use of LevelDB. In our use case, one or more processes must be able to read the database but do not need to make any changes.

A readonly mode feature would be enormously helpful to us.

rikmarais avatar Feb 17 '23 16:02 rikmarais

JQUERY Duplicate of # #

36.1801800, -115.2293010``

Traveler82 avatar Feb 19 '23 03:02 Traveler82

The LOCK file would still be needed to prevent unintended write opens, or opens of an already locked db. Only it should use type F_RDLCK instead of F_WRLCK.

kanongil avatar Sep 14 '23 19:09 kanongil

Disk could be mounted as readonly, I'm happy if it fails with segfault if content changes on disk, since we know what we are doing.

mrx23dot avatar Sep 14 '23 20:09 mrx23dot

The LOCK file would still be needed to prevent unintended write opens, or opens of an already locked db. Only it should use type F_RDLCK instead of F_WRLCK.

Good idea, it would prevent the file from being written to by another process which could interfere with the read-only. I think this would allow apps to ship with read-only databases that could be installed in /usr/share for example without having to make a copy for every user or app-launch in order to access the static data.

kakaroto avatar Sep 14 '23 22:09 kakaroto

one way to achieve the open in read only mode is to write own Env object which provides copy on write operations, when new files are stored in memory (mem-env) and original files are just read,

ondra-novak avatar Nov 27 '23 21:11 ondra-novak

one way to achieve the open in read only mode is to write own Env object which provides copy on write operations, when new files are stored in memory (mem-env) and original files are just read,

Thanks for the suggestion. I just looked into the Environment class and what it's for, and I think it's a brilliant idea. Hopefully, if a write returns a failure, leveldb just rejects the Put, but stays consistent, if not, the copy-on-write idea would work quite well I think.

kakaroto avatar Nov 28 '23 03:11 kakaroto

Thanks for the suggestion. I just looked into the Environment class and what it's for, and I think it's a brilliant idea. Hopefully, if a write returns a failure, leveldb just rejects the Put, but stays consistent, if not, the copy-on-write idea would work quite well I think.

Unfortunately the database writes to files when opened. It performs maintenance, for example it reconstructs the log and compacts the manifest. This always writes several files before you can use the database. Therefore, the "COW" path is the only one that works.

I have tried this implementation. I recommend it as an inspiration, think of it as experimental code. Probably the biggest difficulty was in the implementation of the GetChildren function, where I have to simulate the state of the virtual directory, for example to keep track of deleted or renamed files.

https://github.com/ondra-novak/docdb/blob/main/src/docdb/readonly.h

ondra-novak avatar Nov 28 '23 06:11 ondra-novak