diff options
author | Benoit Foucher <benoit@zeroc.com> | 2013-09-03 15:42:19 +0200 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2013-09-03 15:42:19 +0200 |
commit | 91f6ebb998532b36fc70187b641a5b7404060422 (patch) | |
tree | ac88e961c68e4b09eb819f4b57b9ecac56854567 /cpp/src/IceGrid/FreezeDB/FreezeDB.cpp | |
parent | ICE-5378 - Remove slice35d.dll from Windows installer (diff) | |
download | ice-91f6ebb998532b36fc70187b641a5b7404060422.tar.bz2 ice-91f6ebb998532b36fc70187b641a5b7404060422.tar.xz ice-91f6ebb998532b36fc70187b641a5b7404060422.zip |
Fixed ICE-5358 - allow IceGrid replica to initialize its database from another replica
Diffstat (limited to 'cpp/src/IceGrid/FreezeDB/FreezeDB.cpp')
-rw-r--r-- | cpp/src/IceGrid/FreezeDB/FreezeDB.cpp | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/cpp/src/IceGrid/FreezeDB/FreezeDB.cpp b/cpp/src/IceGrid/FreezeDB/FreezeDB.cpp index 06faa62a020..1cd6479cc74 100644 --- a/cpp/src/IceGrid/FreezeDB/FreezeDB.cpp +++ b/cpp/src/IceGrid/FreezeDB/FreezeDB.cpp @@ -12,6 +12,7 @@ #include <IceGrid/FreezeDB/StringApplicationInfoDict.h> #include <IceGrid/FreezeDB/StringAdapterInfoDict.h> #include <IceGrid/FreezeDB/IdentityObjectInfoDict.h> +#include <IceGrid/FreezeDB/SerialsDict.h> #include <IceUtil/FileUtil.h> @@ -32,6 +33,51 @@ createFreezeDB(const Ice::CommunicatorPtr& communicator, const string& /*name*/, namespace { +Ice::Long +updateSerialDB(const Freeze::ConnectionPtr& connection, const std::string& dbName, Ice::Long serial) +{ + if(serial == -1) // Master doesn't support serials. + { + return -1; + } + + SerialsDict dict(connection, "serials"); + + // + // If a serial number is provided, juste update the serial number from the database, + // otherwise if the serial is 0, we increment the serial from the database. + // + SerialsDict::iterator p = dict.find(dbName); + if(p == dict.end()) + { + dict.insert(pair<string, Ice::Long>(dbName, serial == 0 ? 1 : serial)); + return 1; + } + else + { + p.set(serial == 0 ? p->second + 1 : serial); + return p->second; + } +} + +Ice::Long +getSerialDB(const Freeze::ConnectionPtr& connection, const std::string& dbName) +{ + SerialsDict dict(connection, "serials"); + + // + // If a serial number is provided, juste update the serial number from the database, + // otherwise if the serial is 0, we increment the serial from the database. + // + SerialsDict::iterator p = dict.find(dbName); + if(p == dict.end()) + { + dict.insert(pair<string, long>(dbName, 1)); + return 1; + } + return p->second; +} + // // Freeze wrappers for Freeze dictionaries // @@ -45,6 +91,18 @@ public: FreezeDB::Wrapper<StringApplicationInfoDict, std::string, ApplicationInfo>(connection, dbName) { } + + virtual Ice::Long + updateSerial(Ice::Long serial) + { + return updateSerialDB(_dict.getConnection(), _dbName, serial); + } + + virtual Ice::Long + getSerial() const + { + return getSerialDB(_dict.getConnection(), _dbName); + } }; class FreezeAdaptersWrapper : public FreezeDB::Wrapper<StringAdapterInfoDict, std::string, AdapterInfo>, @@ -67,6 +125,18 @@ public: } return result; } + + virtual Ice::Long + updateSerial(Ice::Long serial) + { + return updateSerialDB(_dict.getConnection(), _dbName, serial); + } + + virtual Ice::Long + getSerial() const + { + return getSerialDB(_dict.getConnection(), _dbName); + } }; class FreezeObjectsWrapper : public FreezeDB::Wrapper<IdentityObjectInfoDict, Ice::Identity, ObjectInfo>, @@ -89,6 +159,18 @@ public: } return result; } + + virtual Ice::Long + updateSerial(Ice::Long serial) + { + return updateSerialDB(_dict.getConnection(), _dbName, serial); + } + + virtual Ice::Long + getSerial() const + { + return getSerialDB(_dict.getConnection(), _dbName); + } }; } @@ -129,6 +211,27 @@ FreezeConnectionPool::getInternalObjects(const IceDB::DatabaseConnectionPtr& con return new FreezeObjectsWrapper(c->freezeConnection(), "internal-objects"); } +map<string, Ice::Long> +FreezeConnectionPool::getSerials() const +{ + map<string, Ice::Long> serials; + try + { + IceDB::DatabaseConnectionPtr connection = const_cast<FreezeConnectionPool*>(this)->newConnection(); + FreezeDB::DatabaseConnection* c = dynamic_cast<FreezeDB::DatabaseConnection*>(connection.get()); + SerialsDict dict(c->freezeConnection(), "serials"); + for(SerialsDict::const_iterator p = dict.begin(); p != dict.end(); ++p) + { + serials.insert(pair<string, Ice::Long>(p->first, p->second)); + } + } + catch(const Freeze::DatabaseException& ex) + { + FreezeDB::throwDatabaseException(__FILE__, __LINE__, ex); + } + return serials; +} + FreezeDBPlugin::FreezeDBPlugin(const Ice::CommunicatorPtr& communicator) : _communicator(communicator) { } |