You are not logged in.
Pages: 1
I'm implementing an interface based service and would like to run each request in a database transaction.
My first attempt was to use an interceptor, it worked, something like this:
procedure TRESTServer.TransactionInterceptor(Sender: TServiceMethodExecute; Step: TServiceMethodExecuteEventStep);
begin
case Step of
smsBefore: BeginTransaction;
smsAfter: Commit;
smsError: Rollback;
end;
end;
The problem is that if the client timesout and is not able to process the result, the `smsAfter` is executed and the transaction is commited.
From what I've noticed in the code, when the timeout occurs the exception is handled in this code:
on E: Exception do
// handle any exception raised during process: show must go on!
if not E.InheritsFrom(EHttpApiServer) or // ensure still connected
(EHttpApiServer(E).LastError<>HTTPAPI_ERROR_NONEXISTENTCONNECTION) then
SendError(STATUS_SERVERERROR,E.Message,E);
The problem is that in the case of client disconnect, it just ignores the error and I can't rollback the transaction.
Is it possible to do this somehow?
Offline
Currently, the idea is to use a TSQLRestBatch and not use manual transaction.
With such a Batch, the transaction is alive during the process of all items, in a very short time, and with explicit and immediate error/rollback process.
To handle such timeout issues, and let several transactions open concurrently is very difficult to manage and do properly...
This is why we usually go into the UnitOfWork pattern, implemented via a Batch.
Online
Yes, the batch mode is very efficient and useful!
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
Unfortunately, this wouldn't work for us.
We need to control the database transaction on the server-side.
We have multiple mormot servers running in parallel (AWS AutoScaling) and receiving the load from a Elastic Load Balancer, so, client requests can hit different servers.
The problem that we are trying to solve is this: A client made a destructive call to the server (Insert/Delete/Update) but the connection was interrupted (client timeout, etc.). In that case, the client would assume that none of the changes are applyed on the database, so, we would like to rollback the transaction if anything goes wrong.
Offline
AB,
Can TSQLRestBatch be used with the crossplatform units?
Offline
Thanks!
I have searched the crossplatform units for 'TSQLRestBatch and came up empty. I should have searched just for 'batch'.
Last edited by Leslie7 (2016-02-27 16:53:53)
Offline
So, I can't handle transactions manually on the server side in case of client timeouts?
Offline
Pages: 1