From c582e65b0cf3479e55e40a4505f80e9a2c1be7af Mon Sep 17 00:00:00 2001 From: Christian Weilbach Date: Sat, 23 May 2020 19:19:59 -0700 Subject: [PATCH] Fix cljs compilation. Remove untested outboard API. Most functions should probably be rebuilt on the konserve backend anyway. --- src/hitchhiker/tree.cljc | 22 +- src/hitchhiker/tree/bootstrap/outboard.clj | 239 --------------------- test/hitchhiker/konserve_test.cljc | 103 ++++----- 3 files changed, 50 insertions(+), 314 deletions(-) delete mode 100644 src/hitchhiker/tree/bootstrap/outboard.clj diff --git a/src/hitchhiker/tree.cljc b/src/hitchhiker/tree.cljc index b3ac0add..95788979 100644 --- a/src/hitchhiker/tree.cljc +++ b/src/hitchhiker/tree.cljc @@ -515,17 +515,17 @@ "Takes the result of a search and puts the iterated elements onto iter-ch going forward over the tree as needed. Does lg(n) backtracking sometimes." [iter-ch path start-key] - (ha/go-try - (loop [path path] - (if path - (let [start-node (peek path) - elements (subseq (:children start-node) - >= - start-key)] - (ha/= + start-key)] + (ha/RedisBackend)))))) - (let [new-root (redis/get-root-key @tree-atom)] - (wcar - {} - (car/incr (str new-root ":rc")) - (redis/drop-ref (wcar {} (car/hget "named-hhs" save-name))) - (car/hset "named-hhs" save-name new-root))))] - (reset! (:thread conn) - (doto (Thread. - (fn* [] - (loop [pending-writes 0 - timed-out false] - (if (not= :shutdown @close-signal) - (if (or timed-out (> pending-writes 1000)) - (do (flush-tree) - (recur 0 false)) - (if-let [update (try - (.poll q 5 TimeUnit/SECONDS) - (catch InterruptedException e - nil))] - (do (swap! tree-atom update) - (recur (inc pending-writes) false)) - (do (recur pending-writes true)))) - (do (flush-tree) - (println "Shutting down" save-name)))))) - (.setName (str "Outboard processor for " save-name)) - (.start))))) - -(defn create - "Creates a new, empty outboard with the given name. Returns a connection to it." - [new-name] - (when (or (contains? @connection-registry new-name) - (wcar {} - (car/hget "named-hhs" new-name))) - (throw (ex-info (str "Cannot create outboard with name " new-name - ", its already in use") {:used-name new-name}))) - ;; TODO race condition where additional calls to create could all - ;; succeed we should guard against this - (let [conn (->OutboardConnection (LinkedBlockingQueue.) - (-> (tree/->Config 30 600 870) - tree/b-tree - ha/OutboardConnection - (LinkedBlockingQueue.) - (atom (redis/create-tree-from-root-key root-key)) - (atom :running) - (atom nil) - name)] - (launch-outboard-processer! conn name) - (swap! connection-registry assoc name conn) - conn) - (throw (ex-info (str "Didn't find root-addr at " name) {}))))) - -(defn close - "Frees the in-VM resources associated with the connection. The connection - will no longer work." - [conn] - (when-not (instance? OutboardConnection conn) - (throw (ex-info "close takes an outboard connection as an argument" {:conn conn}))) - (reset! (:close-signal conn) :shutdown) - (.interrupt ^Thread @(:thread conn)) - (swap! connection-registry dissoc (:tree-name conn))) - -(defn update! - [conn update-fn] - (.put ^LinkedBlockingQueue (:update-queue conn) update-fn)) - -(defn snapshot - [conn] - @(:tree-atom conn)) - -(defn insert - "Inserts key/value pairs into the outboard data snapshot" - [snapshot k v & kvs] - (let [tree snapshot] - (if (and (seq kvs) (even? (count kvs))) - (loop [tree (ha/RedisBackend))))] - (wcar {} - (car/hset "named-hhs" new-name (redis/get-root-key flushed-snapshot)) - (car/incr (str (redis/get-root-key flushed-snapshot) ":rc"))) - (reset! (:tree-atom new-conn) flushed-snapshot) - new-conn)) - -#_(defn extend-lifetime - "Ensures the given snapshot will be readable for at least additional-ms longer." - ;;TODO this is complex b/c we need to find all the reachable non-dirty nodes, and either add or extend their lifetimes... - [snapshot additional-ms] - ;((wcar {} (car/zincrby (re)))) - ) - -(comment - ;First we'll create a new tree - (def my-tree (create "my-tree")) - ;(def my-tree (open "my-tree")) - (println (count @connection-registry)) - ;This is how we'd close the tree - (close my-tree) - ;Once the tree is closed, you can destroy it to free its resources - (destroy "my-tree") - ;Here, we can iterate through the elements of the tree - (lookup-fwd-iter (snapshot my-tree) "") - - ;save-as lets us take a snapshot and save it under another name - (def other-tree (save-as (snapshot my-tree) "other-tree")) - ;it returns a managed connection that can be interacted with like anything usual - (lookup-fwd-iter (snapshot other-tree) "") - (close other-tree) - (destroy "other-tree") - - ; To write to a tree, send it an update function with update! - ; Your function should take a snapshot as the argument, and return the modified snapshot to replace the data structure - (update! my-tree (fn [snapshot] (insert snapshot "first key" "has a value of 22"))) - (update! my-tree (fn [snapshot] (insert snapshot "second key" {:lol 33}))) - (update! my-tree (fn [snapshot] (insert snapshot "3" 4))) - - (wcar {} (car/keys "*")) - (wcar {} (car/flushall)) - (wcar {} (car/zrange "refcount:expiry" 0 -1)) - (wcar {} (car/hget "named-hhs" "my-tree")) - (wcar {} (car/hget "named-hhs" "other-tree")) - (wcar {} (car/get (str (wcar {} (car/hget "named-hhs" "my-tree")) ":rc"))) - - ) diff --git a/test/hitchhiker/konserve_test.cljc b/test/hitchhiker/konserve_test.cljc index e54605c8..a2a159ef 100644 --- a/test/hitchhiker/konserve_test.cljc +++ b/test/hitchhiker/konserve_test.cljc @@ -30,39 +30,14 @@ (ha/go-try (let [iter-ch (async/chan) path (ha/KonserveBackend store) - config (core/->Config 1 3 (- 3 1)) - flushed (ha/js m)) -;; (if (cljs.test/successful? m) -;; (println "Success!") -;; (println "FAIL"))) -;; (run-tests))) +#?(:cljs + (defn ^:export test-all [cb] + (defmethod cljs.test/report [:cljs.test/default :end-run-tests] [m] + (cb (clj->js m)) + (if (cljs.test/successful? m) + (println "Success!") + (println "FAIL"))) + (run-tests)))