datalevin

rafd 2024-09-10T17:00:49.526769Z

I'm encountering occasional db corruption(?) in my production deploy set up, likely due to something I'm doing wrong. I would like some advice. How my deploy works: • v0 clojure application running, with (d/get-conn ...) store to an atom, with continuous updates to the db • v1 clojure application started, also with (d/get-conn ...)` , (attempts to) start reading/writing to db • v0 killed soon after Questions: • Does datalevin need a clean shutdown? (ie. add a shutdown hook to close the connection?) • If a second clojure process connects, should I expect it to error (because of lock files)? Or, will it just connect, but, cause problems? ◦ If I use an out-of-process version of datalevin, will that solve things?

rafd 2024-09-18T17:50:29.275789Z

As an update, I think the issue may have been due to schema changes with insufficient migrations (ex. changing the type of a field). Last several deploys without schema changes have been fine.

Huahai 2024-09-10T23:14:12.007049Z

I wouldn’t expect the use you described to be problematic, though we don’t currently test for such cases: multiple processes accessing the db on and off. We probably should. However, if you could isolate a reproducible case, that would be great. Or write such tests, even better. PR welcome.

Huahai 2024-09-10T23:20:38.070079Z

For the time being though, you can always cleanly close the connection before kill the app.

Huahai 2024-09-10T23:22:55.726539Z

So that you know all txs actually persisted prior to the killing

Huahai 2024-09-10T23:27:29.851579Z

Prior to 0.9, abrupt killing may corrupt the db, post 0.9, corruption is avoided, but the last tx may be lost when app is killed, resulting in inconsistency if another app is concurrently accessing it. So advice is to close the connection before killing.

Huahai 2024-09-10T23:28:38.565039Z

Of course, we can change the default setting to the safest write option.

Huahai 2024-09-10T23:29:31.725599Z

Maybe we should 😀

Huahai 2024-09-10T23:32:40.753659Z

We already have jvm shutdown hooks to close db, but it may not get called if you kill jvm abruptly, also depending on you os

rafd 2024-09-11T04:50:23.830249Z

So, as far as you know, what I'm doing should be ok. I'll try to dig into it further when/if it happens again. I just didn't want to isolate it if it's not a supported use case. Thanks for the replies.

Huahai 2024-09-11T04:52:37.298209Z

Yes, your use case is what we intend to support.