cancel
Showing results for 
Search instead for 
Did you mean: 

CAP Node JS - Transaction handling problem on sqllite?

martinstenzig
Contributor
0 Kudos

Requirement

As part of a longer running service to execute a set of functionalities, I would like to update a processing status in a database table so I can read out that status from yet another service.

Problem description

if I would just execute a db.run with varying CQN statements (i.e. INSERT.into('Synchs').entries(data)), all updates happen as part of the same transaction bracket and I don't seem to get a proper start and update times in the database.

In order to separate out those "status updates" from the rest of the automatically created transaction bracket, I explicitly commit a transaction.

    const tx = connection.tx()
await tx.run(INSERT.into('Synchs').entries(data))
await tx.commit()

but there seem to be some sort of locking problem when running this locally against a SQLlite database.

I run three steps.

1. Insert into table within its own transaction bracket

2. Select on that table

3. Update on the table within its own transaction bracket -> THIS is where the code suddenly hangs.

What's interesting is that when I deploy the same code to the Cloud and run it against HANA, it works.

I created a repo to reproduce the behavior: https://github.com/MartinStenzig/cds-bug-3

Does anybody else observe this problem or am I incorrectly trying to separate out the status updates?

Also, if anybody else has any better ideas as to how to centrally (as I might have multiple instances of a service) monitor the status of long(er) running services, I am all ears.

View Entire Topic
heiko_witteborg
Explorer
0 Kudos

Hi Martin,

Indeed, parallel transactions are not allowed for SQLite, see warning in https://cap.cloud.sap/docs/node.js/cds-tx#manual-transactions.

I talked to the colleagues who implemented the new db layer in the upcoming cds 7: "by default the new sqlite implementation still doesn't allow for parallel transactions, but it is possible to increase the pool size and setting the new sqlite to use a file instead of memory and then it is possible." You might want to update (release will happen hopefully very soon) and try this approach.

Best regards,

Heiko