Fork me on GitHub

I seem to keep getting an NPE when I try to delete a :file database:

(def cfg {:store              {:backend :file
                                 :id      "db1"}
            :name               "db1"
            :schema-flexibility :write
            :keep-history?      true
            :attribute-refs?    true})

  (d/delete-database cfg)
This seems to happen whether or not the db was previously created. Error message in ๐Ÿงต


#error {
 :cause nil
 [{:type clojure.lang.ExceptionInfo
   :message "java.lang.NullPointerException"
   :data {}
   :at [superv.async$throw_if_exception_ invokeStatic "async.cljc" 93]}
  {:type java.lang.NullPointerException
   :message nil
   :at [java.util.Objects requireNonNull "" 208]}]
 [[java.util.Objects requireNonNull "" 208]
  [sun.nio.fs.UnixFileSystem getPath "" 263]
  [konserve.filestore$sync_base invokeStatic "filestore.clj" 34]
  [konserve.filestore$sync_base invoke "filestore.clj" 31]
  [konserve.filestore$delete_store invokeStatic "filestore.clj" 60]
  [konserve.filestore$delete_store invoke "filestore.clj" 51]
  [$eval47429$fn__47431 invoke "store.cljc" 116]
  [clojure.lang.MultiFn invoke "" 229]
  [datahike.writing$eval52657$fn__52666 invoke "writing.cljc" 207]
  [datahike.writing$eval52608$fn__52609$G__52597__52614 invoke "writing.cljc" 136]
  [datahike.writing$delete_database invokeStatic "writing.cljc" 223]
  [datahike.writing$delete_database invoke "writing.cljc" 217]
  [clojure.lang.AFn applyToHelper "" 154]
  [clojure.lang.AFn applyTo "" 144]
  [clojure.core$apply invokeStatic "core.clj" 667]
  [clojure.core$apply invoke "core.clj" 662]
  [datahike.writer$eval52982$fn__52983 doInvoke "writer.cljc" 99]
  [clojure.lang.RestFn invoke "" 408]
  [clojure.lang.MultiFn invoke "" 229]
  [clojure.lang.AFn applyToHelper "" 154]
  [clojure.lang.AFn applyTo "" 144]
  [clojure.core$apply invokeStatic "core.clj" 667]
  [clojure.core$apply invoke "core.clj" 662]
  [datahike.api$delete_database invokeStatic "api.cljc" 130]
  [datahike.api$delete_database doInvoke "api.cljc" 129]
  [clojure.lang.RestFn invoke "" 408]


Using io.replikativ/datahike {:mvn/version "0.6.1539"}


Hey @U4Q7NLNMC! Thanks for reporting. Can you open an issue? I will take a look into it later today.


I refactored the database management functions recently and might have overlooked something.


Deleting the store equals removing all files from the store directory for the filestore, in case you need a quick temporary fix.


Oh, you need to actually provide a :path for the file backend.


:id only works for :memory.


Thanks for checking! I'm still unable to get delete-database to work with a :file db

(def cfg2 {:store              {:backend :file
                                  :path    "datahike-cfg2"}
             :name               "db2"
             :schema-flexibility :write
             :keep-history?      true
             :attribute-refs?    true})

  (d/delete-database cfg2) ;; NPE before create

  (d/create-database cfg2)

  ;; I think it deletes something but still throws NPE
  ;; (this happens regardless of if delete-database was called  earlier)
  (d/delete-database cfg2) 
I've tried variations where I connect and add schema as well but generally the same thing happens. edit: I do realize I could just delete the directory. And I'll open up a github issue


Thanks for opening an issue! :path is a file system path, e.g. "/tmp/my-datahike-db"on Unix.


yeah I assumed a relative path would be fine (and seems to work when not using delete-database)


Ok, let me check that later.

๐Ÿ™ 2

Just to check. Does it work if you use the absolute path?


And also, did this work with older Datahike versions for you?


I didn't try any other versions than the most recent. I didn't think to try absolute path for some reason but I can try it tonight


Ok, thanks!


It would be interesting to know whether (.getParent (io/file path)) is nil.


I can reproduce. I am thinking about whether we want to support relative paths, because the config should actually uniquely locate a store globally. This is not enforced yet and local stores are fine, but it can have unintended consequences atm. E..g when you connect to the file store from another process with another relative directory the same config will not work.


Oh yeah, that makes sense. Sorry I haven't been at a computer to try it out. If it's just a matter of using an absolute path that's no problem. I was coming from datalevin to try out datahike and the relative paths worked there, but likely it makes more sense in that context since only a single process at a time can touch the files.