MCPcopy Create free account
hub / github.com/Niko1221/Strata / open

Method open

engine/src/ngram/ple_reader.cpp:347–390  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

345}
346
347bool PleReader::open(const std::string& path, uint64_t table_offset, uint64_t n_rows, uint32_t max_inflight,
348 uint64_t cache_rows, std::string& err, bool io_thread, uint32_t row_bytes) {
349 close();
350 if (max_inflight == 0 || max_inflight > 1024) { err = "PleReader: max_inflight must be 1..1024"; return false; }
351 if (row_bytes == 0 || row_bytes > PAGE) { err = "PleReader: row_bytes must be 1..4096"; return false; }
352 if (!impl_->file.open(path, err)) return false;
353 impl_->row_bytes = row_bytes;
354 if (table_offset + n_rows * (uint64_t) row_bytes > impl_->file.size()) {
355 err = "PleReader: the table extends past the end of " + path;
356 close();
357 return false;
358 }
359 impl_->table_offset = table_offset;
360 impl_->n_rows = n_rows;
361 impl_->max_inflight = max_inflight;
362 impl_->slab = (uint8_t*) DirectFile::alloc_aligned((size_t) max_inflight * 2 * PAGE);
363 if (impl_->slab == nullptr) { err = "PleReader: cannot allocate read buffers"; close(); return false; }
364 impl_->inflight.assign(max_inflight, Job{});
365 impl_->free_slots.clear();
366 for (uint32_t s = max_inflight; s-- > 0;) impl_->free_slots.push_back(s);
367 impl_->cache.init(cache_rows, row_bytes);
368 impl_->error.clear();
369 impl_->keep_us = 0;
370 impl_->last_issue_us = impl_->last_read_us = 0;
371 impl_->rng = 0x9E3779B97F4A7C15ull ^ (uint64_t) now_us();
372 if (impl_->rng == 0) impl_->rng = 1;
373 reset_stats();
374 impl_->stop = false;
375 impl_->threaded = io_thread;
376 if (io_thread) {
377 try {
378 impl_->worker = std::thread([this] { strata::aux_cpus::pin_current_thread(); impl_->worker_loop(); });
379 } catch (const std::exception& e) {
380 err = std::string("PleReader: cannot create I/O worker: ") + e.what();
381 close();
382 return false;
383 } catch (...) {
384 err = "PleReader: cannot create I/O worker";
385 close();
386 return false;
387 }
388 }
389 return true;
390}
391
392void PleReader::close() {
393 Impl& m = *impl_;

Callers 12

format_round_tripFunction · 0.45
bad_sizes_are_refusedFunction · 0.45
selftestFunction · 0.45
realFunction · 0.45
mainFunction · 0.45
run_configFunction · 0.45
error_does_not_hangFunction · 0.45
big_offsetsFunction · 0.45
mainFunction · 0.45

Calls 10

assignMethod · 0.80
push_backMethod · 0.80
closeFunction · 0.50
now_usFunction · 0.50
pin_current_threadFunction · 0.50
stringFunction · 0.50
sizeMethod · 0.45
clearMethod · 0.45
initMethod · 0.45
worker_loopMethod · 0.45

Tested by 12

format_round_tripFunction · 0.36
bad_sizes_are_refusedFunction · 0.36
selftestFunction · 0.36
realFunction · 0.36
mainFunction · 0.36
run_configFunction · 0.36
error_does_not_hangFunction · 0.36
big_offsetsFunction · 0.36
mainFunction · 0.36