Skip to content

Commit

Permalink
(PDB-3059) Add memoize-resource-identity-hashes opt
Browse files Browse the repository at this point in the history
Add a boolean memoize-resource-identity-hashes option to the developer
config section that defaults to true (the existing behavior), and will
disable the resource hash memoization (for the whole JVM) when set to
false.
  • Loading branch information
rbrw committed Sep 23, 2016
1 parent 4f529ce commit 6b542b4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(def pdb-version "4.1.2")
(def pdb-version "4.1.2-hotfix-3059")

(defn deploy-info
"Generate deployment information from the URL supplied and the username and
Expand Down
4 changes: 4 additions & 0 deletions src/puppetlabs/puppetdb/cli/services.clj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
[puppetlabs.puppetdb.query-eng :as qeng]
[puppetlabs.puppetdb.query.population :as pop]
[puppetlabs.puppetdb.scf.migrate :refer [migrate! indexes!]]
[puppetlabs.puppetdb.scf.hash :as scf-hash]
[puppetlabs.puppetdb.scf.storage :as scf-store]
[puppetlabs.puppetdb.scf.storage-utils :as sutils]
[puppetlabs.puppetdb.time :refer [to-seconds to-millis parse-period
Expand Down Expand Up @@ -256,6 +257,9 @@
(when-let [v (version/version)]
(log/infof "PuppetDB version %s" v))

(reset! scf-hash/memoize-resource-identity-hashes?
(:memoize-resource-identity-hashes developer))

(init-with-db database config)

(let [population-registry (get-in metrics/metrics-registries [:population :registry])]
Expand Down
6 changes: 4 additions & 2 deletions src/puppetlabs/puppetdb/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,12 @@

(def developer-config-in
(all-optional
{:pretty-print (pls/defaulted-maybe String "false")}))
{:pretty-print (pls/defaulted-maybe String "false")
:memoize-resource-identity-hashes (pls/defaulted-maybe String "true")}))

(def developer-config-out
{:pretty-print Boolean})
{:pretty-print Boolean
:memoize-resource-identity-hashes Boolean})

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Database config
Expand Down
6 changes: 5 additions & 1 deletion src/puppetlabs/puppetdb/scf/hash.clj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
;; "medium" site persona
(def memoized-resource-identity-hash* (kitchensink/bounded-memoize resource-identity-hash* 40000))

(def memoize-resource-identity-hashes? (atom true))

(defn resource-identity-hash
"Compute a hash for a given resource that will uniquely identify it
_for storage deduplication only_.
Expand All @@ -60,7 +62,9 @@
[{:keys [type title parameters] :as resource}]
{:pre [(map? resource)]
:post [(string? %)]}
(memoized-resource-identity-hash* type title parameters))
(if @memoize-resource-identity-hashes?
(memoized-resource-identity-hash* type title parameters)
(resource-identity-hash* type title parameters)))

(defn catalog-resource-identity-format
"Narrow `resource` to only contain the needed key/values for computing the hash of
Expand Down

0 comments on commit 6b542b4

Please sign in to comment.