Skip to content

Commit

Permalink
Make Block Cache Optional
Browse files Browse the repository at this point in the history
Also remove the block cache from the resource database because it's not
worth it.
  • Loading branch information
alexanderkiel committed Jun 3, 2023
1 parent c186c8f commit 69cf8a6
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion modules/rocksdb/src/blaze/db/kv/rocksdb.clj
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@


(defmethod ig/pre-init-spec ::kv/rocksdb [_]
(s/keys :req-un [::dir ::block-cache ::stats] :opt-un [::opts]))
(s/keys :req-un [::dir ::stats] :opt-un [::block-cache ::opts]))


(defn- init-log-msg [dir opts]
Expand Down
12 changes: 7 additions & 5 deletions modules/rocksdb/src/blaze/db/kv/rocksdb/impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@
(cond->
(doto (BlockBasedTableConfig.)
(.setVerifyCompression false)
(.setCacheIndexAndFilterBlocks true)
(.setPinL0FilterAndIndexBlocksInCache true)
(.setPinTopLevelIndexAndFilter true)
(.setBlockSize block-size)
(.setBlockCache block-cache))
(.setBlockSize block-size))
(nil? block-cache)
(.setNoBlockCache true)
(some? block-cache)
(-> (.setBlockCache block-cache)
(.setCacheIndexAndFilterBlocks true)
(.setPinL0FilterAndIndexBlocksInCache true))
bloom-filter?
(.setFilterPolicy (BloomFilter. 10 false))
bloom-filter?
Expand Down
2 changes: 1 addition & 1 deletion modules/rocksdb/test/blaze/db/kv/rocksdb/impl_spec.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


(s/fdef impl/column-family-descriptor
:args (s/cat :block-cache ::rocksdb/block-cache
:args (s/cat :block-cache (s/nilable ::rocksdb/block-cache)
:opts (s/tuple keyword? (s/nilable map?))))


Expand Down
10 changes: 9 additions & 1 deletion modules/rocksdb/test/blaze/db/kv/rocksdb/impl_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
:cache-index-and-filter-blocks (.cacheIndexAndFilterBlocks config)
:pin-l0-filter-and-index-blocks-in-cache (.pinL0FilterAndIndexBlocksInCache config)
:block-size (.blockSize config)
:block-cache? (not (.noBlockCache config))
:bloom-filter? (some? (.filterPolicy config))})

DBOptions
Expand All @@ -85,7 +86,7 @@


(deftest column-family-descriptor-test
(testing "with defaults"
(testing "with defaults and block cache"
(with-open [block-cache (LRUCache. 0)]
(given (column-family-descriptor block-cache :default nil)
:name := "default"
Expand All @@ -102,10 +103,17 @@
[:options :table-format-config :cache-index-and-filter-blocks] := true
[:options :table-format-config :pin-l0-filter-and-index-blocks-in-cache] := true
[:options :table-format-config :block-size] := 4096
[:options :table-format-config :block-cache?] := true
[:options :table-format-config :bloom-filter?] := false
[:options :memtable-whole-key-filtering?] := false
[:options :optimize-filters-for-hits?] := false)))

(testing "without block cache"
(given (column-family-descriptor nil :default nil)
[:options :table-format-config :block-cache?] := false
[:options :table-format-config :cache-index-and-filter-blocks] := false
[:options :table-format-config :pin-l0-filter-and-index-blocks-in-cache] := false))

(with-open [block-cache (LRUCache. 0)]
(are [key value]
(given (column-family-descriptor block-cache :default {key value})
Expand Down
15 changes: 6 additions & 9 deletions modules/rocksdb/test/blaze/db/kv/rocksdb_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,15 @@
:key := ::kv/rocksdb
:reason := ::ig/build-failed-spec
[:explain ::s/problems 0 :pred] := `(fn ~'[%] (contains? ~'% :dir))
[:explain ::s/problems 1 :pred] := `(fn ~'[%] (contains? ~'% :block-cache))
[:explain ::s/problems 2 :pred] := `(fn ~'[%] (contains? ~'% :stats))))
[:explain ::s/problems 1 :pred] := `(fn ~'[%] (contains? ~'% :stats))))

(testing "invalid dir"
(given-thrown (ig/init {::kv/rocksdb {:dir ::invalid}})
:key := ::kv/rocksdb
:reason := ::ig/build-failed-spec
[:explain ::s/problems 0 :pred] := `(fn ~'[%] (contains? ~'% :block-cache))
[:explain ::s/problems 1 :pred] := `(fn ~'[%] (contains? ~'% :stats))
[:explain ::s/problems 2 :pred] := `string?
[:explain ::s/problems 2 :val] := ::invalid))
[:explain ::s/problems 0 :pred] := `(fn ~'[%] (contains? ~'% :stats))
[:explain ::s/problems 1 :pred] := `string?
[:explain ::s/problems 1 :val] := ::invalid))

(testing "invalid block-cache"
(given-thrown (ig/init {::kv/rocksdb {:block-cache ::invalid}})
Expand All @@ -75,9 +73,8 @@
:key := ::kv/rocksdb
:reason := ::ig/build-failed-spec
[:explain ::s/problems 0 :pred] := `(fn ~'[%] (contains? ~'% :dir))
[:explain ::s/problems 1 :pred] := `(fn ~'[%] (contains? ~'% :block-cache))
[:explain ::s/problems 2 :via] := [::rocksdb/stats]
[:explain ::s/problems 2 :val] := ::invalid)))
[:explain ::s/problems 1 :via] := [::rocksdb/stats]
[:explain ::s/problems 1 :val] := ::invalid)))


(deftest stats-collector-init-test
Expand Down
1 change: 0 additions & 1 deletion resources/blaze.edn
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,6 @@
;;
[:blaze.db.kv/rocksdb :blaze.db/resource-kv-store]
{:dir #blaze/cfg ["RESOURCE_DB_DIR" string? "resource"]
:block-cache #blaze/ref :blaze.db.kv.rocksdb/block-cache
:stats #blaze/ref :blaze.db.resource-kv-store/stats
:opts
{:wal-dir #blaze/cfg ["RESOURCE_DB_WAL_DIR" string? ""]
Expand Down

0 comments on commit 69cf8a6

Please sign in to comment.