Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- FIXED: Update Node.js binding path from `lib/binding` to `lib/binding_napi_v8` to match node-pre-gyp versioning conventions [#7272](https://github.com/Project-OSRM/osrm-backend/pull/7272)
- FIXED: Reduce MSVC compiler warnings by suppressing informational warnings while preserving bug-indicating warnings [#7253](https://github.com/Project-OSRM/osrm-backend/issues/7253)
- Misc:
- ADDED: `SHM_LOCK_DIR` environment variable for shared memory lock file directory [#7312](https://github.com/Project-OSRM/osrm-backend/pull/7312)
- FIXED: Fix JSON rendering of large OSM IDs (avoids scientific notation) and handle NaN/Infinity gracefully [#7016](https://github.com/Project-OSRM/osrm-backend/issues/7016)
- CHANGED: Add std::format compatibility layer with fallback to fmt::format [#7261](https://github.com/Project-OSRM/osrm-backend/pull/7261)
- FIXED: Update node_osrm to C++20 to fix ABI mismatch with libosrm (was overlooked in #6877) [#7261](https://github.com/Project-OSRM/osrm-backend/pull/7261)
Expand Down
8 changes: 8 additions & 0 deletions docs/routed.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## Environment Variables

### SHM_LOCK_DIR

If the SHM_LOCK_DIR environment variable is set, OSRM will use it as the
directory for shared memory lock files instead of the system temporary directory.
This is useful in containerized environments (Docker/Kubernetes) where the lock
file directory should persist across container restarts when loading from shared
memory.

### SIGNAL_PARENT_WHEN_READY

If the SIGNAL_PARENT_WHEN_READY environment variable is set osrm-routed will
Expand Down
21 changes: 18 additions & 3 deletions include/storage/shared_memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#endif

#include <cstdint>
#include <cstdlib>

#include <algorithm>
#include <filesystem>
Expand All @@ -29,13 +30,27 @@
namespace osrm::storage
{

// Returns directory for OSRM lock files (SHM_LOCK_DIR env var or system temp)
inline std::filesystem::path getLockDir()
{
if (const char *lock_dir = std::getenv("SHM_LOCK_DIR"))
{
std::filesystem::path dir(lock_dir);
if (!std::filesystem::exists(dir))
{
throw util::exception("SHM_LOCK_DIR directory does not exist: " + dir.string() +
SOURCE_REF);
}
return dir;
}
return std::filesystem::temp_directory_path();
}

struct OSRMLockFile
{
template <typename IdentifierT> std::filesystem::path operator()(const IdentifierT &id)
{
std::filesystem::path temp_dir = std::filesystem::temp_directory_path();
std::filesystem::path lock_file = temp_dir / ("osrm-" + std::to_string(id) + ".lock");
return lock_file;
return getLockDir() / ("osrm-" + std::to_string(id) + ".lock");
}
};

Expand Down
3 changes: 1 addition & 2 deletions src/storage/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ int Storage::Run(int max_wait, const std::string &dataset_name, bool only_metric

util::LogPolicy::GetInstance().Unmute();

std::filesystem::path lock_path =
std::filesystem::temp_directory_path() / "osrm-datastore.lock";
std::filesystem::path lock_path = getLockDir() / "osrm-datastore.lock";
if (!std::filesystem::exists(lock_path))
{
std::ofstream ofs(lock_path);
Expand Down
Loading