Delete with Crux – Jupiter Assignment

Introduction

This is the delete installment of the Crux tutorial.

Setup

You need to get Crux running before you can use it.

{:deps
 {org.clojure/clojure {:mvn/version "1.10.0"}
  org.clojure/tools.deps.alpha
  {:git/url "https://github.com/clojure/tools.deps.alpha.git"
   :sha "f6c080bd0049211021ea59e516d1785b08302515"}
  juxt/crux-core {:mvn/version "RELEASE"}}}
deps.edn
Extensible Data Notation
(require '[crux.api :as crux])
0.0s
Clojure

Arrival on Jupiter

You approach Jupiter and marvel at its bands. You wish you could have seen it this close before the Great Red Spot dissipated.

As you enter the Jovian atmosphere your communications panel lights up with the now expected, but rather terse message from boundary control.

"Jupiter’s boundary is controlled.
If you wish to enter, present your papers now."
 Zeus Confederacy  
Boundary Control
Clojure

The government is asking to see your flight manifest.

Choose your path:

You have your manifest : You have permission to land, continue to the space port.

You do not have your manifest : You do not have permission to land. You can either return to Saturn or continue at your own risk.

Space Port

It’s a turbulent ride down to the space port. To take your mind off the colossal storm outside, you check the Crux manual for the delete operation.

"Currently there are only four transaction operations in Crux: put, delete, cas and evict.
		Transaction 	(Description)
    put    		(Writes a version of a document)
    delete    (Deletes a version of a document)
    cas       (Writes new version of a document if the old version is as expected)
    evict    	(Removes an document entirely)
delete:
Deletes a document at a given valid time. Historical version of the document will still be available.
The delete operation takes a valid eid with the option to include a start and end valid-time.
The document will be deleted as of the transaction time, or beteen the start and end valid-times if provided. Historical versions of the document that fall outside of the valid-time window will be preserved.
A complete delete transaction has the form:
[:crux.tx/delete eid valid-time-start valid-time-end]"
 Crux manual
Crux Manual
Clojure

Read More

You are happy with what you have read, and in anticipation of the assignment you define the standalone node.

(def crux
  (crux/start-node
               {:crux.node/topology :crux.standalone/topology
                :crux.node/kv-store "crux.kv.memdb/kv"
                :crux.standalone/event-log-dir "data/eventlog-1"
                :crux.kv/db-dir "data/db-dir-1"
                :crux.standalone/event-log-kv-store "crux.kv.memdb/kv"}))
0.1s
Clojure
user/crux

Assignment

You land on the raised platform and open your job ticket

Ticket

Task 			"Remove assigned clients"
Company		"Helios Banking Inc."
Contact 	"Kaarlang"
Submitted "2115-02-10T13:38:20"
Additional information:
"Help Kaarlang delete client history from his Crux node in accordance with Earth data protection laws."
Job Ticket
Clojure

As you leave your ship, you are met by the martian Kaarlang:

"Hi there, I believe you’re here to help me.
I’ve been told I need to delete my client history with today being my last day.
Is this something you can help me with?"
 Kaarlang
Helios Banking Inc.
Clojure

Choose your path:

"Yes, we'll work together to do this." : Continue to complete the assignment.

"I'm not even sure how to begin" : Take some time to read through the Crux manual again. If you're still unsure then you can follow along anyway and see if things become clear.

Assignment

Kaarlang gives you his client history so you can sync up your Crux node.

(crux/submit-tx crux
                [[:crux.tx/put {:crux.db/id :kaarlang/clients
                                :clients [:encompass-trade]}
                  #inst "2110-01-01T09"
                  #inst "2111-01-01T09"]
                 [:crux.tx/put {:crux.db/id :kaarlang/clients
                                :clients [:encompass-trade :blue-energy]}
                  #inst "2111-01-01T09"
                  #inst "2113-01-01T09"]
                 [:crux.tx/put {:crux.db/id :kaarlang/clients
                                :clients [:blue-energy]}
                  #inst "2113-01-01T09"
                  #inst "2114-01-01T09"]
                 [:crux.tx/put {:crux.db/id :kaarlang/clients
                                :clients [:blue-energy :gold-harmony :tombaugh-resources]}
                  #inst "2114-01-01T09"
                  #inst "2115-01-01T09"]])
0.1s
Clojure
Map {:crux.tx/tx-id: 1609131600425985, :crux.tx/tx-time: #inst "2019-10-18T16:52:58.541Z"}

To get a good visual aid, you show Kaarlang how to view his client history. This way you both can see when the clients are deleted.

(crux/history-ascending
 (crux/db crux)
 (crux/new-snapshot (crux/db crux #inst "2116-01-01T09")) ;; (1)
 :kaarlang/clients)
0.6s
Clojure
  1. You explain that you are using a snapshot of Crux with a future valid-time to see the full history.

The result shows the names of the clients that have been assigned to Kaarlang since he started at the company in 2110.

Next you delete the whole history of clients buy choosing a start and end valid-time that spans his entire employment time.

(crux/submit-tx 
 crux
 [[:crux.tx/delete :kaarlang/clients #inst "2110-01-01" #inst "2116-01-01"]])
0.0s
Clojure
Map {:crux.tx/tx-id: 1609131601074177, :crux.tx/tx-time: #inst "2019-10-18T16:52:59.174Z"}

Using the same method as before you show Kaarlang the effect that this operation has had.

(crux/history-ascending
 (crux/db crux)
 (crux/new-snapshot (crux/db crux #inst "2116-01-01T09"))
 :kaarlang/clients)
0.5s
Clojure

Kaarlang is impressed it is that easy. You point out that there are no longer any documents attached to the transactions.

"I am grateful that you took the time to show me this.
Today is a sad day for me as I have very much enjoyed my time here.
Although, I was expecting to hear from a friend before I left. There is a very important message that I am waiting for."
- Kaarlang
Speaking from the heart
Clojure

You remember the secret note in your pocket and pass it to Kaarlang.

The Secret Note.

Kaarlang reads the note.

He looks at you with the a peculiar facial expression.

"This is the note I was waiting for.
It has information about the a top secret stellar transport shuttle.
If you are interested in a great adventure, the shuttle comes once every hundred years or so to take a select few to a nearby star system. The system is home to a mysterious hyper-intelligent form of life.
I’m sure there would be a place for you if you were willing to help out. The passengers on the shuttle have the right to be forgotten. We need someone that can remove the passengers data from the solar system.
What do you think?"
- Kaarlang
Clojure

Choose your path

"That sounds like a great opportunity, I'm in" - You head off to the secret location of the shuttle.

"No thanks, not for me." - You choose not to got with Kaarlang. You continue working for Helios Banking Inc. for the rest of your days.

Runtimes (1)