Add support for naming the dataset

This commit is contained in:
Patrick Niklaus
2018-04-04 12:51:46 +00:00
committed by Patrick Niklaus
parent 666ce46d36
commit 2c80f76004
11 changed files with 82 additions and 20 deletions
+6 -4
View File
@@ -36,17 +36,18 @@ class DataWatchdogImpl<AlgorithmT, datafacade::ContiguousInternalMemoryDataFacad
using Facade = datafacade::ContiguousInternalMemoryDataFacade<AlgorithmT>;
public:
DataWatchdogImpl() : active(true)
DataWatchdogImpl(const std::string &dataset_name) : dataset_name(dataset_name), active(true)
{
// create the initial facade before launching the watchdog thread
{
boost::interprocess::scoped_lock<mutex_type> current_region_lock(barrier.get_mutex());
auto& shared_register = barrier.data();
auto region_id = shared_register.Find("data");
auto &shared_register = barrier.data();
auto region_id = shared_register.Find(dataset_name + "/data");
if (region_id == storage::SharedRegionRegister::INVALID_REGION_ID)
{
throw util::exception("Could not find shared memory region. Did you run osrm-datastore?");
throw util::exception(
"Could not find shared memory region. Did you run osrm-datastore?");
}
shared_region = &shared_register.GetRegion(region_id);
region = *shared_region;
@@ -101,6 +102,7 @@ class DataWatchdogImpl<AlgorithmT, datafacade::ContiguousInternalMemoryDataFacad
util::Log() << "DataWatchdog thread stopped";
}
const std::string dataset_name;
storage::SharedMonitor<storage::SharedRegionRegister> barrier;
std::thread watcher;
bool active;
+2
View File
@@ -83,6 +83,8 @@ class WatchingProvider : public DataFacadeProvider<AlgorithmT, FacadeT>
public:
using Facade = typename DataFacadeProvider<AlgorithmT, FacadeT>::Facade;
WatchingProvider(const std::string &dataset_name) : watchdog(dataset_name) {}
std::shared_ptr<const Facade> Get(const api::TileParameters &params) const override final
{
return watchdog.Get(params);
+1 -1
View File
@@ -61,7 +61,7 @@ template <typename Algorithm> class Engine final : public EngineInterface
{
util::Log(logDEBUG) << "Using shared memory with algorithm "
<< routing_algorithms::name<Algorithm>();
facade_provider = std::make_unique<WatchingProvider<Algorithm>>();
facade_provider = std::make_unique<WatchingProvider<Algorithm>>(config.dataset_name);
}
else if (!config.memory_file.empty())
{
+1
View File
@@ -91,6 +91,7 @@ struct EngineConfig final
boost::filesystem::path memory_file;
Algorithm algorithm = Algorithm::CH;
std::string verbosity;
std::string dataset_name;
};
}
}
+12
View File
@@ -221,6 +221,18 @@ struct SharedRegionRegister
}
}
template<typename OutIter>
void List(OutIter out) const
{
for (const auto& region : regions)
{
if (!region.IsEmpty())
{
*out++ = region.name;
}
}
}
void Deregister(const RegionID key) { regions[key] = SharedRegion{}; }
const auto &GetRegion(const RegionID key) const { return regions[key]; }
+4 -3
View File
@@ -126,7 +126,6 @@ template <typename Data> struct SharedMonitor
bi::interprocess_condition condition;
};
#else
// Implement a conditional variable using a queue of semaphores.
// OSX checks the virtual address of a mutex in pthread_cond_wait and fails with EINVAL
@@ -207,8 +206,10 @@ template <typename Data> struct SharedMonitor
static_assert(buffer_size >= 2, "buffer size is too small");
#endif
static constexpr int rounded_internal_size = ((sizeof(InternalData) + alignof(Data) - 1) / alignof(Data)) * alignof(Data);
static_assert(rounded_internal_size < sizeof(InternalData) + sizeof(Data), "Data and internal data need to fit into shared memory");
static constexpr int rounded_internal_size =
((sizeof(InternalData) + alignof(Data) - 1) / alignof(Data)) * alignof(Data);
static_assert(rounded_internal_size < sizeof(InternalData) + sizeof(Data),
"Data and internal data need to fit into shared memory");
InternalData &internal() const
{
+1 -1
View File
@@ -44,7 +44,7 @@ class Storage
public:
Storage(StorageConfig config);
int Run(int max_wait);
int Run(int max_wait, const std::string &name);
void PopulateLayout(DataLayout &layout);
void PopulateData(const DataLayout &layout, char *memory_ptr);