Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

langc interface and catching exceptions #27

Closed
prajnoha opened this issue Feb 15, 2022 · 6 comments
Closed

langc interface and catching exceptions #27

prajnoha opened this issue Feb 15, 2022 · 6 comments

Comments

@prajnoha
Copy link

Is the langc interface catching all exceptions and returning them/translating them into TkrzwStatus?

I'm specifically interested in what happens if, for example, the malloc inside an API call fails. I've tried this through gdb quickly, inducing the malloc to return NULL and I got SIGART due to the default exception handling taking place. That is, exception is "unhandled".

Also, I'm interested in what happens if during ProcessMulti (tkrzw_dbm_process_multi in langc API) there's a fail in a processing one record (like that allocation failure) while we're in the middle of the overall processing and there area records already processed successfully. Is the transaction discarded and original values for already processed/edited records put back and new records discarded?

@estraier
Copy link
Owner

estraier commented Feb 15, 2022 via email

@estraier
Copy link
Owner

estraier commented Feb 15, 2022 via email

@prajnoha
Copy link
Author

Whereas writing the "cache" block in each langc functions is a possible workaround, I haven't done it because there's few practical ways to recover from malloc's failure.

By default, any updating operations of Tkrzw including ProcessMulti could result in data loss and inconsistency if the process crashes during the operation. Meanwhile, you can configure it for ACID properties of transactions. Please take a look at these sections in the document. https://dbmx.net/tkrzw/#tips_restore https://dbmx.net/tkrzw/#tips_acid

For that, I'd need to write the database to a file. I don't actually mind if the database is not durable enough and I'm counting only with in-memory database use. If anything fails, I can just throw away all the existing database and recreate it quite easily. For that, it would be great if we had a way to detect this condition so I can act appropriately. Receiving SIGABRT is just very rough for that. In general, the SIGABRT may have different reasons/sources so it's harder to detect that it comes exactly because the malloc inside a library failed. Getting proper return value in all failure cases (including the failed malloc) would be of great help here.

@estraier
Copy link
Owner

estraier commented Feb 15, 2022 via email

@estraier
Copy link
Owner

I modified the C interface and released 1.0.23.
Now, every function of the C interface is guarded by the catch block and returns false/null/0 when exceptions are thrown.

@prajnoha
Copy link
Author

Great! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants