From 57c063ef58b4438ace6c1854245efba253a6813e Mon Sep 17 00:00:00 2001 From: Casey Marshall Date: Mon, 18 Nov 2019 14:01:19 -0800 Subject: [PATCH] Tracing GC. Based partially on https://github.com/datacrypt-project/hitchhiker-tree/pull/24 Rewritten to primarily use core.async. * src/hitchhiker/tree/konserve.cljc (create-id): new function; prepends the current timestamp as hex to the UUID key. (KonserveBackend.-write-node): use create-id to generate the storage ID. * src/hitchhiker/tree/tracing-gc/konserve.cljc: new namespace. * src/hitchhiker/tree/tracing-gc.cljc: new namespace. * .gitignore: ignore IntelliJ files. * project.clj: update konserve to 0.6.0-SNAPSHOT. --- .gitignore | 4 ++ project.clj | 4 +- src/hitchhiker/tree/bootstrap/konserve.cljc | 11 +++- src/hitchhiker/tree/tracing_gc.cljc | 54 ++++++++++++++++++++ src/hitchhiker/tree/tracing_gc/konserve.cljc | 28 ++++++++++ 5 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 src/hitchhiker/tree/tracing_gc.cljc create mode 100644 src/hitchhiker/tree/tracing_gc/konserve.cljc diff --git a/.gitignore b/.gitignore index 8fc68fb..c610d70 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,7 @@ pom.xml.asc *.swo *.swn *~ +/.idea +*.iml +profiles.clj +/scripts \ No newline at end of file diff --git a/project.clj b/project.clj index 167bd60..91090ef 100644 --- a/project.clj +++ b/project.clj @@ -9,7 +9,7 @@ [com.taoensso/carmine "2.12.2" :scope "provided"] [org.clojure/core.rrb-vector "0.0.14"] [org.clojure/core.cache "0.7.2"] - [io.replikativ/konserve "0.5.1"]] + [io.replikativ/konserve "0.6.0-SNAPSHOT"]] :aliases {"bench" ["with-profile" "profiling" "run" "-m" "hitchhiker.bench"]} :jvm-opts ["-server" "-Xmx3700m" "-Xms3700m"] :profiles {:test @@ -42,7 +42,7 @@ :compiler {:main hitchhiker.tree.core :asset-path "js/out" :output-to "resources/public/js/core.js" - :output-dir "resources/public/js/out" }} + :output-dir "resources/public/js/out"}} ;; inspired by datascript project.clj {:id "test" :source-paths ["src" "test"] diff --git a/src/hitchhiker/tree/bootstrap/konserve.cljc b/src/hitchhiker/tree/bootstrap/konserve.cljc index 78a0564..fe47b27 100644 --- a/src/hitchhiker/tree/bootstrap/konserve.cljc +++ b/src/hitchhiker/tree/bootstrap/konserve.cljc @@ -53,6 +53,15 @@ [key] (ha/promise-chan key)) +(defn create-id + "Generate a storage ID from a content UUID. + + Adds a (hexadecimal) timestamp in milliseconds to the start of the + key; this is so the GC can properly delete keys that don't exist in + the tree anymore" + [uuid] + (format "%016x.%s" (System/currentTimeMillis) uuid)) + (defrecord KonserveAddr [store last-key konserve-key storage-addr] n/INode (-last-key [_] last-key) @@ -90,7 +99,7 @@ (ha/go-try (swap! session update-in [:writes] inc) (let [pnode (encode node) - id (h/uuid pnode) + id (create-id (h/uuid pnode)) ch (k/assoc-in store [id] node)] (ha/ (when (string? address) + (re-matches #"([0-9a-f]{16})\.[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" address)) + (second))] + (not (pos? (compare addr-ts epoch))) + true)) + +(defrecord KonserveGCScratch [store epoch] + gc/IGCScratch + (observe-addr! [_ addr] + (log/debug :task ::gc/observe-addr! :addr addr) + (k/assoc store addr :marked)) + + (observed? [_ addr] + (async/go + (log/debug :task ::gc/observed? :phase :begin :addr addr) + (let [result (or (within-epoch? addr epoch) + (= :marked (async/