lucaong / cubdb

Elixir embedded key/value database
Apache License 2.0
556 stars 23 forks source link

Errant files in db folder crash application permanently #35

Closed meyercm closed 3 years ago

meyercm commented 3 years ago

I copied a version of the database file that had an example of an application bug I've been chasing in it, for future analysis, but didn't change the folder immediately.

cp 4750.cub blah.cub

As soon as the next compaction started, the entire app crashed and couldn't restart, dying with:

** (ArgumentError) argument error
        :erlang.binary_to_integer("blah", 16)
        (cubdb 1.0.0-rc.9) lib/cubdb.ex:807: CubDB.file_name_to_n/1

The app immediately hit max restart intensity and died completely.

I thought I remembered a function that was supposed to weed out non-hex filenames, and I found it: CubDB.cubdb_file?/1, but quickly realized that the regex in it is wrong:

I've got a couple tests and a fix ready for you, I'll submit a PR in just a bit.

lucaong commented 3 years ago

Hi @meyercm , Thanks a lot for the bug report and the PR! I will check it tomorrow (it’s late here).

lucaong commented 3 years ago

Great catch 👍🏼 I just merged your PR and will release a new version soon