implements #947, free osrm-datastore's shared memory

This commit is contained in:
Dennis Luxen 2014-05-27 18:14:43 +02:00
parent 38ebdbb563
commit 3d691a3aec
2 changed files with 52 additions and 4 deletions

View File

@ -43,12 +43,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string> #include <string>
// generate boost::program_options object for the routing part // generate boost::program_options object for the routing part
inline bool GenerateDataStoreOptions(const int argc, const char *argv[], ServerPaths &paths) inline bool GenerateDataStoreOptions(const int argc, const char *argv[], ServerPaths &paths, bool & springclean)
{ {
// declare a group of options that will be allowed only on command line // declare a group of options that will be allowed only on command line
boost::program_options::options_description generic_options("Options"); boost::program_options::options_description generic_options("Options");
generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")( generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")
"config,c", ("springclean,s", "Remove all regions in shared memory")("config,c",
boost::program_options::value<boost::filesystem::path>(&paths["config"]) boost::program_options::value<boost::filesystem::path>(&paths["config"])
->default_value("server.ini"), ->default_value("server.ini"),
"Path to a configuration file"); "Path to a configuration file");
@ -122,6 +122,11 @@ inline bool GenerateDataStoreOptions(const int argc, const char *argv[], ServerP
return false; return false;
} }
if (option_variables.count("springclean"))
{
springclean = true;
return true;
}
boost::program_options::notify(option_variables); boost::program_options::notify(option_variables);
const bool parameter_present = (paths.find("hsgrdata") != paths.end() && const bool parameter_present = (paths.find("hsgrdata") != paths.end() &&

View File

@ -89,10 +89,53 @@ int main(const int argc, const char *argv[])
SimpleLogger().Write(logDEBUG) << "Checking input parameters"; SimpleLogger().Write(logDEBUG) << "Checking input parameters";
ServerPaths server_paths; ServerPaths server_paths;
if (!GenerateDataStoreOptions(argc, argv, server_paths)) bool springclean = false;
if (!GenerateDataStoreOptions(argc, argv, server_paths, springclean))
{ {
return 0; return 0;
} }
if (springclean)
{
SimpleLogger().Write() << "spring-cleaning all shared memory regions";
// find all existing shmem regions and remove them.
if (SharedMemory::RegionExists(DATA_1))
{
if (!SharedMemory::Remove(DATA_1))
{
SimpleLogger().Write(logWARNING) << "could not delete DATA_1";
}
}
if (SharedMemory::RegionExists(LAYOUT_1))
{
if (!SharedMemory::Remove(LAYOUT_1))
{
SimpleLogger().Write(logWARNING) << "could not delete LAYOUT_1";
}
}
if (SharedMemory::RegionExists(DATA_2))
{
if (!SharedMemory::Remove(DATA_2))
{
SimpleLogger().Write(logWARNING) << "could not delete DATA_2";
}
}
if (SharedMemory::RegionExists(LAYOUT_2))
{
if (!SharedMemory::Remove(LAYOUT_2))
{
SimpleLogger().Write(logWARNING) << "could not delete LAYOUT_2";
}
}
if (SharedMemory::RegionExists(CURRENT_REGIONS))
{
if (!SharedMemory::Remove(CURRENT_REGIONS))
{
SimpleLogger().Write(logWARNING) << "could not delete CURRENT_REGIONS";
}
}
return 0;
}
if (server_paths.find("hsgrdata") == server_paths.end()) if (server_paths.find("hsgrdata") == server_paths.end())
{ {
throw OSRMException("no hsgr file found"); throw OSRMException("no hsgr file found");