[SQL 2005] Deadlock simulatie

Pagina: 1
Acties:
  • 305 views sinds 30-01-2008
  • Reageer

  • jeroendevries
  • Registratie: November 2000
  • Laatst online: 31-03-2025
Ik wil hier voor beginnende functionele testers een applicatie ontwikkelen zodat zij hier met test tools op kunnen testen. 1 van de test is het simuleren of het echt laten optreden van een deathlock in sql server. Heeft iemand een script die ervoor kan zorgen dat ik een deathlook veroorzaak in sql server.

Sex is like hacking. You get in, you get out, and you hope you didn't leave something behind that can be traced


  • Gonadan
  • Registratie: Februari 2004
  • Laatst online: 19:23

Gonadan

Admin Beeld & Geluid, Harde Waren
Schoolopdracht? Klinkt bekend namelijk :)

Ik weet niet meer precies wat het was, maar je moest 2 resources elkaar laten gebruiken ofzo.
Dan blijven ze op elkaar wachten.

Toch denk ik dat met een simpele zoekopdracht op Google of GoT dat je er zo bent. O-)

Look for the signal in your life, not the noise.

Canon R6 | RF 24-70 f/2.8 L | 50 f/1.8 STM | 430EX II
Sigma 85 f/1.4 Art | 100-400 Contemporary
Zeiss Distagon 21 f/2.8


  • P_de_B
  • Registratie: Juli 2003
  • Niet online
Weet je wat een deadlock is?
Deadlocking
A deadlock occurs when there is a cyclic dependency between two or more threads for some set of resources.

Deadlock is a condition that can occur on any system with multiple threads, not just on a relational database management system. A thread in a multi-threaded system may acquire one or more resources (for example, locks). If the resource being acquired is currently owned by another thread, the first thread may have to wait for the owning thread to release the target resource. The waiting thread is said to have a dependency on the owning thread for that particular resource.

If the owning thread wants to acquire another resource that is currently owned by the waiting thread, the situation becomes a deadlock: both threads cannot release the resources they own until their transactions are committed or rolled back, and their transactions cannot be committed or rolled back because they are waiting on resources the other owns. For example, thread T1 running transaction 1 has an exclusive lock on the Supplier table. Thread T2 running transaction 2 obtains an exclusive lock on the Part table, and then wants a lock on the Supplier table. Transaction 2 cannot obtain the lock because transaction 1 has it. Transaction 2 is blocked, waiting on transaction 1. Transaction 1 then wants a lock on the Part table, but cannot obtain it because transaction 2 has it locked. The transactions cannot release the locks held until the transaction is committed or rolled back. The transactions cannot commit or roll back because they require a lock held by the other transaction to continue.
Het is toch niet zo moeilijk dit te simuleren?

Oops! Google Chrome could not find www.rijks%20museum.nl


  • jeroendevries
  • Registratie: November 2000
  • Laatst online: 31-03-2025
nee geen school opdracht, en ik weet wat een deathlook is alleen sql server heeft zelf meganismes in zich om deatlocks te verkomen. Maar ik wil der graag 1 hebben of simuleren indien niet anders mogelijk.

Sex is like hacking. You get in, you get out, and you hope you didn't leave something behind that can be traced


  • kenneth
  • Registratie: September 2001
  • Niet online

kenneth

achter de duinen

Het is trouwens deadlock :) deathlook klinkt als een naam uit Monkey Island :P

Maar, je voert een operatie uit die een exclusieve lock op object A neemt, en vervolgens even niets doet en dan een exclusieve lock op object B neemt. Tegelijkertijd laat je een proces lopen dat het in omgekeerde volgorde doet.

Look, runners deal in discomfort. After you get past a certain point, that’s all there really is. There is no finesse here.


  • whoami
  • Registratie: December 2000
  • Laatst online: 18:08
SQL Server zal normaal gezien die deadlock zelf oplossen, door een deadlock victim te kiezen.
Ik weet niet of het mogelijk is om dit uit te schakelen.

Om deadlocks te voorkomen heb je trouwens meestal geen speciale tools nodig. Gewoon netjes programmeren, en ervoor zorgen dat je de resources altijd in dezelfde volgorde benaderd, zou al veel problemen moeten voorkomen.

[ Voor 43% gewijzigd door whoami op 03-04-2006 10:59 ]

https://fgheysels.github.io/


  • jeroendevries
  • Registratie: November 2000
  • Laatst online: 31-03-2025
Whoami,

Inderdaad maar ik wil het juist niet voorkomen, ik wil hem er keihard in zetten. Ik zal nog eens wat verder googlen, kwam wel wat in het duits tegen maar daar ben ik geen ster in.

Sex is like hacking. You get in, you get out, and you hope you didn't leave something behind that can be traced


  • jeroendevries
  • Registratie: November 2000
  • Laatst online: 31-03-2025
heb het 1 en ander gevonden:

In Query Analyzer, run the following statements first:

CREATE TABLE t1 (i int)
CREATE TABLE t2 (i int)

INSERT t1 SELECT 1
INSERT t2 SELECT 9

Open a new window (say Window1) in Query Analyzer, paste the following SQL statements:

BEGIN TRAN
UPDATE t1 SET i = 11 WHERE i = 1
WAITFOR DELAY ‘00:00:20′
UPDATE t2 SET i = 99 WHERE i = 9
COMMIT

Open another window (say Window2) in Query Analyzer and paste the following code:

BEGIN TRAN
UPDATE t2 SET i = 99 WHERE i = 9
WAITFOR DELAY ‘00:00:20′
UPDATE t1 SET i = 11 WHERE i = 1
COMMIT

Now run the code from Window1, followed by Window2 simultaneously. Briefly after 20 seconds, one of the windows will
experience a dead lock!

Even kijken of ik begrijp wat ze doen..

Sex is like hacking. You get in, you get out, and you hope you didn't leave something behind that can be traced


  • Gonadan
  • Registratie: Februari 2004
  • Laatst online: 19:23

Gonadan

Admin Beeld & Geluid, Harde Waren
Ze doen precies wat kenneth zei ;)

[ Voor 17% gewijzigd door Gonadan op 03-04-2006 11:11 ]

Look for the signal in your life, not the noise.

Canon R6 | RF 24-70 f/2.8 L | 50 f/1.8 STM | 430EX II
Sigma 85 f/1.4 Art | 100-400 Contemporary
Zeiss Distagon 21 f/2.8


  • whoami
  • Registratie: December 2000
  • Laatst online: 18:08
Ook daar wordt er volgens mij door Sql Server een victim gekozen als ik het goed heb (niet getest).
Echter, de Topicstart wil dus blijkbaar die functionaliteit (Sql Server die zelf een victim kiest), uitschakelen ?

https://fgheysels.github.io/


  • jeroendevries
  • Registratie: November 2000
  • Laatst online: 31-03-2025
Dat klopt whoami, ik wil dat uitschakelen.

Sex is like hacking. You get in, you get out, and you hope you didn't leave something behind that can be traced


  • Gonadan
  • Registratie: Februari 2004
  • Laatst online: 19:23

Gonadan

Admin Beeld & Geluid, Harde Waren
whoami schreef op maandag 03 april 2006 @ 11:14:
Ook daar wordt er volgens mij door Sql Server een victim gekozen als ik het goed heb (niet getest).
Echter, de Topicstart wil dus blijkbaar die functionaliteit (Sql Server die zelf een victim kiest), uitschakelen ?
Daar lijkt het wel op, hij wil een deadlock simuleren.
Dus dan moeten beveiligingen tegen een deadlock uitgeschakeld zijn.

Al begrijp ik niet waarom hij het wil simuleren.
Misschien om te testen of er wel beveiligingen op zitten ;)

Look for the signal in your life, not the noise.

Canon R6 | RF 24-70 f/2.8 L | 50 f/1.8 STM | 430EX II
Sigma 85 f/1.4 Art | 100-400 Contemporary
Zeiss Distagon 21 f/2.8


  • jeroendevries
  • Registratie: November 2000
  • Laatst online: 31-03-2025
Hoeft niet zo zeer simuleren te zijn hoor, het is geen productie database.

Sex is like hacking. You get in, you get out, and you hope you didn't leave something behind that can be traced


  • Gonadan
  • Registratie: Februari 2004
  • Laatst online: 19:23

Gonadan

Admin Beeld & Geluid, Harde Waren
jeroendevries schreef op maandag 03 april 2006 @ 11:21:
Hoeft niet zo zeer simuleren te zijn hoor, het is geen productie database.
:?

Als hij niet optreedt door gebruik van de software of site of wat dan ook, dan creëer de de deadlock handmatig.
Dat noem je toch simuleren? :)

si·mu·le·ren (ov.ww.)
1 (een ziekte) voorwenden
2 nabootsen

O-)

Look for the signal in your life, not the noise.

Canon R6 | RF 24-70 f/2.8 L | 50 f/1.8 STM | 430EX II
Sigma 85 f/1.4 Art | 100-400 Contemporary
Zeiss Distagon 21 f/2.8


  • P_de_B
  • Registratie: Juli 2003
  • Niet online
Wat SQL Server doet bij het kiezen van een deadlock victim is niet zozeer het voorkomen van een deadlock, die is immers dan al opgetreden. SQL Server zorgt er wel voor dat de hele database niet hangt door een transactie terug te draaien (de deadlock victim). Ik snap niet wat je wilt bereiken door dit mechanisme uit te willen schakelen?

Oops! Google Chrome could not find www.rijks%20museum.nl


Verwijderd

Your server command (process id #%d) was deadlocked with another process and has been chosen as deadlock victim. Re-run your command.
Is de bovenstaande melding dan niet voldoende? Er staat immers dat er een deadlock is ontstaan. Het heeft zowel voor SqlServer als voor de gebruiker geen nut om te wachten tot de deadlock zichzelf oplost.
Pagina: 1