dbTalk Databases Forums  

failchk and set_isalive with Concurrent Datastore

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


Discuss failchk and set_isalive with Concurrent Datastore in the comp.databases.berkeley-db forum.



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

Default failchk and set_isalive with Concurrent Datastore - 05-16-2006 , 06:39 AM






Hi

has anyone succesfully used the failure checking mechanism of
DB_ENV->failchk with the Concurrent Datastore instead of the
Transactional one?
http://www.sleepycat.com/docs/ref/cam/fail.html
says you can use this method. However, when I try the following code, I
get the error:

"ex_env: is_alive method specified but no thread region allocated
DB_ENV->set_isalive: Invalid argument"

from set_isalive() via the set_errfile() function. This is on
Centos 4.3 Linux with db-4.4.20

Any suggestions?
Thanks,
Arno

/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1996-2005
* Sleepycat Software. All rights reserved.
*
* $Id: ex_env.c,v 12.1 2005/06/16 20:22:03 bostic Exp $
*/

#include <sys/types.h>

#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>

#include <db.h>

#ifdef macintosh
#define DATABASE_HOME ":database"
#define CONFIG_DATA_DIR ":database"
#else
#ifdef DB_WIN32
#define DATABASE_HOME "\\tmp\\database"
#define CONFIG_DATA_DIR "\\database\\files"
#else
#define DATABASE_HOME "/home/arno/.Tribler/bsddb"
#define CONFIG_DATA_DIR "/home/arno/.Tribler/bsddb"
#endif
#endif

int db_setup __P((const char *, const char *, FILE *, const char *));
int db_teardown __P((const char *, const char *, FILE *, const char *));
int main __P((void));


int arno_is_alive(DB_ENV *dbenv, pid_t pid, db_threadid_t tid)
{
return 0; /* all souls lost */
}



/*
* An example of a program creating/configuring a Berkeley DB environment.
*/
int
main()
{
const char *data_dir, *home;
const char *progname = "ex_env"; /* Program name. */

/*
* All of the shared database files live in DATABASE_HOME, but
* data files will live in CONFIG_DATA_DIR.
*/
home = DATABASE_HOME;
data_dir = CONFIG_DATA_DIR;

printf("Setup env\n");
if (db_setup(home, data_dir, stderr, progname) != 0)
return (EXIT_FAILURE);

printf("Teardown env\n");
if (db_teardown(home, data_dir, stderr, progname) != 0)
return (EXIT_FAILURE);

return (EXIT_SUCCESS);
}

int
db_setup(home, data_dir, errfp, progname)
const char *home, *data_dir, *progname;
FILE *errfp;
{
DB_ENV *dbenv;
int ret;

/*
* Create an environment object and initialize it for error
* reporting.
*/
if ((ret = db_env_create(&dbenv, 0)) != 0) {
fprintf(errfp, "%s: %s\n", progname, db_strerror(ret));
return (1);
}


dbenv->set_errfile(dbenv, errfp);
dbenv->set_errpfx(dbenv, progname);

/* if ((ret = dbenv->set_thread_count(dbenv, 8)) != 0) {
fprintf(stderr, "DB_ENV->set_thread_count: %s\n",
db_strerror(ret));
return (1);
}*/


/*
* We want to specify the shared memory buffer pool cachesize,
* but everything else is the default.
*/
if ((ret = dbenv->set_cachesize(dbenv, 0, 64 * 1024, 0)) != 0) {
dbenv->err(dbenv, ret, "set_cachesize");
dbenv->close(dbenv, 0);
return (1);
}

/* Databases are in a subdirectory. */
/* (void)dbenv->set_data_dir(dbenv, data_dir); */



/* Open the environment with full transactional support. */
if ((ret = dbenv->open(dbenv, home,
DB_CREATE | DB_INIT_CDB | DB_INIT_MPOOL | DB_THREAD,
0)) != 0) {
dbenv->err(dbenv, ret, "environment open: %s", home);
dbenv->close(dbenv, 0);
return (1);
}


/* Do something interesting... */

if ((ret = dbenv->set_isalive(dbenv, arno_is_alive)) != 0) {
fprintf(stderr, "DB_ENV->set_isalive: %s\n",
db_strerror(ret));
return (1);
}

if ((ret = dbenv->failchk(dbenv, 0)) != 0) {
fprintf(stderr, "DB_ENV->failchk: %s\n", db_strerror(ret));
return (1);
}


/* Close the handle. */
if ((ret = dbenv->close(dbenv, 0)) != 0) {
fprintf(stderr, "DB_ENV->close: %s\n", db_strerror(ret));
return (1);
}
return (0);
}

int
db_teardown(home, data_dir, errfp, progname)
const char *home, *data_dir, *progname;
FILE *errfp;
{
DB_ENV *dbenv;
int ret;
return 0;

/* Remove the shared database regions. */
if ((ret = db_env_create(&dbenv, 0)) != 0) {
fprintf(errfp, "%s: %s\n", progname, db_strerror(ret));
return (1);
}
dbenv->set_errfile(dbenv, errfp);
dbenv->set_errpfx(dbenv, progname);

(void)dbenv->set_data_dir(dbenv, data_dir);
if ((ret = dbenv->remove(dbenv, home, 0)) != 0) {
fprintf(stderr, "DB_ENV->remove: %s\n", db_strerror(ret));
return (1);
}
return (0);
}

Reply With Quote
  #2  
Old   
Joseph Bruni
 
Posts: n/a

Default Re: failchk and set_isalive with Concurrent Datastore - 05-16-2006 , 09:38 PM







Arno Bakker <arno=trn (AT) cs (DOT) vu.nl> wrote:
Quote:

Hi

has anyone succesfully used the failure checking mechanism of
DB_ENV->failchk with the Concurrent Datastore instead of the
Transactional one?
http://www.sleepycat.com/docs/ref/cam/fail.html
says you can use this method. However, when I try the following code, I
get the error:

"ex_env: is_alive method specified but no thread region allocated
DB_ENV->set_isalive: Invalid argument"

from set_isalive() via the set_errfile() function. This is on
Centos 4.3 Linux with db-4.4.20

Any suggestions?
Thanks,
Arno


Yes. A couple months ago, I experienced the same pain that you're
currently going through. As described in the SleepyCat documentation, you'll
need to define a process or thread that periodically calls
DB_ENV->failchk(). Before you can do this, you must set an "is_alive" function on your
environment. This function must be able to determine if the thread or
process in question (based on the input pid or tid parameter) is still
alive and return the appropriate value (see the documentation for
set_is_alive). On Linux, you should be able to simply check /proc for the pid.
If your function returns false for the given process or thread, DB will
release the locks leaked by that (non-existent) process.
Now, before you can call set_is_alive(), you'll need to call the
function DB_ENV->set_thread_count() with a value that should be large enough to
contain the most threads/processes you might encounter.
Also -- and this is very important -- there is a memory leak bug in the
GA 4.4.20 that will cause a crash if you call failchk() enough times.
SleepyCat supplied me with a patch to address this problem. Please contact
them at support (AT) sleepcat (DOT) com for the failchk() patch.





Reply With Quote
  #3  
Old   
Arno Bakker
 
Posts: n/a

Default Re: failchk and set_isalive with Concurrent Datastore - 05-17-2006 , 01:54 AM



Joseph Bruni wrote:
Quote:
Now, before you can call set_is_alive(), you'll need to call the
function DB_ENV->set_thread_count() with a value that should be large enough to
contain the most threads/processes you might encounter.
Also -- and this is very important -- there is a memory leak bug in the
GA 4.4.20 that will cause a crash if you call failchk() enough times.
SleepyCat supplied me with a patch to address this problem. Please contact
them at support (AT) sleepcat (DOT) com for the failchk() patch.

Thanks for the reply. I came across that remark in a forum, but it
doesn't work for me. When I place a set_thread_count(256) before the
DB_ENV->open(), I get:

ex_env: thread table must be allocated at environment create time
ex_env: environment open: /home/arno/.Tribler/bsddb: Invalid argument

When I place the call after the open and before the set_isalive() I get:

ex_env: DB_ENV->set_thread_count: method not permitted after handle's
open method
DB_ENV->set_thread_count: Invalid argument

(the same for 8 and 32 threads).

So I'm still stuck :-(
Arno


Reply With Quote
  #4  
Old   
Arno Bakker
 
Posts: n/a

Default Re: failchk and set_isalive with Concurrent Datastore - 05-17-2006 , 02:30 AM



Arno Bakker wrote:
Quote:
So I'm still stuck :-(

Just found out that it works when using the database in single-process
mode, that is, when you specify the DB_PRIVATE when creating the
environment. Note that the database will ask whether the current
process/thread is still alive (!). Issue remains why this
doesn't work in standard = multi-process mode.

Arno


Reply With Quote
  #5  
Old   
EelBait
 
Posts: n/a

Default Re: failchk and set_isalive with Concurrent Datastore - 05-17-2006 , 11:02 AM




Arno Bakker wrote:
Quote:
Arno Bakker wrote:

So I'm still stuck :-(


Just found out that it works when using the database in single-process
mode, that is, when you specify the DB_PRIVATE when creating the
environment. Note that the database will ask whether the current
process/thread is still alive (!). Issue remains why this
doesn't work in standard = multi-process mode.

Arno

It does work. You'll need to remove the environment and re-create it
with the thread count set prior to the open. In your environment
directory, remove the __DB* files. Then make sure you call
set_thread_count() prior to the call to DB_ENV->open that specifies the
DB_CREATE. This will allocate the thread table when the environment is
created.

-Joe



Reply With Quote
  #6  
Old   
EelBait
 
Posts: n/a

Default Re: failchk and set_isalive with Concurrent Datastore - 05-17-2006 , 11:45 AM



By the way, when you contact sleepcat for the patch, specify that it is
for #14425 in their issue database.

-Joe


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.