From 23668b14830611cd3ac037f323b0e60a67a8dc3d Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 28 Nov 2020 18:17:23 +0100 Subject: [PATCH] =?utf8?q?Honor=20the=20=E2=80=9Crequire=20visibility?= =?utf8?q?=E2=80=9D=20flag=20(in=20the=20negative).?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- access_rx_cache.cpp | 5 +++++ access_rx_cache.h | 5 +++-- db.h | 3 +++ plocate.cpp | 8 ++++++-- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/access_rx_cache.cpp b/access_rx_cache.cpp index c6f5634..a16a1fc 100644 --- a/access_rx_cache.cpp +++ b/access_rx_cache.cpp @@ -11,6 +11,11 @@ using namespace std; void AccessRXCache::check_access(const char *filename, bool allow_async, function cb) { + if (!require_visibility) { + cb(true); + return; + } + lock_guard lock(mu); if (engine == nullptr || !engine->get_supports_stat()) { allow_async = false; diff --git a/access_rx_cache.h b/access_rx_cache.h index 8757b94..80383ea 100644 --- a/access_rx_cache.h +++ b/access_rx_cache.h @@ -12,8 +12,8 @@ class IOUringEngine; class AccessRXCache { public: - AccessRXCache(IOUringEngine *engine) - : engine(engine) {} + AccessRXCache(IOUringEngine *engine, bool require_visibility) + : engine(engine), require_visibility(require_visibility) {} void check_access(const char *filename, bool allow_async, std::function cb); private: @@ -25,6 +25,7 @@ private: std::map> pending_stats; IOUringEngine *engine; std::mutex mu; + bool require_visibility; }; #endif // !defined(_ACCESS_RX_CACHE_H) diff --git a/db.h b/db.h index e23d478..722e567 100644 --- a/db.h +++ b/db.h @@ -24,6 +24,9 @@ struct Header { uint64_t next_zstd_dictionary_offset_bytes; uint64_t conf_block_length_bytes; uint64_t conf_block_offset_bytes; + + // Only if max_version >= 2. + bool require_visibility; }; struct Trigram { diff --git a/plocate.cpp b/plocate.cpp index 6fe46a4..4f88b4b 100644 --- a/plocate.cpp +++ b/plocate.cpp @@ -105,6 +105,10 @@ Corpus::Corpus(int fd, IOUringEngine *engine) hdr.zstd_dictionary_offset_bytes = 0; hdr.zstd_dictionary_length_bytes = 0; } + if (hdr.max_version < 2) { + // This too. (We ignore the other max_version 2 fields.) + hdr.require_visibility = true; + } } Corpus::~Corpus() @@ -230,7 +234,7 @@ void scan_file_block(const vector &needles, string_view compressed, size_t scan_docids(const vector &needles, const vector &docids, const Corpus &corpus, IOUringEngine *engine) { Serializer docids_in_order; - AccessRXCache access_rx_cache(engine); + AccessRXCache access_rx_cache(engine, corpus.get_hdr().require_visibility); atomic matched{ 0 }; for (size_t i = 0; i < docids.size(); ++i) { uint32_t docid = docids[i]; @@ -306,7 +310,7 @@ uint64_t scan_all_docids(const vector &needles, int fd, const Corpus &co } } - AccessRXCache access_rx_cache(nullptr); + AccessRXCache access_rx_cache(nullptr, corpus.get_hdr().require_visibility); Serializer serializer; uint32_t num_blocks = corpus.get_num_filename_blocks(); unique_ptr offsets(new uint64_t[num_blocks + 1]); -- 2.39.2