dbTalk Databases Forums  

dbms_lock

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss dbms_lock in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
mh@pixar.com
 
Posts: n/a

Default dbms_lock - 08-08-2009 , 05:53 AM






I have a server program that should run in active/standby mode:

- a copy of the program is running on two different computers
- only one copy should be active
- if the active copy exits, fails, etc, the standby should take
over and become the active
- when the original active resumes, it is now the standby

Using a dbms_lock makes this quite simple, put this code
at the top of the program:

dbms_lock.allocate_unique('myserver', v_lockhandle);
v_result := dbms_lock.request(v_lockhandle, dbms_lock.x_mode);

1. Is there any problem with holding a lock for a long time? The
active may stay active for months on end.

2. If there is a problem with holding a lock for a long time,
what is a "reasonable" time to keep a lock open?

3. The most common way this lock will be released is for the
process or the computer to die. Are there any problems
related to this?

Many TIA,
Mark

--
Mark Harrison
Pixar Animation Studios

Reply With Quote
  #2  
Old   
Mark D Powell
 
Posts: n/a

Default Re: dbms_lock - 08-08-2009 , 01:19 PM






On Aug 8, 6:53*am, m... (AT) pixar (DOT) com wrote:
Quote:
I have a server program that should run in active/standby mode:

* *- a copy of the program is running on two different computers
* *- only one copy should be active
* *- if the active copy exits, fails, etc, the standby should take
* * *over and become the active
* *- when the original active resumes, it is now the standby

Using a dbms_lock makes this quite simple, put this code
at the top of the program:

* * dbms_lock.allocate_unique('myserver', v_lockhandle);
* * v_result := dbms_lock.request(v_lockhandle, dbms_lock.x_mode);

1. *Is there any problem with holding a lock for a long time? *The
* * active may stay active for months on end.

2. *If there is a problem with holding a lock for a long time,
* * what is a "reasonable" time to keep a lock open?

3. *The most common way this lock will be released is for the
* * process or the computer to die. *Are there any problems
* * related to this?

Many TIA,
Mark

--
Mark Harrison
Pixar Animation Studios
We have used user locks since Oracle introduced them, usually to
prevent concurrent running of a business process that cannot support
concurrent use. Most of our single-threaded processes use the timeout
parameter to notify the running program that the lock is in use,
meaning the process is already running, so the second execution
usually terminates. In cases where we just want to single thread the
process we either do not use the timeout or the program loops and
tries again a few seconds latter.

In theory you can wait forever though I have to wonder if a program
that was blocked for months would not get swapped out or otherwise be
subject to some type of network/OS timeout depending on your
environment.

I would say try it and see how it works. You could always change the
program(s) to poll for the lock, sleep, and try again so it is an
active process. This second approach would be my approach to the
problem.

I do not see any issue with a session holding the UL for as long as
the instance is running even if it is months. Oracle does the same
with file recovery locks.

HTH -- Mark D Powell --




Is the standby process going to be lock waited this entire time, or
are you going to use the timeout parameters so the second session will
be notified the lock is being held and it will cycle through logic

Reply With Quote
  #3  
Old   
mh@pixar.com
 
Posts: n/a

Default Re: dbms_lock - 08-20-2009 , 07:52 PM



Mark D Powell <Mark.Powell (AT) eds (DOT) com> wrote:
Quote:
I do not see any issue with a session holding the UL for as long as
the instance is running even if it is months. Oracle does the same
with file recovery locks.
This is perfect. I have an active/standby server pair running behind
a load-balancer. It's important that only the active is processing
messages, since there is some program state involved.

Now I can
- open the DB connection
- grab the lock
- start the service

and the database locking takes care of the exclusive active/standby
portion, and the load-balancing switch takes care of routing the
traffic to the box that has the service running.

I am very pleased, I used to do this kind of coding for telecom
apps and it was a lot of work to get it running and debugged!

Thanks again!!
Mark





--
Mark Harrison
Pixar Animation Studios

Reply With Quote
Reply




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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.