#1  
Old 29th October 2024, 09:35 PM
Enrico Enrico is offline
Senior Member
 
Join Date: Apr 2009
Posts: 312
Default Nested transactions> Do I understand it correctly?

" Proper support of nested transactions means that you may commit or rollback an inner or nested transaction without affecting the outer transaction's ability to commit or rollback.".
Does this mean that I can have something like this, and still ensure that in the end either is all committed or nothing is? (I omit the RETRY stuff for simplicity of the example)
And if this pseudo-code is correct, if another user is waitng to access the affected tableS, right after the inner commit would he be allowed to start his transaction?
Code:
procedure do_long_update();*
var
  i: integer;
begin

  for i:=1 t0 100000 do begin
    starttransaction;
    try
      for n:=1 to i+110000 do
          update_it();
      commit;
    except
      raise;
    end;
  end;

end;

procedure main;
begin
  starttransaction
  try*
    do_long_update();*
    commit();
  except* *
     on E:Sysutils.Exception do begin
         rollback;
        show(e.message)
     end;

  end;
end;
  #2  
Old 30th October 2024, 06:50 AM
Enrico Enrico is offline
Senior Member
 
Join Date: Apr 2009
Posts: 312
Default

Sorry. This seems to make a little bit more sense?
Code:
procedure do_long_update();*
var
  i: integer;
begin

  for i:=1 t0 100000 do begin
    if i=1 then
       starttransaction;
    try
      if 1000000 mod 10000 =0 do
          update_it();
      commit;
      starttransaction
    except
      rollback;
      raise;
    end;
  end;
  if inTransaction then
   commit;

end;
  #3  
Old 30th October 2024, 11:14 PM
Eivind
 
Posts: n/a
Default Re: Nested transactions> Do I understand it correctly?

> Does this mean that I can have something like this, and still ensure
> that in the end either is all committed or nothing is? (I omit the
> RETRY stuff for simplicity of the example)


That's essentially what the quoted text says. The outermost (first
started / "parent" transaction if you like) in the end controls if
everything is either committed or rolled back.

> And if this pseudo-code is correct, if another user is waitng to
> access the affected tableS, right after the inner commit would he be
> allowed to start his transaction?


If the table(s) in the inner transaction are not also referenced in the
outer transaction, then I think the answer would be yes. Thorsten?



--
Eivind Bakkestuen [NDD]
  #4  
Old 31st October 2024, 10:14 AM
Enrico Enrico is offline
Senior Member
 
Join Date: Apr 2009
Posts: 312
Default

Thanks Eivind.
In my example, the outer transaction does "nothing" except ensuring that the inner transaction is committed or rolled back.

Between Starttransacion/Commit/Rollback in the outer code there is no touching of the tables at all.
My intent is to avoid "freezing" the second user for too long: to that purpose I spawn the update to the inner code where commit() startransaction() gives the second user a chance to move on.
I have not seen Thorsten's answer to your question.
Can I assume my "logic" is correct?
Thanks.
  #5  
Old 31st October 2024, 12:06 PM
Eivind
 
Posts: n/a
Default Re: Nested transactions> Do I understand it correctly?

> My intent is to avoid "freezing" the second user for too long: to that
> purpose I spawn the update to the inner code where commit()
> startransaction() gives the second user a chance to move on.


Actually, thinking about it, my previous answer was likely wrong. In
order to preserve transaction integrity for the outer transaction,
table locks in the inner transaction must propagate to the outer, and
have to stay in place for the outer transaction's duration. Otherwise,
integrity would not be guaranteed if other clients could update tables
while the outer transaction was still active.

So, nested transactions won't help.

What amount of record updates are you expecting to for a large update?
How regularly?

--
Eivind Bakkestuen [NDD]
  #6  
Old 31st October 2024, 02:00 PM
Thorsten Engler [NDA]
 
Posts: n/a
Default Re: Nested transactions> Do I understand it correctly?

Eivind wrote:

> > And if this pseudo-code is correct, if another user is waitng to
> > access the affected tableS, right after the inner commit would he be
> > allowed to start his transaction?

>
> If the table(s) in the inner transaction are not also referenced in the
> outer transaction, then I think the answer would be yes. Thorsten?


The inner transaction, and all its changes and locks, become part of the next
outer transaction on a nested commit.
  #7  
Old 9th November 2024, 07:19 AM
Enrico Enrico is offline
Senior Member
 
Join Date: Apr 2009
Posts: 312
Default

Hi Eivind.
The thing is that I am making a test with a large number of updates.
Say some 5,000 passes, each pass contains an Edit and an Insert on a table with record length of 152 bytes. But there are a dozen smoller tables that need to be updated concurrently, some with Edits, some with Inserts.
The test takes about 40 seconds on a PC with SSD.disk (75 on the other
hard-drive PC).
My only option is to raise the number of RETRY?
  #8  
Old 9th November 2024, 01:20 PM
Eivind
 
Posts: n/a
Default Re: Nested transactions> Do I understand it correctly?

> My only option is to raise the number of RETRY?

That, and reducing the time the entire operation takes, if possible. If
you are using TnxTable components and you are doing this using a
transport to connect to a remote NexusDB Server, batch operations may
help reduce message overhead.

--
Eivind Bakkestuen [NDD]


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Understanding exception correctly David Rose nexusdb.public.support 1 26th May 2023 12:48 PM
Sql timeout and can't understand why... Roberto Nicchi nexusdb.public.support.sql 8 10th May 2022 01:39 AM
The filter don't returns records correctly (NexusDB 3.1202) Samuel nexusdb.public.support 2 11th September 2013 03:54 PM
V1 odbc drivers issue: ADO Queries not working correctly in VB6 Darren Reist nexusdb.public.support.odbc 7 21st September 2006 07:22 AM
Don't understand the following line Bernhard Roos nexusdb.public.support 3 6th December 2005 09:26 PM


All times are GMT +11. The time now is 09:42 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.