Move IPC tools functionality into osrm-datastore
This commit is contained in:
parent
fbc7189cf8
commit
a48cf58468
@ -637,17 +637,8 @@ if(BUILD_TOOLS)
|
||||
message(STATUS "Activating OSRM internal tools")
|
||||
add_executable(osrm-io-benchmark src/tools/io-benchmark.cpp $<TARGET_OBJECTS:UTIL>)
|
||||
target_link_libraries(osrm-io-benchmark ${BOOST_BASE_LIBRARIES})
|
||||
add_executable(osrm-unlock-all src/tools/unlock_all_mutexes.cpp $<TARGET_OBJECTS:UTIL>)
|
||||
target_link_libraries(osrm-unlock-all ${BOOST_BASE_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
|
||||
if(UNIX AND NOT APPLE)
|
||||
target_link_libraries(osrm-unlock-all rt)
|
||||
endif()
|
||||
add_executable(osrm-springclean src/tools/springclean.cpp $<TARGET_OBJECTS:UTIL>)
|
||||
target_link_libraries(osrm-springclean ${BOOST_BASE_LIBRARIES})
|
||||
|
||||
install(TARGETS osrm-io-benchmark DESTINATION bin)
|
||||
install(TARGETS osrm-unlock-all DESTINATION bin)
|
||||
install(TARGETS osrm-springclean DESTINATION bin)
|
||||
endif()
|
||||
|
||||
if (ENABLE_ASSERTIONS)
|
||||
|
@ -1,67 +0,0 @@
|
||||
#include <cstdio>
|
||||
|
||||
#include "storage/shared_datatype.hpp"
|
||||
#include "storage/shared_memory.hpp"
|
||||
#include "util/log.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace tools
|
||||
{
|
||||
|
||||
// FIXME remove after folding back into datastore
|
||||
using namespace storage;
|
||||
|
||||
void deleteRegion(const SharedDataType region)
|
||||
{
|
||||
if (SharedMemory::RegionExists(region) && !SharedMemory::Remove(region))
|
||||
{
|
||||
const std::string name = [&] {
|
||||
switch (region)
|
||||
{
|
||||
case CURRENT_REGION:
|
||||
return "CURRENT_REGIONS";
|
||||
case REGION_1:
|
||||
return "REGION_1";
|
||||
case REGION_2:
|
||||
return "REGION_2";
|
||||
default: // REGION_NONE:
|
||||
return "REGION_NONE";
|
||||
}
|
||||
}();
|
||||
|
||||
util::Log(logWARNING) << "could not delete shared memory region " << name;
|
||||
}
|
||||
}
|
||||
|
||||
// find all existing shmem regions and remove them.
|
||||
void springclean()
|
||||
{
|
||||
util::Log() << "spring-cleaning all shared memory regions";
|
||||
deleteRegion(REGION_1);
|
||||
deleteRegion(REGION_2);
|
||||
deleteRegion(CURRENT_REGION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
osrm::util::LogPolicy::GetInstance().Unmute();
|
||||
osrm::util::Log() << "Releasing all locks";
|
||||
osrm::util::Log() << "ATTENTION! BE CAREFUL!";
|
||||
osrm::util::Log() << "----------------------";
|
||||
osrm::util::Log() << "This tool may put osrm-routed into an undefined state!";
|
||||
osrm::util::Log() << "Type 'Y' to acknowledge that you know what your are doing.";
|
||||
osrm::util::Log() << "\n\nDo you want to purge all shared memory allocated "
|
||||
<< "by osrm-datastore? [type 'Y' to confirm]";
|
||||
|
||||
const auto letter = getchar();
|
||||
if (letter != 'Y')
|
||||
{
|
||||
osrm::util::Log() << "aborted.";
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
osrm::tools::springclean();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
#include "storage/shared_barriers.hpp"
|
||||
#include "storage/shared_memory.hpp"
|
||||
#include "storage/storage.hpp"
|
||||
#include "util/exception.hpp"
|
||||
#include "util/log.hpp"
|
||||
@ -13,6 +14,41 @@
|
||||
|
||||
using namespace osrm;
|
||||
|
||||
void removeLocks() { osrm::storage::SharedBarriers::remove(); }
|
||||
|
||||
void deleteRegion(const storage::SharedDataType region)
|
||||
{
|
||||
if (storage::SharedMemory::RegionExists(region) && !storage::SharedMemory::Remove(region))
|
||||
{
|
||||
util::Log(logWARNING) << "could not delete shared memory region "
|
||||
<< storage::regionToString(region);
|
||||
}
|
||||
}
|
||||
|
||||
void springClean()
|
||||
{
|
||||
osrm::util::Log() << "Releasing all locks";
|
||||
osrm::util::Log() << "ATTENTION! BE CAREFUL!";
|
||||
osrm::util::Log() << "----------------------";
|
||||
osrm::util::Log() << "This tool may put osrm-routed into an undefined state!";
|
||||
osrm::util::Log() << "Type 'Y' to acknowledge that you know what your are doing.";
|
||||
osrm::util::Log() << "\n\nDo you want to purge all shared memory allocated "
|
||||
<< "by osrm-datastore? [type 'Y' to confirm]";
|
||||
|
||||
const auto letter = getchar();
|
||||
if (letter != 'Y')
|
||||
{
|
||||
osrm::util::Log() << "aborted.";
|
||||
}
|
||||
else
|
||||
{
|
||||
deleteRegion(storage::REGION_1);
|
||||
deleteRegion(storage::REGION_2);
|
||||
deleteRegion(storage::CURRENT_REGION);
|
||||
removeLocks();
|
||||
}
|
||||
}
|
||||
|
||||
// generate boost::program_options object for the routing part
|
||||
bool generateDataStoreOptions(const int argc,
|
||||
const char *argv[],
|
||||
@ -22,7 +58,8 @@ bool generateDataStoreOptions(const int argc,
|
||||
// declare a group of options that will be allowed only on command line
|
||||
boost::program_options::options_description generic_options("Options");
|
||||
generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")(
|
||||
"remove-locks,r", "Remove locks");
|
||||
"remove-locks,r", "Remove locks")("spring-clean,s",
|
||||
"Spring-cleaning all shared memory regions");
|
||||
|
||||
// declare a group of options that will be allowed both on command line
|
||||
// as well as in a config file
|
||||
@ -89,7 +126,13 @@ bool generateDataStoreOptions(const int argc,
|
||||
|
||||
if (option_variables.count("remove-locks"))
|
||||
{
|
||||
osrm::storage::SharedBarriers::remove();
|
||||
removeLocks();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (option_variables.count("spring-clean"))
|
||||
{
|
||||
springClean();
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -100,7 +143,7 @@ bool generateDataStoreOptions(const int argc,
|
||||
|
||||
[[noreturn]] void CleanupSharedBarriers(int signum)
|
||||
{ // Here the lock state of named mutexes is unknown, make a hard cleanup
|
||||
osrm::storage::SharedBarriers::remove();
|
||||
removeLocks();
|
||||
std::_Exit(128 + signum);
|
||||
}
|
||||
|
||||
|
@ -1,14 +0,0 @@
|
||||
#include "storage/shared_barriers.hpp"
|
||||
#include "util/log.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
osrm::util::LogPolicy::GetInstance().Unmute();
|
||||
osrm::util::Log() << "Releasing all locks";
|
||||
|
||||
osrm::storage::SharedBarriers::remove();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user