Open
Description
I have this code which is designed to atomically read/write a counter in the DB:
const db = new sql.Database(dbPth, function (err) {
// error handling logic removed for simplicity
db.configure('busyTimeout', 4000);
db.serialize(function () {
db.run('BEGIN EXCLUSIVE TRANSACTION;');
db.all('SELECT run_id from suman_run_id', function (err, rows) {
// error handling logic removed for simplicity
db.serialize(function () {
const runId = rows[0] ? rows[0].run_id : 1;
const updatedValue = runId + 1;
db.run('UPDATE suman_run_id SET run_id = ' + updatedValue);
db.run('COMMIT TRANSACTION;', function (err) {
db.close();
err ? first(err) : createDir(runId);
});
});
});
});
});
my concern is that for even this simple use case of merely creating an atomic read/write with an exclusive transaction, with several concurrent requests to get the lock on the transaction, there is a high likelihood of failure due to timeout.
My feeling is that there may be some work to be done to improve this part of the code. Do you at least agree that there may be some performance improvements here? Is it possible to improve it? thanks