Fork me on GitHub
#datalevin
<
2022-03-23
>
fs4206:03:39

Not sure how to work the api with a reference to db (instead of conn):

(d/with-conn [conn "/pbdb"]
    (assert (d/db? (d/db conn)))
    ;(pp/pprint (d/stat conn))
    ;(d/copy (d/db conn) "/pbdb-backup")
    ;(d/copy conn "/pbdb-backup")
both the stat and copy functions seem to work on a "db" instance, but not sure how to concoct a db from a connection or a directory-path to the db-files... Error message in stack trace not too helpful: "No implementation of method: :copy of protocol: #'datalevin.lmdb/ILMDB found for class: datalevin.db.DB", :at [clojure.core$cacheprotocol_fn invokeStatic "core_deftype.clj" 583]}],

Huahai15:03:09

copy takes a key-value db, not a datalog db

Huahai15:03:31

the error message is very clear on that

Huahai15:03:44

to get a LMDB instance of the datalog db, you can try (.-lmdb (.-store db))

Huahai16:03:09

I expect people to use dtlv command line tool to do database backup, so the API is not really designed for people to do this programmatically. It’s doable, but not as convenient as it could be.

Huahai16:03:00

i can update the doc-string to make it clear that copy expect a key-value db.

Huahai16:03:06

actually, I will do better, I will release a version to allow datalog db to be copied programmatically easily, just like the code you tried.

fs4217:03:07

Thanks! That would make integration easier. It’s a little confusing that datalevin has the concepts of those different dbs that all are build off the same db-files… and the docs do not really distinguish those. Most users will happily use datalevin without ever having to know about those details - guess I’m the lucky one ;-)

fs4217:03:08

An easy programmatic way to copy the datalevin db would be nice. Also because using dtlv to do that while the datalevin java-runtime is still active in another process made me wonder if that could cause issues. (?)

Huahai17:03:43

it’s not a problem to copy a db file that is being used by another process. LMDB handles that correctly. Just copy away.

fs4220:03:52

Ok… the following seems to work: (when-not data-mdb (d/with-conn [conn "/pbdb"] (let [dl-db (d/db conn) lmdb-db (.-lmdb (.-store dl-db))] (assert (d/db? dl-db)) (pp/pprint (d/stat lmdb-db)) (d/copy lmdb-db "/pbdb-backup") ))) Which yields a single data.mdb file in the newly created /pbdb-backup dir - so no lock.mdb file - is that expected?

Huahai20:03:12

the lock file will be created when you open the db

👍 1