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
......
This diff is collapsed.
......@@ -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