Commit 71bc37bd authored by lw's avatar lw

*** empty log message ***

parent eeb2ef9e
......@@ -12,6 +12,29 @@
#include "wb_export.h"
wb_db_info::wb_db_info(wb_db *db) :
m_db(db), m_data(&m_volume, sizeof(m_volume))
{
}
void wb_db_info::get(wb_db_txn *txn)
{
int index = 0;
m_key.set_data(&index);
m_key.set_size(sizeof(index));
m_db->m_t_info->get(txn, &m_key, &m_data, 0);
}
void wb_db_info::put(wb_db_txn *txn)
{
int index = 0;
m_key.set_data(&index);
m_key.set_size(sizeof(index));
m_db->m_t_info->put(txn, &m_key, &m_data, 0);
}
wb_db_class::wb_db_class(wb_db *db, wb_db_txn *txn, pwr_tCid cid) :
m_db(db), m_key(&m_k, sizeof(m_k)), m_data(0, 0), m_dbc(0)
{
......@@ -185,21 +208,50 @@ wb_db_rbody::wb_db_rbody(wb_db *db, pwr_tOid oid, size_t size, void *p) :
{
}
wb_db_rbody::wb_db_rbody(wb_db *db, pwr_tOid oid) :
m_db(db), m_oid(oid), m_size(0), m_p(0), m_key(&m_oid, sizeof(m_oid)), m_data(0, 0)
{
}
void wb_db_rbody::put(wb_db_txn *txn)
{
m_db->m_t_rbody->put(txn, &m_key, &m_data, 0);
}
void wb_db_rbody::get(wb_db_txn *txn, size_t offset, size_t size, void *p)
{
m_data.set_doff(offset);
m_data.set_dlen(size);
m_data.set_data(p);
m_db->m_t_rbody->get(txn, &m_key, &m_data, DB_DBT_PARTIAL);
}
wb_db_dbody::wb_db_dbody(wb_db *db, pwr_tOid oid, size_t size, void *p) :
m_db(db), m_oid(oid), m_size(size), m_p(p), m_key(&m_oid, sizeof(m_oid)), m_data(p, size)
{
}
wb_db_dbody::wb_db_dbody(wb_db *db, pwr_tOid oid) :
m_db(db), m_oid(oid), m_size(0), m_p(0), m_key(&m_oid, sizeof(m_oid)), m_data(0, 0)
{
}
void wb_db_dbody::put(wb_db_txn *txn)
{
m_db->m_t_dbody->put(txn, &m_key, &m_data, 0);
}
void wb_db_dbody::get(wb_db_txn *txn, size_t offset, size_t size, void *p)
{
m_data.set_doff(offset);
m_data.set_dlen(size);
m_data.set_data(p);
m_db->m_t_dbody->get(txn, &m_key, &m_data, DB_DBT_PARTIAL);
}
wb_db::wb_db()
{
......@@ -229,18 +281,32 @@ void wb_db::create(pwr_tVid vid, pwr_tCid cid, const char *volumeName, const cha
strcpy(m_volumeName, volumeName);
dcli_translate_filename(m_fileName, fileName);
open(m_fileName);
openDb();
}
void wb_db::open(char *name)
void wb_db::open(const char *fileName)
{
dcli_translate_filename(m_fileName, fileName);
openDb();
m_env->txn_begin(0, (DbTxn **)&m_txn, 0);
wb_db_info i(this);
i.get(m_txn);
m_vid = i.vid();
m_cid = i.cid();
strcpy(m_volumeName, i.name());
}
void wb_db::openDb()
{
struct stat sb;
/* Create the directory, read/write/access owner only. */
if (stat(name, &sb) != 0) {
if (mkdir(name, S_IRWXU) != 0) {
fprintf(stderr, "txnapp: mkdir: %s, %s\n", name, strerror(errno));
if (stat(m_fileName, &sb) != 0) {
if (mkdir(m_fileName, S_IRWXU) != 0) {
fprintf(stderr, "txnapp: mkdir: %s, %s\n", m_fileName, strerror(errno));
//exit(1);
}
......@@ -249,7 +315,7 @@ void wb_db::open(char *name)
m_env = new DbEnv(0/*DB_CXX_NO_EXCEPTIONS*/);
m_env->set_errpfx("PWR db");
m_env->open(name,
m_env->open(m_fileName,
DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_RECOVER,
S_IRUSR | S_IWUSR);
......
......@@ -47,11 +47,6 @@ public:
Db *m_t_info;
wb_db_txn *m_txn;
//wb_db_ohead m_ohead;
public:
......@@ -62,7 +57,9 @@ public:
pwr_tOid new_oid(wb_db_txn *txn);
void close();
void open(char *fileName);
void open(const char *fileName);
void openDb();
void create(pwr_tVid vid, pwr_tCid cid, const char *volumeName, const char *fileName);
int del_family(wb_db_txn *txn, Dbc *cp, pwr_tOid poid);
......@@ -96,6 +93,40 @@ public:
};
class wb_db_info
{
public:
struct
{
pwr_tVid vid;
pwr_tCid cid;
pwr_tTime time;
pwr_tObjName name;
} m_volume;
wb_db *m_db;
Dbt m_key;
Dbt m_data;
wb_db_info(wb_db *db);
~wb_db_info();
void put(wb_db_txn *txn);
void get(wb_db_txn *txn);
pwr_tCid cid() { return m_volume.cid;}
pwr_tVid vid() { return m_volume.vid;}
pwr_tTime time() { return m_volume.time;}
char *name() { return m_volume.name;}
void cid(pwr_tCid cid) { m_volume.cid = cid;}
void vid(pwr_tVid vid) { m_volume.vid = vid;}
void time(pwr_tTime time) { m_volume.time = time;}
void name(char const *name) { strcpy(m_volume.name, name);}
};
class wb_db_ohead
{
public:
......@@ -132,6 +163,9 @@ public:
char *name() { return m_o.name;}
char *normname() {return m_o.normname;}
size_t rbSize() { return m_o.body[0].size;}
size_t dbSize() { return m_o.body[1].size;}
void name(wb_name &name);
......@@ -240,9 +274,11 @@ public:
Dbt m_key;
Dbt m_data;
wb_db_rbody(wb_db *db, pwr_tOid oid);
wb_db_rbody(wb_db *db, pwr_tOid oid, size_t size, void *p);
void put(wb_db_txn *txn);
void get(wb_db_txn *txn, size_t offset, size_t size, void *p);
};
class wb_db_dbody
......@@ -257,9 +293,11 @@ public:
Dbt m_key;
Dbt m_data;
wb_db_dbody(wb_db *db, pwr_tOid oid);
wb_db_dbody(wb_db *db, pwr_tOid oid, size_t size, void *p);
void put(wb_db_txn *txn);
void get(wb_db_txn *txn, size_t offset, size_t size, void *p);
};
class wb_db_txn : public DbTxn
......
......@@ -19,9 +19,33 @@ wb_vrep *wb_vrepdb::ref()
}
wb_vrepdb::wb_vrepdb(wb_erep *erep, const char *fileName) :
m_erep(erep)
{
strcpy(m_fileName, fileName);
m_db = new wb_db();
m_db->open(fileName);
#if 0
m_isDbsenvLoaded = false;
if ( isCommonMeta())
m_merep = m_erep->merep();
else
m_merep = new wb_merep(m_erep, (wb_mvrep *)this);
#endif
}
void wb_vrepdb::load()
{
}
//
// Save all changes done in the current transaction.
//
bool wb_vrepdb::commit(pwr_tStatus *sts)
{
return m_db->commit(m_txn);
......@@ -38,24 +62,50 @@ bool wb_vrepdb::abort(pwr_tStatus *sts)
wb_orep* wb_vrepdb::object(pwr_tStatus *sts)
{
// m_ohead.get(m_txn, wb_oid(m_vid, 0));
m_ohead.get(m_txn, m_ohead.foid());
try {
pwr_tOid oid;
oid.vid = m_vid;
oid.oix = pwr_cNOix;
m_ohead.get(m_txn, oid);
m_ohead.get(m_txn, m_ohead.foid());
return new (this) wb_orepdb(&m_ohead.m_o);
return new (this) wb_orepdb(&m_ohead.m_o);
}
catch (DbException &e) {
*sts = LDH__NOSUCHOBJ;
printf("vrepdb: %s\n", e.what());
return 0;
}
}
wb_orep* wb_vrepdb::object(pwr_tStatus *sts, pwr_tOid oid)
{
m_ohead.get(m_txn, oid);
try {
m_ohead.get(m_txn, oid);
return new (this) wb_orepdb(&m_ohead.m_o);
return new (this) wb_orepdb(&m_ohead.m_o);
}
catch (DbException &e) {
*sts = LDH__NOSUCHOBJ;
printf("vrepdb: %s\n", e.what());
return 0;
}
}
wb_orep* wb_vrepdb::object(pwr_tStatus *sts, wb_orep *parent, wb_name name)
{
wb_db_name n(m_db, m_txn, parent->oid(), name);
m_ohead.get(m_txn, n.oid());
return new (this) wb_orepdb(&m_ohead.m_o);
try {
wb_db_name n(m_db, m_txn, parent->oid(), name);
m_ohead.get(m_txn, n.oid());
return new (this) wb_orepdb(&m_ohead.m_o);
}
catch (DbException &e) {
*sts = LDH__NOSUCHOBJ;
printf("vrepdb: %s\n", e.what());
return 0;
}
}
wb_orep* wb_vrepdb::createObject(pwr_tStatus *sts, wb_cdef cdef, wb_destination d, wb_name name)
......@@ -185,7 +235,7 @@ bool wb_vrepdb::renameObject(pwr_tStatus *sts, wb_orep *orp, wb_name name)
}
}
bool wb_vrepdb::writeAttribute(pwr_tStatus *sts, wb_orep *o, pwr_eBix bix, unsigned int offset, unsigned int size, void *p)
bool wb_vrepdb::writeAttribute(pwr_tStatus *sts, wb_orep *o, pwr_eBix bix, size_t offset, size_t size, void *p)
{
//body.oid = ?;
//body.bix = ?;
......@@ -201,32 +251,70 @@ bool wb_vrepdb::writeAttribute(pwr_tStatus *sts, wb_orep *o, pwr_eBix bix, unsig
return true;
}
void *wb_vrepdb::readAttribute(pwr_tStatus *sts, wb_orep *o, pwr_eBix bix, unsigned int offset, unsigned int size, void *p)
void *wb_vrepdb::readAttribute(pwr_tStatus *sts, wb_orep *orp, pwr_eBix bix, size_t offset, size_t size, void *p)
{
// ob_k obk(o->oid(), bix);
//ob_d obd;
//obd.set_doff(offset);
//obd.set_dlen(size);
try {
m_ohead.get(m_txn, orp->oid());
*sts = LDH__SUCCESS;
switch (bix) {
case pwr_eBix_rt:
{
wb_db_rbody rb(m_db, m_ohead.oid());
rb.get(m_txn, offset, size, p);
break;
}
case pwr_eBix_dev:
{
wb_db_txn *txn = m_db->begin(0);
try {
//m_db.obody.get(txn, &bk, &bd, 0);
m_db->commit(txn);
wb_db_rbody db(m_db, m_ohead.oid());
db.get(m_txn, offset, size, p);
break;
}
default:
p = 0;
}
return p;
}
catch (DbException &e) {
m_db->abort(txn);
// ?? How do we reset the Orep ???, the name was changed
*sts = LDH__NOSUCHOBJ;
printf("vrepdb: %s\n", e.what());
return 0;
}
return 0;
}
void *wb_vrepdb::readBody(pwr_tStatus *sts, wb_orep *o, pwr_eBix bix, void *p)
void *wb_vrepdb::readBody(pwr_tStatus *sts, wb_orep *orp, pwr_eBix bix, void *p)
{
return 0;
try {
m_ohead.get(m_txn, orp->oid());
*sts = LDH__SUCCESS;
switch (bix) {
case pwr_eBix_rt:
{
wb_db_rbody rb(m_db, m_ohead.oid());
rb.get(m_txn, 0, m_ohead.rbSize(), p);
break;
}
case pwr_eBix_dev:
{
wb_db_rbody db(m_db, m_ohead.oid());
db.get(m_txn, 0, m_ohead.dbSize(), p);
break;
}
default:
p = 0;
}
return p;
}
catch (DbException &e) {
*sts = LDH__NOSUCHOBJ;
printf("vrepdb: %s\n", e.what());
return 0;
}
}
bool wb_vrepdb::writeBody(pwr_tStatus *sts, wb_orep *o, pwr_eBix bix, void *p)
......@@ -241,93 +329,191 @@ wb_orep *wb_vrepdb::ancestor(pwr_tStatus *sts, wb_orep *o)
pwr_tCid wb_vrepdb::cid(pwr_tStatus *sts, const wb_orep * const orp)
{
return m_ohead.get(m_txn, orp->oid()).cid();
try {
return m_ohead.get(m_txn, orp->oid()).cid();
}
catch (DbException &e) {
*sts = LDH__NOSUCHOBJ;
printf("vrepdb: %s\n", e.what());
return 0;
}
}
pwr_tOid wb_vrepdb::poid(pwr_tStatus *sts, const wb_orep * const orp)
{
return m_ohead.get(m_txn, orp->oid()).poid();
try {
return m_ohead.get(m_txn, orp->oid()).poid();
}
catch (DbException &e) {
*sts = LDH__NOSUCHOBJ;
printf("vrepdb: %s\n", e.what());
return pwr_cNOid;
}
}
pwr_tOid wb_vrepdb::foid(pwr_tStatus *sts, const wb_orep * const orp)
{
return m_ohead.get(m_txn, orp->oid()).foid();
try {
return m_ohead.get(m_txn, orp->oid()).foid();
}
catch (DbException &e) {
*sts = LDH__NOSUCHOBJ;
printf("vrepdb: %s\n", e.what());
return pwr_cNOid;
}
}
pwr_tOid wb_vrepdb::loid(pwr_tStatus *sts, const wb_orep * const orp)
{
return m_ohead.get(m_txn, orp->oid()).loid();
try {
return m_ohead.get(m_txn, orp->oid()).loid();
}
catch (DbException &e) {
*sts = LDH__NOSUCHOBJ;
printf("vrepdb: %s\n", e.what());
return pwr_cNOid;
}
}
pwr_tOid wb_vrepdb::aoid(pwr_tStatus *sts, const wb_orep * const orp)
{
return m_ohead.get(m_txn, orp->oid()).aoid();
try {
return m_ohead.get(m_txn, orp->oid()).aoid();
}
catch (DbException &e) {
*sts = LDH__NOSUCHOBJ;
printf("vrepdb: %s\n", e.what());
return pwr_cNOid;
}
}
pwr_tOid wb_vrepdb::boid(pwr_tStatus *sts, const wb_orep * const orp)
{
return m_ohead.get(m_txn, orp->oid()).boid();
try {
return m_ohead.get(m_txn, orp->oid()).boid();
}
catch (DbException &e) {
*sts = LDH__NOSUCHOBJ;
printf("vrepdb: %s\n", e.what());
return pwr_cNOid;
}
}
wb_orep *wb_vrepdb::parent(pwr_tStatus *sts, wb_orep *orp)
{
m_ohead.get(m_txn, m_ohead.get(m_txn, orp->oid()).poid());
return new (this) wb_orepdb(&m_ohead.m_o);
try {
m_ohead.get(m_txn, m_ohead.get(m_txn, orp->oid()).poid());
return new (this) wb_orepdb(&m_ohead.m_o);
}
catch (DbException &e) {
*sts = LDH__NOSUCHOBJ;
printf("vrepdb: %s\n", e.what());
return 0;
}
}
wb_orep *wb_vrepdb::after(pwr_tStatus *sts, wb_orep *orp)
{
m_ohead.get(m_txn, m_ohead.get(m_txn, orp->oid()).aoid());
return new (this) wb_orepdb(&m_ohead.m_o);
try {
m_ohead.get(m_txn, m_ohead.get(m_txn, orp->oid()).aoid());
return new (this) wb_orepdb(&m_ohead.m_o);
}
catch (DbException &e) {
*sts = LDH__NOSUCHOBJ;
printf("vrepdb: %s\n", e.what());
return 0;
}
}
wb_orep *wb_vrepdb::before(pwr_tStatus *sts, wb_orep *orp)
{
m_ohead.get(m_txn, m_ohead.get(m_txn, orp->oid()).boid());
return new (this) wb_orepdb(&m_ohead.m_o);
try {
m_ohead.get(m_txn, m_ohead.get(m_txn, orp->oid()).boid());
return new (this) wb_orepdb(&m_ohead.m_o);
}
catch (DbException &e) {
*sts = LDH__NOSUCHOBJ;
printf("vrepdb: %s\n", e.what());
return 0;
}
}
wb_orep *wb_vrepdb::first(pwr_tStatus *sts, wb_orep *orp)
{
m_ohead.get(m_txn, m_ohead.get(m_txn, orp->oid()).foid());
return new (this) wb_orepdb(&m_ohead.m_o);
try {
m_ohead.get(m_txn, m_ohead.get(m_txn, orp->oid()).foid());
return new (this) wb_orepdb(&m_ohead.m_o);
}
catch (DbException &e) {
*sts = LDH__NOSUCHOBJ;
printf("vrepdb: %s\n", e.what());
return 0;
}
}
wb_orep *wb_vrepdb::child(pwr_tStatus *sts, wb_orep *orp, const char *name)
{
wb_db_name n(m_db, m_txn, orp->oid(), name);
m_ohead.get(m_txn, n.oid());
return new (this) wb_orepdb(&m_ohead.m_o);
try {
wb_db_name n(m_db, m_txn, orp->oid(), name);
m_ohead.get(m_txn, n.oid());
return new (this) wb_orepdb(&m_ohead.m_o);
}
catch (DbException &e) {
*sts = LDH__NOSUCHOBJ;
printf("vrepdb: %s\n", e.what());
return 0;
}
}
wb_orep *wb_vrepdb::last(pwr_tStatus *sts, wb_orep *orp)
{
m_ohead.get(m_txn, m_ohead.get(m_txn, orp->oid()).loid());
return new (this) wb_orepdb(&m_ohead.m_o);
try {
m_ohead.get(m_txn, m_ohead.get(m_txn, orp->oid()).loid());
return new (this) wb_orepdb(&m_ohead.m_o);
}
catch (DbException &e) {
*sts = LDH__NOSUCHOBJ;
printf("vrepdb: %s\n", e.what());
return 0;
}
}
wb_orep *wb_vrepdb::next(pwr_tStatus *sts, wb_orep *orp)
{
m_ohead.get(m_txn, orp->oid());
wb_db_class c(m_db, m_ohead.cid());
if (c.succ(m_ohead.oid())) {
m_ohead.get(m_txn, c.oid());
return new (this) wb_orepdb(&m_ohead.m_o);
} else {
//*sts = LDH__?;
try {
m_ohead.get(m_txn, orp->oid());
wb_db_class c(m_db, m_ohead.cid());
if (c.succ(m_ohead.oid())) {
m_ohead.get(m_txn, c.oid());
return new (this) wb_orepdb(&m_ohead.m_o);
} else {
//*sts = LDH__?;
return 0;
}
}
catch (DbException &e) {
*sts = LDH__NOSUCHOBJ;
printf("vrepdb: %s\n", e.what());
return 0;
}
}
wb_orep *wb_vrepdb::previous(pwr_tStatus *sts, wb_orep *orp)
{
m_ohead.get(m_txn, orp->oid());
wb_db_class c(m_db, m_ohead.cid());
if (c.pred(m_ohead.oid())) {
m_ohead.get(m_txn, c.oid());
return new (this) wb_orepdb(&m_ohead.m_o);
} else {
//*sts = LDH__?;
try {
m_ohead.get(m_txn, orp->oid());
wb_db_class c(m_db, m_ohead.cid());
if (c.pred(m_ohead.oid())) {
m_ohead.get(m_txn, c.oid());
return new (this) wb_orepdb(&m_ohead.m_o);
} else {
//*sts = LDH__?;
return 0;
}
}
catch (DbException &e) {
*sts = LDH__NOSUCHOBJ;
printf("vrepdb: %s\n", e.what());
return 0;
}
}
......
......@@ -17,125 +17,7 @@ protected:
unsigned int m_nSession;
unsigned int m_nRef;
#if 0
DbEnv *m_dbenv;
Db *m_t_ohead;
Db *m_t_obody;
Db *m_t_class;
Db *m_t_name;
Db *m_t_info;
DbTxn *m_txn;
class db_ohead
{
public:
db_sObject m_o;
Dbt m_key;
Dbt m_data;
Db *m_t_ohead;
db_ohead(Db *t_ohead);
db_ohead(Db *t_ohead, pwr_tOid oid);
db_ohead(Db *t_ohead, DbTxn *txn, pwr_tOid oid);
db_ohead(Db *t_ohead, DbTxn *txn, wb_orep *orp);
db_ohead &get(DbTxn *txn);
db_ohead &get(DbTxn *txn, wb_orep *o);
db_ohead &get(DbTxn *txn, pwr_tOid oid);
void put(DbTxn *txn);
void del(DbTxn *txn);
pwr_tOid oid() { return m_o.oid;}
pwr_tCid cid() { return m_o.cid;}
pwr_tOid poid() { return m_o.poid;}
pwr_tOid foid() { return m_o.foid;}
pwr_tOid loid() { return m_o.loid;}
pwr_tOid boid() { return m_o.boid;}
pwr_tOid aoid() { return m_o.aoid;}
char *name();
void name(wb_name &name);
void poid(pwr_tOid oid) { m_o.poid = oid;}
void foid(pwr_tOid oid) { m_o.foid = oid;}
void loid(pwr_tOid oid) { m_o.loid = oid;}
void boid(pwr_tOid oid) { m_o.boid = oid;}
void aoid(pwr_tOid oid) { m_o.aoid = oid;}
void clear();
};
class db_name
{
public:
struct
{
pwr_tOid poid;
pwr_tObjName normname;
} m_k;
struct
{
pwr_tOid oid;
//pwr_tCid cid; // saved here to optimize tree traversal
//pwr_mClassDef flags; // saved here to optimize tree traversal
} m_d;
Dbt m_key;
Dbt m_data;
Db *m_t_name;
db_name(Db *t_name, DbTxn *txn);
db_name(Db *t_name, db_ohead &o);
db_name(Db *t_name, pwr_tOid, char *name);
db_name(Db *t_name, DbTxn *txn, pwr_tOid poid, const char *name);
db_name(Db *t_name, DbTxn *txn, pwr_tOid poid, wb_name name);
void get(DbTxn *txn);
void put(DbTxn *txn);
void del(DbTxn *txn);
void name(wb_name &name);
pwr_tOid oid() { return m_d.oid;}
};
class db_class
{
public:
struct
{
pwr_tCid cid;
pwr_tOid oid;
} m_k;
Dbt m_key;
Db *m_t_class;
Dbc *m_dbc;
db_class(Db *t_class, pwr_tCid cid);
db_class(Db *t_class, db_ohead &o);
db_class(Db *t_class, DbTxn *txn, pwr_tCid cid);
~db_class();
bool succ(DbTxn *txn, pwr_tOid oid);
bool pred(DbTxn *txn, pwr_tOid oid);
void put(DbTxn *txn);
void del(DbTxn *txn);
pwr_tCid cid() { return m_k.cid;}
pwr_tOid oid() { return m_k.oid;}
};
wb_db::db_ohead m_ohead;
pwr_tOix wb_vrepdb::new_oix(DbTxn *txn);
int wb_vrepdb::del_family(DbTxn *txn, Dbc *cp, pwr_tOix poix);
#endif
char m_fileName[512];
public:
......@@ -143,15 +25,13 @@ public:
wb_db_txn *m_txn;
wb_db_ohead m_ohead;
wb_vrepdb();
wb_vrepdb(wb_erep *erep, const char *fileName);
~wb_vrepdb();
virtual void unref();
virtual wb_vrep *ref();
virtual wb_erep *erep();
pwr_tTime ohTime(pwr_tStatus *sts, const wb_orep * const o);
pwr_tOid oid(pwr_tStatus *sts, const wb_orep * const o);
......@@ -225,7 +105,7 @@ public:
virtual pwr_tVid vid() const;
virtual void objectName(wb_orep *o, const char *str);
void load(char *name);
void load();
virtual bool exportVolume(wb_import &e);
......@@ -237,7 +117,6 @@ public:
virtual bool exportMeta(wb_import &e);
//pwr_tOid new_oid(DbTxn *txn);
#if 0
int del_family(DbTxn *txn, Dbc *cp, pwr_tOid poid);
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment