 (defmethod state-extensions/close-log onyx.state.log.bookkeeper.BookKeeperLog
   [{:keys [client ledger-handle next-ledger-handle]} event] 
   (try
-    (close-handle @ledger-handle)
+    (when @ledger-handle 
+      (close-handle @ledger-handle))
     (when @next-ledger-handle
       (close-handle @next-ledger-handle))
     (catch Throwable t

  (:require [onyx.log.curator :as curator]
            [taoensso.timbre :refer [info error warn trace fatal] :as timbre]
            [com.stuartsierra.component :as component]
            [clojure.core.async :refer  [chan timeout thread go >! <! <!! >!! alts!! close!]]
            [onyx.compression.nippy :as nippy]
            [onyx.extensions :as extensions]
            [onyx.monitoring.measurements :refer [emit-latency-value emit-latency]]


(def HandleWriteCallback
  (reify AsyncCallback$AddCallback
    (addComplete [this rc lh entry-id [success-fn fail-fn]]
      (if (= rc (BKException$Code/OK))
        (success-fn)
        (do (warn "Unable to complete async write to bookkeeper. BookKeeper exception code:" rc)
            (fail-fn))))))

(defn compaction-transition 
  "Transitions to a new compacted ledger, plus a newly created ledger created
