Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/konserve/filestore.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[konserve.protocols :as kp]
[konserve.utils :refer [async+sync *default-sync-translation*]]
[superv.async :refer [go-try- <?-]]
[taoensso.timbre :refer [info trace]])
[taoensso.timbre :refer [info debug]])
(:import
[java.io ByteArrayInputStream FileInputStream Closeable]
[java.nio.channels FileChannel AsynchronousFileChannel CompletionHandler FileLock]
Expand Down Expand Up @@ -240,7 +240,7 @@
(<?- ch)
(recur (+ buffer-size start-byte) (+ buffer-size stop-byte)))))
(catch Exception e
(trace "write-binary error: " e)
(debug "write-binary error: " e)
e)
(finally
(.close ^Closeable bis)))))
Expand All @@ -250,8 +250,13 @@
buffer (ByteBuffer/allocate header-size)]
(.read this buffer 0 header-size
(proxy [CompletionHandler] []
(completed [a b]
(put! ch (.array buffer)))
(completed [len _res]
(put! ch
(if-not (or (= 20 len) (= 8 len))
(do (debug "Header size does not match." len)
(ex-info "Header size does not match." {:type :header-size-does-not-match
:length len}))
(.array buffer))))
(failed [t _att]
(put! ch (ex-info "Could not read key."
(assoc msg :exception t))))))
Expand Down Expand Up @@ -309,7 +314,7 @@
ch)))
:size total-size}))
(catch Exception e
(trace "read-binary error: " e)
(debug "read-binary error: " e)
e)))))

(extend-type FileChannel
Expand Down Expand Up @@ -346,7 +351,10 @@
(-read-header [this _env]
(let [buffer (ByteBuffer/allocate header-size)
len (.read this buffer 0)]
(assert (or (= 20 len) (= 8 len)) (str "Header size does not match. Length: " len))
(when-not (or (= 20 len) (= 8 len))
(debug "Header size does not match." len)
(throw (ex-info "Header size does not match." {:type :header-size-does-not-match
:length len})))
(.array buffer)))
(-read-meta [this meta-size env]
(let [{:keys [header-size]} env
Expand Down