Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions include/engine/data_watchdog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "engine/datafacade_factory.hpp"

#include "storage/shared_datatype.hpp"
#include "storage/shared_memory.hpp"
#include "storage/shared_monitor.hpp"

#include <boost/interprocess/sync/named_upgradable_mutex.hpp>
Expand Down Expand Up @@ -59,8 +58,8 @@ class DataWatchdogImpl<AlgorithmT, datafacade::ContiguousInternalMemoryDataFacad
facade_factory =
DataFacadeFactory<datafacade::ContiguousInternalMemoryDataFacade, AlgorithmT>(
std::make_shared<datafacade::SharedMemoryAllocator>(
std::vector<storage::SharedRegionRegister::ShmKey>{
static_region.shm_key, updatable_region.shm_key}));
std::vector<storage::ProjID>{static_region.proj_id,
updatable_region.proj_id}));
}
}

Expand Down Expand Up @@ -112,18 +111,18 @@ class DataWatchdogImpl<AlgorithmT, datafacade::ContiguousInternalMemoryDataFacad
updatable_region = *updatable_shared_region;
}

util::Log() << "updated facade to regions " << (int)static_region.shm_key << " and "
<< (int)updatable_region.shm_key << " with timestamps "
<< static_region.timestamp << " and " << updatable_region.timestamp;

{
boost::unique_lock<boost::shared_mutex> swap_lock(factory_mutex);
facade_factory =
DataFacadeFactory<datafacade::ContiguousInternalMemoryDataFacade, AlgorithmT>(
std::make_shared<datafacade::SharedMemoryAllocator>(
std::vector<storage::SharedRegionRegister::ShmKey>{
static_region.shm_key, updatable_region.shm_key}));
std::vector<storage::ProjID>{static_region.proj_id,
updatable_region.proj_id}));
}

util::Log() << "updated facade to regions " << (int)static_region.proj_id << " and "
<< (int)updatable_region.proj_id << " with timestamps "
<< static_region.timestamp << " and " << updatable_region.timestamp;
}

util::Log() << "DataWatchdog thread stopped";
Expand Down
3 changes: 1 addition & 2 deletions include/engine/datafacade/shared_memory_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ namespace osrm::engine::datafacade
class SharedMemoryAllocator final : public ContiguousBlockAllocator
{
public:
explicit SharedMemoryAllocator(
const std::vector<storage::SharedRegionRegister::ShmKey> &shm_keys);
explicit SharedMemoryAllocator(const std::vector<storage::ProjID> &proj_ids);
~SharedMemoryAllocator() override final;

// interface to give access to the datafacades
Expand Down
29 changes: 14 additions & 15 deletions include/storage/shared_datatype.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
#define SHARED_DATA_TYPE_HPP

#include "storage/block.hpp"
#include "storage/io_fwd.hpp"

#include "util/exception.hpp"
#include "util/exception_utils.hpp"

#include <array>
#include <cstdint>
#include <map>
#include <numeric>
#include <unordered_set>

namespace osrm::storage
Expand Down Expand Up @@ -67,10 +64,7 @@ class BaseDataLayout
return GetBlock(name).byte_size;
}

inline bool HasBlock(const std::string &name) const
{
return blocks.find(name) != blocks.end();
}
inline bool HasBlock(const std::string &name) const { return blocks.contains(name); }

// Depending on the name prefix this function either lists all blocks with the same prefix
// or all entries in the sub-directory.
Expand Down Expand Up @@ -192,13 +186,19 @@ class TarDataLayout final : public BaseDataLayout
}
};

// The second parameter passed to ftok(). See: man 3 ftok
// It should actually be an int, but for compatibility with earlier versions of OSRM it
// is an uint16. It should't matter since, according to the man page, only the lowest 8
// bits are used.
using ProjID = uint16_t;

struct SharedRegion
{
static constexpr const int MAX_NAME_LENGTH = 254;

SharedRegion() : name{0}, timestamp{0} {}
SharedRegion(const std::string &name_, std::uint64_t timestamp, std::uint16_t shm_key)
: name{0}, timestamp{timestamp}, shm_key{shm_key}
SharedRegion(const std::string &name_, std::uint64_t timestamp, ProjID proj_id)
: name{0}, timestamp{timestamp}, proj_id{proj_id}
{
std::copy_n(name_.begin(), std::min<std::size_t>(MAX_NAME_LENGTH, name_.size()), name);
}
Expand All @@ -207,7 +207,7 @@ struct SharedRegion

char name[MAX_NAME_LENGTH + 1];
std::uint64_t timestamp;
std::uint16_t shm_key = 0;
ProjID proj_id = 0;
};

// Keeps a list of all shared regions in a fixed-sized struct
Expand All @@ -216,7 +216,6 @@ struct SharedRegionRegister
{
using RegionID = std::uint16_t;
static constexpr const RegionID INVALID_REGION_ID = std::numeric_limits<RegionID>::max();
using ShmKey = decltype(SharedRegion::shm_key);

// Returns the key of the region with the given name
RegionID Find(const std::string &name) const
Expand All @@ -238,7 +237,7 @@ struct SharedRegionRegister
}
}

RegionID Register(const std::string &name, ShmKey key)
RegionID Register(const std::string &name, ProjID proj_id)
{
auto iter = std::find_if(
regions.begin(), regions.end(), [&](const auto &region) { return region.IsEmpty(); });
Expand All @@ -250,7 +249,7 @@ struct SharedRegionRegister
else
{
constexpr std::uint32_t INITIAL_TIMESTAMP = 1;
*iter = SharedRegion{name, INITIAL_TIMESTAMP, key};
*iter = SharedRegion{name, INITIAL_TIMESTAMP, proj_id};
RegionID key = std::distance(regions.begin(), iter);
return key;
}
Expand All @@ -271,7 +270,7 @@ struct SharedRegionRegister

auto &GetRegion(const RegionID key) { return regions[key]; }

ShmKey ReserveKey()
ProjID ReserveKey()
{
auto free_key_iter = std::find(shm_key_in_use.begin(), shm_key_in_use.end(), false);
if (free_key_iter == shm_key_in_use.end())
Expand All @@ -283,7 +282,7 @@ struct SharedRegionRegister
return std::distance(shm_key_in_use.begin(), free_key_iter);
}

void ReleaseKey(ShmKey key) { shm_key_in_use[key] = false; }
void ReleaseKey(ProjID proj_id) { shm_key_in_use[proj_id] = false; }

static constexpr const std::size_t MAX_SHARED_REGIONS = 512;
static_assert(MAX_SHARED_REGIONS < std::numeric_limits<RegionID>::max(),
Expand Down
Loading
Loading