Skip to Main Content

Berkeley DB Family

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Transactional cursor error

886723Sep 7 2011 — edited Oct 5 2011
Hi there.

I am new to BDB and am using version 4.8.26.

I am experiencing an issue with the Db::cursor() method. It blows up with a DBException where the 'what' informs me "Error:Unable to create variable object"

Can someone please review the code below and tell me what I am doing wrong?

Thanks alot in advance!!

////////////////////////////////////////////////////////////////
CTOR
////////////////////////////////////////////////////////////////
BDBManager(const std::string& env, u_int32_t pagesize, u_int32_t lg_buf_size): m_dbEnv(0){
u_int32_t envflags =
DB_CREATE
| DB_RECOVER
| DB_INIT_TXN
| DB_INIT_MPOOL
| DB_INIT_LOG
| DB_INIT_LOCK;

u_int32_t dbflags = DB_CREATE;//don't perform I/O to write to logging subsystem

/*
* because we are using transactions we need to make sure the
* log file can hold at least a couple of
* */
m_dbEnv.set_lg_bsize(lg_buf_size);
m_dbEnv.open(env.c_str(), envflags, 0);
m_dbEnv.set_flags(DB_TXN_NOSYNC, 1);

m_rawMsgs = new Db(&m_dbEnv, 0);
m_rawMsgs->set_bt_compare(&sortkey);
m_rawMsgs->open(NULL, "raw.db", NULL, DB_BTREE, dbflags, 0);

m_state = new Db(&m_dbEnv, 0);
m_state->set_bt_compare(&sortkey);
m_state->set_pagesize(pagesize);
m_state->set_flags(DB_DUPSORT);
m_state->open(NULL, "state.db", NULL, DB_BTREE, dbflags, 0);
}

/////////////////////////////////////////////////////////////////
My Dodgy Method
////////////////////////////////////////////////////////////////

void openTxn(){

m_currentTxn = NULL;
m_putCurs = NULL;

m_dbEnv.txn_begin(NULL, &m_currentTxn, 0);
if(tx){
try{
m_state->cursor(m_currentTxn, &m_putCurs, 0);//cursor only needed for state
}
catch(DbException dbE){
m_state->err(dbE.get_errno(), dbE.what());
}
catch(std::exception e){
m_state->errx(e.what());
}
}
}


private:

static int sortkey(Db* db, const Dbt* a, const Dbt* z){
u_int64_t aa,zz;
memcpy(&aa, a->get_data(), sizeof(u_int64_t));
memcpy(&zz, z->get_data(), sizeof(u_int64_t));
return (aa-zz);
}

DbEnv m_dbEnv;
Db* m_rawMsgs;
Db* m_state;
DbTxn* m_currentTxn;
Dbc* m_putCurs;
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 2 2011
Added on Sep 7 2011
1 comment
157 views