diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/IceGrid/IceGridNode.cpp | 10 | ||||
-rw-r--r-- | cpp/src/IceGrid/IceGridRegistry.cpp | 4 | ||||
-rw-r--r-- | cpp/src/IceGrid/NodeI.cpp | 109 | ||||
-rw-r--r-- | cpp/src/IceGrid/NodeI.h | 4 | ||||
-rw-r--r-- | cpp/src/IceGrid/RegistryI.cpp | 63 | ||||
-rw-r--r-- | cpp/src/IceGrid/RegistryI.h | 13 | ||||
-rw-r--r-- | cpp/src/IceGrid/ServerI.cpp | 45 | ||||
-rw-r--r-- | cpp/src/IceGrid/ServerI.h | 4 |
8 files changed, 116 insertions, 136 deletions
diff --git a/cpp/src/IceGrid/IceGridNode.cpp b/cpp/src/IceGrid/IceGridNode.cpp index 9f997d2b577..c8ee67a6d18 100644 --- a/cpp/src/IceGrid/IceGridNode.cpp +++ b/cpp/src/IceGrid/IceGridNode.cpp @@ -97,7 +97,7 @@ class CollocatedRegistry : public RegistryI { public: - CollocatedRegistry(const CommunicatorPtr&, const ActivatorPtr&); + CollocatedRegistry(const CommunicatorPtr&, const ActivatorPtr&, bool); virtual void shutdown(); private: @@ -135,8 +135,8 @@ private: } -CollocatedRegistry::CollocatedRegistry(const CommunicatorPtr& communicator, const ActivatorPtr& activator) : - RegistryI(communicator, new TraceLevels(communicator, "IceGrid.Registry")), +CollocatedRegistry::CollocatedRegistry(const CommunicatorPtr& com, const ActivatorPtr& activator, bool nowarn) : + RegistryI(com, new TraceLevels(com, "IceGrid.Registry"), nowarn), _activator(activator) { } @@ -300,8 +300,8 @@ NodeService::start(int argc, char* argv[]) // if(properties->getPropertyAsInt("IceGrid.Node.CollocateRegistry") > 0) { - _registry = new CollocatedRegistry(communicator(), _activator); - if(!_registry->start(nowarn)) + _registry = new CollocatedRegistry(communicator(), _activator, nowarn); + if(!_registry->start()) { return false; } diff --git a/cpp/src/IceGrid/IceGridRegistry.cpp b/cpp/src/IceGrid/IceGridRegistry.cpp index 7bb5a5fa73a..ef2f30747e4 100644 --- a/cpp/src/IceGrid/IceGridRegistry.cpp +++ b/cpp/src/IceGrid/IceGridRegistry.cpp @@ -117,8 +117,8 @@ RegistryService::start(int argc, char* argv[]) TraceLevelsPtr traceLevels = new TraceLevels(communicator(), "IceGrid.Registry"); - _registry = new RegistryI(communicator(), traceLevels); - if(!_registry->start(nowarn)) + _registry = new RegistryI(communicator(), traceLevels, nowarn); + if(!_registry->start()) { return false; } diff --git a/cpp/src/IceGrid/NodeI.cpp b/cpp/src/IceGrid/NodeI.cpp index fad3df4afcc..63471ae03b4 100644 --- a/cpp/src/IceGrid/NodeI.cpp +++ b/cpp/src/IceGrid/NodeI.cpp @@ -212,7 +212,8 @@ NodeI::NodeI(const Ice::ObjectAdapterPtr& adapter, _userAccountMapper(mapper), _platform("IceGrid.Node", _communicator, _traceLevels), _fileCache(new FileCache(_communicator)), - _serial(1) + _serial(1), + _consistencyCheckDone(false) { Ice::PropertiesPtr props = _communicator->getProperties(); @@ -790,6 +791,16 @@ void NodeI::checkConsistency(const NodeSessionPrx& session) { // + // Only do the consistency check on the startup. This ensures that servers can't + // be removed by a bogus master when the master session is re-established. + // + if(_consistencyCheckDone) + { + return; + } + _consistencyCheckDone = true; + + // // We use a serial number to keep track of the concurrent changes // on the node. When a server is loaded/destroyed the serial is // incremented. This allows to ensure that the list of servers @@ -1085,6 +1096,7 @@ NodeI::checkConsistencyNoSync(const Ice::StringSeq& servers) out << "removing server directory `" << _serversDir << "/" << *p << "' failed:\n" << msg; } + *p = _serversDir + "/" + *p; ++p; } } @@ -1097,68 +1109,12 @@ NodeI::checkConsistencyNoSync(const Ice::StringSeq& servers) return commands; } - if(remove.empty()) - { - return commands; - } - - // - // If there's server that couldn't be removed we move them to the - // temporary backup directory. First, we rotate the temporary - // backup directories. - // - try - { - contents.clear(); - contents = readDirectory(_tmpDir); - } - catch(const string& msg) - { - Ice::Error out(_traceLevels->logger); - out << "couldn't read directory `" << _tmpDir << "':\n" << msg; - return commands; - } - - if(contents.size() < 10) - { - ostringstream os; - os << "servers-" << contents.size(); - contents.push_back(os.str()); - sort(contents.begin(), contents.end(), greater<string>()); - } - else if(contents.size() == 10) - { - sort(contents.begin(), contents.end(), greater<string>()); - try - { - removeRecursive(_tmpDir + "/" + *contents.begin()); - } - catch(const string& msg) - { - Ice::Warning out(_traceLevels->logger); - out << msg; - } - } - - try - { - Ice::StringSeq::const_iterator p; - for(p = contents.begin(); p != (contents.end() - 1); ++p) - { - rename(_tmpDir + "/" + *(p + 1), _tmpDir + "/" + *p); - } - createDirectoryRecursive(_tmpDir + "/servers-0"); - for(p = remove.begin(); p != remove.end(); ++p) - { - rename(_serversDir + "/" + *p, _tmpDir + "/servers-0/" + *p); - } - } - catch(const string& msg) + if(!remove.empty()) { Ice::Warning out(_traceLevels->logger); - out << "rotation failed: " << msg; + out << "server directories containing data not created or written by IceGrid were not removed:\n"; + out << toString(remove); } - return commands; } @@ -1174,19 +1130,21 @@ NodeI::canRemoveServerDirectory(const string& name) // // Check if there's files which we didn't create. // - Ice::StringSeq contents = readDirectory(_serversDir + "/" + name); - remove(contents.begin(), contents.end(), "dbs"); - remove(contents.begin(), contents.end(), "config"); - remove(contents.begin(), contents.end(), "distrib"); + Ice::StringSeq c = readDirectory(_serversDir + "/" + name); + set<string> contents(c.begin(), c.end()); + contents.erase("dbs"); + contents.erase("dbs"); + contents.erase("config"); + contents.erase("distrib"); + contents.erase("revision"); if(!contents.empty()) { return false; } - contents = readDirectory(_serversDir + "/" + name + "/config"); - + c = readDirectory(_serversDir + "/" + name + "/config"); Ice::StringSeq::const_iterator p; - for(p = contents.begin() ; p != contents.end(); ++p) + for(p = c.begin() ; p != c.end(); ++p) { if(p->find("config") != 0) { @@ -1194,12 +1152,19 @@ NodeI::canRemoveServerDirectory(const string& name) } } - contents = readDirectory(_serversDir + "/" + name + "/dbs"); - for(p = contents.begin() ; p != contents.end(); ++p) + c = readDirectory(_serversDir + "/" + name + "/dbs"); + for(p = c.begin() ; p != c.end(); ++p) { - Ice::StringSeq files = readDirectory(_serversDir + "/" + name + "/dbs/" + *p); - remove(files.begin(), files.end(), "DB_CONFIG"); - if(!files.empty()) + try + { + Ice::StringSeq files = readDirectory(_serversDir + "/" + name + "/dbs/" + *p); + files.erase(remove(files.begin(), files.end(), "DB_CONFIG"), files.end()); + if(!files.empty()) + { + return false; + } + } + catch(const string&) { return false; } diff --git a/cpp/src/IceGrid/NodeI.h b/cpp/src/IceGrid/NodeI.h index 612c371d135..36ac0019c0e 100644 --- a/cpp/src/IceGrid/NodeI.h +++ b/cpp/src/IceGrid/NodeI.h @@ -104,10 +104,11 @@ public: Ice::Identity createServerIdentity(const std::string&) const; std::string getServerAdminCategory() const; + bool canRemoveServerDirectory(const std::string&); + private: std::vector<ServerCommandPtr> checkConsistencyNoSync(const Ice::StringSeq&); - bool canRemoveServerDirectory(const std::string&); void patch(const IcePatch2::FileServerPrx&, const std::string&, const std::vector<std::string>&); std::set<ServerIPtr> getApplicationServers(const std::string&) const; @@ -135,6 +136,7 @@ private: PropertyDescriptorSeq _propertiesOverride; unsigned long _serial; + bool _consistencyCheckDone; IceUtil::Mutex _observerMutex; std::map<NodeSessionPrx, NodeObserverPrx> _observers; diff --git a/cpp/src/IceGrid/RegistryI.cpp b/cpp/src/IceGrid/RegistryI.cpp index 07c8daa7b30..bd0d94b508e 100644 --- a/cpp/src/IceGrid/RegistryI.cpp +++ b/cpp/src/IceGrid/RegistryI.cpp @@ -148,9 +148,10 @@ private: } -RegistryI::RegistryI(const CommunicatorPtr& communicator, const TraceLevelsPtr& traceLevels) : +RegistryI::RegistryI(const CommunicatorPtr& communicator, const TraceLevelsPtr& traceLevels, bool nowarn) : _communicator(communicator), _traceLevels(traceLevels), + _nowarn(nowarn), _platform("IceGrid.Registry", communicator, traceLevels) { } @@ -160,7 +161,7 @@ RegistryI::~RegistryI() } bool -RegistryI::start(bool nowarn) +RegistryI::start() { assert(_communicator); PropertiesPtr properties = _communicator->getProperties(); @@ -214,7 +215,7 @@ RegistryI::start(bool nowarn) if(!properties->getProperty("IceGrid.Registry.SessionManager.Endpoints").empty()) { - if(!nowarn) + if(!_nowarn) { Warning out(_communicator->getLogger()); out << "session manager endpoints `IceGrid.Registry.SessionManager.Endpoints' enabled"; @@ -227,7 +228,7 @@ RegistryI::start(bool nowarn) if(!properties->getProperty("IceGrid.Registry.AdminSessionManager.Endpoints").empty()) { - if(!nowarn) + if(!_nowarn) { Warning out(_communicator->getLogger()); out << "administrative session manager endpoints `IceGrid.Registry.AdminSessionManager.Endpoints' enabled"; @@ -340,10 +341,10 @@ RegistryI::start(bool nowarn) _wellKnownObjects = new WellKnownObjectsManager(_database); // - // Get the saved replica/node proxies and remove them from the database. + // Get the saved replica/node proxies. // - Ice::ObjectProxySeq proxies; - Ice::ObjectProxySeq::const_iterator p; + ObjectProxySeq proxies; + ObjectProxySeq::const_iterator p; NodePrxSeq nodes; proxies = _database->getInternalObjectsByType(Node::ice_staticId()); @@ -361,9 +362,9 @@ RegistryI::start(bool nowarn) // // NOTE: The internal registry object must be added only once the - // node/replica proxies are retrieved and removed from the - // database. Otherwise, if some replica/node register as soon as - // the internal registry is setup we might clear valid proxies. + // node/replica proxies are retrieved. Otherwise, if some + // replica/node register as soon as the internal registry is setup + // we might clear valid proxies. // InternalRegistryPrx internalRegistry = setupInternalRegistry(registryAdapter); if(_master) @@ -378,8 +379,7 @@ RegistryI::start(bool nowarn) registerNodes(internalRegistry, _session.getNodes(nodes)); } - Ice::ObjectAdapterPtr serverAdapter = - _communicator->createObjectAdapter("IceGrid.Registry.Server"); + ObjectAdapterPtr serverAdapter = _communicator->createObjectAdapter("IceGrid.Registry.Server"); _clientAdapter = _communicator->createObjectAdapter("IceGrid.Registry.Client"); Ice::Identity dummy; @@ -413,9 +413,10 @@ RegistryI::start(bool nowarn) // accessed by the connection that created the session. The session servant manager // also takes care of providing the router servant for server admin objects. // - Ice::ObjectPtr serverAdminRouter = new RegistryServerAdminRouter(_database); + ObjectPtr serverAdminRouter = new RegistryServerAdminRouter(_database); - _servantManager = new SessionServantManager(_clientAdapter, _instanceName, true, getServerAdminCategory(), serverAdminRouter, adminCallbackRouter); + _servantManager = new SessionServantManager(_clientAdapter, _instanceName, true, getServerAdminCategory(), + serverAdminRouter, adminCallbackRouter); _clientAdapter->addServantLocator(_servantManager, ""); @@ -425,8 +426,8 @@ RegistryI::start(bool nowarn) _adminCallbackRouterAdapter->addServantLocator(new DefaultServantLocator(adminCallbackRouter), ""); } - Ice::ObjectAdapterPtr sessionAdpt = setupClientSessionFactory(registryAdapter, internalLocator, nowarn); - Ice::ObjectAdapterPtr admSessionAdpt = setupAdminSessionFactory(registryAdapter, serverAdminRouter, internalLocator, nowarn); + ObjectAdapterPtr sessionAdpt = setupClientSessionFactory(registryAdapter, internalLocator); + ObjectAdapterPtr admSessionAdpt = setupAdminSessionFactory(registryAdapter, serverAdminRouter, internalLocator); _wellKnownObjects->finish(); if(_master) @@ -581,9 +582,7 @@ RegistryI::setupUserAccountMapper(const Ice::ObjectAdapterPtr& registryAdapter) } Ice::ObjectAdapterPtr -RegistryI::setupClientSessionFactory(const Ice::ObjectAdapterPtr& registryAdapter, - const IceGrid::LocatorPrx& locator, - bool nowarn) +RegistryI::setupClientSessionFactory(const Ice::ObjectAdapterPtr& registryAdapter, const IceGrid::LocatorPrx& locator) { Ice::PropertiesPtr properties = _communicator->getProperties(); @@ -626,12 +625,9 @@ RegistryI::setupClientSessionFactory(const Ice::ObjectAdapterPtr& registryAdapte _clientVerifier = getPermissionsVerifier(registryAdapter, locator, "IceGrid.Registry.PermissionsVerifier", - properties->getProperty("IceGrid.Registry.CryptPasswords"), - nowarn); + properties->getProperty("IceGrid.Registry.CryptPasswords")); - _sslClientVerifier = getSSLPermissionsVerifier(locator, - "IceGrid.Registry.SSLPermissionsVerifier", - nowarn); + _sslClientVerifier = getSSLPermissionsVerifier(locator, "IceGrid.Registry.SSLPermissionsVerifier"); return adapter; } @@ -639,8 +635,7 @@ RegistryI::setupClientSessionFactory(const Ice::ObjectAdapterPtr& registryAdapte Ice::ObjectAdapterPtr RegistryI::setupAdminSessionFactory(const Ice::ObjectAdapterPtr& registryAdapter, const Ice::ObjectPtr& router, - const IceGrid::LocatorPrx& locator, - bool nowarn) + const IceGrid::LocatorPrx& locator) { Ice::PropertiesPtr properties = _communicator->getProperties(); @@ -687,12 +682,9 @@ RegistryI::setupAdminSessionFactory(const Ice::ObjectAdapterPtr& registryAdapter _adminVerifier = getPermissionsVerifier(registryAdapter, locator, "IceGrid.Registry.AdminPermissionsVerifier", - properties->getProperty("IceGrid.Registry.AdminCryptPasswords"), - nowarn); + properties->getProperty("IceGrid.Registry.AdminCryptPasswords")); - _sslAdminVerifier = getSSLPermissionsVerifier(locator, - "IceGrid.Registry.AdminSSLPermissionsVerifier", - nowarn); + _sslAdminVerifier = getSSLPermissionsVerifier(locator, "IceGrid.Registry.AdminSSLPermissionsVerifier"); return adapter; } @@ -1035,8 +1027,7 @@ Glacier2::PermissionsVerifierPrx RegistryI::getPermissionsVerifier(const ObjectAdapterPtr& adapter, const IceGrid::LocatorPrx& locator, const string& verifierProperty, - const string& passwordsProperty, - bool nowarn) + const string& passwordsProperty) { // // Get the permissions verifier, or create a default one if no @@ -1149,7 +1140,7 @@ RegistryI::getPermissionsVerifier(const ObjectAdapterPtr& adapter, } catch(const LocalException& ex) { - if(!nowarn) + if(!_nowarn) { Warning out(_communicator->getLogger()); out << "couldn't contact permissions verifier `" + verifierProperty + "':\n" << ex; @@ -1160,7 +1151,7 @@ RegistryI::getPermissionsVerifier(const ObjectAdapterPtr& adapter, } Glacier2::SSLPermissionsVerifierPrx -RegistryI::getSSLPermissionsVerifier(const IceGrid::LocatorPrx& locator, const string& verifierProperty, bool nowarn) +RegistryI::getSSLPermissionsVerifier(const IceGrid::LocatorPrx& locator, const string& verifierProperty) { // // Get the permissions verifier, or create a default one if no @@ -1233,7 +1224,7 @@ RegistryI::getSSLPermissionsVerifier(const IceGrid::LocatorPrx& locator, const s } catch(const LocalException& ex) { - if(!nowarn) + if(!_nowarn) { Warning out(_communicator->getLogger()); out << "couldn't contact ssl permissions verifier `" + verifierProperty + "':\n" << ex; diff --git a/cpp/src/IceGrid/RegistryI.h b/cpp/src/IceGrid/RegistryI.h index bc3e9ece731..060dd405103 100644 --- a/cpp/src/IceGrid/RegistryI.h +++ b/cpp/src/IceGrid/RegistryI.h @@ -48,10 +48,10 @@ class RegistryI : public Registry { public: - RegistryI(const Ice::CommunicatorPtr&, const TraceLevelsPtr&); + RegistryI(const Ice::CommunicatorPtr&, const TraceLevelsPtr&, bool); ~RegistryI(); - bool start(bool); + bool start(); void stop(); virtual SessionPrx createSession(const std::string&, const std::string&, const Ice::Current&); @@ -82,15 +82,15 @@ private: InternalRegistryPrx setupInternalRegistry(const Ice::ObjectAdapterPtr&); void setupNullPermissionsVerifier(const Ice::ObjectAdapterPtr&); bool setupUserAccountMapper(const Ice::ObjectAdapterPtr&); - Ice::ObjectAdapterPtr setupClientSessionFactory(const Ice::ObjectAdapterPtr&, const LocatorPrx&, bool); + Ice::ObjectAdapterPtr setupClientSessionFactory(const Ice::ObjectAdapterPtr&, const LocatorPrx&); Ice::ObjectAdapterPtr setupAdminSessionFactory(const Ice::ObjectAdapterPtr&, const Ice::ObjectPtr&, - const LocatorPrx&, bool); + const LocatorPrx&); void setupThreadPool(const Ice::PropertiesPtr&, const std::string&, int, int = 0); Glacier2::PermissionsVerifierPrx getPermissionsVerifier(const Ice::ObjectAdapterPtr&, const LocatorPrx&, - const std::string&, const std::string&, bool); + const std::string&, const std::string&); - Glacier2::SSLPermissionsVerifierPrx getSSLPermissionsVerifier(const LocatorPrx&, const std::string&, bool); + Glacier2::SSLPermissionsVerifierPrx getSSLPermissionsVerifier(const LocatorPrx&, const std::string&); Glacier2::SSLInfo getSSLInfo(const Ice::ConnectionPtr&, std::string&); NodePrxSeq registerReplicas(const InternalRegistryPrx&, const InternalRegistryPrxSeq&, const NodePrxSeq&); @@ -98,6 +98,7 @@ private: const Ice::CommunicatorPtr _communicator; const TraceLevelsPtr _traceLevels; + const bool _nowarn; DatabasePtr _database; Ice::ObjectAdapterPtr _clientAdapter; diff --git a/cpp/src/IceGrid/ServerI.cpp b/cpp/src/IceGrid/ServerI.cpp index e78ccf2f86c..f0a6772379d 100644 --- a/cpp/src/IceGrid/ServerI.cpp +++ b/cpp/src/IceGrid/ServerI.cpp @@ -425,9 +425,10 @@ LoadCommand::finished(const ServerPrx& proxy, const AdapterPrxDict& adapters, in } } -DestroyCommand::DestroyCommand(const ServerIPtr& server, bool loadFailure) : +DestroyCommand::DestroyCommand(const ServerIPtr& server, bool loadFailure, bool clearDir) : ServerCommand(server), - _loadFailure(loadFailure) + _loadFailure(loadFailure), + _clearDir(clearDir) { } @@ -470,6 +471,12 @@ DestroyCommand::loadFailure() const return _loadFailure; } +bool +DestroyCommand::clearDir() const +{ + return _clearDir; +} + PatchCommand::PatchCommand(const ServerIPtr& server) : ServerCommand(server), _notified(false), @@ -1082,7 +1089,11 @@ ServerI::destroy(const AMD_Node_destroyServerPtr& amdCB, const string& uuid, int } if(!_destroy) { - _destroy = new DestroyCommand(this); + // + // If uuid is empty, the destroy call comes from the the consistency check. In + // this case, we clear the server directory only if it contains non-user data. + // + _destroy = new DestroyCommand(this, false, !uuid.empty()); } if(amdCB) { @@ -1529,17 +1540,25 @@ ServerI::destroy() } _node->removeServer(this, _desc->application); - - try - { - IcePatch2::removeRecursive(_serverDir); - } - catch(const string& msg) + + // + // Remove the server directory only if the clear dir flag is set (user + // explicitly destroyed the server) or if the server directory doesn't + // contain user data). + // + if(_destroy->clearDir() || _node->canRemoveServerDirectory(_id)) { - if(!_destroy->loadFailure()) + try { - Ice::Warning out(_node->getTraceLevels()->logger); - out << "removing server directory `" << _serverDir << "' failed:\n" << msg; + IcePatch2::removeRecursive(_serverDir); + } + catch(const string& msg) + { + if(!_destroy->loadFailure()) + { + Ice::Warning out(_node->getTraceLevels()->logger); + out << "removing server directory `" << _serverDir << "' failed:\n" << msg; + } } } @@ -1752,7 +1771,7 @@ ServerI::update() } else if(!_destroy) { - _destroy = new DestroyCommand(this, true); + _destroy = new DestroyCommand(this, true, true); } _load->failed(ex); diff --git a/cpp/src/IceGrid/ServerI.h b/cpp/src/IceGrid/ServerI.h index be6200d6e1e..3cd6441447e 100644 --- a/cpp/src/IceGrid/ServerI.h +++ b/cpp/src/IceGrid/ServerI.h @@ -213,7 +213,7 @@ class DestroyCommand : public ServerCommand { public: - DestroyCommand(const ServerIPtr&, bool = false); + DestroyCommand(const ServerIPtr&, bool, bool); bool canExecute(ServerI::InternalServerState); ServerI::InternalServerState nextState(); @@ -222,10 +222,12 @@ public: void addCallback(const AMD_Node_destroyServerPtr&); void finished(); bool loadFailure() const; + bool clearDir() const; private: const bool _loadFailure; + const bool _clearDir; std::vector<AMD_Node_destroyServerPtr> _destroyCB; }; |