ahyatt / ekg

The emacs knowledge graph, app for notes and structured data.
GNU General Public License v3.0
230 stars 19 forks source link

disk I/O error #152

Closed walseb closed 3 months ago

walseb commented 3 months ago

Hello!

After I install this library on my Nixos laptop and run ekg-capture, I get an IO error.

Upon investigation, the error is with the ekg-add-schema function. When I run it, emacs gives with the following error:

Debugger entered--Lisp error: (sqlite-error "disk I/O error")
  sqlite-execute(#<sqlite db=0x47193388 name=/home/admin/.emacs.d/triples-4.db> "REPLACE INTO triples VALUES (?, ?, ?, ?)" ("text/mode" "base/unique" "t" "()"))
  triples-db-insert(#<sqlite db=0x47193388 name=/home/admin/.emacs.d/triples-4.db> text/mode base/unique t)
  apply(triples-db-insert #<sqlite db=0x47193388 name=/home/admin/.emacs.d/triples-4.db> (text/mode base/unique t))
  #f(compiled-function (triple) #<bytecode 0x1d7438b6fd243890>)((text/mode base/unique t))
  mapc(#f(compiled-function (triple) #<bytecode 0x1d7438b6fd243890>) ((text base/type schema) (text schema/property text) (text/text base/unique t) (text/text base/type string) (text schema/property mode) (text/mode base/unique t) (text/mode base/type symbol) (text schema/property inlines) (text/inlines base/virtual-reversed inline/for-text)))
  triples--add(#<sqlite db=0x47193388 name=/home/admin/.emacs.d/triples-4.db> (replace-subject-type (text base/type schema) (text schema/property text) (text/text base/unique t) (text/text base/type string) (text schema/property mode) (text/mode base/unique t) (text/mode base/type symbol) (text schema/property inlines) (text/inlines base/virtual-reversed inline/for-text)))
  triples-add-schema(#<sqlite db=0x47193388 name=/home/admin/.emacs.d/triples-4.db> text (text :base/unique t :base/type string) (mode :base/unique t :base/type symbol) (inlines :base/virtual-reversed inline/for-text))
  ekg-add-schema()
  eval((ekg-add-schema) nil)
  elisp--eval-last-sexp(nil)
  #f(compiled-function () #<bytecode 0x184a83b9b632a>)()
  eval-last-sexp(nil)

When entering the function and executing each step manually, the call to

(triples-add-schema ekg-db 'tagged '(tag :base/type string))

suceeds always unless I execute it too quickly. When it fails, it fails with the IO error above. Running the more complex calls to triples-add-schema fails more reliably.

Running it twice in a row makes it almost always fail:

(progn
(triples-add-schema ekg-db 'tagged '(tag :base/type string))
(triples-add-schema ekg-db 'tagged '(tag :base/type string)))

Running the function triples calls under the hood many times also causes the same IO error consistently:

(progn
  (sqlite-execute ekg-db "REPLACE INTO triples VALUES (?, ?, ?, ?)" '("text/mode" "base/unique" "t" "()"))
  (sqlite-execute ekg-db "REPLACE INTO triples VALUES (?, ?, ?, ?)" '("text/mode" "base/unique" "t" "()"))
  (sqlite-execute ekg-db "REPLACE INTO triples VALUES (?, ?, ?, ?)" '("text/mode" "base/unique" "t" "()"))
  (sqlite-execute ekg-db "REPLACE INTO triples VALUES (?, ?, ?, ?)" '("text/mode" "base/unique" "t" "()"))
  (sqlite-execute ekg-db "REPLACE INTO triples VALUES (?, ?, ?, ?)" '("text/mode" "base/unique" "t" "()"))
  (sqlite-execute ekg-db "REPLACE INTO triples VALUES (?, ?, ?, ?)" '("text/mode" "base/unique" "t" "()"))
  (sqlite-execute ekg-db "REPLACE INTO triples VALUES (?, ?, ?, ?)" '("text/mode" "base/unique" "t" "()"))
  (sqlite-execute ekg-db "REPLACE INTO triples VALUES (?, ?, ?, ?)" '("text/mode" "base/unique" "t" "()"))
  (sqlite-execute ekg-db "REPLACE INTO triples VALUES (?, ?, ?, ?)" '("text/mode" "base/unique" "t" "()")))

I haven't done much work with Sqlite in the past. Have you encountered something like this before in regard to the emacs sqlite library? Do you know what the issue could be?

I tried running hundereds of SQL write commands from the console as fast as possible and got no error.

Is there a way to make this library use the CLI version?

I have tried this in both Emacs 30 and Emacs 29.3 with the same results.

Thanks for any help!

walseb commented 3 months ago

I get the same error when running emacs -Q -l /home/admin/nixos/deps/emacs/sql-test.el where the contents of that file is:

(let ((con (sqlite-open "/home/admin/nixos/deps/emacs/triples.db")))
    (sqlite-execute con "REPLACE INTO triples VALUES (?, ?, ?, ?)" '("text/mode" "base/unique" "t" "()"))
    (sqlite-execute con "REPLACE INTO triples VALUES (?, ?, ?, ?)" '("text/mode" "base/unique" "t" "()"))
    (sqlite-execute con "REPLACE INTO triples VALUES (?, ?, ?, ?)" '("text/mode" "base/unique" "t" "()"))
    (sqlite-execute con "REPLACE INTO triples VALUES (?, ?, ?, ?)" '("text/mode" "base/unique" "t" "()"))
    (sqlite-execute con "REPLACE INTO triples VALUES (?, ?, ?, ?)" '("text/mode" "base/unique" "t" "()"))
    (sqlite-execute con "REPLACE INTO triples VALUES (?, ?, ?, ?)" '("text/mode" "base/unique" "t" "()"))
    (sqlite-execute con "REPLACE INTO triples VALUES (?, ?, ?, ?)" '("text/mode" "base/unique" "t" "()"))
    (sqlite-execute con "REPLACE INTO triples VALUES (?, ?, ?, ?)" '("text/mode" "base/unique" "t" "()"))
    (sqlite-execute con "REPLACE INTO triples VALUES (?, ?, ?, ?)" '("text/mode" "base/unique" "t" "()"))))

Probably it's a bug relating to emac's implementation of sqlite.

ahyatt commented 3 months ago

Thanks for the investigation! You should probably open an emacs bug (M-x report-emacs-bug) with a small test-case that you can verify in a plain emacs (emacs -Q).

For using ekg if sqlite-execute doesn't work, you can try using emacsql. Install the emacs package separately, and then (setq triples-sqlite-interface 'emacsql). This should work for you, let me know if you have issues.

walseb commented 3 months ago

Yes although my issue probably doesn't happen on anyone else's machine because it affects all complex or rapid calls to sqlite. I think this is related to my system configuration. I will try to test this issue on my other machines to see which parts of my configuration might be causing the issue.

Thanks so much for the tip! When using emacsql it works fine, although I'm getting an error after saving changes to an imported org-roam note. I will look into it more later.

I'm wondering, is there a simple way to interactively search across all note contents with a live preview of results? Like grep with consult? I didn't find any functions for that, and it was useful in org-roam when quickly searching for some note I remembered a part of that wasn't the tag.

Thanks so much for this package and the help!

ahyatt commented 3 months ago

We don't have the kind of search you are thinking of, although it'd be a good idea to add. What we do have is, llm-embedding, where you can do a semantic search after you hook up your notes to a provider of embeddings (Open AI, etc).