-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.cc
32 lines (27 loc) · 951 Bytes
/
common.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "common.hh"
#include <seastar/core/coroutine.hh>
#include <seastar/core/file.hh>
#include <seastar/core/seastar.hh>
seastar::logger logger("external-sort");
record_generator get_record_iterator(
seastar::coroutine::experimental::buffer_size_t max_buffer_size,
seastar::file &f, uint64_t start_offset, uint64_t end_offset) {
if (end_offset <= 0) {
// read the file until end
end_offset = co_await f.size();
}
while (start_offset < end_offset) {
try {
co_yield co_await f.dma_read<char>(start_offset, record_size);
start_offset += record_size;
} catch (const std::bad_alloc &e) {
// no more memory in this shard to load records
break;
} catch (...) {
logger.error(
"get_record_iterator generator failed with exception {}",
std::current_exception());
break;
}
}
}