Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Berkeley DB: Corrupt DB Question

3 views
Skip to first unread message

Mark D Wolinski

unread,
Aug 21, 1999, 3:00:00 AM8/21/99
to
I'm using Berkeley DB 2.x in a Linux environment via Perl with DB_File.
The database I'm creating is a hash database.

Via Perl, I'm locking and unlocking the database as I believe I should,
ie read access when reading, write access when writing to the database
and SYNCing before I close, etc.

Via the web, the database is opened, key/values read as needed, and then
closed. There may be multiple accesses to the database at the same time
from different people.

The problem I'm having is this:

On occasion, a database file will be corrupt where a key/value is no
longer readable, rendering the file pretty much useless. In some cases
the file isn't readable at all. In other cases it's still accessible to
a point.

Questions,

Am I overlooking something that should be done via the program to prevent
this? What can I do to prevent this from happening?

I have looked at mySQL, however, I feel it's more power than I need since
all I'm doing is the basic $key/$value pair and not full tables of
information. Am I wrong in this thinking?

Thanks for any help you can provide.

Mark

David Krinsky

unread,
Aug 30, 1999, 3:00:00 AM8/30/99
to getp...@yahoo.com
>Via Perl, I'm locking and unlocking the database as I believe I should,
>ie read access when reading, write access when writing to the database
>and SYNCing before I close, etc.

This sounds right, although the sync before close is probably
unnecessary (but harmless).

>Via the web, the database is opened, key/values read as needed, and then
>closed. There may be multiple accesses to the database at the same time
>from different people.

By this do you mean that there's a separate CGI that accesses the
database, or is this just what the above perl does?

If the former, be sure it uses read-locking appropriately;
all locking in db is advisory, so if one app or thread has a lock and
another app or thread tries to read the locked data without attempting
to get a lock, the second app might well see corrupt data, which
sounds a lot like your problem.

>Am I overlooking something that should be done via the program to prevent
>this? What can I do to prevent this from happening?

Just double-check your locking. Oh, and have you initialized the
locking subsystem when you open the environment? I'm not quite sure
what the calls are supposed to look like in Perl (my db experience is
almost exclusively in C), but in C this would mean supplying *either*
the DB_INIT_CDB or the DB_INIT_LOCK calls to db_appinit(), depending
on whether or not there might be multiple writers in contention.

>I have looked at mySQL, however, I feel it's more power than I need since
>all I'm doing is the basic $key/$value pair and not full tables of
>information. Am I wrong in this thinking?

Nope. mySQL sounds like overkill, and is more trouble than it's worth
for this application.

Dave.

0 new messages