Commit bd7a82e0 authored by lw's avatar lw

Implemented paste in volrepdb

parent 1350c290
This diff is collapsed.
......@@ -166,6 +166,8 @@
%#define dbs_dAlign(size) (((size) + dbs_cAlignInc) & ~dbs_cAlignInc)
%#define dbs_dPadding(size) ((((size) + dbs_cAlignInc) & ~dbs_cAlignInc) - (size))
%#define dbs_dMakeRef(sect, offset) (0 | ((sect) << dbs_cOffsBits) | (offset))
%#define dbs_cAlignPage 511
%#define dbs_dAlignPage(size) (((size) + dbs_cAlignPage) & ~dbs_cAlignPage)
%
%typedef union {
% struct {
......@@ -526,6 +528,7 @@ struct dbs_sScObject {
#ifdef PDR_HDR
%#define dbs_cVersionFixup 1
%
%
%typedef union {
% pwr_tBitMask m;
% pwr_32Bits (
......@@ -543,7 +546,9 @@ struct dbs_sScObject {
%#define dbs_mEnv_ (~dbs_mEnv__)
%} dbs_mEnv;
%
%typedef struct dbs_sMenv dbs_sMenv;
%typedef struct {
% //dbs_sFileEnv *fp;
% FILE *f;
% dbs_sFile file;
% pwr_tUInt32 nSect;
......@@ -552,13 +557,39 @@ struct dbs_sScObject {
% /* the rest is used only if mapped */
% pwr_tUInt32 size; /**< size of mapped file */
% char *base;
% dbs_mEnv flags;
% //dbs_sVolume *vp;
% //dbs_sBintab *name_bt; /**< search for object with parent and name */
% //dbs_sBintab *oid_bt; /**< search for object with identity */
% //dbs_sBintab *class_bt; /**< search for object with class */
%} dbs_sEnv;
%
%typedef struct {
% dbs_sMenv *mp;
% pwr_tUInt32 index;
% pwr_tUInt32 nSect;
% dbs_sSect *sect;
%
% /* the rest is used only if mapped */
% pwr_tUInt32 size; /**< size of mapped file */
% char *base;
% dbs_sVolume *vp;
% dbs_sVolRef *vrp;
% dbs_sBintab *name_bt; /**< search for object with parent and name */
% dbs_sBintab *oid_bt; /**< search for object with identity */
% dbs_sBintab *class_bt; /**< search for object with class */
%} dbs_sEnv;
%} dbs_sVenv;
%
%struct dbs_sMenv {
% FILE *f;
% dbs_sFile file;
% dbs_mEnv flags;
% pwr_tUInt32 nVolRef;
%
% /* the rest is used only if mapped */
% pwr_tUInt32 size; /**< size of mapped file */
% char *base;
% dbs_sVolRef *vrp;
% dbs_sVenv venv[1];
%};
%
%
%#define dbs_Qitem(a, b, c) ((b *)((char *)a - offsetof(b, c)))
......@@ -568,56 +599,47 @@ struct dbs_sScObject {
%pwr_tBoolean dbs_Close(pwr_tStatus *sts, dbs_sEnv *ep);
%dbs_sEnv *dbs_Open(pwr_tStatus *sts, dbs_sEnv *ep, const char *filename);
%#if defined(OS_LINUX) || defined(OS_LYNX)
%void *dbs_Address(pwr_tStatus*, const dbs_sEnv*, dbs_tRef);
%void *dbs_Alloc(pwr_tStatus*, const dbs_sEnv*, pwr_tUInt32);
%pwr_tBoolean dbs_AllocLookasideSegment(pwr_tStatus*, const dbs_sEnv*, pwr_tUInt32, pwr_tUInt32);
%void *dbs_AllocNamedSegment(pwr_tStatus*, const dbs_sEnv*, pwr_tUInt32, char*);
%dbs_sEnv *dbs_Create(pwr_tStatus*, dbs_sEnv*, char*, pwr_tUInt32, pwr_tUInt32);
%dbs_sVolRef *dbs_VolRef(pwr_tStatus *sts, pwr_tUInt32 index, dbs_sVolRef *vp, const dbs_sEnv *ep);
%void *dbs_Address(pwr_tStatus*, const dbs_sVenv*, dbs_tRef);
%void dbs_Dump(pwr_tStatus*, const dbs_sEnv*);
%pwr_tBoolean dbs_Free(pwr_tStatus*, const dbs_sEnv*, void*);
%pwr_tBoolean dbs_FreeReference(pwr_tStatus*, const dbs_sEnv*, dbs_tRef);
%dbs_tRef dbs_InDbs(pwr_tStatus*, const dbs_sEnv*, void*, pwr_tUInt32);
%dbs_tRef dbs_ItemReference(pwr_tStatus*, const dbs_sEnv*, void*);
%dbs_sQlink *dbs_Qalloc(pwr_tStatus*, const dbs_sEnv*);
%pwr_tBoolean dbs_QhasOne(pwr_tStatus*, const dbs_sEnv*, dbs_sQlink*);
%pwr_tBoolean dbs_QhasOne(pwr_tStatus*, const dbs_sVenv*, dbs_sQlink*);
%dbs_tRef dbs_Qinit(pwr_tStatus*, dbs_sQlink*, dbs_tRef);
%dbs_sQlink *dbs_Qinsert(pwr_tStatus*, dbs_sQlink*, dbs_sQlink*, dbs_sQlink*);
%dbs_sQlink *dbs_QinsertPred(pwr_tStatus*, const dbs_sEnv*, dbs_sQlink*, dbs_sQlink*);
%dbs_sQlink *dbs_QinsertSucc(pwr_tStatus*, const dbs_sEnv*, dbs_sQlink*, dbs_sQlink*);
%pwr_tBoolean dbs_QisEmpty(pwr_tStatus*, const dbs_sEnv*, dbs_sQlink*);
%pwr_tBoolean dbs_QisLinked(pwr_tStatus*, const dbs_sEnv*, dbs_sQlink*);
%pwr_tBoolean dbs_QisNull(pwr_tStatus*, const dbs_sEnv*, dbs_sQlink*);
%dbs_sQlink *dbs_Qmove(pwr_tStatus*, const dbs_sEnv*, dbs_sQlink*, dbs_sQlink*);
%dbs_sQlink *dbs_Qpred(pwr_tStatus*, const dbs_sEnv*, dbs_sQlink*);
%dbs_sQlink *dbs_Qremove(pwr_tStatus*, const dbs_sEnv*, dbs_sQlink*);
%dbs_sQlink *dbs_QremovePred(pwr_tStatus*, const dbs_sEnv*, dbs_sQlink*);
%dbs_sQlink *dbs_QremoveSucc(pwr_tStatus*, const dbs_sEnv*, dbs_sQlink*);
%dbs_sQlink *dbs_Qsucc(pwr_tStatus*, const dbs_sEnv*, dbs_sQlink*);
%dbs_tRef dbs_RefAlloc(pwr_tStatus*, const dbs_sEnv*, pwr_tUInt32);
%dbs_tRef dbs_Reference(pwr_tStatus*, const dbs_sEnv*, void*);
%
%dbs_sEnv *dbs_Map(pwr_tStatus *sts, dbs_sEnv *ep, const char *filename);
%
%dbs_sObject *dbs_OidToObject(pwr_tStatus *sts, const dbs_sEnv *ep, pwr_tOid oid);
%dbs_sObject *dbs_NameToObject(pwr_tStatus *sts, const dbs_sEnv *ep, pwr_tOid oid, char *name);
%dbs_sObject *dbs_Parent(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sObject *op);
%dbs_sObject *dbs_After(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sObject *op);
%dbs_sObject *dbs_Before(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sObject *op);
%dbs_sObject *dbs_First(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sObject *op);
%dbs_sObject *dbs_Last(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sObject *op);
%dbs_sObject *dbs_ClassToObject(pwr_tStatus *sts, const dbs_sEnv *ep, pwr_tCid cid);
%dbs_sObject *dbs_Next(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sObject *op);
%dbs_sObject *dbs_Previous(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sObject *op);
%dbs_sObject *dbs_Child(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sObject *op, char *name);
%dbs_sObject *dbs_Ancestor(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sObject *op);
%void dbs_GetVolumeName(pwr_tStatus *sts, dbs_sEnv *ep, char *name);
%dbs_sObject *dbs_VolumeObject(pwr_tStatus *sts, const dbs_sEnv *ep);
%dbs_sObject *dbs_Object(pwr_tStatus *sts, const dbs_sEnv *ep);
%void dbs_ObjectToName(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sObject *op, char *name);
%void *dbs_Body(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sObject *op, pwr_eBix bix);
%dbs_sObject *dbs_NextHead(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sObject *op);
%dbs_sBody *dbs_NextRbody(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sBody *bp);
%dbs_sBody *dbs_NextDbody(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sBody *bp);
%pwr_tBoolean dbs_QisEmpty(pwr_tStatus*, const dbs_sVenv*, dbs_sQlink*);
%pwr_tBoolean dbs_QisLinked(pwr_tStatus*, const dbs_sVenv*, dbs_sQlink*);
%pwr_tBoolean dbs_QisNull(pwr_tStatus*, const dbs_sVenv*, dbs_sQlink*);
%dbs_sQlink *dbs_Qpred(pwr_tStatus*, const dbs_sVenv*, dbs_sQlink*);
%dbs_sQlink *dbs_Qsucc(pwr_tStatus*, const dbs_sVenv*, dbs_sQlink*);
%dbs_tRef dbs_Reference(pwr_tStatus*, const dbs_sVenv*, void*);
%
%dbs_sMenv *dbs_Map(pwr_tStatus*, const char*);
%dbs_sVenv *dbs_Vmap(pwr_tStatus*, int index, dbs_sMenv *);
%void dbs_Split(pwr_tStatus *sts, dbs_sMenv *mep);
%pwr_tBoolean dbs_Unmap(pwr_tStatus *sts, dbs_sMenv *);
%int dbs_nVolRef(pwr_tStatus *sts, const dbs_sMenv *mep);
%
%dbs_sObject *dbs_OidToObject(pwr_tStatus *sts, const dbs_sVenv *vep, pwr_tOid oid);
%dbs_sObject *dbs_NameToObject(pwr_tStatus *sts, const dbs_sVenv *vep, pwr_tOid oid, char *name);
%dbs_sObject *dbs_Parent(pwr_tStatus *sts, const dbs_sVenv *vep, dbs_sObject *op);
%dbs_sObject *dbs_After(pwr_tStatus *sts, const dbs_sVenv *vep, dbs_sObject *op);
%dbs_sObject *dbs_Before(pwr_tStatus *sts, const dbs_sVenv *vep, dbs_sObject *op);
%dbs_sObject *dbs_First(pwr_tStatus *sts, const dbs_sVenv *vep, dbs_sObject *op);
%dbs_sObject *dbs_Last(pwr_tStatus *sts, const dbs_sVenv *vep, dbs_sObject *op);
%dbs_sObject *dbs_ClassToObject(pwr_tStatus *sts, const dbs_sVenv *vep, pwr_tCid cid);
%dbs_sObject *dbs_Next(pwr_tStatus *sts, const dbs_sVenv *vep, dbs_sObject *op);
%dbs_sObject *dbs_Previous(pwr_tStatus *sts, const dbs_sVenv *vep, dbs_sObject *op);
%dbs_sObject *dbs_Child(pwr_tStatus *sts, const dbs_sVenv *vep, dbs_sObject *op, char *name);
%dbs_sObject *dbs_Ancestor(pwr_tStatus *sts, const dbs_sVenv *vep, dbs_sObject *op);
%void dbs_GetVolumeName(pwr_tStatus *sts, dbs_sVenv *vep, char *name);
%dbs_sObject *dbs_VolumeObject(pwr_tStatus *sts, const dbs_sVenv *vep);
%dbs_sObject *dbs_Object(pwr_tStatus *sts, const dbs_sVenv *vep);
%void dbs_ObjectToName(pwr_tStatus *sts, const dbs_sVenv *vep, dbs_sObject *op, char *name);
%void *dbs_Body(pwr_tStatus *sts, const dbs_sVenv *vep, dbs_sObject *op, pwr_eBix bix);
%dbs_sObject *dbs_NextHead(pwr_tStatus *sts, const dbs_sVenv *vep, dbs_sObject *op);
%dbs_sBody *dbs_NextRbody(pwr_tStatus *sts, const dbs_sVenv *vep, dbs_sBody *bp);
%dbs_sBody *dbs_NextDbody(pwr_tStatus *sts, const dbs_sVenv *vep, dbs_sBody *bp);
%#endif
%
%#ifdef __cplusplus
......
......@@ -169,6 +169,8 @@ printname(pwr_tOid poid, pwr_tObjName name, pwr_tOid oid)
sOentry *oep;
count_name++;
printf("N [%10.10d.%10.10d] %d:%s\n", oid.vid, oid.oix, strlen(name), name);
oep = (sOentry *)tree_Find(&sts, oid_th, &oid);
if (EVEN(sts)) {
printf("Name: object not found %d.%d, %s\n", oid.vid, oid.oix, name);
......@@ -195,6 +197,8 @@ printclass(pwr_tOid oid, pwr_tCid cid)
sOentry *oep;
count_class++;
printf("C [%10.10d.%10.10d] <%d>\n", oid.vid, oid.oix, cid);
oep = (sOentry *)tree_Find(&sts, oid_th, &oid);
if (EVEN(sts)) {
printf("Class: object not found %d.%d, %d\n", oid.vid, oid.oix, cid);
......@@ -218,6 +222,9 @@ printohead(pwr_tOid oid, db_sObject *op)
if (cdh_ObjidIsNotEqual(oid, op->oid))
printf("Ohead: oid not equal %s oid: %d.%d != %d.%d\n", op->name, oid.vid, oid.oix, op->oid.vid, op->oid.oix);
// printf("O [%10.10d.%10.10d] [%10.10d.%10.10d] P [%10.10d.%10.10d] %d:%s\n B [%10.10d.%10.10d] A [%10.10d.%10.10d] F [%10.10d.%10.10d] L [%10.10d.%10.10d] \n", oid.vid, oid.oix, op->oid.vid, op->oid.oix, op->poid.vid, op->poid.oix, strlen(op->name), op->name, op->boid.vid, op->boid.oix, op->aoid.vid, op->aoid.oix, op->foid.vid, op->foid.oix, op->loid.vid, op->loid.oix);
printf("P [%6.6d] B [%6.6d] O [%6.6d] A [%6.6d] F [%6.6d] L [%6.6d]\n", op->poid.oix, op->boid.oix, op->oid.oix, op->aoid.oix, op->foid.oix, op->loid.oix);
oep = (sOentry *)tree_Insert(&sts, oid_th, &oid);
if (sts == TREE__INSERTED) {
oep->flags.b.inOhead = 1;
......
......@@ -18,6 +18,114 @@
#include "co_time.h"
#if 1
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int main( int argc, char *argv[])
{
struct stat sb;
int ret;
pwr_tStatus sts;
dbs_sMenv *mep;
if (argc < 2)
exit(0);
if ((ret = stat(argv[1], &sb)) != 0) {
perror("stat");
exit(ret);
}
printf("stat %s\n", argv[1]);
printf("st_atime...: %ld\n", sb.st_atime);
printf("st_mtime...: %ld\n", sb.st_mtime);
printf("st_ctime...: %ld\n", sb.st_ctime);
mep = dbs_Map(&sts, argv[1]);
dbs_Split(&sts, mep);
return 0;
}
#elif 0
int main( int argc, char *argv[])
{
int a;
int b;
int i;
int c;
for (i = 0; i < 100; i++) {
if (i % 3 == 0) {
a = rand() % 101;
b = rand() % 101;
printf("[%d] vad blir %d + %d = ", i + 1, a, b);
scanf("%d", &c);
if (c == a + b) {
printf("\nKorrekt!\n");
} else {
printf("Fel\007! Det blir: %d\n", a + b);
}
}
else if (i % 3 == 1) {
int tmp;
a = rand() % 101;
b = rand() % 101;
if (a < b) {
tmp = b;
b = a;
a = tmp;
}
printf("[%d] vad blir %d - %d = ", i + 1, a, b);
scanf("%d", &c);
if (c == a - b) {
printf("\nKorrekt!\n");
} else {
printf("Fel\007! Det blir %d\n", a - b);
}
}
else if (i % 3 == 2) {
a = rand() % 11;
b = rand() % 11;
printf("[%d] vad blir %d * %d = ", i + 1, a, b);
scanf("%d", &c);
if (c == a * b) {
printf("\nKorrekt!\n");
} else {
printf("Fel\007! Det blir %d\n", a * b);
}
}
}
}
#elif 0
int main( int argc, char *argv[])
{
char namn[50];
char bnamn[50];
int len;
printf("Vad heter du? ");
scanf("%s", namn);
len = strlen(namn);
for (int i = 0; i < len; i++) {
bnamn[len - i -1] = namn[i];
}
bnamn[len+1] = '\0';
printf("\nDitt namn baklnges r: %s\n", bnamn);
}
#elif 0
int main( int argc, char *argv[])
{
pwr_tStatus sts;
......
......@@ -976,6 +976,23 @@ pwr_tOid wb_db::new_oid(wb_db_txn *txn)
return oid;
}
pwr_tOid wb_db::new_oid(wb_db_txn *txn, pwr_tOid oid)
{
if (oid.vid == m_vid) {
try {
wb_db_ohead o(this, txn, oid);
} catch (DbException &e) {
cout << e.what() << " old oid not found, keep\n";
return oid;
}
cout << " Old oid found, force new!\n";
} else {
cout << "in an other volume\n";
}
return new_oid(txn);
}
int wb_db::del_family(wb_db_txn *txn, Dbc *cp, pwr_tOid poid)
{
int ret = 0;
......@@ -1133,7 +1150,19 @@ bool wb_db::importHead(pwr_tOid oid, pwr_tCid cid, pwr_tOid poid,
o.put(m_txn);
//printf("head put: %d.%d %s\n", oid.vid, oid.oix, name);
wb_db_name n(this, oid, poid, normname);
n.put(m_txn);
int rc = n.put(m_txn);
if (rc) {
//printf("importHead: n.put: %d, %d.%d %s\n", rc, poid.vid, poid.oix, name);
char newName[50];
sprintf(newName, "O%u_%s", oid.oix, name);
newName[31] = '\0';
wb_name nn(newName);
o.name(nn);
o.put(m_txn);
n.name(nn);
n.put(m_txn);
}
wb_db_class c(this, cid, oid);
c.put(m_txn);
if (oid.oix == pwr_cNOix) { // This is the volume object
......
......@@ -60,6 +60,7 @@ public:
char *volumeName() { return m_volumeName;}
pwr_tOid new_oid(wb_db_txn *txn);
pwr_tOid new_oid(wb_db_txn *txn, pwr_tOid oid);
void close();
void open(const char *fileName);
......
This diff is collapsed.
......@@ -31,7 +31,8 @@ public:
struct sOentry;
struct sNentry;
struct sCentry;
struct sVentry;
struct sOentry {
tree_sNode node;
dbs_sObject o;
......@@ -67,6 +68,12 @@ public:
sOentry *o_lt; // Tail of object list
};
struct sVentry {
tree_sNode node;
dbs_sVolRef v;
dbs_sEnv env;
};
FILE *m_fp; /**< file pointer */
char m_fileName[512]; /**< name of load file */
// wb_object *m_o; /* Volume object header. */
......@@ -90,6 +97,7 @@ public:
tree_sTable *m_oid_th;
tree_sTable *m_name_th;
tree_sTable *m_class_th;
tree_sTable *m_vol_th;
wb_dbs();
wb_dbs(wb_vrep *);
......@@ -119,16 +127,18 @@ public:
void classInsert(sOentry *oep);
pwr_tStatus openFile();
pwr_tStatus writeSectFile();
pwr_tStatus writeSectFile(size_t size);
pwr_tStatus writeSectDirectory();
pwr_tStatus writeSectVolume();
pwr_tStatus writeSectVolref();
pwr_tStatus prepareSectVolref();
pwr_tStatus writeSectVolref(size_t size);
pwr_tStatus writeSectOid();
pwr_tStatus writeSectObject();
pwr_tStatus writeSectRbody();
pwr_tStatus writeSectName();
pwr_tStatus writeSectClass();
pwr_tStatus writeSectDbody();
pwr_tStatus writeReferencedVolumes();
virtual bool importVolume(wb_export &e);
......
......@@ -230,7 +230,7 @@ void wb_erep::addDbs( pwr_tStatus *sts, wb_vrep *vrep)
vrep_iterator it = m_vrepdbs.find( vrep->vid());
if ( it == m_vrepdbs.end()) {
m_vrepdbs[vrep->vid()] = vrep;
vrep->ref();
vrep->ref();
*sts = LDH__SUCCESS;
}
else {
......@@ -238,8 +238,9 @@ void wb_erep::addDbs( pwr_tStatus *sts, wb_vrep *vrep)
return;
}
if ( vrep->cid() == pwr_eClass_ClassVolume)
if ( vrep->cid() == pwr_eClass_ClassVolume) {
m_merep->addDbs( sts, (wb_mvrep *)vrep);
}
}
void wb_erep::addExtern( pwr_tStatus *sts, wb_vrep *vrep)
......
......@@ -952,8 +952,10 @@ ldh_ObjidToName(ldh_tSession session, pwr_tOid oid, ldh_eName type, char *buf, i
char name[200];
strcpy( name, o.name());
*size = strlen( name);
if ( *size > maxsize - 1)
if ( *size > maxsize - 1) {
return LDH__NAMEBUF;
}
strcpy( buf, name);
}
catch ( wb_error& e) {
......@@ -976,8 +978,9 @@ ldh_ObjidToName(ldh_tSession session, pwr_tOid oid, ldh_eName type, char *buf, i
char name[200];
strcpy( name, o.longName().name( type));
*size = strlen( name);
if ( *size > maxsize - 1)
if ( *size > maxsize - 1) {
return LDH__NAMEBUF;
}
strcpy( buf, name);
}
catch ( wb_error& e) {
......@@ -996,8 +999,9 @@ ldh_ObjidToName(ldh_tSession session, pwr_tOid oid, ldh_eName type, char *buf, i
wb_name n = wb_name( cdh_ObjidToString( NULL, oid, 1));
strcpy( str, n.name( type));
*size = strlen(str);
if ( *size > maxsize - 1)
if ( *size > maxsize - 1) {
return LDH__NAMEBUF;
}
strcpy( buf, str);
break;
}
......
......@@ -58,19 +58,31 @@ wb_mvrep *wb_merep::volume(pwr_tStatus *sts, const char *name)
return 0;
}
wb_orep *wb_merep::object(pwr_tStatus *sts, pwr_tOid oid)
{
wb_vrep *vrep = volume( sts, oid.vid);
if ( EVEN(*sts)) return 0;
return vrep->object( sts, oid);
}
void wb_merep::addDbs( pwr_tStatus *sts, wb_mvrep *mvrep)
{
printf("wb_merep::addDbs: %d, %s\n", mvrep->vid(), mvrep->name());
mvrep_iterator it = m_mvrepdbs.find( mvrep->vid());
if ( it == m_mvrepdbs.end()) {
// Look for vrep in erep list... TODO
m_mvrepdbs[mvrep->vid()] = mvrep;
mvrep->ref();
cout << "Metavolume " << mvrep->vid() << " inserted\n";
cout << "merep Metavolume " << mvrep->vid() << ": " << mvrep->name() << " inserted\n";
*sts = LDH__SUCCESS;
}
else
else {
printf("wb_merep::addDbs, existed: %d, %s\n", mvrep->vid(), mvrep->name());
*sts = LDH__VOLIDALREXI;
}
}
void wb_merep::removeDbs(pwr_tStatus *sts, wb_mvrep *mvrep)
......
......@@ -28,6 +28,7 @@ public:
wb_mvrep *volume(pwr_tStatus *sts, pwr_tVid vid);
wb_mvrep *volume(pwr_tStatus *sts, const char *name);
wb_orep *object(pwr_tStatus *sts, pwr_tOid oid);
void addDbs( pwr_tStatus *sts, wb_mvrep *mvrep);
void removeDbs( pwr_tStatus *sts, wb_mvrep *mvrep);
......
......@@ -112,6 +112,8 @@ wb_object wb_volume::object(pwr_tOid oid) const
if (oid.vid == m_vrep->vid())
// This volume
orep = m_vrep->object( &sts, oid);
else if (oid.vid < 65536)
orep = m_vrep->merep()->object(&sts, oid);
else
// Other volume
orep = m_vrep->erep()->object(&sts, oid);
......
......@@ -140,6 +140,8 @@ public:
void removeSrep( wb_srep *srep);
wb_srep *srep( pwr_tStatus *sts);
wb_srep *nextSrep( pwr_tStatus *sts, wb_srep* srep);
virtual const char *fileName() = 0;
};
#endif
#include <sys/stat.h>
#include <errno.h>
#include "co_cdh.h"
#include "co_tree.h"
#include "wb_db.h"
#include "wb_vrepdb.h"
#include "wb_orepdb.h"
......@@ -24,7 +25,7 @@ wb_vrep *wb_vrepdb::ref()
wb_vrepdb::wb_vrepdb(wb_erep *erep, const char *fileName) :
m_erep(erep), m_nRef(0), m_ohead()
m_erep(erep), m_nRef(0), m_ohead(), m_oid_th(0)
{
strcpy(m_fileName, fileName);
......@@ -39,7 +40,7 @@ wb_vrepdb::wb_vrepdb(wb_erep *erep, const char *fileName) :
}
wb_vrepdb::wb_vrepdb(wb_erep *erep, pwr_tVid vid, pwr_tCid cid, const char *volumeName, const char *fileName) :
m_erep(erep), m_nRef(0), m_ohead()
m_erep(erep), m_nRef(0), m_ohead(), m_oid_th(0)
{
strcpy(m_fileName, fileName);
......@@ -684,8 +685,41 @@ void *wb_vrepdb::readBody(pwr_tStatus *sts, const wb_orep *orp, pwr_eBix bix, vo
bool wb_vrepdb::writeBody(pwr_tStatus *sts, wb_orep *o, pwr_eBix bix, void *p)
{
*sts = LDH__NYI;
return true;
try {
int rc = 0;
m_ohead.get(m_db->m_txn, o->oid());
*sts = LDH__SUCCESS;
switch (bix) {
case pwr_eBix_rt:
{
wb_db_rbody rb(m_db, m_ohead.oid());
rc = rb.put(m_db->m_txn, 0, m_ohead.rbSize(), p);
if (rc)
printf("wb_vrepdb::writeBody rb.put rc %d\n", rc);
break;
}
case pwr_eBix_dev:
{
wb_db_dbody db(m_db, m_ohead.oid());
rc = db.put(m_db->m_txn, 0, m_ohead.dbSize(), p);
if (rc)
printf("wb_vrepdb::writeBody db.put rc %d\n", rc);
break;
}
default:
break;
}
return true;
}
catch (DbException &e) {
*sts = LDH__NOSUCHOBJ;
printf("vrepdb: %s\n", e.what());
return false;
}
}
wb_orep *wb_vrepdb::ancestor(pwr_tStatus *sts, const wb_orep *o)
......@@ -1143,3 +1177,195 @@ void wb_vrepdb::delete_wb_orepdb(void *p)
{
free(p);
}
bool wb_vrepdb::importPasteObject(pwr_tOid doid, ldh_eDest destcode,
bool keepoid, pwr_tOid oid,
pwr_tCid cid, pwr_tOid poid,
pwr_tOid boid, const char *name, pwr_mClassDef flags,
size_t rbSize, size_t dbSize, void *rbody, void *dbody,
pwr_tOid *roid)
{
pwr_tStatus sts;
static pwr_tTime oTime;
if (cdh_ObjidIsNull(poid) && cdh_ObjidIsNull(boid)) {
if (m_oid_th) {
tree_DeleteTable(&sts, m_oid_th);
}
importTranslationTableClear();
importSetSourceVid(oid.vid);
m_oid_th = tree_CreateTable(&sts, sizeof(pwr_tOid), offsetof(sOentry, o_oid), sizeof(sOentry), 1000, tree_Comp_oid);
m_poep = (sOentry *)tree_Insert(&sts, m_oid_th, &poid);
clock_gettime(CLOCK_REALTIME, &oTime);
memset(&m_destination, 0, sizeof(m_destination));
m_destination.oid = doid;
if (cdh_ObjidIsNotNull(doid)) {
try {
m_ohead.get(m_db->m_txn, doid);
//printf("vrepdb, desination (%d.%d, %s) does exist\n", doid.vid, doid.oix, m_ohead.name());
//printf(" p (%d.%d), b (%d.%d), a (%d.%d), f (%d.%d), l (%d.%d)\n", m_ohead.poid().vid, m_ohead.poid().oix, m_ohead.boid().vid, m_ohead.boid().oix, m_ohead.aoid().vid, m_ohead.aoid().oix, m_ohead.foid().vid, m_ohead.foid().oix, m_ohead.loid().vid, m_ohead.loid().oix);
//return m_ohead.name();
}
catch (DbException &e) {
//*sts = LDH__NOSUCHOBJ;
printf("vrepdb, desination (%d.%d) does not exist: %s\n", doid.vid, doid.oix, e.what());
throw wb_error(LDH__PASTEINCON);
}
}
switch (destcode) {
case ldh_eDest_After:
//printf("After\n");
m_destination.poid = m_ohead.poid();
m_destination.foid = m_ohead.oid();
m_destination.loid = m_ohead.aoid();
break;
case ldh_eDest_IntoFirst:
//printf("Into first\n");
m_destination.poid = m_ohead.oid();
m_destination.loid = m_ohead.foid();
break;
default:
printf("Into other\n");
throw wb_error(LDH__NYI);
}
//printf("dest o (%d.%d), p (%d.%d), f (%d.%d), l (%d.%d)\n", m_destination.oid.vid, m_destination.oid.oix, m_destination.poid.vid, m_destination.poid.oix, m_destination.foid.vid, m_destination.foid.oix, m_destination.loid.vid, m_destination.loid.oix);
m_poep->n_oid = m_destination.poid;
}
//printf("wb_vrepdb::importPasteObject: %s, poid: %d.%d boid: %d.%d\n", name, poid.vid, poid.oix, boid.vid, boid.oix);
sOentry *oep = (sOentry *)tree_Insert(&sts, m_oid_th, &oid);
sOentry *poep = oep->parent = (sOentry *)tree_Insert(&sts, m_oid_th, &poid);
if (cdh_ObjidIsNotNull(boid)) {
oep->before = (sOentry *)tree_Insert(&sts, m_oid_th, &boid);
poep->last = oep->before->after = oep;
} else {
poep->first = poep->last = oep;
}
if (keepoid) {
oep->n_oid = m_db->new_oid(m_db->m_txn, oid);
} else {
oep->n_oid = m_db->new_oid(m_db->m_txn);
}
importTranslationTableInsert(oid.oix, oep->n_oid.oix);
wb_name n(name);
m_db->importHead(oep->n_oid, cid, oep->parent->n_oid, pwr_cNOid, pwr_cNOid, pwr_cNOid, pwr_cNOid,
name, n.normName(), flags, oTime, oTime, oTime, rbSize, dbSize);
if (rbSize > 0) {
m_db->importRbody(oep->n_oid, rbSize, rbody);
}
if (dbSize > 0) {
m_db->importDbody(oep->n_oid, dbSize, dbody);
}
return true;
}
bool wb_vrepdb::importPaste()
{
pwr_tStatus sts;
pwr_tTime oTime;
clock_gettime(CLOCK_REALTIME, &oTime);
sOentry *oep = (sOentry*)tree_Minimum(&sts, m_oid_th);
while (oep) {
if (oep != m_poep) {
m_ohead.get(m_db->m_txn, oep->n_oid);
m_ohead.poid(oep->parent->n_oid);
if (oep->before)
m_ohead.boid(oep->before->n_oid);
if (oep->after)
m_ohead.aoid(oep->after->n_oid);
if (oep->first)
m_ohead.foid(oep->first->n_oid);
if (oep->last)
m_ohead.loid(oep->last->n_oid);
m_ohead.ohTime(oTime);
m_ohead.put(m_db->m_txn);
}
oep = (sOentry*)tree_Successor(&sts, m_oid_th, oep);
}
if (cdh_ObjidIsNull(m_destination.foid)) {
m_ohead.get(m_db->m_txn, m_destination.poid);
m_ohead.foid(m_poep->first->n_oid);
m_ohead.ohTime(oTime);
m_ohead.put(m_db->m_txn);
if (cdh_ObjidIsNotNull(m_destination.loid)) {
m_ohead.get(m_db->m_txn, m_destination.loid);
m_ohead.boid(m_poep->last->n_oid);
m_ohead.ohTime(oTime);
m_ohead.put(m_db->m_txn);
m_ohead.get(m_db->m_txn, m_poep->last->n_oid);
m_ohead.aoid(m_destination.loid);
m_ohead.ohTime(oTime);
m_ohead.put(m_db->m_txn);
}
}
if (cdh_ObjidIsNull(m_destination.loid)) {
m_ohead.get(m_db->m_txn, m_destination.poid);
m_ohead.loid(m_poep->last->n_oid);
m_ohead.ohTime(oTime);
m_ohead.put(m_db->m_txn);
if (cdh_ObjidIsNotNull(m_destination.foid)) {
m_ohead.get(m_db->m_txn, m_destination.foid);
m_ohead.aoid(m_poep->first->n_oid);
m_ohead.ohTime(oTime);
m_ohead.put(m_db->m_txn);
m_ohead.get(m_db->m_txn, m_poep->first->n_oid);
m_ohead.boid(m_destination.foid);
m_ohead.ohTime(oTime);
m_ohead.put(m_db->m_txn);
}
}
if (cdh_ObjidIsNotNull(m_destination.foid) && cdh_ObjidIsNotNull(m_destination.loid)) {
m_ohead.get(m_db->m_txn, m_destination.foid);
m_ohead.aoid(m_poep->first->n_oid);
m_ohead.ohTime(oTime);
m_ohead.put(m_db->m_txn);
m_ohead.get(m_db->m_txn, m_poep->first->n_oid);
m_ohead.boid(m_destination.foid);
m_ohead.ohTime(oTime);
m_ohead.put(m_db->m_txn);
m_ohead.get(m_db->m_txn, m_destination.loid);
m_ohead.boid(m_poep->last->n_oid);
m_ohead.ohTime(oTime);
m_ohead.put(m_db->m_txn);
m_ohead.get(m_db->m_txn, m_poep->last->n_oid);
m_ohead.aoid(m_destination.loid);
m_ohead.ohTime(oTime);
m_ohead.put(m_db->m_txn);
}
importUpdateTree(this);
importTranslationTableClear();
tree_DeleteTable(&sts, m_oid_th);
m_oid_th = 0;
return true;
}
......@@ -5,12 +5,50 @@
#include "wb_orepdb.h"
#include "wb_db.h"
#include "db_cxx.h"
#include "co_tree.h"
class wb_vrepdb : public wb_vrep
{
private:
bool deleteFamilyMember(pwr_tOid oid, wb_db_txn *txn);
typedef union {
struct {
pwr_tBit temporary : 1;
pwr_tBit exist : 1;
} b;
pwr_tBitMask m;
#define mOentry_temporary 1
#define mOentry_exist 2
} mOentry;
typedef struct sOentry
{
tree_sNode node;
pwr_tOid o_oid;
pwr_tOid n_oid;
struct sOentry *parent;
struct sOentry *before;
struct sOentry *after;
struct sOentry *first;
struct sOentry *last;
} sOentry;
sOentry *m_poep;
typedef struct sDestination
{
pwr_tOid oid;
pwr_tOid poid;
pwr_tOid foid;
pwr_tOid loid;
} sDestination;
sDestination m_destination;
protected:
wb_erep *m_erep;
wb_merep *m_merep;
......@@ -27,6 +65,8 @@ public:
wb_vrepdb(wb_erep *erep, const char *fileName);
wb_vrepdb(wb_erep *erep, pwr_tVid, pwr_tCid, const char *volumeName, const char *fileName);
tree_sTable *m_oid_th;
virtual void unref();
virtual wb_vrep *ref();
......@@ -132,17 +172,16 @@ public:
virtual bool exportTree(wb_treeimport &i, pwr_tOid oid) { return false;}
virtual bool importTree(bool keepref) { return false;}
virtual bool importTreeObject(wb_merep *merep, pwr_tOid oid, pwr_tCid cid, pwr_tOid poid,
pwr_tOid boid, const char *name, pwr_mClassDef flags,
size_t rbSize, size_t dbSize, void *rbody, void *dbody)
pwr_tOid boid, const char *name, pwr_mClassDef flags,
size_t rbSize, size_t dbSize, void *rbody, void *dbody)
{ return false;}
virtual bool importPaste() { return false;}
virtual bool importPaste();
virtual bool importPasteObject(pwr_tOid destination, ldh_eDest destcode,
bool keepoid, pwr_tOid oid,
pwr_tCid cid, pwr_tOid poid,
pwr_tOid boid, const char *name, pwr_mClassDef flags,
size_t rbSize, size_t dbSize, void *rbody, void *dbody,
pwr_tOid *roid)
{ return false;}
bool keepoid, pwr_tOid oid,
pwr_tCid cid, pwr_tOid poid,
pwr_tOid boid, const char *name, pwr_mClassDef flags,
size_t rbSize, size_t dbSize, void *rbody, void *dbody,
pwr_tOid *roid);
#if 0
int del_family(DbTxn *txn, Dbc *cp, pwr_tOid poid);
......@@ -153,7 +192,7 @@ public:
wb_orepdb *new_wb_orepdb(size_t size);
void delete_wb_orepdb(void *p);
virtual bool accessSupported( ldh_eAccess access) { return true;}
virtual const char *fileName() { return m_fileName;}
};
#endif
......@@ -19,42 +19,66 @@ wb_vrep *wb_vrepdbs::ref()
wb_vrepdbs::wb_vrepdbs(wb_erep *erep, const char *fileName) : m_erep(erep), m_nRef(0), m_duplicate(false)
{
printf("wb_vrepdbs(erep, fileName):%s\n", fileName);
strcpy(m_fileName, fileName);
m_isDbsenvLoaded = false;
if ( isCommonMeta())
if (false && isCommonMeta())
m_merep = m_erep->merep();
else
m_merep = new wb_merep(m_erep, (wb_mvrep *)this);
}
dbs_sEnv *wb_vrepdbs::dbsenv()
wb_vrepdbs::wb_vrepdbs(wb_erep *erep, wb_merep * merep, const char *fileName, dbs_sMenv *mep, dbs_sVenv *vep) : m_erep(erep), m_merep(merep), m_nRef(0), m_dbsmep(mep), m_dbsvep(vep), m_duplicate(false)
{
dbs_sEnv *ep;
printf("wb_vrepdbs(erep, fileName, mep, vep):%d,%s\n", vep->vp->vid, fileName);
strcpy(m_fileName, fileName);
strcpy(m_name, m_dbsvep->vp->name);
m_vid = m_dbsvep->vp->vid;
m_cid = m_dbsvep->vp->cid;
printf("m_name: %s, m_vid: %d, m_cid: %d\n", m_name, m_vid, m_cid);
m_isDbsenvLoaded = true;
}
dbs_sVenv *wb_vrepdbs::dbsenv()
{
pwr_tStatus sts;
if (!m_isDbsenvLoaded) {
ep = dbs_Map(&sts, &m_dbsenv, m_fileName);
if (!ep) {
m_dbsmep = dbs_Map(&sts, m_fileName);
if (!m_dbsmep) {
throw wb_error(sts);
}
m_isDbsenvLoaded = true;
strcpy(m_name, m_dbsenv.vp->name);
m_vid = m_dbsenv.vp->vid;
m_cid = m_dbsenv.vp->cid;
m_dbsvep = dbs_Vmap(&sts, 0, m_dbsmep);
strcpy(m_name, m_dbsvep->vp->name);
m_vid = m_dbsvep->vp->vid;
m_cid = m_dbsvep->vp->cid;
printf("m_name: %s, m_vid: %d, m_cid: %d\n", m_name, m_vid, m_cid);
for (int i = 0; i < dbs_nVolRef(&sts, m_dbsmep); i++) {
dbs_sVenv *vep = dbs_Vmap(&sts, i + 1, m_dbsmep);
wb_vrepdbs *vp = new wb_vrepdbs(m_erep, m_merep, m_fileName, m_dbsmep, vep);
printf("before addDbs, i:%d, name: %s, vid: %d\n", i, vep->vp->name, vep->vp->vid);
m_merep->addDbs(&sts, (wb_mvrep *)vp);
}
} else {
ep = &m_dbsenv;
if (strstr(m_fileName, "x86")) {
//printf("%s::%s\n", m_dbsvep->vp->name, m_fileName);
}
}
return ep;
return m_dbsvep;
}
bool wb_vrepdbs::load()
{
pwr_tStatus sts;
bool rsts = ( dbsenv() != 0);
bool rsts = (dbsenv() != 0);
if ( isMeta())
if (isMeta())
m_merep->addDbs(&sts, (wb_mvrep *)this);
return rsts;
......@@ -387,7 +411,7 @@ bool wb_vrepdbs::isLocal(const wb_orep *)
pwr_tCid wb_vrepdbs::cid() const
{
return m_dbsenv.vp->cid;;
return m_dbsvep->vp->cid;;
}
pwr_tVid wb_vrepdbs::vid() const
......
......@@ -18,12 +18,14 @@ public:
char m_fileName[200];
bool m_isDbsenvLoaded;
dbs_sEnv m_dbsenv;
dbs_sMenv *m_dbsmep;
dbs_sVenv *m_dbsvep;
bool m_duplicate;
wb_vrepdbs(wb_erep *erep, const char *fileName);
wb_vrepdbs(wb_erep *erep, wb_merep * merep, const char *fileName, dbs_sMenv *mep, dbs_sVenv *vep);
dbs_sEnv *dbsenv();
dbs_sVenv *dbsenv();
bool load();
void objectName(const wb_orep *o, char *str);
......@@ -123,7 +125,7 @@ public:
virtual wb_merep *merep () const;
virtual bool createSnapshot (const char *);
virtual bool isCommonMeta() const { return true;}
virtual bool isCommonMeta() const { return false;}
virtual bool isMeta() const { return (cid() == pwr_eClass_ClassVolume);}
......@@ -151,6 +153,7 @@ public:
virtual bool accessSupported( ldh_eAccess access) { return access == ldh_eAccess_ReadOnly; }
virtual bool duplicateDb() const { return m_duplicate;}
virtual void setDuplicateDb( bool duplicate) { m_duplicate = duplicate;}
virtual const char *fileName() { return m_fileName;}
};
......
......@@ -321,6 +321,7 @@ public:
bool updateObject( wb_orep *o, bool keepref);
bool updateSubClass( wb_adrep *subattr, char *body, bool keepref);
virtual bool accessSupported( ldh_eAccess access) { return true;}
virtual const char *fileName() { return "";}
virtual bool importVolume(wb_export &e);
virtual bool importHead(pwr_tOid oid, pwr_tCid cid, pwr_tOid poid,
......
......@@ -202,6 +202,7 @@ public:
pwr_tOid *roid)
{ return false;}
virtual bool accessSupported( ldh_eAccess access) { return access == ldh_eAccess_ReadOnly;}
virtual const char *fileName() { return "";}
};
#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