Fork me on GitHub
#datahike
<
2023-03-17
>
jjttjj20:03:22

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 ๐Ÿงต

2
jjttjj20:03:37

#error {
 :cause nil
 :via
 [{: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 "Objects.java" 208]}]
 :trace
 [[java.util.Objects requireNonNull "Objects.java" 208]
  [sun.nio.fs.UnixFileSystem getPath "UnixFileSystem.java" 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]
  [datahike.store$eval47429$fn__47431 invoke "store.cljc" 116]
  [clojure.lang.MultiFn invoke "MultiFn.java" 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 "AFn.java" 154]
  [clojure.lang.AFn applyTo "AFn.java" 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 "RestFn.java" 408]
  [clojure.lang.MultiFn invoke "MultiFn.java" 229]
  [clojure.lang.AFn applyToHelper "AFn.java" 154]
  [clojure.lang.AFn applyTo "AFn.java" 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 "RestFn.java" 408]
...
 

jjttjj20:03:04

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

whilo22:03:09

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

whilo22:03:49

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

whilo22:03:51

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

whilo23:03:11

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

whilo23:03:24

:id only works for :memory.

jjttjj15:03:54

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

whilo17:03:11

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

jjttjj17:03:15

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

whilo18:03:04

Ok, let me check that later.

๐Ÿ™ 2
whilo18:03:42

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

whilo18:03:22

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

jjttjj18:03:16

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

whilo18:03:35

Ok, thanks!

whilo21:03:35

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

whilo01:03:39

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.

jjttjj03:03:00

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.