Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loader: handle file access errors on windows #248

Merged
merged 3 commits into from
May 24, 2022
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
4 changes: 2 additions & 2 deletions .pkg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[cista]
[email protected]:felixguendling/cista.git
branch=master
commit=9d5efe87ac5ee8215e26900cdcc5a13ce3381f0b
commit=3e6c6cec9593ae253a258a13c915677c19cab29e
[conf]
[email protected]:motis-project/conf.git
branch=master
Expand Down Expand Up @@ -77,7 +77,7 @@
[utl]
[email protected]:motis-project/utl.git
branch=master
commit=6d7c7fd4e6167a1232bb5f7affcda9003e657ecf
commit=67524961674da10379ad82be71f29a0a003dd209
[guess]
[email protected]:motis-project/guess.git
branch=master
Expand Down
6 changes: 3 additions & 3 deletions .pkg.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
13018458183320054341
cista 9d5efe87ac5ee8215e26900cdcc5a13ce3381f0b
8480001355610021823
cista 3e6c6cec9593ae253a258a13c915677c19cab29e
zlib 1e1dfdedddb54a2e2cb8fec3b67f925233c495aa
boost c90d53bdcd7ff741a416ae122b33c9c2a96e8be7
cereal 5afa46f98d1c22627777c3f9d048fffe3f9763dc
Expand All @@ -10,7 +10,7 @@ libosmium e35f4f63facbc87a0a5bf388bce19e6c4ed1dca7
protozero 8c9f3fa97c2cfdceef86d0b61818ae98e9328f29
Catch2 e5c9a58d66ff0780e956b5447573af9d6b9b2ca3
fmt c68ab4be8f3cb0e5c6eb181b3f419622e15e02bd
utl 6d7c7fd4e6167a1232bb5f7affcda9003e657ecf
utl 67524961674da10379ad82be71f29a0a003dd209
address-typeahead 9b33a191c05ee3f489492ea9a89253eaa26b91d4
conf 71febe940c0715ea69aa0c9980e08d31c5c946b8
context 797dd16e2b5e959997ddcd5bdeac4f80931169b6
Expand Down
38 changes: 35 additions & 3 deletions base/loader/src/loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include <variant>
#include <vector>

#ifdef _WIN32
#include <windows.h>
#endif

#include "cista/serialization.h"
#include "cista/targets/file.h"

Expand Down Expand Up @@ -46,9 +50,9 @@ std::vector<std::unique_ptr<format_parser>> parsers() {

using dataset_mem_t = std::variant<cista::mmap, typed_flatbuffer<Schedule>>;

schedule_ptr load_schedule(loader_options const& opt,
cista::memory_holder& schedule_buf,
std::string const& data_dir) {
schedule_ptr load_schedule_impl(loader_options const& opt,
cista::memory_holder& schedule_buf,
std::string const& data_dir) {
ml::scoped_timer time("loading schedule");

// ensure there is an active progress tracker (e.g. for test cases)
Expand Down Expand Up @@ -160,6 +164,34 @@ schedule_ptr load_schedule(loader_options const& opt,
return sched;
}

#ifdef _WIN32
bool load_schedule_checked(loader_options const& opt,
cista::memory_holder& schedule_buf,
std::string const& data_dir, schedule_ptr& ptr) {
__try {
[&]() { ptr = load_schedule_impl(opt, schedule_buf, data_dir); }();
return true;
} __except (GetExceptionCode() == EXCEPTION_IN_PAGE_ERROR
? EXCEPTION_EXECUTE_HANDLER
: EXCEPTION_CONTINUE_SEARCH) {
return false;
}
}
#endif

schedule_ptr load_schedule(loader_options const& opt,
cista::memory_holder& schedule_buf,
std::string const& data_dir) {
#ifdef _WIN32
auto ptr = schedule_ptr{};
utl::verify(load_schedule_checked(opt, schedule_buf, data_dir, ptr),
"load_schedule: file access error: EXCEPTION_IN_PAGE_ERROR");
return ptr;
#else
return load_schedule_impl(opt, schedule_buf, data_dir);
#endif
}

schedule_ptr load_schedule(loader_options const& opt) {
utl::verify(!opt.read_graph_, "load_schedule: read_graph requires buffer");
cista::memory_holder buf{};
Expand Down
6 changes: 4 additions & 2 deletions base/loader/src/timezone_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ timezone_name_idx tz_cache::lookup_name(std::string_view timezone_name) {
} else {
prev_name_ = timezone_name;
return prev_name_idx_ =
utl::get_or_create(timezone_name_idx_, timezone_name,
[&]() { return timezone_name_idx_.size(); });
utl::get_or_create(timezone_name_idx_, timezone_name, [&]() {
return static_cast<timezone_name_idx>(
timezone_name_idx_.size());
});
}
}

Expand Down
6 changes: 4 additions & 2 deletions libs/path/src/path_database_query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ void path_database_query::resolve_sequences_and_build_subqueries(

for (auto j = 0ULL; j < segment->hints_rle()->Get(i + 1); ++j) {
auto feature_id = segment->features()->Get(k);
auto const abs_feature_id =
static_cast<uint64_t>(std::abs(feature_id));
auto* resolvable =
utl::get_or_create(subquery.map_, std::abs(feature_id), [&] {
utl::get_or_create(subquery.map_, abs_feature_id, [&] {
auto r = std::make_unique<resolvable_feature>();
r->feature_id_ = std::abs(feature_id);
r->feature_id_ = abs_feature_id;
return subquery.mem_.emplace_back(std::move(r)).get();
});

Expand Down