I’m using: SWI-Prolog version 8.1.2, library(persistency) for a web application.
I want the code to:
Accept 8+ async requests via AJAX that do a read, retract and write on a persistent predicate stored in the attached db file. I want the db file to periodically sync, as this will be running as a web application if the process were to end it’s likely going to be in an unwanted and uncontrolled manner.
But what I’m getting is:
I’ll get about 6/8 requests succeed, but for a couple it’ll fail, telling me the database file doesn’t exist. I’m assuming this is because at that moment a gc operation is running. I’m hoping that I simply need to change the
db_sync(gc) to something else, but I’m somewhat confused as to what the best option would be. Only one module touches this database via 4 predicates that could potentially be called simultaneously.
My code looks like this:
:- persistent project(id:atom, situation:any). do_action(Action) :- user_current_project(ID), with_mutex(project_db, ( project(ID, Sit) , do(Action, Sit, NewSit) , retractall_project(ID, _) , assert_project(ID, NewSit) ) ), db_sync(gc).