#1 2021-08-27 03:00:38

wxinix
Member
Registered: 2020-09-07
Posts: 121

mORMot2, TRestServerDB threadsafe?

Is TRestServerDB threadsafe?

In one running process, there is an active TRestServerDB instance, which itself is a SQLite in memory server.

I'd like to access that same TRestServerDB instance from different threads.  Is that allowed?

Offline

#2 2021-08-27 06:20:16

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,238
Website

Re: mORMot2, TRestServerDB threadsafe?

Of course, the whole REST framework is thread-safe.
It has to be, because when served over one of our HTTP servers, TRestServerDB is called from several threads at once.
Only your method based services code should be thread safe.
But the ORM layer is thread-safe.

Please ensure you read https://synopse.info/files/html/Synopse … ml#TITL_25
(also applied to mORMot 2)

Offline

#3 2021-08-27 11:26:35

wxinix
Member
Registered: 2020-09-07
Posts: 121

Re: mORMot2, TRestServerDB threadsafe?

ab wrote:

Of course, the whole REST framework is thread-safe.

Thank you very much.

Is it allowed to change SQL Model (e.g., adding more tables), and call VirtualTableExternalRegister again,  after TRestServerDB instance has been created?

For example:

FSQLModel := TSQLModel.Create([FTable1, FTable2]);
FServer := TRestServerDB.Create(FSQLModel, SQLITE_MEMORY_DATABASE_NAME, False, '');

Then, I need to add more tables FTable3, FTables4 to FSQLModel, LATER after FServer is created.  Can I used the following code?

FSQLModel.AddTable(FTable3);
FSQLModel.AddTable(FTable4);

Last edited by wxinix (2021-08-27 11:30:17)

Offline

#4 2021-08-27 12:59:51

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,238
Website

Re: mORMot2, TRestServerDB threadsafe?

It is not supported after CreateMissingTables is called.

It may somewhat work, but it may fail miserably in most use cases...

Offline

Board footer

Powered by FluxBB