Skip to content

Instantly share code, notes, and snippets.

@tolitius
Last active August 22, 2020 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tolitius/bc981b2d6c4e8ff47ae65d3776501ea5 to your computer and use it in GitHub Desktop.
Save tolitius/bc981b2d6c4e8ff47ae65d3776501ea5 to your computer and use it in GitHub Desktop.
(get-in crux [:mindset])

several facts "at once"

=> (crux/submit-tx node [[:crux.tx/put {:crux.db/id :legend/picasso :kind :human}]
                         [:crux.tx/put {:crux.db/id :legend/picasso :planet :earth}]
                         [:crux.tx/put {:crux.db/id :legend/picasso :alive? :always}]
                         [:crux.tx/put {:crux.db/id :legend/picasso :location "Barcelona"}]])
=> (crux/entity-history (crux/db node) :legend/picasso :desc {:with-docs? true})
[{:crux.tx/tx-time #inst "2020-08-22T13:50:46.966-00:00",
  :crux.tx/tx-id 0,
  :crux.db/valid-time #inst "2020-08-22T13:50:46.966-00:00",
  :crux.db/content-hash
  #crux/id "ea449b1f1d7bb0ef7ad3ddf83f36e4eff18c9869",
  :crux.db/doc {:crux.db/id :legend/picasso, :location "Barcelona"}}]

question #1

would the only way not to lose #{:kind :planet :alive?} attributes be to provide them a different #inst as a part of the same transaction?

rolling up "as of"s

=> (crux/submit-tx node [[:crux.tx/put {:crux.db/id :legend/picasso :kind :human}           #inst "2020-08-19"]
                         [:crux.tx/put {:crux.db/id :legend/picasso :planet :earth}         #inst "2020-08-20"]
                         [:crux.tx/put {:crux.db/id :legend/picasso :alive? :always}        #inst "2020-08-21"]
                         [:crux.tx/put {:crux.db/id :legend/picasso :location "Barcelona"}  #inst "2020-08-22"]])
=> (crux/entity-history (crux/db node) :legend/picasso :desc {:with-docs? true})
[{:crux.tx/tx-time #inst "2020-08-22T13:59:16.368-00:00",
  :crux.tx/tx-id 0,
  :crux.db/valid-time #inst "2020-08-22T00:00:00.000-00:00",
  :crux.db/content-hash
  #crux/id "ea449b1f1d7bb0ef7ad3ddf83f36e4eff18c9869",
  :crux.db/doc {:crux.db/id :legend/picasso, :location "Barcelona"}}
 {:crux.tx/tx-time #inst "2020-08-22T13:59:16.368-00:00",
  :crux.tx/tx-id 0,
  :crux.db/valid-time #inst "2020-08-21T00:00:00.000-00:00",
  :crux.db/content-hash
  #crux/id "32c630cc43444c1bef891a25d1c764463386f7b4",
  :crux.db/doc {:crux.db/id :legend/picasso, :alive? :always}}
 {:crux.tx/tx-time #inst "2020-08-22T13:59:16.368-00:00",
  :crux.tx/tx-id 0,
  :crux.db/valid-time #inst "2020-08-20T00:00:00.000-00:00",
  :crux.db/content-hash
  #crux/id "f5f0304f5d32b98b83a41e38a98904b97bf9c36a",
  :crux.db/doc {:crux.db/id :legend/picasso, :planet :earth}}
 {:crux.tx/tx-time #inst "2020-08-22T13:59:16.368-00:00",
  :crux.tx/tx-id 0,
  :crux.db/valid-time #inst "2020-08-19T00:00:00.000-00:00",
  :crux.db/content-hash
  #crux/id "fe64a4d1e0b747ad68b93e1ab677d71681607431",
  :crux.db/doc {:crux.db/id :legend/picasso, :kind :human}}]

question #2

what is a crux way to do history rollups? i.e. "as of" 2020-08-21 I know this about Picasso:

{:crux.db/id :legend/picasso
 :kind :human
 :planet :earth
 :alive? :always}

I could walk the history with a manual merge, but before doing that want to make sure crux does not already have something up its sleeve to roll these up.

replaying tx log on start

apps use crux as a library with postgres as its storage (crux-jdbc) when an app is started it goes through all the transactions to index them:

2020-08-22T10:24:56,745 [crux-polling-tx-consumer] DEBUG crux.tx - Indexing tx-id: 7
2020-08-22T10:24:56,746 [crux-polling-tx-consumer] DEBUG crux.tx - Indexing tx-id: 9
2020-08-22T10:24:56,882 [crux-polling-tx-consumer] DEBUG crux.tx - Indexing tx-id: 10
2020-08-22T10:24:56,884 [crux-polling-tx-consumer] DEBUG crux.tx - Indexing tx-id: 14
2020-08-22T10:24:56,937 [crux-polling-tx-consumer] DEBUG crux.tx - Indexing tx-id: 15
2020-08-22T10:24:56,938 [crux-polling-tx-consumer] DEBUG crux.tx - Indexing tx-id: 16
2020-08-22T10:24:56,939 [crux-polling-tx-consumer] DEBUG crux.tx - Indexing tx-id: 18
2020-08-22T10:24:56,977 [crux-polling-tx-consumer] DEBUG crux.tx - Indexing tx-id: 19
2020-08-22T10:24:56,980 [crux-polling-tx-consumer] DEBUG crux.tx - Indexing tx-id: 20
...

question #3

given these conditions:

  • there are/will be millions of transactions
  • the startup time is important, currently, without crux, it is in a matter of seconds
  • crux needs to run embedded (as a lib), can't currently manage a separate cluster of crux instances

what would be the recommended approach? i.e. can the index loading be lazy; can it be loaded on demand; is it something not to worry and mute these crux-polling-tx-consumer debug messages; etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment