From a86022fc495e64e1673d6ba2c2911fc47cbdb6c2 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Wed, 12 Aug 2015 15:44:11 +0200 Subject: [PATCH] RdExtInit is now OK for recovery. --- idl/SALOME_SDS.idl | 1 + src/SALOMESDS/SALOMESDS_DataScopeServer.cxx | 41 ++++++++++++++----- src/SALOMESDS/SALOMESDS_DataScopeServer.hxx | 4 +- ...LOMESDS_PickelizedPyObjRdExtInitServer.cxx | 5 +++ ...LOMESDS_PickelizedPyObjRdExtInitServer.hxx | 1 + src/SALOMESDS/SALOMESDS_Transaction.cxx | 9 +++- src/SALOMESDS/SALOMESDS_Transaction.hxx | 7 ++++ src/SALOMESDS/TestSalomeSDS.py | 24 +++++++++++ 8 files changed, 80 insertions(+), 12 deletions(-) diff --git a/idl/SALOME_SDS.idl b/idl/SALOME_SDS.idl index e0ccd185b..cabea85c9 100644 --- a/idl/SALOME_SDS.idl +++ b/idl/SALOME_SDS.idl @@ -117,6 +117,7 @@ module SALOME string getAccessOfVar(in string varName) raises (SALOME::SALOME_Exception); Transaction createRdOnlyVarTransac(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception); Transaction createRdExtVarTransac(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception); + Transaction createRdExtInitVarTransac(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception); Transaction createRdWrVarTransac(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception); Transaction addKeyValueInVarHard(in string varName, in ByteVec keyValue, in ByteVec constValue) raises (SALOME::SALOME_Exception); Transaction addKeyValueInVarErrorIfAlreadyExisting(in string varName, in ByteVec keyValue, in ByteVec constValue) raises (SALOME::SALOME_Exception); diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx index 528e25664..e471c502f 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx @@ -362,19 +362,23 @@ void DataScopeServerBase::moveStatusOfVarFromRdOnlyToRdWr(const std::string& var varc->decrRef(); } -void DataScopeServerBase::moveStatusOfVarFromRdExtToRdExtInit(const std::string& varName) +void DataScopeServerBase::moveStatusOfVarFromRdExtOrRdExtInitToRdExtInit(const std::string& varName) { std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator it(retrieveVarInternal4(varName)); std::pair< SALOME::BasicDataServer_var, BasicDataServer * >& p(*it); - PickelizedPyObjRdExtServer *varc(dynamic_cast(p.second)); - if(!varc) - throw Exception("DataScopeServerBase::moveStatusOfVarFromRdExtToRdExtInit : var is not a RdExt !"); - PyObject *pyobj(varc->getPyObj()); Py_XINCREF(pyobj); - PickelizedPyObjRdExtInitServer *newVar(new PickelizedPyObjRdExtInitServer(this,varName,pyobj)); - CORBA::Object_var obj(newVar->activate()); - SALOME::BasicDataServer_var obj2(SALOME::BasicDataServer::_narrow(obj)); - p.first=obj2; p.second=newVar; - varc->decrRef(); + PickelizedPyObjRdExtServer *varc0(dynamic_cast(p.second)); + PickelizedPyObjRdExtInitServer *varc1(dynamic_cast(p.second)); + if(!varc0 && !varc1) + throw Exception("DataScopeServerBase::moveStatusOfVarFromRdExtOrRdExtInitToRdExtInit : var is neither RdExt nor RdExtInit !"); + if(varc0) + { + PyObject *pyobj(varc0->getPyObj()); Py_XINCREF(pyobj); + PickelizedPyObjRdExtInitServer *newVar(new PickelizedPyObjRdExtInitServer(this,varName,pyobj)); + CORBA::Object_var obj(newVar->activate()); + SALOME::BasicDataServer_var obj2(SALOME::BasicDataServer::_narrow(obj)); + p.first=obj2; p.second=newVar; + varc0->decrRef(); + } } void DataScopeServerBase::moveStatusOfVarFromRdExtInitToRdExt(const std::string& varName) @@ -525,6 +529,15 @@ void DataScopeServerTransaction::createRdExtVarInternal(const std::string& varNa _vars.push_back(p); } +void DataScopeServerTransaction::createRdExtInitVarInternal(const std::string& varName, const SALOME::ByteVec& constValue) +{ + checkNotAlreadyExistingVar(varName); + PickelizedPyObjRdExtInitServer *tmp(new PickelizedPyObjRdExtInitServer(this,varName,constValue)); + CORBA::Object_var ret(tmp->activate()); + std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(ret),tmp); + _vars.push_back(p); +} + void DataScopeServerTransaction::createRdWrVarInternal(const std::string& varName, const SALOME::ByteVec& constValue) { checkNotAlreadyExistingVar(varName); @@ -550,6 +563,14 @@ SALOME::Transaction_ptr DataScopeServerTransaction::createRdExtVarTransac(const return SALOME::Transaction::_narrow(obj); } +SALOME::Transaction_ptr DataScopeServerTransaction::createRdExtInitVarTransac(const char *varName, const SALOME::ByteVec& constValue) +{ + checkNotAlreadyExistingVar(varName); + TransactionRdExtInitVarCreate *ret(new TransactionRdExtInitVarCreate(this,varName,constValue)); + CORBA::Object_var obj(ret->activate()); + return SALOME::Transaction::_narrow(obj); +} + SALOME::Transaction_ptr DataScopeServerTransaction::createRdWrVarTransac(const char *varName, const SALOME::ByteVec& constValue) { checkNotAlreadyExistingVar(varName); diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx index cab0c12bd..261b5ac00 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx @@ -85,7 +85,7 @@ namespace SALOMESDS public: void moveStatusOfVarFromRdWrToRdOnly(const std::string& varName); void moveStatusOfVarFromRdOnlyToRdWr(const std::string& varName); - void moveStatusOfVarFromRdExtToRdExtInit(const std::string& varName); + void moveStatusOfVarFromRdExtOrRdExtInitToRdExtInit(const std::string& varName); void moveStatusOfVarFromRdExtInitToRdExt(const std::string& varName); protected: std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::const_iterator retrieveVarInternal3(const std::string& varName) const; @@ -122,6 +122,7 @@ namespace SALOMESDS ~DataScopeServerTransaction(); void createRdOnlyVarInternal(const std::string& varName, const SALOME::ByteVec& constValue); void createRdExtVarInternal(const std::string& varName, const SALOME::ByteVec& constValue); + void createRdExtInitVarInternal(const std::string& varName, const SALOME::ByteVec& constValue); void createRdWrVarInternal(const std::string& varName, const SALOME::ByteVec& constValue); PortableServer::POA_var getPOA4KeyWaiter() const { return _poa_for_key_waiter; } void addWaitKey(KeyWaiter *kw); @@ -132,6 +133,7 @@ namespace SALOMESDS char *getAccessOfVar(const char *varName); SALOME::Transaction_ptr createRdOnlyVarTransac(const char *varName, const SALOME::ByteVec& constValue); SALOME::Transaction_ptr createRdExtVarTransac(const char *varName, const SALOME::ByteVec& constValue); + SALOME::Transaction_ptr createRdExtInitVarTransac(const char *varName, const SALOME::ByteVec& constValue); SALOME::Transaction_ptr createRdWrVarTransac(const char *varName, const SALOME::ByteVec& constValue); SALOME::Transaction_ptr addKeyValueInVarHard(const char *varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value); SALOME::Transaction_ptr addKeyValueInVarErrorIfAlreadyExisting(const char *varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value); diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtInitServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtInitServer.cxx index 608af2dfb..d345fd15a 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtInitServer.cxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtInitServer.cxx @@ -29,6 +29,11 @@ using namespace SALOMESDS; const char PickelizedPyObjRdExtInitServer::ACCESS_REPR[]="RdExtInit"; +PickelizedPyObjRdExtInitServer::PickelizedPyObjRdExtInitServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServerModifiable(father,varName,value) +{ + _self_deep_copy=DeepCopyPyObj(_self); +} + //! obj is consumed PickelizedPyObjRdExtInitServer::PickelizedPyObjRdExtInitServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj):PickelizedPyObjServerModifiable(father,varName,obj),_self_deep_copy(0) { diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtInitServer.hxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtInitServer.hxx index d5b7c781c..25f94d6f7 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtInitServer.hxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtInitServer.hxx @@ -33,6 +33,7 @@ namespace SALOMESDS class PickelizedPyObjRdExtInitServer : public PickelizedPyObjServerModifiable, public virtual POA_SALOME::PickelizedPyObjRdExtInitServer { public: + PickelizedPyObjRdExtInitServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value); PickelizedPyObjRdExtInitServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj); ~PickelizedPyObjRdExtInitServer(); public: diff --git a/src/SALOMESDS/SALOMESDS_Transaction.cxx b/src/SALOMESDS/SALOMESDS_Transaction.cxx index a903cca49..6b4577cfa 100644 --- a/src/SALOMESDS/SALOMESDS_Transaction.cxx +++ b/src/SALOMESDS/SALOMESDS_Transaction.cxx @@ -87,6 +87,13 @@ void TransactionRdExtVarCreate::perform() _dsct->createRdExtVarInternal(_var_name,data2); } +void TransactionRdExtInitVarCreate::perform() +{ + SALOME::ByteVec data2; + FromVBToByteSeq(_data,data2); + _dsct->createRdExtInitVarInternal(_var_name,data2); +} + void TransactionRdWrVarCreate::perform() { SALOME::ByteVec data2; @@ -228,7 +235,7 @@ void TransactionMorphRdWrIntoRdOnly::notify() TransactionMultiKeyAddSession::TransactionMultiKeyAddSession(DataScopeServerTransaction *dsct, const std::string& varName):Transaction(dsct,varName) { - _dsct->moveStatusOfVarFromRdExtToRdExtInit(_var_name); + _dsct->moveStatusOfVarFromRdExtOrRdExtInitToRdExtInit(_var_name); } void TransactionMultiKeyAddSession::addKeyValueInVarErrorIfAlreadyExistingNow(const SALOME::ByteVec& key, const SALOME::ByteVec& value) diff --git a/src/SALOMESDS/SALOMESDS_Transaction.hxx b/src/SALOMESDS/SALOMESDS_Transaction.hxx index 8d3db4479..c58ccd929 100644 --- a/src/SALOMESDS/SALOMESDS_Transaction.hxx +++ b/src/SALOMESDS/SALOMESDS_Transaction.hxx @@ -83,6 +83,13 @@ namespace SALOMESDS void perform(); }; + class TransactionRdExtInitVarCreate : public TransactionVarCreate + { + public: + TransactionRdExtInitVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):TransactionVarCreate(dsct,varName,constValue) { } + void perform(); + }; + class TransactionRdWrVarCreate : public TransactionVarCreate { public: diff --git a/src/SALOMESDS/TestSalomeSDS.py b/src/SALOMESDS/TestSalomeSDS.py index 80557dc58..bd333ca39 100644 --- a/src/SALOMESDS/TestSalomeSDS.py +++ b/src/SALOMESDS/TestSalomeSDS.py @@ -277,6 +277,30 @@ class SalomeSDSTest(unittest.TestCase): dsm.removeDataScope(scopeName) pass + def testTransaction7(self): + """Like testTransaction5 but after a recovery.""" + scopeName="Scope1" + varName="a" + dsm=salome.naming_service.Resolve("/DataServerManager") + dsm.cleanScopesInNS() + if scopeName in dsm.listScopes(): + dsm.removeDataScope(scopeName) + dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName) + self.assertTrue(isCreated) + # + t0=dss.createRdExtInitVarTransac(varName,obj2Str({"ab":[4,5,6]})) + dss.atomicApply([t0]) + # + self.assertEqual(dss.getAccessOfVar(varName),"RdExtInit") + t1=dss.addMultiKeyValueSession(varName) + self.assertEqual(dss.getAccessOfVar(varName),"RdExtInit") + t1.addKeyValueInVarErrorIfAlreadyExistingNow(obj2Str("cd"),obj2Str([7,8,9,10])) + self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6]})# it is not a bug ! commit of t1 not done ! + dss.atomicApply([t1]) + self.assertEqual(dss.getAccessOfVar(varName),"RdExt") + self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6],'cd':[7,8,9,10]}) + pass + def setUp(self): salome.salome_init() pass -- 2.39.2