Commit 87a1636d authored by Claes Sjofors's avatar Claes Sjofors

Mysql classvolume databases

parent 0bf0dc63
...@@ -151,3 +151,4 @@ ...@@ -151,3 +151,4 @@
091209 cs wb ConnectAttribute method added to SevHist. 091209 cs wb ConnectAttribute method added to SevHist.
091218 cs wb Bugfix for next cix and next oix in ced. 091218 cs wb Bugfix for next cix and next oix in ced.
091218 cs wb Bugfix in wb_vrepdb:child(). 091218 cs wb Bugfix in wb_vrepdb:child().
100111 cs wb Mysql classvolume databases.
\ No newline at end of file
...@@ -2765,7 +2765,7 @@ WttGtk::WttGtk( ...@@ -2765,7 +2765,7 @@ WttGtk::WttGtk(
wnavnode->volume_attached( wbctx, ldhses, 0); wnavnode->volume_attached( wbctx, ldhses, 0);
} }
if ( wb_type == wb_eType_Directory || wb_type == wb_eType_Volume) { if ( (wb_type == wb_eType_Directory || wb_type == wb_eType_Volume) && ldhses) {
// Start configuration wizard if volume is empty // Start configuration wizard if volume is empty
pwr_tOid oid; pwr_tOid oid;
......
...@@ -1501,6 +1501,15 @@ int wb_dbms_rbody::ins(wb_dbms_txn *txn) ...@@ -1501,6 +1501,15 @@ int wb_dbms_rbody::ins(wb_dbms_txn *txn)
return m_db->m_t_rbody->ins(txn, &m_key, &m_data); return m_db->m_t_rbody->ins(txn, &m_key, &m_data);
} }
int wb_dbms_rbody::ins(wb_dbms_txn *txn, size_t offset, size_t size, void *p)
{
m_data.bSize(size);
m_data.size(size);
m_data.data(p);
return m_db->m_t_rbody->ins(txn, &m_key, &m_data);
}
int wb_dbms_rbody::upd(wb_dbms_txn *txn, size_t offset, size_t size, void *p) int wb_dbms_rbody::upd(wb_dbms_txn *txn, size_t offset, size_t size, void *p)
{ {
m_data.size(sizeof(m_db->m_buf)); m_data.size(sizeof(m_db->m_buf));
...@@ -1537,6 +1546,7 @@ int wb_dbms_rbody::get(wb_dbms_txn *txn, size_t offset, size_t size, void *p) ...@@ -1537,6 +1546,7 @@ int wb_dbms_rbody::get(wb_dbms_txn *txn, size_t offset, size_t size, void *p)
memcpy(p, m_db->m_buf + offset, size); memcpy(p, m_db->m_buf + offset, size);
m_size = m_data.size();
return 0; return 0;
} }
...@@ -1630,6 +1640,15 @@ int wb_dbms_dbody::ins(wb_dbms_txn *txn) ...@@ -1630,6 +1640,15 @@ int wb_dbms_dbody::ins(wb_dbms_txn *txn)
return m_db->m_t_dbody->ins(txn, &m_key, &m_data); return m_db->m_t_dbody->ins(txn, &m_key, &m_data);
} }
int wb_dbms_dbody::ins(wb_dbms_txn *txn, size_t offset, size_t size, void *p)
{
m_data.bSize(size);
m_data.size(size);
m_data.data(p);
return m_db->m_t_rbody->ins(txn, &m_key, &m_data);
}
int wb_dbms_dbody::upd(wb_dbms_txn *txn, size_t offset, size_t size, void *p) int wb_dbms_dbody::upd(wb_dbms_txn *txn, size_t offset, size_t size, void *p)
{ {
m_data.size(sizeof(m_db->m_buf)); m_data.size(sizeof(m_db->m_buf));
...@@ -1663,6 +1682,7 @@ int wb_dbms_dbody::get(wb_dbms_txn *txn, size_t offset, size_t size, void *p) ...@@ -1663,6 +1682,7 @@ int wb_dbms_dbody::get(wb_dbms_txn *txn, size_t offset, size_t size, void *p)
printf("*** dbody::get(offset %zd, size %zd, oix %d), size: %zd\n", offset, size, m_oid.oix, m_data.size()); printf("*** dbody::get(offset %zd, size %zd, oix %d), size: %zd\n", offset, size, m_oid.oix, m_data.size());
memcpy(p, m_db->m_buf + offset, size); memcpy(p, m_db->m_buf + offset, size);
m_size = m_data.size();
return 0; return 0;
} }
......
...@@ -55,6 +55,12 @@ extern "C" { ...@@ -55,6 +55,12 @@ extern "C" {
pwr_dImport pwr_BindClasses(System); pwr_dImport pwr_BindClasses(System);
pwr_dImport pwr_BindClasses(Base); pwr_dImport pwr_BindClasses(Base);
typedef enum {
eDbType_db,
eDbType_dbms,
eDbType_wbl
} eDbType;
wb_erep::wb_erep( unsigned int options) : m_nRef(0), m_dir_cnt(0), m_volatile_idx(0), m_buffer_max(10), wb_erep::wb_erep( unsigned int options) : m_nRef(0), m_dir_cnt(0), m_volatile_idx(0), m_buffer_max(10),
m_ref_merep_occupied(false), m_options( options) m_ref_merep_occupied(false), m_options( options)
{ {
...@@ -535,6 +541,11 @@ void wb_erep::loadMeta( pwr_tStatus *status, char *db) ...@@ -535,6 +541,11 @@ void wb_erep::loadMeta( pwr_tStatus *status, char *db)
pwr_tStatus sts; pwr_tStatus sts;
wb_vrepdbs *vrep; wb_vrepdbs *vrep;
int vol_cnt = 0; int vol_cnt = 0;
eDbType db_type;
int is_classvolume = 0;
int load_externvolume;
int load_dbs;
int load_db;
strcpy( fname, load_cNameVolumeList); strcpy( fname, load_cNameVolumeList);
dcli_translate_filename( fname, fname); dcli_translate_filename( fname, fname);
...@@ -546,19 +557,6 @@ void wb_erep::loadMeta( pwr_tStatus *status, char *db) ...@@ -546,19 +557,6 @@ void wb_erep::loadMeta( pwr_tStatus *status, char *db)
*status = LDH__PROJCONFIG; *status = LDH__PROJCONFIG;
// Load directory volume // Load directory volume
#if 0
strcpy( vname, "$pwrp_db/directory.db");
dcli_translate_filename( vname, vname);
sts = dcli_search_file( vname, found_file, DCLI_DIR_SEARCH_INIT);
dcli_search_file( vname, found_file, DCLI_DIR_SEARCH_END);
if ( ODD(sts)) {
wb_vrepdb *vrepdb = new wb_vrepdb( this, vname);
vrepdb->name("directory");
addDb( &sts, vrepdb);
MsgWindow::message( 'I', "Directory database opened", vname);
}
#endif
strcpy( vname, "$pwrp_db/directory.wb_load"); strcpy( vname, "$pwrp_db/directory.wb_load");
dcli_translate_filename( vname, vname); dcli_translate_filename( vname, vname);
...@@ -590,8 +588,30 @@ void wb_erep::loadMeta( pwr_tStatus *status, char *db) ...@@ -590,8 +588,30 @@ void wb_erep::loadMeta( pwr_tStatus *status, char *db)
cdh_StringToVolumeId( vol_array[1], &vid); cdh_StringToVolumeId( vol_array[1], &vid);
if ( cdh_NoCaseStrcmp( vol_array[2], "ExternVolume") == 0) { // Find out what to do with this volume
if ( j == 1) { load_externvolume = 0;
load_dbs = 0;
load_db = 0;
if ( cdh_NoCaseStrcmp( vol_array[2], "ExternVolume") == 0 && j == 1)
load_externvolume = 1;
else if ( cdh_NoCaseStrcmp( vol_array[2], "ClassVolume") == 0 ||
cdh_NoCaseStrcmp( vol_array[2], "DetachedClassVolume") == 0 ||
strcmp( vol_array[3], "load") == 0) {
if ( j == 0)
load_dbs = 1;
if ( ((cdh_NoCaseStrcmp( vol_array[2], "ClassVolume") == 0 ||
cdh_NoCaseStrcmp( vol_array[2], "DetachedClassVolume") == 0) &&
( strcmp( vol_array[3], "cnf") == 0 &&
db && cdh_NoCaseStrcmp( db, vol_array[0]) == 0 ))) {
if ( j == 1)
load_db = 1;
}
}
else if ( j == 1)
load_db = 1;
if ( load_externvolume) {
if ( nr != 6) if ( nr != 6)
cout << "Syntax error in file: " << fname << endl; cout << "Syntax error in file: " << fname << endl;
...@@ -608,11 +628,8 @@ void wb_erep::loadMeta( pwr_tStatus *status, char *db) ...@@ -608,11 +628,8 @@ void wb_erep::loadMeta( pwr_tStatus *status, char *db)
MsgWindow::message( 'E', "Unable to open volume", vname, e.what().c_str()); MsgWindow::message( 'E', "Unable to open volume", vname, e.what().c_str());
} }
} }
}
else if ( cdh_NoCaseStrcmp( vol_array[2], "ClassVolume") == 0 || if ( load_dbs) {
cdh_NoCaseStrcmp( vol_array[2], "DetachedClassVolume") == 0 ||
strcmp( vol_array[3], "load") == 0) {
if ( j == 0) {
if ( nr < 4) if ( nr < 4)
cout << "Syntax error in file: " << fname << endl; cout << "Syntax error in file: " << fname << endl;
...@@ -640,21 +657,6 @@ void wb_erep::loadMeta( pwr_tStatus *status, char *db) ...@@ -640,21 +657,6 @@ void wb_erep::loadMeta( pwr_tStatus *status, char *db)
else else
MsgWindow::message( 'E', "Unable to open volume snapshot file", vname, e.what().c_str()); MsgWindow::message( 'E', "Unable to open volume snapshot file", vname, e.what().c_str());
} }
if ( nr >= 5 && vol_array[4][0] == '1') {
// BerkelyDb class volume
strcpy( vname, "$pwrp_db/");
strcat( vname, vol_array[0]);
strcat( vname, ".db");
dcli_translate_filename( vname, vname);
wb_vrepdb *vrepdb = new wb_vrepdb( this, vname);
wb_vrepced *vrepced = new wb_vrepced( this, vrepdb);
vrepced->name(vol_array[0]);
addDb( &sts, vrepced);
MsgWindow::message( 'I', "Classvolume Database opened", vname);
vol_cnt++;
}
} }
else { else {
// Imported loadfile // Imported loadfile
...@@ -688,9 +690,8 @@ void wb_erep::loadMeta( pwr_tStatus *status, char *db) ...@@ -688,9 +690,8 @@ void wb_erep::loadMeta( pwr_tStatus *status, char *db)
MsgWindow::message( 'E', "Volume snapshotfile not found", vname); MsgWindow::message( 'E', "Volume snapshotfile not found", vname);
} }
} }
} if ( load_db) {
else {
if ( j == 1) {
// Load db for this volume // Load db for this volume
char uname[80]; char uname[80];
...@@ -728,10 +729,31 @@ void wb_erep::loadMeta( pwr_tStatus *status, char *db) ...@@ -728,10 +729,31 @@ void wb_erep::loadMeta( pwr_tStatus *status, char *db)
strcpy( vname, "$pwrp_db/"); strcpy( vname, "$pwrp_db/");
strcat( vname, vol_array[0]); strcat( vname, vol_array[0]);
cdh_ToLower( vname, vname); cdh_ToLower( vname, vname);
if ( cdh_NoCaseStrcmp( vol_array[2], "ClassVolume") == 0) {
is_classvolume = 1;
if ( nr >= 5 && vol_array[4][0] == '2')
db_type = eDbType_dbms;
else if ( nr >= 5 && vol_array[4][0] == '1')
db_type = eDbType_db;
else
db_type = eDbType_wbl;
}
else {
if ( nr >= 5 && vol_array[4][0] == '1') if ( nr >= 5 && vol_array[4][0] == '1')
strcat( vname, ".dbms"); db_type = eDbType_dbms;
else else
db_type = eDbType_db;
}
switch ( db_type) {
case eDbType_dbms:
strcat( vname, ".dbms");
break;
case eDbType_db:
strcat( vname, ".db"); strcat( vname, ".db");
break;
default:
strcat( vname, ".dbxx");
}
dcli_translate_filename( vname, vname); dcli_translate_filename( vname, vname);
sts = dcli_search_file( vname, found_file, DCLI_DIR_SEARCH_INIT); sts = dcli_search_file( vname, found_file, DCLI_DIR_SEARCH_INIT);
...@@ -795,15 +817,38 @@ void wb_erep::loadMeta( pwr_tStatus *status, char *db) ...@@ -795,15 +817,38 @@ void wb_erep::loadMeta( pwr_tStatus *status, char *db)
} }
else { else {
// Open db // Open db
if ( nr >= 5 && vol_array[4][0] == '1') {
if ( nr >= 5 && db_type == eDbType_dbms) {
#if defined PWRE_CONF_MYSQL #if defined PWRE_CONF_MYSQL
if ( is_classvolume) {
wb_vrepdbms *vrepdbms = new wb_vrepdbms( this, vname);
wb_vrepced *vrepced = new wb_vrepced( this, vrepdbms);
vrepced->name(vol_array[0]);
addDb( &sts, vrepced);
MsgWindow::message( 'I', "Classvolume Database opened", vname);
vol_cnt++;
}
else {
wb_vrepdbms *vrepdbms = new wb_vrepdbms( this, vname); wb_vrepdbms *vrepdbms = new wb_vrepdbms( this, vname);
vrepdbms->name(vol_array[0]); vrepdbms->name(vol_array[0]);
addDb( &sts, vrepdbms); addDb( &sts, vrepdbms);
MsgWindow::message( 'I', "Database opened", vname); MsgWindow::message( 'I', "Database opened", vname);
vol_cnt++; vol_cnt++;
}
#endif #endif
} }
else {
if ( is_classvolume) {
wb_vrepdb *vrepdb = new wb_vrepdb( this, vname);
wb_vrepced *vrepced = new wb_vrepced( this, vrepdb);
vrepced->name(vol_array[0]);
addDb( &sts, vrepced);
MsgWindow::message( 'I', "Classvolume Database opened", vname);
vol_cnt++;
}
else { else {
wb_vrepdb *vrepdb = new wb_vrepdb( this, vname); wb_vrepdb *vrepdb = new wb_vrepdb( this, vname);
vrepdb->name(vol_array[0]); vrepdb->name(vol_array[0]);
...@@ -834,48 +879,6 @@ void wb_erep::loadMeta( pwr_tStatus *status, char *db) ...@@ -834,48 +879,6 @@ void wb_erep::loadMeta( pwr_tStatus *status, char *db)
if ( !db || (db && cdh_NoCaseStrcmp( "directory", db) == 0)) { if ( !db || (db && cdh_NoCaseStrcmp( "directory", db) == 0)) {
char uname[80]; char uname[80];
#if 0
strcpy( vname, "$pwrp_db/directory.db");
dcli_translate_filename( vname, vname);
sts = dcli_search_file( vname, found_file, DCLI_DIR_SEARCH_INIT);
dcli_search_file( vname, found_file, DCLI_DIR_SEARCH_END);
if ( EVEN(sts)) {
*status = LDH__PROJCONFIG;
return;
}
if ( wb_dblock::is_locked(vname, uname)) {
char msg[120];
sprintf( msg, "Database directory.db is locked by user %s", uname);
MsgWindow::message( 'E', msg, msgw_ePop_No);
CoWow *wow = MsgWindow::get_wow();
if ( wow) {
int res = wow->CreateModalDialog( "Database Locked", msg, "Exit", 0, "Remove lock", "$pwr_exe/wtt_padlock.png");
switch( res) {
case wow_eModalDialogReturn_NYI:
case wow_eModalDialogReturn_Button2:
case wow_eModalDialogReturn_Button1:
case wow_eModalDialogReturn_Deleted:
exit(0);
case wow_eModalDialogReturn_Button3:
// Remove lock
wb_dblock::dbunlock(vname);
break;
}
}
else
exit(0);
}
wb_vrepdb *vrepdb = new wb_vrepdb( this, vname);
vrepdb->name("directory");
addDb( &sts, vrepdb);
MsgWindow::message( 'I', "Database opened", vname);
#endif
strcpy( vname, "$pwrp_db/directory.wb_load"); strcpy( vname, "$pwrp_db/directory.wb_load");
dcli_translate_filename( vname, vname); dcli_translate_filename( vname, vname);
......
...@@ -886,8 +886,10 @@ pwr_tStatus lfu_SaveDirectoryVolume( ...@@ -886,8 +886,10 @@ pwr_tStatus lfu_SaveDirectoryVolume(
"Database", (char **) &dbenum, &size); "Database", (char **) &dbenum, &size);
if ( EVEN(sts)) return sts; if ( EVEN(sts)) return sts;
if (( cdh_isClassVolumeClass(cid) && *dbenum == 2) || if (( (cid == pwr_cClass_ClassVolumeConfig ||
( !cdh_isClassVolumeClass(cid) && *dbenum == 1)) { cid == pwr_cClass_DetachedClassVolumeConfig) && *dbenum == 2) ||
( !(cid == pwr_cClass_ClassVolumeConfig ||
cid == pwr_cClass_DetachedClassVolumeConfig) && *dbenum == 1)) {
sts = ldh_GetObjectPar( ldhses, envobjid, "RtBody", sts = ldh_GetObjectPar( ldhses, envobjid, "RtBody",
"Server", (char **) &server, &size); "Server", (char **) &server, &size);
if ( EVEN(sts)) return sts; if ( EVEN(sts)) return sts;
...@@ -2635,6 +2637,8 @@ pwr_tStatus lfu_GetVolumeCnf( char *name, pwr_tVid *vid, pwr_tCid *cid, ldh_eVol ...@@ -2635,6 +2637,8 @@ pwr_tStatus lfu_GetVolumeCnf( char *name, pwr_tVid *vid, pwr_tCid *cid, ldh_eVol
*volrep = ldh_eVolRep_Dbms; *volrep = ldh_eVolRep_Dbms;
if ( nr > 5) if ( nr > 5)
strcpy( server, vol_array[5]); strcpy( server, vol_array[5]);
else
strcpy( server, "");
} }
} }
break; break;
...@@ -2648,6 +2652,8 @@ pwr_tStatus lfu_GetVolumeCnf( char *name, pwr_tVid *vid, pwr_tCid *cid, ldh_eVol ...@@ -2648,6 +2652,8 @@ pwr_tStatus lfu_GetVolumeCnf( char *name, pwr_tVid *vid, pwr_tCid *cid, ldh_eVol
*volrep = ldh_eVolRep_Dbms; *volrep = ldh_eVolRep_Dbms;
if ( nr > 5) if ( nr > 5)
strcpy( server, vol_array[5]); strcpy( server, vol_array[5]);
else
strcpy( server, "");
} }
} }
break; break;
......
...@@ -2558,7 +2558,7 @@ void wb_vrepced::printStructFile( bool hpp) ...@@ -2558,7 +2558,7 @@ void wb_vrepced::printStructFile( bool hpp)
if ( !body_found) { if ( !body_found) {
fp << fp <<
"#ifndef pwr_cClass_" << pgmname << endl << "#ifndef pwr_cClass_" << pgmname << endl <<
"#define pwr_cClass_" << pgmname << " " << o_cdef->cid() << "UL" << endl << endl; "#define pwr_cClass_" << pgmname << " " << cdh_ClassObjidToId( o_cdef->oid()) << "UL" << endl << endl;
body_found = true; body_found = true;
} }
......
...@@ -300,7 +300,7 @@ wb_orep* wb_vrepdbms::object(pwr_tStatus *sts, pwr_tOid oid) ...@@ -300,7 +300,7 @@ wb_orep* wb_vrepdbms::object(pwr_tStatus *sts, pwr_tOid oid)
} }
catch (wb_dbms_error &e) { catch (wb_dbms_error &e) {
*sts = LDH__NOSUCHOBJ; *sts = LDH__NOSUCHOBJ;
printf("vrepdbms: %s\n", e.what().c_str()); // printf("vrepdbms: %s\n", e.what().c_str());
return 0; return 0;
} }
} }
...@@ -329,7 +329,7 @@ wb_orep* wb_vrepdbms::object(pwr_tStatus *sts, wb_name &name) ...@@ -329,7 +329,7 @@ wb_orep* wb_vrepdbms::object(pwr_tStatus *sts, wb_name &name)
} }
catch (wb_dbms_error &e) { catch (wb_dbms_error &e) {
*sts = LDH__NOSUCHOBJ; *sts = LDH__NOSUCHOBJ;
printf("vrepdbms: %s\n", e.what().c_str()); // printf("vrepdbms: %s\n", e.what().c_str());
return 0; return 0;
} }
} }
...@@ -344,7 +344,7 @@ wb_orep* wb_vrepdbms::object(pwr_tStatus *sts, const wb_orep *parent, wb_name &n ...@@ -344,7 +344,7 @@ wb_orep* wb_vrepdbms::object(pwr_tStatus *sts, const wb_orep *parent, wb_name &n
} }
catch (wb_dbms_error &e) { catch (wb_dbms_error &e) {
*sts = LDH__NOSUCHOBJ; *sts = LDH__NOSUCHOBJ;
printf("vrepdbms: %s\n", e.what().c_str()); // printf("vrepdbms: %s\n", e.what().c_str());
return 0; return 0;
} }
} }
...@@ -706,7 +706,6 @@ bool wb_vrepdbms::renameObject(pwr_tStatus *sts, wb_orep *orp, wb_name &name) ...@@ -706,7 +706,6 @@ bool wb_vrepdbms::renameObject(pwr_tStatus *sts, wb_orep *orp, wb_name &name)
n.name(name); n.name(name);
rc = n.ins(txn); rc = n.ins(txn);
if (rc) { if (rc) {
printf("wb_vrepdbms::renameObject, n.ins rc %d\n", rc);
*sts = LDH__NAMALREXI; *sts = LDH__NAMALREXI;
txn->abort(); txn->abort();
m_ohead.clear(); m_ohead.clear();
...@@ -721,9 +720,9 @@ bool wb_vrepdbms::renameObject(pwr_tStatus *sts, wb_orep *orp, wb_name &name) ...@@ -721,9 +720,9 @@ bool wb_vrepdbms::renameObject(pwr_tStatus *sts, wb_orep *orp, wb_name &name)
} }
catch (wb_dbms_error &e) { catch (wb_dbms_error &e) {
txn->subAbort(); txn->subAbort();
printf("wb_vrepdbms::renameObject, exception %s\n", e.what().c_str()); // printf("wb_vrepdbms::renameObject, exception %s\n", e.what().c_str());
m_ohead.clear(); m_ohead.clear();
*sts = LDH__DBERROR; *sts = LDH__NAMALREXI;
return false; return false;
} }
} }
...@@ -2239,6 +2238,11 @@ wb_vrepdbms::updateObject(pwr_tOid oid, pwr_tCid cid) ...@@ -2239,6 +2238,11 @@ wb_vrepdbms::updateObject(pwr_tOid oid, pwr_tCid cid)
time_GetTime( &time); time_GetTime( &time);
if (rbody) { if (rbody) {
if ( rsize != rb.m_size) {
rc = rb.del(m_db->m_txn);
rc = rb.ins(m_db->m_txn, 0, rsize, rbody);
}
else
rc = rb.upd(m_db->m_txn, 0, rsize, rbody); rc = rb.upd(m_db->m_txn, 0, rsize, rbody);
if (rc) if (rc)
printf("wb_vrepdbms:writeBody rb.upd rc %d\n", rc); printf("wb_vrepdbms:writeBody rb.upd rc %d\n", rc);
...@@ -2249,6 +2253,11 @@ wb_vrepdbms::updateObject(pwr_tOid oid, pwr_tCid cid) ...@@ -2249,6 +2253,11 @@ wb_vrepdbms::updateObject(pwr_tOid oid, pwr_tCid cid)
} }
if (dbody) { if (dbody) {
if ( dsize != db.m_size) {
rc = db.del(m_db->m_txn);
rc = db.ins(m_db->m_txn, 0, dsize, dbody);
}
else
rc = db.upd(m_db->m_txn, 0, dsize, dbody); rc = db.upd(m_db->m_txn, 0, dsize, dbody);
if (rc) if (rc)
printf("wb_vrepdbms:writeBody db.upd rc %d\n", rc); printf("wb_vrepdbms:writeBody db.upd rc %d\n", rc);
......
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