Add support for naming the dataset
This commit is contained in:
committed by
Patrick Niklaus
parent
666ce46d36
commit
2c80f76004
@@ -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;
|
||||
|
||||
@@ -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 ¶ms) const override final
|
||||
{
|
||||
return watchdog.Get(params);
|
||||
|
||||
@@ -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())
|
||||
{
|
||||
|
||||
@@ -91,6 +91,7 @@ struct EngineConfig final
|
||||
boost::filesystem::path memory_file;
|
||||
Algorithm algorithm = Algorithm::CH;
|
||||
std::string verbosity;
|
||||
std::string dataset_name;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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]; }
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user