I have a Mnesia database and when I restart my application, I get an error (badarg) in the pending transactions. I think an invalid value was about to be inserted. How can I inspect the pending transactions to look up what the bad value is and how can I drop that value from the pending transactions without deleting the whole database.
Update:
The crash report is the following:
{badarg, [{ets, insert, [{image_db...}, {image_db...}...]
Where image_db
is my struct which gets inserted into the database. Unforunately the list of items to get inserted is so long, that I don't see the corrupt value.
The command mnesia:info()
shows me 1 aborted transaction on startup.
Update 2:
How can I read the binary log files in the mnesia db directory?
Update 3:
It's a local single-node Mnesia Table. I initialize it like this:
mnesia:stop(),
catch(mnesia:create_schema([node()])),
mnesia:start(),
timer:sleep(1000), % vital but ugly as hell
mnesia:create_table(?DBNAME, [{disc_copies, [node()]}, {type, ordered_set},
{attributes, record_info(fields, image_db)}]),
mnesia:wait_for_tables(?DBNAME, 1000),
where the image_db
record looks like this:
-type now_time() :: {integer(), integer(), integer() }.
-record(image_db, {time :: now_time(),
path :: string(),
size :: integer() }).
The Problem appears from time to time, I think after an invalid record gets inserted into the db. I added a record-validation function now to avoid this, but the question still remains, how to recover the database by dropping the invalid values in the stored transactions?