xtdb

benny 2024-10-21T10:08:47.092159Z

xtdbv1: I've started a small project without an index-store and let xtdb rebuilt it on start up. Now the start-up and memory costs are getting annoying, so I wanted to add an index-store. I configured lmdb as per https://v1-docs.xtdb.com/storage/1.24.3/lmdb/, but no index appears. I've enabled :sync? and submitted some docs, and still nothing appears. I tried to close the xtdb resource and that never returns. (Never means 30min+) Is there a way to force the generation of an index or was it a mistake to start without an index-store and I should decant the old db into a new db?

refset 2024-10-21T10:54:55.904019Z

Hi @b minor clarification to make sure we're on the same page: • "without an index-store" - v1 always has an index-store, it's just that by default the index-store isn't durable because it's backed by an in-memory KV store (more or less just a sorted map) Can you share the configuration map you are passing to start-node? > I tried to close the xtdb resource and that never returns. (Never means 30min+) this doesn't sound right - are calling .close at the REPL? Which JVM/Clojure versions are you using?

benny 2024-10-21T11:00:11.108199Z

Yes, I meant without a durable index-store.

(let [dbname "development/data/db.sqlite"

                 index-dir "development/data/index"

                 node (xt/start-node

                       {:xtdb.jdbc/connection-pool {:dialect {:xtdb/module 'xtdb.jdbc.sqlite/->dialect}

                                                    :pool-opts {}

                                                    :db-spec {:dbname dbname}}

                        :xtdb/tx-log {:xtdb/module 'xtdb.jdbc/->tx-log

                                      :connection-pool :xtdb.jdbc/connection-pool}

                        :xtdb/document-store {:xtdb/module 'xtdb.jdbc/->document-store

                                              :connection-pool :xtdb.jdbc/connection-pool}

                        ;; for performance reasons, enable index store (not a golden store)

                        :xtdb/index-store {:kv-store {:xtdb-module 'xtdb.rocksdb/->kv-store

                                                      :db-dir (io/file index-dir)}}})]

             node)
clojure 1.11.1 and openjdk 17.0.4.1 (zulu)

benny 2024-10-21T11:00:42.003169Z

I'm calling (.close ...) interactively via nrepl in a (comment block)

benny 2024-10-21T11:01:06.022879Z

I went to lunch and came back and I got a java heap error, I guess after 30 mins that happens. 🙂

benny 2024-10-21T11:02:25.769499Z

Sorry about this, I switched to rocksdb for testing purposes to see if that changes things. But the behavior is the same as with lmdb. @taylor.jeremydavid

benny 2024-10-21T11:06:48.500649Z

and for completeness sake: Before I ran the program without any :index-store key and could persist and restart the program (but the first xt/sync took longer and longer)

👍 1
refset 2024-10-21T12:31:08.213919Z

ah, so we've not tested with Zulu/Azul before - I wonder whether that's the issue 🤔

refset 2024-10-21T12:31:23.305019Z

would it be a huge pain to try a different JDK?

benny 2024-10-21T12:33:27.741589Z

Not huge, but in the meantime I've tried a backup from when I had <30k tx and when I .close xtdb, it writes the index. So maybe the size of the index is also part of this. But I can try jdk21 or higher

refset 2024-10-21T12:35:19.033159Z

oh interesting - that shouldn't really be an issue, unless maybe you have an absolutely enormous individual transaction or something ...but I assume you're not storing video BLOBs or similar(?)

benny 2024-10-21T12:35:52.548029Z

nope, the size of the db is 1080 MB right now, it's 300k tx.

👍 1
refset 2024-10-21T12:36:50.457949Z

> I got a java heap error if you have a copy of any of the stracktrace, hprof etc. outputted it might be useful

benny 2024-10-21T12:47:51.263769Z

I've re-ran it and got another heap error: https://pastebin.com/wDxhLhaG

refset 2024-10-21T12:56:45.316389Z

thanks, that is useful - looks like something is preventing the node from being closed, but then the error message attempting to feed that back is blowing up https://github.com/xtdb/xtdb/blob/06132bc1fad63944d144d79a90053b05d78a41c8/core/src/xtdb/io.clj#L134

refset 2024-10-21T12:57:26.414199Z

are you calling open-db, open-q, open-entity-history or open-tx-log in your code?

benny 2024-10-21T12:58:54.027469Z

I've disabled everything but the db part, but I also enabled sqlite pragma like shared memory for performance, which could have the same effect?

benny 2024-10-21T12:59:05.642339Z

so right now there is no open-db, open-q, etc in the code

refset 2024-10-21T13:01:04.038849Z

what about any background writers to submit-tx are you disabling those before attempting the .close?

refset 2024-10-21T13:01:27.178539Z

(it's possible our integration with sqlite is the actual culprit)

benny 2024-10-21T13:02:44.203439Z

I'm merely bringing up the xtdb, sync it and wait until the index is built (`xt-latest-completed-tx`) and then I .close it. So everything in the system outside that part is currently disabled.

👍 1
refset 2024-10-21T13:05:27.240389Z

thanks for clarifying. Any joy trying a different JDK? Also, have you tried the same config/setup but with an empty database (just in case it's your specific data that's somehow causing the issue)?

refset 2024-10-21T13:07:19.556939Z

you could maybe also try monkey-patching that try-close function I linked above, see if there's a way to bypass the out-of-heap issue while printing

benny 2024-10-21T13:08:30.254579Z

the db from before with the 30K transactions is the same kind of data, just 400mb instead of the 1080mb right now (300K tx) - I've not yet tried another jdk. I'm right now trying to disable the journal_mode in sqlite because of the shm part.

👍 1
benny 2024-10-21T13:09:18.925919Z

why I think that is relevant should've said before: I'm on Windows which may be a different kind of beast when it comes to multiple processes working on the same data

💯 1
refset 2024-10-21T13:35:32.148719Z

ah yes, that's an important detail too, I think it's fair to say I think most people working with XT v1 have been using Linux (sorry!) 🙂

benny 2024-10-21T13:41:52.688719Z

I've updated to jdk21 (Eclipse Temerium) and also monkey patched try-close to not log c but rather just a generic string. It's still trying to .close right now and has been for over a few minutes. That usually is a bad sign.

😒 1
benny 2024-10-21T13:45:02.597989Z

I can try the migration on Linux later. I've intentionally chosen sqlite on Windows because a single file should work better than multiple files with ntfs. What an annoying system to work with, but that's the requirement at the moment. 😉

benny 2024-10-21T13:48:27.450099Z

different java heap space error: https://pastebin.com/078kWcMx

refset 2024-10-21T13:52:34.817589Z

interesting - begs the question...what is the memory config on this JVM? 🙂

benny 2024-10-21T13:53:20.502769Z

-Xss2m, -Xmx12G, but I've tried with up to -Xmx40G (but before I did the monkeypatching, jdk upgrade and disabling journal_mode)

benny 2024-10-21T13:55:41.191889Z

one last hail mary: I'm going with -Xmx40G on this physical 16GB system and see how far pagefiles get me.

benny 2024-10-21T14:07:14.965659Z

more like the first one: https://pastebin.com/v7SwgVXK

benny 2024-10-21T14:12:52.642119Z

I wasn't recording the memory consumption, but it didn't look like it was pressuring the system and swapping. Extreme pressure anyway, it does use the memory that is there... Hm.

refset 2024-10-21T14:21:11.216259Z

was that last pastebin with Rocks/LMDB configured? looks like it was struggling to serialise the in-memory KV store ("mem-kv")

benny 2024-10-21T14:21:35.817429Z

yeah

benny 2024-10-21T14:22:12.699329Z

I saw a github issue (https://github.com/xtdb/xtdb/issues/1644) that is ignores certain keys and now thinking back to the success with the 480mb, that also created a file called "memkv" under the given path

benny 2024-10-21T14:22:46.769669Z

so I reordered the index-store to be at the top

benny 2024-10-21T14:32:38.395599Z

maybe it's not something order specific but some NREP when using both jdbc and also a kv-store. But seeing that github issue also using jdbc and having options ignored is very similar.

benny 2024-10-21T14:49:51.111129Z

OK. That memkv thing really helped. Now I don't have to wait until OOM to figure out what's wrong, I can just check -> :index-store :kv-store type

benny 2024-10-21T14:50:14.059049Z

it's MemKv with the above configuration for some reason

refset 2024-10-21T15:03:14.556429Z

oh, how weird(!)

benny 2024-10-21T15:03:18.161309Z

Wow. @taylor.jeremydavid, I got it. I have a fricking typo.

benny 2024-10-21T15:03:31.737029Z

look at the config I posted, see if you can spot it 😉

refset 2024-10-21T15:03:43.429379Z

xtdb-module facepalm right?

benny 2024-10-21T15:03:52.440789Z

sorry for wasting your time

benny 2024-10-21T15:04:01.474779Z

damn, egg on face 3000 😄

benny 2024-10-21T15:04:07.514409Z

yes

refset 2024-10-21T15:04:10.860829Z

aha, no not at all, it's way too easy

refset 2024-10-21T15:04:55.497869Z

I guess some spec assertions or something can help with validation there.... "unexpected key" or whatever - sorry I couldn't help you sooner! I'm glad you persevered

benny 2024-10-21T15:09:23.888579Z

yeah, I'm in the middle of writing a blogpost how static typing would've saved me and how Clojure isn't ready for primetime. But the better blog post would be about humans and because of the late failure mode I just chased the wrong tunnel down. Anyway, thanks again for the journey. 😉

🙂 1
benny 2024-10-21T15:09:57.665499Z

now I'm on jdk21 at least, looking at the bright side of life

🤘 1
refset 2024-10-21T15:10:21.589969Z

yeah virtual threads are cool, we use them a lot in v2

🚀 1
kpassapk 2024-10-21T20:56:35.873389Z

In v2, what would be the recommended way to implement a uniqueness constraint?

jarohen 2024-10-22T08:30:11.426429Z

A natural primary key is probably the easiest, if the attribute(s) you're looking to make easiest are also guaranteed not to change for the lifetime of the entity. Otherwise, you could consider using ASSERT/`[:assert-{not-}exists ...]` to verify constraints on creation/update as required

🙏 1