Commit 22474a51 authored by Jonas Nylund's avatar Jonas Nylund

SEV If an attribute is changed the table will be recreated instead of altered....

SEV If an attribute is changed the table will be recreated instead of altered. A copy of the old table will be saved. This due to very slow alter of table
parent 72e34299
......@@ -585,6 +585,7 @@ int sev_server::check_histitems( sev_sMsgHistItems *msg, unsigned int size)
storagetime = net_NetTimeToDeltaTime( &buffP->storagetime );
sprintf( tablename, "obj_%s", m_db->oid_to_table( buffP->oid, attributeName) );
bool newobject = false;
if ( !m_db->check_objectitem( &m_sts,
tablename,
buffP->oid,
......@@ -608,12 +609,14 @@ int sev_server::check_histitems( sev_sMsgHistItems *msg, unsigned int size)
buffP->options,
&idx);
if ( EVEN(m_sts)) return m_sts;
newobject = true;
}
vector<sev_attr> oldattrVec = m_db->m_items[idx].attr;
vector<sev_attr> newattrVec;
m_db->m_items[idx].value_size = 0;
//Check if any new attributes is found if so add column
bool tableChange = false;
for(size_t j = 0; j < buffP->attrnum; j++) {
//printf( "Received: %s.%s\n", buffP->oname, buffP->attr[j].aname);
sev_attr newattr;
......@@ -624,7 +627,6 @@ int sev_server::check_histitems( sev_sMsgHistItems *msg, unsigned int size)
newattr.elem = 0;
newattrVec.push_back(newattr);
bool tableChange = false;
if ( !m_db->check_objectitemattr( &m_sts,
tablename,
buffP->oid,
......@@ -633,23 +635,24 @@ int sev_server::check_histitems( sev_sMsgHistItems *msg, unsigned int size)
buffP->attr[j].type,
buffP->attr[j].size,
&idx) ) {
m_db->add_objectitemattr( &m_sts,
tablename,
buffP->oid,
buffP->attr[j].aname,
buffP->oname,
buffP->attr[j].type,
buffP->attr[j].size,
&idx);
if ( EVEN(m_sts)) return m_sts;
tableChange = true;
}
}
//Be sure that we have the correct attribute order. Use the list from the client
m_db->m_items[idx].attr.clear();
m_db->m_items[idx].attr = newattrVec;
m_db->m_items[idx].attrnum = newattrVec.size();
if(tableChange) {
//Either an attribute has changed type or size or we have a new attribute
//rename the table to something and create a new one.
//this is the only way to do this without hanging the server for several minutes
m_db->handle_objectchange(&m_sts, tablename, idx, newobject);
}
//If node is coming up again we do not want deadband to be active due to init of old_value
m_db->m_items[idx].deadband_active = 0;
m_db->m_items[idx].first_storage = 1;
......@@ -675,7 +678,6 @@ int sev_server::check_histitems( sev_sMsgHistItems *msg, unsigned int size)
rk = buffP->sevid;
rp = (sev_sRefid *) tree_Insert(&sts, m_refid, &rk);
rp->idx = idx;
}
int numberOfAttributes = buffP->attrnum;
......
......@@ -106,8 +106,6 @@ class sev_db {
pwr_tFloat32 deadband, pwr_tMask options, unsigned int *idx) { return 0;}
virtual int store_objectitem( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *oname, char *aname,
pwr_tDeltaTime storagetime, char *description, pwr_tFloat32 scantime, pwr_tFloat32 deadband, pwr_tMask options) { return 0;}
virtual int add_objectitemattr( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *aname, char *oname,
pwr_eType type, unsigned int size, unsigned int *idx) { return 0;}
virtual int get_item( pwr_tStatus *sts, sev_item *item, char *tablename) { return 0;}
virtual int get_objectitem( pwr_tStatus *sts, sev_item *item, char *tablename) { return 0;}
virtual int get_objectitems( pwr_tStatus *sts) { return 0;}
......@@ -118,6 +116,7 @@ class sev_db {
virtual int get_objectvalues( pwr_tStatus *sts, sev_item *item,
unsigned int size, pwr_tTime *starttime, pwr_tTime *endtime,
int maxsize, pwr_tTime **tbuf, void **vbuf, unsigned int *bsize) { return 0;}
virtual int handle_objectchange(pwr_tStatus *sts, char *tablename, unsigned int item_idx, bool newObject) { return 0;}
};
......
This diff is collapsed.
......@@ -149,10 +149,7 @@ class sev_dbms : public sev_db {
int store_objectitem( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *oname, char *aname,
pwr_tDeltaTime storagetime, char *description, pwr_tFloat32 scantime,
pwr_tFloat32 deadband, pwr_tMask options);
int create_objecttable( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *aname,
pwr_tMask options, float deadband);
int add_objectitemattr( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *aname, char *oname,
pwr_eType type, unsigned int size, unsigned int *idx);
int create_objecttable( pwr_tStatus *sts, char *tablename, pwr_tMask options, float deadband);
int store_objectvalue( pwr_tStatus *sts, int item_idx, int attr_idx,
pwr_tTime time, void *buf, void *oldbuf, unsigned int size);
int get_item( pwr_tStatus *sts, sev_item *item, char *tablename);
......@@ -161,19 +158,15 @@ class sev_dbms : public sev_db {
int get_objectitemattributes( pwr_tStatus *sts, sev_item *item, char *tablename);
int check_objectitemattr( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *aname, char *oname,
pwr_eType type, unsigned int size, unsigned int *idx);
int get_nextattridx( pwr_tStatus *sts, char *tablename );
int delete_old_objectdata( pwr_tStatus *sts, char *tablename,
pwr_tMask options, pwr_tTime limit);
int alter_attrcolumn(pwr_tStatus *sts, char *tablename, char *aname, pwr_eType newtype, unsigned int newsize, pwr_eType oldtype, unsigned int oldsize);
int rename_attrcolumn(pwr_tStatus *sts, char *tablename, char *aname, pwr_eType type, unsigned int size);
int remove_objectitemattr( pwr_tStatus *sts, char *tablename, char *aname);
int update_objectitemattr( pwr_tStatus *sts, char *tablename, char *aname, pwr_eType type, unsigned int size);
int check_deadband(pwr_eType type, unsigned int size, pwr_tFloat32 deadband, void *value, void *oldvalue);
int get_objectvalues( pwr_tStatus *sts, sev_item *item, unsigned int size, pwr_tTime *starttime, pwr_tTime *endtime,
int maxsize, pwr_tTime **tbuf, void **vbuf, unsigned int *bsize);
pwr_tUInt64 get_minFromIntegerColumn( char *tablename, char *colname );
int handle_attrchange(pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *aname, char *oname,
pwr_eType type, unsigned int size, unsigned int item_idx, unsigned int attr_idx);
pwr_tUInt64 get_maxFromIntegerColumn( char *tablename, char *colname );
int handle_itemchange(pwr_tStatus *sts, char *tablename, unsigned int item_idx);
int handle_objectchange(pwr_tStatus *sts, char *tablename, unsigned int item_idx, bool newObject);
};
#endif
#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