Fork me on GitHub
#datomic
<
2017-07-25
>
danielcompton02:07:20

@apsey, that's very interesting. > a way to get the transactor host from the connection I don't know if this is part of the public API > encode and decode data that is being transacted or queried I'm not sure what this would get for you?

danielcompton02:07:39

Datomic has a new HTTP endpoint you can query to get some status info, but I'm not sure if that's what you need here

danielcompton02:07:50

Datomic has a lot of the HA stuff built-in, as well as connection retries I think

danielcompton02:07:02

But it's all internal, I'm not sure how well it's exposed to the user

danielcompton02:07:40

Is it possible to just monitor the queries and transactions, and fail if they fail, but in the background retry to try and let Finagle handle the self-healing and backoff?

nonrecursive03:07:19

hey y’all, what are the best practices around creating datomic connections? I’m using datomic for a web app, and is it ok to call d/connect once per API request?

danielcompton06:07:33

> Datomic connections do not adhere to an acquire/use/release pattern. They are thread-safe and long lived. Connections are cached such that calling datomic.api/connect multiple times with the same database value will return the same connection object.

danielcompton06:07:52

from d/connect docstring

danielcompton06:07:44

however as a matter of code architecture, I would suggest maybe using the Component architecture that does use a long-lived connection

danielcompton06:07:21

It makes reloading easy, and helps you easily use a memory database for testing

danielcompton06:07:46

You can do it either way, but if you need to inject a URI to connect to, then you may as well inject a full Datomic Component

val_waeselynck07:07:08

@U0AQ1R7FG not relying on URIs also gives you the opportunity to do things like forking etc.

danielcompton22:07:08

Here's a fully worked component that might be useful as a starting point:

(ns app.system.datomic
  (:require [com.stuartsierra.component :as component]
            [datomic.api :as d]
            [app.datomic.schema :as schema]
            [clojure.spec :as s]
            [clojure.string :as str]
            [suspendable.core :as suspendable]
            [clojure.tools.logging :as log])
  (:import (datomic Connection)))

(s/def :datomic/conn (partial instance? Connection))
(s/def :datomic/uri (s/and string?
                           #(str/starts-with? % "datomic:")))

(defrecord Datomic [uri conn]
  component/Lifecycle
  (start [component]
    (let [created? (d/create-database uri)
          conn (d/connect uri)]
      (when created?
        (log/info "Creating a new datomic database:" uri))
      (schema/ensure-schema conn)
      (assoc component :conn conn)))
  (stop [component]
    (when conn (d/release conn))
    (assoc component :conn nil))
  suspendable/Suspendable
  (suspend [component]
    component)
  (resume [component old-component]
    (if (and (= (dissoc component :conn) (dissoc old-component :conn))
             (some? (:conn old-component))
             ;; Try and sync the db, to ensure that we are still connected
             ;; If not, we shut down the component and try to reconnect.
             (try
               (deref (d/sync (:conn old-component)) 500 false)
               (catch Exception e
                 false)))
      (assoc component :conn (:conn old-component))
      (do (component/stop old-component)
          (component/start component)))))

(defn new-datomic [{:keys [uri] :as config}]
  (map->Datomic {:uri uri}))

(s/fdef new-datomic
        :args (s/cat :config (s/keys :req-un [:datomic/uri])))
YMMV ofc

ckaratza14:07:46

Hello! Question regarding txReportQueue. So if I subscribe from a Peer to txReportQueue at Time=t0 where maxTxId=XXX and keep getting messages until Time=t1 where maxTxId=YYY, if for some reason connection to datomic breaks from t1 to Time=t3 where maxTxId=ZZZ, when my Peer recovers will it get all the txIds YYY-ZZZ or it will start getting after ZZZ?

val_waeselynck16:07:26

No, txReportQueue is a realtime notification system, use the Log API for catching up

chrjs15:07:13

Hey all. Noob question. Is it possible to start datomic in local (in memory) mode, and then migrate to a backing store, without losing all the in memory datoms?

chrjs15:07:59

http://docs.datomic.com/backup.html seems to suggest swapping out the backing store is possible.

favila15:07:13

In memory databases can't be backed up, so they can't be restored

favila15:07:38

You need to replay the tx-log of the mem db and manually copy

chrjs15:07:55

Ah, ok. Thought that might be the case. Thanks!

apsey16:07:28

@danielcompton can you guide me to the new HTTP endpoint status info API? I am still researching, but I dont think it is possible to activate finagle only in the failing cases, if that is what you are suggesting

bbloom17:07:05

that’s probably worth studying - thx @robert-stuttaford

hmaurer18:07:03

Can I call functions from my application’s namespace / librairies in a Datalog queries? I tried but got an error. I suspected it’s because the quoted query could not reference the functions I was using, so I tried syntax quoting (which auto-prefixes every symbol), but then the variables (e.g. ?trete) got prefixed too and everything broke

hmaurer18:07:25

I would like to use some functions from the clj-time package in my query

hmaurer18:07:59

Ah, I found the relevant passage of the doc

hmaurer18:07:00

> Function names outside clojure.core need to be fully qualified, and their namespaces must be loaded before use in query.

hmaurer18:07:10

I tried that and still got an error, but will try again

hmaurer18:07:02

nevermind, full qualification does fix it. I must have made a mistake earlier

beders18:07:21

are you doing it using the client library?

hmaurer18:07:35

peer library

gonewest81822:07:58

Can datomic-console-0.1.214 be installed and run with datomic-free-0.9.5561.50 ?

gonewest81822:07:18

could be I blew the installation, but for me it's crashing at startup with

console_1     | Exception in thread "main" java.lang.IncompatibleClassChangeError: Implementing class
console_1     | 	at java.lang.ClassLoader.defineClass1(Native Method)
console_1     | 	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
console_1     | 	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
...

gonewest81822:07:55

same issue with datomic-free-0.9.5561.54 and each version back to 0.9.5544

gonewest81823:07:21

ah, nevermind. I found this comment in the Google group https://groups.google.com/forum/#!topic/datomic/TiRcDBqs9cM