dbTalk Databases Forums  

DB exclusive mode

comp.databases.berkeley-db comp.databases.berkeley-db


Discuss DB exclusive mode in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
AT
 
Posts: n/a

Default DB exclusive mode - 05-09-2006 , 08:54 AM






Hi,
I am working on a deployment of berkeley DB, where must be possible
open the database in exclusive mode. I have thought to do that with
Locking.
But I don't understand how Locking Subsystem work. When I lock an
object, it doesn't concern to a DB: it's general.
So, if i've 2 DB with 2 records equal, which is the object locked?

Thanks


Reply With Quote
  #2  
Old   
Ron
 
Posts: n/a

Default Re: DB exclusive mode - 05-09-2006 , 02:12 PM






Hi,

Assuming everyone follows the same protocol this could work for you.
The protocol is everyone tries to obtain a lock and that determines if
they can go ahead and open the database with that access. The basic
outline:

All processes share the same Berkeley DB Environment.
1. Prior to open call env->lock_id and env->lock_get with the
appropriate access flag you are looking for. The object could be
"YourDatabase" as documented.
2. If you get the lock, you can open the database.
3. When database is closed free the lock and the locker id. (call
lock_put and lock_id_free).
4. close the environment.

I hope this helps.

Ron


Reply With Quote
  #3  
Old   
davide.belloni (AT) gmail (DOT) com
 
Posts: n/a

Default Re: DB exclusive mode - 05-10-2006 , 07:00 AM



"YourDatabase" is the DB* to the database?
Where i can find the docs that you named?
Thanks!


Reply With Quote
  #4  
Old   
Ron
 
Posts: n/a

Default Re: DB exclusive mode - 05-10-2006 , 08:38 AM



It is a DBT:
http://www.sleepycat.com/docs/api_c/lock_list.html

Ron


Reply With Quote
  #5  
Old   
davide.belloni (AT) gmail (DOT) com
 
Posts: n/a

Default Re: DB exclusive mode - 05-10-2006 , 09:07 AM



Ok, but to locking the entire database mydb, open so:

DB_ENV *myenv;
DB * mydb;
mydb->open(...)

i can call:
myenv->lock_get(myenv,locker,flags,(DBT *) mydb,lock_mode,lock);


Reply With Quote
  #6  
Old   
davide.belloni (AT) gmail (DOT) com
 
Posts: n/a

Default Re: DB exclusive mode - 05-10-2006 , 09:52 AM



Ok, but to locking the entire database mydb, open so:

DB_ENV *myenv;
DB * mydb;
mydb->open(...)

i can call:
myenv->lock_get(myenv,locker,flags,(DBT *) mydb,lock_mode,lock);


Reply With Quote
  #7  
Old   
Ron
 
Posts: n/a

Default Re: DB exclusive mode - 05-12-2006 , 12:14 PM



Davide,

I'm not sure about why you want to use this technique but something
*like* this can help serialize access if everyone follows the same
protocol.

{
int iret = 0;
char * mydb = "MYDBEXCL";
DBT theObject;
DB_LOCK theLock;
u_int32_t lkid;
memset (&theObject, 0, sizeof(DBT));
theObject.data = mydb;
theObject.size = 8;

iret = envCorp->lock_id(envCorp, &lkid);
iret = envCorp->lock_get(envCorp, lkid, DB_LOCK_NOWAIT, &theObject,
DB_LOCK_WRITE, &theLock);

//if(iret = envCorp->lock_get(envCorp, lkid, 0, &theObject,
DB_LOCK_WRITE, &theLock)!=0); //Another option wait for it
if (iret ==0) return EXIT_SUCCESS; //Allow DB Open

if(iret == DB_LOCK_NOTGRANTED)
{
printf("This is a DB_LOCK_NOTGRANTED Do not allow DB open\n");
return (DB_LOCK_NOTGRANTED);
}
else {
printf("Error Calling lock_get: %i\t%s", iret, db_strerror(iret));
return(EXIT_FAILURE);
}



}

Ron


Reply With Quote
  #8  
Old   
davide.belloni (AT) gmail (DOT) com
 
Posts: n/a

Default Re: DB exclusive mode - 05-15-2006 , 07:55 AM



Ok, this for only one DB.
But if i have an indefinite number of DB, and i would lock one or more
DB in exclusive mode, i've to lock omething of DB.
And my question is: can the object to be the DB Handler?
If no, how can i lock one or more DB in a set of indefinite DB?

Thanks for your patience


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.