stagas
stagas2w ago

Local KV not saving data

I find very often that local KV data are not persisted when the server restarts, not all the time but it happens. Is there a way to force KV to write-to-disk always?
5 Replies
tobsch
tobsch2w ago
Can you share how you initialize the database? Deno.openKv(":memory:"); would be lost after a server restart. Another thing I can think of: If you write to a location that is inside of a Docker container or devcontainer then it is important that you mount that location somehwhere on your host system. Otherwise it will be lost when the container is rebuilt.
stagas
stagasOP2w ago
it's not memory i do: await Deno.openKv(Deno.env.get('KV_PATH')) where KV_PATH=./storage/kv.sqlite3 so it's a local path
tobsch
tobsch2w ago
I would check next if the file shows up in the right place and you can maybe connect a database viewer to see what's in the sqlite database. Then maybe observe a bit how the entries change while you use your app. Maybe there is some accidental reset or overwrite?
stagas
stagasOP2w ago
most of the time it's working, so it's a bug, writes are not being flushed out to the disk on every write
tobsch
tobsch2w ago
The only open bug about this I could find was https://github.com/denoland/denokv/issues/101 If you can build a reproducible example you could open an issue?
GitHub
What are the circumstances under which data loss is possible? · Is...
From the docs on the latest KV release: Deno KV is currently experimental and subject to change. While we do our best to ensure data durability, data loss is possible, especially around Deno update...

Did you find this page helpful?