niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » Berkeley DB
Database update done by writer not visible to the reader
Post new topic   Reply to topic Page 1 of 1 [2 Posts] View previous topic :: View next topic
Author Message
Michael Cahill
*nix forums Guru Wannabe


Joined: 26 May 2005
Posts: 219

PostPosted: Thu Apr 07, 2005 10:38 pm    Post subject: Re: Database update done by writer not visible to the reader Reply with quote

Hi,

Quote:
db_create( &dbp, NULL, 0 );

You aren't creating the database in the environment. That second
parameter should be dbenv, not NULL.

Regards,
Michael.
Back to top
oleksandr kalinin
*nix forums beginner


Joined: 07 Apr 2005
Posts: 2

PostPosted: Thu Apr 07, 2005 5:28 pm    Post subject: Database update done by writer not visible to the reader Reply with quote

Hi All,

I am wondering on how can I make sure that within the multiple-writer /
multiple-reader environment database update done by the writer will become
actual to the reader. The problem I have is that whenever the writer has
updated (or added) the record with given key, another reader process looks
up the database by that key and data appears to be old as if the writer has
not updated/added it.

The sequence of events is the following:

- Process A - creates an environment handle and open an environment with
DB_INIT_MPOOL | DB_INIT_LOCK | DB_CREATE | DB_THREAD flags set.
- Process A - creates a database file with DB_CREATE flag.
- Process B - creates an environment handle and open an environment with
DB_INIT_MPOOL | DB_INIT_LOCK | DB_THREAD flags set, using the same db_home
as Process A.
- Process B - opens a database previously created by Process A, no flags
set.
- Process A - modifies a record with some key (data used to be X, now
Y )
- Process B - retrieves a record by the same key, data is still X.

Is there anything wrong with such sequence? Am I missing any flags?

Here is an example of code, just in case:

Process A code:

#include <unistd.h>
#include <stdio.h>
#include <db.h>
#include <assert.h>

struct rec {
int x; /* key field */
int y; /* data field */
};

int main(int argc, char *argv[])
{
DB_ENV* dbenv;
DB* dbp;
DBT key, data;
struct rec r;
struct rec *pr;
int ret;

db_env_create( &dbenv, NULL );
assert( 0 == dbenv->open( dbenv, ".", DB_INIT_LOCK | DB_INIT_MPOOL |
DB_CREATE | DB_THREAD, 0) );

db_create( &dbp, NULL, 0 );
assert( 0 == dbp->open( dbp, NULL, "test.db", NULL, DB_BTREE, DB_CREATE,
0 ) );

/* First command line parameter is key, second parameter is data */
r.x = atoi( argv[1] );
r.y = atoi( argv[2] );

memset( &key, 0, sizeof(key) );
memset( &data, 0, sizeof(data) );

key.data = (void *) &r.x;
key.size = sizeof( r.x );

data.data = &r;
data.size = sizeof( r );

/* Add a record */
ret = dbp->put( dbp, NULL, &key, &data, 0 );
/* Adding dbp->sync(dbp, 0); here does not help */

/* Now retrieve a record and display data, repeat every 2 seconds */
for (;Wink
{
memset( &key, 0, sizeof(key) );
memset( &data, 0, sizeof(data) );

key.data = (void *) &r.x;
key.size = sizeof( r.x );

dbp->get( dbp, NULL, &key, &data, 0 );
pr = (struct rec*) data.data;
if (pr != NULL)
printf( "DATA=%i\n", pr->y );

sleep(2);
}
}

Process B code is exactly the same, but without DB_CREATE flag in open
calls.

Start first process and add a record {3, 4}:
$ ./mytest 3 4
DATA=4
DATA=4
....

Start second process, while first process is running and modify a record to
become {3, 8}:
$ ./mytest 3 8
DATA=8
DATA=8
....

Second process has updated the database, but the output from first process
remains the same, as if it is sitting in some cache:
DATA=4

The change becomes actual to the reader only after re-opening the database.
I've been reading documentation for some time now, looking at other people's
code and still can't get what is wrong in the example above. Many thanks in
advance for your reply!

Best wishes,
Oleksandr
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [2 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 2:43 am | All times are GMT
navigation Forum index » Databases » Berkeley DB
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Move Oracle 10g database to another location Selt Server 0 Fri Jul 21, 2006 2:14 pm
No new posts database Share Memory Limit (2 GB ) in a Instance is tota... sadanjan@gmail.com IBM DB2 0 Fri Jul 21, 2006 12:57 pm
No new posts C# MSSQL2000 update pln C 5 Fri Jul 21, 2006 7:41 am
No new posts A webserver (PHP 5) with a few database server (MySQL) ¥|¥J PHP 2 Fri Jul 21, 2006 1:43 am
No new posts HPSBMA02133 SSRT061201 rev.1 - HP Oracle for OpenView (Of... Security Alert HP-UX 0 Thu Jul 20, 2006 6:43 pm

Credit Counseling | Debt Consolidation | Loans | Free website & online homepage | Looking for Credit Cards?
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1634s ][ Queries: 20 (0.0833s) ][ GZIP on - Debug on ]