Fork me on GitHub
#datomic
<
2015-12-08
>
pesterhazy08:12:56

@robert-stuttaford: I decided to rewrite it mostly so that I understand it better

pesterhazy09:12:54

When restoring, I'm using a two-phase approach to deal with tempids. First I safe bogus refs, then I fix them to point to the new entities.

jonpither10:12:32

Hi, is it possible given a connection to restore an in-memory db to db from an earlier point in time? For test purposes (using conformity for migrated a DB to the desired version, but it's too slow for each test we have)

ustunozgur10:12:47

I'm running a datomic instance and a simple jetty/ring web server on a 2GB RAM instance, but it is consuming about 1.5GB RAM. The database is pretty empty, maybe 1000 records or so. Is this normal?

ustunozgur10:12:26

does datomic consume that much memory out of the box or am I doing something wrong in my server?

ustunozgur10:12:21

I just attach to the db at every function call, for example, I have the following db queries: https://github.com/YoungTurks/hackerdict/blob/master/src/hackerdict/db.clj

ustunozgur10:12:42

I have also experimented with storing the connection in an atomic

ustunozgur10:12:57

but then reverted back to using a function call to get a brand new one each time.

ustunozgur10:12:11

what is the ideal way to keep a connection to the db?

jonpither10:12:08

Any ideas, I'm stumped

robert-stuttaford10:12:22

so you have a storage-backed db and you want to take an in-mem db pointing to a particular point in that storage db for tests to use?

jonpither10:12:23

Looking at excision also, but that seems non-trivial

jonpither10:12:33

no it's not storaged backed

robert-stuttaford10:12:51

what form does your test data take when your tests aren’t running? transactions in edn?

jonpither10:12:02

It's a pure in-memory DB, the problem is the cost of creating a new DB for each test (running schema migrations) is around ~ .5 sec

robert-stuttaford10:12:55

i assume you transact in your tests?

robert-stuttaford10:12:22

yeah we use that too

jonpither10:12:53

ideally, given a freshly created in-mem DB, I'd like to shove it back down the connection, saying "revert/restore yourself to this"

robert-stuttaford10:12:59

how many datoms in the test database post schema?

jonpither10:12:14

not a great deal

jonpither10:12:18

(just rocked on to this codebase)

robert-stuttaford10:12:55

one approach is to use d/with instead of d/transact

robert-stuttaford10:12:07

but that means alterations to production code which sucks

robert-stuttaford10:12:04

you can’t rewind datomic databases like that. you can assert mirror transactions in reverse order, but that’s probably going to be slower than simply remaking it

robert-stuttaford10:12:30

you could also make the db, save off the datoms (out of :EAVT) and simply transact the whole lot into a new in-mem db for each test

jonpither10:12:08

yeah the latter sounds better

jonpither10:12:33

is there a resource you could point me at?

robert-stuttaford10:12:46

to save off the datoms, or to build a tx based on them?

jonpither10:12:31

given I have a freshly created / migrated DB with some initial seed data, can I extract all the txs from this necessary for building up a new db?

robert-stuttaford10:12:54

(vec (for [[e a v] (d/datoms db :eavt)] [:db/add e (d/ident db a) v]))

robert-stuttaford10:12:29

you’d have to filter out all the stuff present in every datomic database, so a’s with :db/ or :fressian/ as a namespace

jonpither10:12:10

I'll give this a go, thanks Bob, be interesting to see if it's faster

robert-stuttaford10:12:12

should be, you’d get full persistent data-structure advantages

robert-stuttaford10:12:07

@jonpither: untested, but i’m fairly sure this’ll work:

robert-stuttaford10:12:10

(vec (for [[e a v] (d/datoms db :eavt)
           :let [a (d/ident db a)]
           :when (not (-> a namespace #{"db" "db.install" "fressian"}))]
       [:db/add e a v]))

robert-stuttaford10:12:23

that should be empty for a completely new database

jonpither10:12:34

nice - legend

robert-stuttaford10:12:28

of course, you can optimise further; keep the db around too because you can use it for any tests that don’t transact anything (as few as those might be)

robert-stuttaford10:12:28

@jonpither: one small fix to the snippet above

jonpither10:12:02

I see namespaces such as db.install

jonpither10:12:04

`(defn- db-creation-datoms
  [db]
  (vec (for [[e a v] (d/datoms db :eavt)
             :let [a (d/ident db a)]
             :when (not (or (-> a namespace #{"db" "fressian"})
                            (.startsWith (namespace a) "db.")))]
         [(namespace a) :db/add e a v])))
`

robert-stuttaford10:12:52

@jonpither, i’m a dork. i’ve completely ignored that transacting requires tempids, so you’ll need to post-process the e and v values in that output to replace all the ids with tempids, and you’ll need to make sure that schema gets db partition tempids

robert-stuttaford11:12:57

not insurmountable, and it’s work that would only happen once at the start of the test run, so still worth trying

robert-stuttaford11:12:17

just not a 4 line code snippet any more, heh

robert-stuttaford11:12:44

good luck. must run

jonpither11:12:04

I'll let you know of my travails

currentoor18:12:21

Hi, if transact a few entities using tempids, is there a way to get the entity ids they resolved to from the tx-data?

currentoor18:12:31

returned from transact

currentoor18:12:24

or should i just query the DB after the transaction, i'm interested in a subset of the new entity ids

currentoor18:12:52

the entity ids for some of the newly transacted entities

marshall18:12:22

@currentoor: They are returned from transact in the map. They’re in the :tempids entry of the map.

currentoor18:12:19

Looking forward to talking to you this afternoon.

currentoor18:12:11

resolve-tempid was exactly what I needed

Lambda/Sierra22:12:18

As I understand it, you must use d/resolve-tempid to correctly resolve tempids, you can't just get them from the map returned by d/transact.