This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-18
Channels
- # aws (1)
- # babashka (35)
- # beginners (52)
- # biff (4)
- # calva (55)
- # cider (19)
- # clojure (54)
- # clojure-dev (3)
- # clojure-europe (23)
- # clojure-nl (1)
- # clojure-norway (3)
- # clojure-uk (2)
- # clojurescript (9)
- # code-reviews (3)
- # datahike (1)
- # fulcro (1)
- # funcool (4)
- # graalvm (21)
- # gratitude (2)
- # java (5)
- # jobs (2)
- # joyride (1)
- # kaocha (13)
- # malli (2)
- # off-topic (22)
- # other-languages (11)
- # pathom (4)
- # re-frame (35)
- # reagent (3)
- # reitit (3)
- # releases (2)
- # remote-jobs (1)
- # rum (1)
- # shadow-cljs (42)
- # sql (18)
- # tools-deps (72)
- # web-security (6)
- # xtdb (15)
Has the answer by C. Grote been superseded by any new functionality? (and Iβm open to other approaches) https://stackoverflow.com/questions/69291427/how-do-you-update-a-single-value-in-xtdb
Transaction functions are still a good way to do it. Another method is via https://docs.xtdb.com/language-reference/datalog-transactions/#match (i.e. do the same thing as in that SO question, but add a match so that you don't lose any data if two transactions try to update the same doc concurrently). And then you if the match fails, you can redo the transaction after querying for the document's new value. Biff takes that approach.
I thought the preferred method in biff was to use :db/op :update and pass in a single field
Yes, but under the hood that gets translated into match + put + retries
There's a biff/biff-tx->xt
function you can use to see what the transaction looks like after it gets translated by the way, for example:
(let [{:keys [biff/db] :as sys} (get-sys)
user-id (biff/lookup-id db :user/email "")]
(biff/biff-tx->xt
sys
[{:db/doc-type :user
:db/op :update
:xt/id user-id
:user/email ""}]))
=> ([:xtdb.api/match
#uuid "122c07db-1c20-446b-91b1-0817f0a86faa"
{:user/email "",
:user/foo "Some Value",
:user/joined-at #inst "2022-12-10T00:54:02.831-00:00",
:xt/id #uuid "122c07db-1c20-446b-91b1-0817f0a86faa"}]
[:xtdb.api/put
{:user/email "",
:user/foo "Some Value",
:user/joined-at #inst "2022-12-10T00:54:02.831-00:00",
:xt/id #uuid "122c07db-1c20-446b-91b1-0817f0a86faa"}])
How does xtdb enforce a total ordering over transaction time, if transaction time is based on system time? β’ Firstly does xtdb have a single transactor (like datomic)? If it does how does it: 1. Break ties if two transaction requests are received concurrently? 2. Ensure that transaction time is monotonically increasing after deciding an order of events? i.e. how does it ensure that transaction time is a total order; not just a partial order; or is a partial order somehow ok? Finally If it supports committing concurrent transactions; how does it break ties?
ok just seen the architecture diagram (which implies a single transactor) and this comment: > the transaction time provided is no earlier than any other transaction currently in the system - i.e. transaction times must be increasing. https://docs.xtdb.com/language-reference/datalog-transactions/#transaction-time Which implies to me a total order - but that itβs on the application/loader to convert any partial ordering on tx-time into a total order.
Hey @U06HHF230 π As you suspected, yes - XT is a single-threaded writer system. Transaction time may not be monotonically increasing (it's possible for two consecutive transactions to have the same timestamp) - instead we use transaction id to break ties (which is monotonically increasing), and this is what gives us the total order
this tx-id is provided to us by the transaction log (e.g. Kafka) - it's not something users can override
ah ok thanks β the possibility for timestamps to be the same is exactly the problem I was highlighting β and the presence of a monotonically increasing tx-id is the missing piece I was looking for. Thanks π . Can you use tx-id in queries; to join / compare transactions inside the query language?
(obviously youβd be able to compare outside yourself)
Can you compare the state of the world at T1 with the state of the world at T2 in a normal query (not within a transaction)?